Skip to content

Commit d2b4f13

Browse files
committed
Add children in data view
1 parent 942d005 commit d2b4f13

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This changelog covers all three packages, as they are (for now) updated as a whole
44

5-
## UNRELEASED
5+
## v0.35.0
66

77
### @tomic/browser
88

@@ -28,7 +28,7 @@ This changelog covers all three packages, as they are (for now) updated as a who
2828
- Add `buildSearchSubject` in `search.ts` which allows you to build full text search queries to send to Atomic-Server.
2929
- Add `importJSONADString` function, allowing you to import resources from external sources.
3030

31-
## v0.35.0
31+
## v0.35.0-beta.1
3232

3333
### @tomic/react
3434

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { useChildren } from '@tomic/react';
2+
import React from 'react';
3+
import { FaCaretDown, FaCaretRight } from 'react-icons/fa';
4+
import { ResourceInline } from '../views/ResourceInline';
5+
import { Button } from './Button';
6+
import { Card, CardInsideFull, CardRow } from './Card';
7+
8+
export function Childrenlist({ resource }) {
9+
const [show, setShow] = React.useState(false);
10+
11+
return (
12+
<>
13+
<Button onClick={() => setShow(!show)}>
14+
{show ? <FaCaretDown /> : <FaCaretRight />}
15+
{' children'}
16+
</Button>
17+
{show && <ChildrenList resource={resource} />}
18+
</>
19+
);
20+
}
21+
22+
function ChildrenList({ resource }) {
23+
const children = useChildren(resource);
24+
25+
return (
26+
<Card>
27+
<CardInsideFull>
28+
{children.map(s => (
29+
<CardRow key={s}>
30+
<ResourceInline subject={s} />
31+
</CardRow>
32+
))}
33+
</CardInsideFull>
34+
</Card>
35+
);
36+
}

data-browser/src/routes/DataRoute.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { CodeBlock } from '../components/CodeBlock';
1818
import { Title } from '../components/Title';
1919
import { Row } from '../components/Row';
2020
import { ErrorLook } from '../components/ErrorLook';
21+
import { Childrenlist as ChildrenCard } from '../components/ChildrenList';
2122

2223
/** Renders the data of some Resource */
2324
function Data(): JSX.Element {
@@ -77,6 +78,7 @@ function Data(): JSX.Element {
7778
<AtomicLink subject={subject}>{subject}</AtomicLink>
7879
</PropValRow>
7980
<AllProps resource={resource} editable columns />
81+
<ChildrenCard resource={resource} />
8082
{resource.getCommitBuilder().hasUnsavedChanges() ? (
8183
<>
8284
<h2>⚠️ contains uncommitted changes</h2>

data-browser/src/views/ImporterPage.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function ImporterPage({ resource }: ImporterPageProps) {
2828
const [overwriteOutside, setOverwriteOutside] = useState(false);
2929
const [parent, setParent] = useCurrentSubject();
3030
const resourceByS = useResource(parent);
31+
const [isImporting, setIsImporting] = useState(false);
3132

3233
resource = resourceByS || resource;
3334

@@ -36,13 +37,16 @@ export function ImporterPage({ resource }: ImporterPageProps) {
3637

3738
const handleImport = useCallback(async () => {
3839
try {
40+
setIsImporting(true);
3941
await importJsonAdString(store, jsonAd, {
4042
overwriteOutside,
4143
parent: parent!,
4244
});
4345
toast.success('Imported!');
46+
setIsImporting(false);
4447
} catch (e) {
4548
toast.error(e.message);
49+
setIsImporting(false);
4650
}
4751
}, [parent, jsonAd, overwriteOutside, store]);
4852

@@ -112,7 +116,7 @@ export function ImporterPage({ resource }: ImporterPageProps) {
112116
disabled={!parent}
113117
onClick={handleImport}
114118
>
115-
Send JSON
119+
{isImporting ? 'Importing...' : 'Send JSON'}
116120
</Button>
117121
)}
118122
</Column>

lib/src/endpoints.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function importJsonAdString(
3737
) {
3838
const url = addParams(store.getServerUrl() + urls.endpoints.import, {
3939
parent: opts.parent,
40+
'overwrite-outside': opts.overwriteOutside ? 'true' : 'false',
4041
});
4142

4243
return resourceToErr(await store.postToServer(url, jsonAdString));

0 commit comments

Comments
 (0)