diff options
author | 2023-08-30 02:12:23 +0200 | |
---|---|---|
committer | 2023-08-30 02:36:21 +0200 | |
commit | 4746d5e671a50fb900ff8c9252c26cca72278dc0 (patch) | |
tree | c8152cbd2435d64f07b0669b16ac11dddc277c9b /subprojects/frontend/src/graph/RelationName.tsx | |
parent | refactor(frontend): containment arrow size (diff) | |
download | refinery-4746d5e671a50fb900ff8c9252c26cca72278dc0.tar.gz refinery-4746d5e671a50fb900ff8c9252c26cca72278dc0.tar.zst refinery-4746d5e671a50fb900ff8c9252c26cca72278dc0.zip |
feat(frontend): projection dialog
Diffstat (limited to 'subprojects/frontend/src/graph/RelationName.tsx')
-rw-r--r-- | subprojects/frontend/src/graph/RelationName.tsx | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/subprojects/frontend/src/graph/RelationName.tsx b/subprojects/frontend/src/graph/RelationName.tsx new file mode 100644 index 00000000..ec26fb21 --- /dev/null +++ b/subprojects/frontend/src/graph/RelationName.tsx | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | |||
7 | import { styled } from '@mui/material/styles'; | ||
8 | import { observer } from 'mobx-react-lite'; | ||
9 | |||
10 | import { RelationMetadata } from '../xtext/xtextServiceResults'; | ||
11 | |||
12 | const Error = styled('span', { | ||
13 | name: 'RelationName-Error', | ||
14 | })(({ theme }) => ({ | ||
15 | color: theme.palette.error.main, | ||
16 | })); | ||
17 | |||
18 | const Qualifier = styled('span', { | ||
19 | name: 'RelationName-Qualifier', | ||
20 | })(({ theme }) => ({ | ||
21 | color: theme.palette.text.secondary, | ||
22 | })); | ||
23 | |||
24 | const FormattedName = observer(function FormattedName({ | ||
25 | name, | ||
26 | metadata, | ||
27 | }: { | ||
28 | name: string; | ||
29 | metadata: RelationMetadata; | ||
30 | }): React.ReactNode { | ||
31 | const { detail } = metadata; | ||
32 | if (detail.type === 'class' && detail.abstractClass) { | ||
33 | return <i>{name}</i>; | ||
34 | } | ||
35 | if (detail.type === 'reference' && detail.containment) { | ||
36 | return <b>{name}</b>; | ||
37 | } | ||
38 | if (detail.type === 'predicate' && detail.error) { | ||
39 | return <Error>{name}</Error>; | ||
40 | } | ||
41 | return name; | ||
42 | }); | ||
43 | |||
44 | function RelationName({ | ||
45 | metadata, | ||
46 | abbreviate, | ||
47 | }: { | ||
48 | metadata: RelationMetadata; | ||
49 | abbreviate?: boolean; | ||
50 | }): JSX.Element { | ||
51 | const { name, simpleName } = metadata; | ||
52 | if (abbreviate ?? RelationName.defaultProps.abbreviate) { | ||
53 | return <FormattedName name={simpleName} metadata={metadata} />; | ||
54 | } | ||
55 | if (name.endsWith(simpleName)) { | ||
56 | return ( | ||
57 | <> | ||
58 | <Qualifier> | ||
59 | {name.substring(0, name.length - simpleName.length)} | ||
60 | </Qualifier> | ||
61 | <FormattedName name={simpleName} metadata={metadata} /> | ||
62 | </> | ||
63 | ); | ||
64 | } | ||
65 | return <FormattedName name={name} metadata={metadata} />; | ||
66 | } | ||
67 | |||
68 | RelationName.defaultProps = { | ||
69 | abbreviate: false, | ||
70 | }; | ||
71 | |||
72 | export default observer(RelationName); | ||