Skip to content

Commit 4728af6

Browse files
committed
Add import context menu, allows importing anywhere
Importer to context menu with e2e test
1 parent 4165667 commit 4728af6

File tree

18 files changed

+278
-194
lines changed

18 files changed

+278
-194
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This changelog covers all three packages, as they are (for now) updated as a who
1212
- Add new file preview types to the folder grid view.
1313
- Fix Dialogue form #308
1414
- Refactor search, escape query strings for Tantivy
15+
- Add `import` context menu, allows importing anywhere
1516

1617
### @tomic/react
1718

@@ -25,6 +26,7 @@ This changelog covers all three packages, as they are (for now) updated as a who
2526
- Add `store.preloadClassesAndProperties` and remove `urls.properties.getAll` and `urls.classes.getAll`. This enables using `atomic-data-browser` without relying on `atomicdata.dev` being available.
2627
- Fix Race condition of `store.getResourceAsync` #309
2728
- Add `buildSearchSubject` in `search.ts` which allows you to build full text search queries to send to Atomic-Server.
29+
- Add `importJSONADString` function, allowing you to import resources from external sources.
2830

2931
## v0.35.0
3032

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ export function useDefaultNewInstanceHandler(klass: string, parent?: string) {
5656
break;
5757
}
5858

59-
case classes.importer: {
60-
createResourceAndNavigate('importer', {
61-
[properties.isA]: [classes.importer],
62-
});
63-
break;
64-
}
65-
6659
case classes.drive: {
6760
const agent = store.getAgent();
6861

data-browser/src/components/ResourceContextMenu/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
constructOpenURL,
88
versionsURL,
99
shareURL,
10+
importerURL,
1011
} from '../../helpers/navigation';
1112
import { DIVIDER, DropdownMenu, isItem, Item } from '../Dropdown';
1213
import toast from 'react-hot-toast';
@@ -16,6 +17,7 @@ import { DropdownTriggerRenderFunction } from '../Dropdown/DropdownTrigger';
1617
import { buildDefaultTrigger } from '../Dropdown/DefaultTrigger';
1718
import {
1819
FaClock,
20+
FaDownload,
1921
FaEdit,
2022
FaEllipsisV,
2123
FaRedo,
@@ -144,6 +146,13 @@ function ResourceContextMenu({
144146
helper: 'Show the versions of this resource',
145147
onClick: () => navigate(versionsURL(subject, store.getServerUrl())),
146148
},
149+
{
150+
id: 'import',
151+
icon: <FaDownload />,
152+
label: 'import',
153+
helper: 'Import Atomic Data to this resource',
154+
onClick: () => navigate(importerURL(subject)),
155+
},
147156
];
148157

149158
const filteredItems = hide

data-browser/src/components/forms/Field.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function Field({
7474
);
7575
}
7676

77-
const FieldLabel = styled.label`
77+
export const FieldLabel = styled.label`
7878
text-transform: capitalize;
7979
display: inline-flex;
8080
gap: 0.2rem;

data-browser/src/components/forms/InputStyles.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export const InputStyled = styled.input`
8181

8282
export const TextAreaStyled = styled.textarea`
8383
${inputStyle}
84+
min-height: 5rem;
85+
height: unset;
8486
`;
8587

8688
export const ErrMessage = styled.div`

data-browser/src/helpers/navigation.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ export function pathToURL(path: string): string {
9797
return window.location.origin + path;
9898
}
9999

100+
export function importerURL(subject: string): string {
101+
return constructURL(paths.import, { subject });
102+
}
103+
100104
/**
101105
* Constructs the URL for the `all-versions` endpoint. Assumes the current URL
102106
* supports that endpoint

data-browser/src/routes/NewRoute.tsx

Lines changed: 60 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,32 @@ import { getIconForClass } from '../views/FolderPage/iconMap';
2121
import { NewFormFullPage } from '../components/forms/NewForm/NewFormPage';
2222

2323
/** Start page for instantiating a new Resource from some Class */
24-
function New(): JSX.Element {
24+
function NewRoute(): JSX.Element {
2525
const [classSubject] = useQueryString('classSubject');
26+
27+
return (
28+
<ContainerNarrow>
29+
{classSubject ? (
30+
<NewFormFullPage classSubject={classSubject.toString()} />
31+
) : (
32+
<NewResourceSelector />
33+
)}
34+
</ContainerNarrow>
35+
);
36+
}
37+
38+
function NewResourceSelector() {
2639
const [parentSubject] = useQueryString('parentSubject');
27-
// For selecting a class
40+
const { drive } = useSettings();
41+
const calculatedParent = parentSubject || drive;
42+
const parentResource = useResource(calculatedParent);
43+
const [error, setError] = useState<Error | undefined>(undefined);
2844
const [classInputValue, setClassInputValue] = useState<string | undefined>(
2945
undefined,
3046
);
31-
const [error, setError] = useState<Error | undefined>(undefined);
32-
const navigate = useNavigate();
3347
const classFull = useResource(classInputValue);
3448
const [className] = useString(classFull, urls.properties.shortname);
35-
const { drive } = useSettings();
36-
37-
const calculatedParent = parentSubject || drive;
38-
const parentResource = useResource(calculatedParent);
49+
const navigate = useNavigate();
3950

4051
const buttons = [
4152
urls.classes.folder,
@@ -44,7 +55,6 @@ function New(): JSX.Element {
4455
urls.classes.bookmark,
4556
urls.classes.class,
4657
urls.classes.property,
47-
urls.classes.importer,
4858
];
4959

5060
function handleClassSet(e) {
@@ -70,52 +80,46 @@ function New(): JSX.Element {
7080
);
7181

7282
return (
73-
<ContainerNarrow>
74-
{classSubject ? (
75-
<NewFormFullPage classSubject={classSubject.toString()} />
76-
) : (
77-
<StyledForm onSubmit={handleClassSet}>
78-
<h1>
79-
Create new resource{' '}
80-
{parentSubject && (
81-
<>
82-
{`under `}
83-
<ResourceInline subject={parentSubject} />
84-
</>
85-
)}
86-
</h1>
87-
<div>
88-
<ResourceSelector
89-
setSubject={setClassInputValue}
90-
value={classInputValue}
91-
error={error}
92-
setError={setError}
93-
classType={urls.classes.class}
94-
/>
95-
</div>
96-
<Row wrapItems>
97-
{classInputValue && (
98-
<Button onClick={handleClassSet}>new {className}</Button>
99-
)}
100-
{!classInputValue && (
101-
<>
102-
{buttons.map(classType => (
103-
<WrappedButton
104-
key={classType}
105-
classType={classType}
106-
parent={calculatedParent}
107-
/>
108-
))}
109-
</>
110-
)}
111-
</Row>
112-
<FileDropzoneInput
113-
parentResource={parentResource}
114-
onFilesUploaded={onUploadComplete}
115-
/>
116-
</StyledForm>
117-
)}
118-
</ContainerNarrow>
83+
<StyledForm onSubmit={handleClassSet}>
84+
<h1>
85+
Create new resource{' '}
86+
{parentSubject && (
87+
<>
88+
{`under `}
89+
<ResourceInline subject={parentSubject} />
90+
</>
91+
)}
92+
</h1>
93+
<div>
94+
<ResourceSelector
95+
setSubject={setClassInputValue}
96+
value={classInputValue}
97+
error={error}
98+
setError={setError}
99+
classType={urls.classes.class}
100+
/>
101+
</div>
102+
<Row wrapItems>
103+
{classInputValue && (
104+
<Button onClick={handleClassSet}>new {className}</Button>
105+
)}
106+
{!classInputValue && (
107+
<>
108+
{buttons.map(classType => (
109+
<WrappedButton
110+
key={classType}
111+
classType={classType}
112+
parent={calculatedParent}
113+
/>
114+
))}
115+
</>
116+
)}
117+
</Row>
118+
<FileDropzoneInput
119+
parentResource={parentResource}
120+
onFilesUploaded={onUploadComplete}
121+
/>
122+
</StyledForm>
119123
);
120124
}
121125

@@ -125,7 +129,7 @@ const StyledForm = styled.form`
125129
gap: ${({ theme }) => theme.margin}rem;
126130
`;
127131

128-
export default New;
132+
export default NewRoute;
129133

130134
interface WrappedButtonProps {
131135
classType: string;

data-browser/src/routes/Routes.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Route, Routes } from 'react-router-dom';
44

55
import Show from './ShowRoute';
66
import { Search } from './SearchRoute';
7-
import New from './NewRoute';
7+
import NewRoute from './NewRoute';
88
import { SettingsTheme } from './SettingsTheme';
99
import { Edit } from './EditRoute';
1010
import Data from './DataRoute';
@@ -17,6 +17,7 @@ import { paths } from './paths';
1717
import ResourcePage from '../views/ResourcePage';
1818
import { ShareRoute } from './ShareRoute';
1919
import { Sandbox } from './Sandbox';
20+
import { ImporterPage } from '../views/ImporterPage';
2021

2122
const homeURL = window.location.origin;
2223

@@ -31,13 +32,14 @@ const isDev = import.meta.env.MODE === 'development';
3132
export function AppRoutes(): JSX.Element {
3233
return (
3334
<Routes>
34-
<Route path={paths.new} element={<New />} />
35+
<Route path={paths.new} element={<NewRoute />} />
3536
<Route path={paths.themeSettings} element={<SettingsTheme />} />
3637
<Route path={paths.agentSettings} element={<SettingsAgent />} />
3738
<Route path={paths.serverSettings} element={<SettingsServer />} />
3839
<Route path={paths.shortcuts} element={<Shortcuts />} />
3940
<Route path={paths.data} element={<Data />} />
4041
<Route path={paths.edit} element={<Edit />} />
42+
<Route path={paths.import} element={<ImporterPage />} />
4143
<Route path={paths.share} element={<ShareRoute />} />
4244
<Route path={paths.show} element={<Show />} />
4345
<Route path={paths.about} element={<About />} />

data-browser/src/routes/paths.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const paths = {
1010
data: '/app/data',
1111
edit: '/app/edit',
1212
about: '/app/about',
13+
import: '/app/import',
1314
allVersions: '/all-versions',
1415
sandbox: '/sandbox',
1516
fetchBookmark: '/fetch-bookmark',

0 commit comments

Comments
 (0)