Skip to content

Commit a11995f

Browse files
committed
sandbox progress
1 parent e71f941 commit a11995f

File tree

14 files changed

+693
-384
lines changed

14 files changed

+693
-384
lines changed

packages/tdb-dashboard/src/components/DiffView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export const DiffView = ({diffs, CRObject}) => {
258258
<Col/>
259259
<Col>
260260
<Pagination className="justify-content-center ">{paginationItems}</Pagination>
261-
</Col>
261+
</Col>
262262
<Col/>
263263
</Row>
264264
</React.Fragment>
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from "react"
1+
import React, { useState } from "react"
22
import { FrameObj } from "./frameInit"
3-
import Button from 'react-bootstrap/Button';
4-
import ButtonGroup from 'react-bootstrap/ButtonGroup';
3+
import Nav from 'react-bootstrap/Nav';
54

65
export const DocumentTypes = () => {
6+
const [activeKey, setActiveKey] = useState("Theme")
77
const {
88
frames,
99
setType
@@ -12,17 +12,28 @@ export const DocumentTypes = () => {
1212
if(!frames) return <div/>
1313
let docTypes = []
1414

15+
function handleNavClick(selectedKey) {
16+
setActiveKey(selectedKey)
17+
setType(selectedKey)
18+
}
19+
1520
for(let docs in frames) {
1621
// display on classes
1722
if(frames[docs].hasOwnProperty("@type") &&
1823
frames[docs]["@type"] === "Class" &&
1924
!frames[docs].hasOwnProperty("@subdocument")) {
20-
docTypes.push(<Button variant="secondary" key={docs} onClick={(e) => setType(docs)}>{docs}</Button>)
25+
docTypes.push(<Nav.Item>
26+
<Nav.Link eventKey={docs}>{docs}</Nav.Link>
27+
</Nav.Item>)
2128
}
2229
}
2330

24-
return <ButtonGroup aria-label="Basic example" vertical>
31+
return <Nav
32+
activeKey={activeKey}
33+
className="mt-5 mb-3"
34+
onSelect={(selectedKey) => handleNavClick(selectedKey)}
35+
>
2536
{docTypes}
26-
</ButtonGroup>
37+
</Nav>
2738

2839
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { useEffect, useState } from "react"
2+
import Accordion from 'react-bootstrap/Accordion'
3+
import { SubmittedData } from "./SubmittedData"
4+
import { FrameEditor } from "./FrameEditor"
5+
6+
7+
export const Editor = () => {
8+
const [activeKey, setActiveKey]=useState("Frames")
9+
10+
function handleSelect(key) {
11+
setActiveKey(key)
12+
}
13+
14+
return <Accordion onSelect={handleSelect}>
15+
<Accordion.Item eventKey={"Frames"}>
16+
<Accordion.Header>{"Frames"}</Accordion.Header>
17+
<Accordion.Body>
18+
<FrameEditor/>
19+
</Accordion.Body>
20+
</Accordion.Item>
21+
<Accordion.Item eventKey={"Submitted Data"}>
22+
<Accordion.Header>{"Submitted Data"}</Accordion.Header>
23+
<Accordion.Body>
24+
<SubmittedData/>
25+
</Accordion.Body>
26+
</Accordion.Item>
27+
</Accordion>
28+
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from "react"
2+
import { FrameObj } from "./frameInit"
3+
import JSONInput from 'react-json-editor-ajrm'
4+
import locale from 'react-json-editor-ajrm/locale/en'
5+
6+
export const FrameEditor = () => {
7+
const {
8+
frames,
9+
setFrames
10+
} = FrameObj()
11+
12+
if(!frames) return <Loading/>
13+
14+
function handleInput (data) {
15+
setFrames(data.jsObject)
16+
}
17+
if(!frames) return <div/>
18+
//JSON Editor dimensions
19+
return <JSONInput
20+
id='json_type_field'
21+
locale={ locale }
22+
placeholder={frames}
23+
height= {"550px"}
24+
width= {"500px"}
25+
onBlur={handleInput}
26+
/>
27+
28+
}

packages/tdb-documents-ui/sandbox/src/Layout.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import React from 'react'
2-
import { NavBar } from './Nav';
3-
import { Container, Row, Stack } from 'react-bootstrap';
2+
import { Container, Row, Col, Stack } from 'react-bootstrap';
43
import { View } from "./View"
54
import { ModeBar } from "./ModeBar"
65
import { DocumentTypes } from "./DocumentTypes"
6+
import { Editor } from './Editors';
77

88

99
const App= (props) =>{
1010

1111
return <Container>
12-
<NavBar/>
12+
<DocumentTypes/>
1313
<ModeBar/>
14-
<Stack direction='horizontal' gap={3}>
15-
<DocumentTypes/>
16-
<View/>
17-
</Stack>
14+
<Row>
15+
<Col md={5}><Editor/></Col>
16+
<Col md={7}><View/></Col>
17+
</Row>
1818
</Container>
1919

2020
}

packages/tdb-documents-ui/sandbox/src/Nav.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react"
2+
import { FrameObj } from "./frameInit"
3+
import JSONInput from 'react-json-editor-ajrm'
4+
import locale from 'react-json-editor-ajrm/locale/en'
5+
6+
export const SubmittedData = () => {
7+
const {
8+
data
9+
} = FrameObj()
10+
11+
return <JSONInput
12+
id='submitted_data_field'
13+
locale={ locale }
14+
placeholder={data}
15+
viewOnly={true}
16+
height= {"550px"}
17+
width= {"500px"}
18+
/>
19+
}

packages/tdb-documents-ui/sandbox/src/View.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,34 @@ import React from "react"
22
import Card from "react-bootstrap/Card"
33
import { FrameObj } from "./frameInit"
44
import { FrameViewer } from '@terminusdb/terminusdb-documents-ui'
5+
import { getFormData, handleTraverse } from "./controller"
56

67
export const View = () => {
78

89
const {
910
frames,
1011
type,
11-
mode
12+
mode,
13+
setData
1214
} = FrameObj()
1315

16+
function handleSubmit(data) {
17+
setData(data)
18+
}
19+
1420
return <Card className="w-100">
15-
<Card.Header>{`Document Type - ${type}`}</Card.Header>
21+
<Card.Header className="d-flex">
22+
<div> {`Document Type - `}</div>
23+
<div className="text-warning fw-bolder">{type}</div>
24+
</Card.Header>
1625
<Card.Body>
1726
<FrameViewer frame={frames}
1827
mode={mode}
28+
formData={getFormData(mode, type)}
29+
onTraverse={handleTraverse}
30+
//onSelect={handleSelect}
1931
theme="darkly"
32+
onSubmit={handleSubmit}
2033
type={type}
2134
/>
2235
</Card.Body>

packages/tdb-documents-ui/sandbox/src/constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// DATA PRODUCTS
22
export const LEGO = "Lego"
3-
export const STARWARS = "StarWars"
43

54
//modes
65
export const CREATE="Create"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { CREATE } from "./constants"
2+
import * as lego from "./lego.constants"
3+
4+
5+
export function getFormData(mode, type) {
6+
if(mode === CREATE) return {}
7+
8+
if(type === "Color") return lego.COLOR_DATA
9+
else if(type === "Element") return lego.ELEMENT_DATA
10+
else if(type === "Inventory") return lego.INVENTORY_DATA
11+
else if(type === "LegoSet") return lego.LEGO_SET_DATA
12+
else if(type === "Minifig") return lego.MINIFIG_DATA
13+
else if(type === "Part") return lego.PART_DATA
14+
else if(type === "PartRelation") return lego.PART_RELATION_DATA
15+
else if(type === "Theme") return lego.THEME_DATA
16+
}
17+
18+
/**
19+
*
20+
* @param {*} clicked callback function which returns back the ID of element clicked
21+
*/
22+
export function handleTraverse (clicked) {
23+
alert(`You have clicked on document ID ${clicked}`)
24+
}

0 commit comments

Comments
 (0)