Skip to content

Commit 22e5399

Browse files
Pollepsjoepio
authored andcommitted
WIP #747 New Resource Refactor
1 parent b69687d commit 22e5399

25 files changed

+818
-512
lines changed

browser/data-browser/src/App.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ if (isDev()) {
6969
}
7070

7171
import isPropValid from '@emotion/is-prop-valid';
72+
import { NewResourceUIProvider } from './components/forms/NewForm/useNewResourceUI';
7273

7374
// This implements the default behavior from styled-components v5
7475
function shouldForwardProp(propName, target) {
@@ -107,10 +108,12 @@ function App(): JSX.Element {
107108
<DialogContainer>
108109
<PopoverContainer>
109110
<DropdownContainer>
110-
<SkipNav />
111-
<NavWrapper>
112-
<AppRoutes />
113-
</NavWrapper>
111+
<NewResourceUIProvider>
112+
<SkipNav />
113+
<NavWrapper>
114+
<AppRoutes />
115+
</NavWrapper>
116+
</NewResourceUIProvider>
114117
</DropdownContainer>
115118
</PopoverContainer>
116119
<NetworkIndicator />

browser/data-browser/src/components/IconButton/IconButton.story.mdx

Lines changed: 0 additions & 55 deletions
This file was deleted.

browser/data-browser/src/components/IconButton/IconButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const IconButtonBase = styled.button<ButtonBaseProps>`
8989
color: ${p => p.theme.colors.text};
9090
font-size: ${p => p.size ?? '1em'};
9191
border: none;
92-
92+
user-select: none;
9393
padding: var(--button-padding);
9494
width: calc(${p => p.size} + var(--button-padding) * 2);
9595
height: calc(${p => p.size} + var(--button-padding) * 2);
@@ -115,7 +115,7 @@ const SimpleIconButton = styled(IconButtonBase)<ButtonStyleProps>`
115115
background-color: ${p => p.theme.colors.bg1};
116116
}
117117
118-
:active {
118+
&:active {
119119
background-color: ${p => p.theme.colors.bg2};
120120
}
121121
}

browser/data-browser/src/components/NewInstanceButton/NewBookmarkButton.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { classes, properties, useResource, useTitle } from '@tomic/react';
1+
import { dataBrowser, properties, useResource, useTitle } from '@tomic/react';
22
import { FormEvent, useCallback, useState } from 'react';
33
import { Button } from '../Button';
44
import {
@@ -38,19 +38,22 @@ export function NewBookmarkButton({
3838

3939
const [dialogProps, show, hide] = useDialog();
4040

41-
const createResourceAndNavigate = useCreateAndNavigate(klass, parent);
41+
const createResourceAndNavigate = useCreateAndNavigate();
4242

4343
const onDone = useCallback(
4444
(e: FormEvent) => {
4545
e.preventDefault();
4646

4747
const normalizedUrl = normalizeWebAddress(url);
4848

49-
createResourceAndNavigate('bookmark', {
50-
[properties.name]: 'New Bookmark',
51-
[properties.bookmark.url]: normalizedUrl,
52-
[properties.isA]: [classes.bookmark],
53-
});
49+
createResourceAndNavigate(
50+
dataBrowser.classes.bookmark,
51+
{
52+
[properties.name]: 'New Bookmark',
53+
[properties.bookmark.url]: normalizedUrl,
54+
},
55+
parent,
56+
);
5457
},
5558
[url],
5659
);
Lines changed: 17 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
1-
import {
2-
Datatype,
3-
classes,
4-
properties,
5-
useResource,
6-
validateDatatype,
7-
} from '@tomic/react';
8-
import { FormEvent, useCallback, useState } from 'react';
9-
import { Button } from '../Button';
10-
import { Dialog, DialogActions, DialogContent, useDialog } from '../Dialog';
11-
import Field from '../forms/Field';
12-
import { InputStyled, InputWrapper } from '../forms/InputStyles';
1+
import { core, useResource } from '@tomic/react';
132
import { Base } from './Base';
14-
import { useCreateAndNavigate } from './useCreateAndNavigate';
153
import { NewInstanceButtonProps } from './NewInstanceButtonProps';
16-
import { stringToSlug } from '../../helpers/stringToSlug';
17-
import { styled } from 'styled-components';
4+
import { useNewResourceUI } from '../forms/NewForm/useNewResourceUI';
5+
import { useSettings } from '../../helpers/AppSettings';
186

197
export function NewOntologyButton({
208
klass,
@@ -26,91 +14,24 @@ export function NewOntologyButton({
2614
label,
2715
}: NewInstanceButtonProps): JSX.Element {
2816
const ontology = useResource(klass);
29-
const [shortname, setShortname] = useState('');
30-
const [valid, setValid] = useState(false);
17+
const { drive } = useSettings();
3118

32-
const createResourceAndNavigate = useCreateAndNavigate(klass, parent);
19+
const showNewResourceUI = useNewResourceUI();
3320

34-
const onSuccess = useCallback(async () => {
35-
createResourceAndNavigate('ontology', {
36-
[properties.shortname]: shortname,
37-
[properties.isA]: [classes.ontology],
38-
[properties.description]: 'description',
39-
[properties.classes]: [],
40-
[properties.properties]: [],
41-
[properties.instances]: [],
42-
});
43-
}, [shortname, createResourceAndNavigate]);
44-
45-
const [dialogProps, show, hide] = useDialog({ onSuccess });
46-
47-
const onShortnameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
48-
const value = stringToSlug(e.target.value);
49-
setShortname(value);
50-
51-
try {
52-
validateDatatype(value, Datatype.SLUG);
53-
setValid(true);
54-
} catch (_) {
55-
setValid(false);
56-
}
21+
const show = () => {
22+
showNewResourceUI(core.classes.ontology, parent ?? drive);
5723
};
5824

5925
return (
60-
<>
61-
<Base
62-
onClick={show}
63-
title={ontology.title}
64-
icon={icon}
65-
IconComponent={IconComponent}
66-
subtle={subtle}
67-
label={label}
68-
>
69-
{children}
70-
</Base>
71-
<Dialog {...dialogProps}>
72-
<H1>New Ontology</H1>
73-
<DialogContent>
74-
<form
75-
onSubmit={(e: FormEvent) => {
76-
e.preventDefault();
77-
hide(true);
78-
}}
79-
>
80-
<Explanation>
81-
An ontology is a collection of classes and properties that
82-
together describe a concept. Great for data models.
83-
</Explanation>
84-
<Field required label='Shortname'>
85-
<InputWrapper>
86-
<InputStyled
87-
placeholder='my-ontology'
88-
value={shortname}
89-
autoFocus={true}
90-
onChange={onShortnameChange}
91-
/>
92-
</InputWrapper>
93-
</Field>
94-
</form>
95-
</DialogContent>
96-
<DialogActions>
97-
<Button onClick={() => hide(false)} subtle>
98-
Cancel
99-
</Button>
100-
<Button onClick={() => hide(true)} disabled={!valid}>
101-
Create
102-
</Button>
103-
</DialogActions>
104-
</Dialog>
105-
</>
26+
<Base
27+
onClick={show}
28+
title={ontology.title}
29+
icon={icon}
30+
IconComponent={IconComponent}
31+
subtle={subtle}
32+
label={label}
33+
>
34+
{children}
35+
</Base>
10636
);
10737
}
108-
109-
const H1 = styled.h1`
110-
margin: 0;
111-
`;
112-
113-
const Explanation = styled.p`
114-
color: ${p => p.theme.colors.textLight};
115-
max-width: 60ch;
116-
`;

0 commit comments

Comments
 (0)