Skip to content

Commit 1da89cc

Browse files
committed
merge newDoc
2 parents 6ef97d9 + a629ade commit 1da89cc

26 files changed

+435
-271
lines changed

packages/tdb-dashboard/src/pages/DocumentEdit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const DocumentEdit = () => {
1515
const [showModal, setShowModal] = useState(false)
1616
const {type, docid} = useParams()
1717
const navigate = useNavigate()
18-
18+
1919
const {
2020
updateDocument,
2121
getSelectedDocument,
@@ -61,7 +61,7 @@ export const DocumentEdit = () => {
6161
type={type}
6262
frames={frames}
6363
closeButtonClick={closeButtonClick}
64-
selectedDocument={selectedDocument}
64+
documentJson={selectedDocument}
6565
/>
6666
}
6767
</React.Fragment>

packages/tdb-dashboard/src/pages/DocumentNew.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {CreateChangeRequestModal} from "../components/CreateChangeRequestModal"
88
import {DocumentSearchComponent} from "../components/DocumentSearchComponent"
99
import '@terminusdb/terminusdb-documents-ui/dist/css/terminusdb__darkly.css'
1010

11+
1112
export const DocumentNew = () => {
1213
const {organization,dataProduct,type} = useParams()
1314
const {setChangeRequestBranch, branch,woqlClient,currentChangeRequest} = WOQLClientObj()
@@ -18,7 +19,8 @@ export const DocumentNew = () => {
1819
error,
1920
setError,
2021
getDocumentFrames,
21-
createDocument
22+
createDocument,
23+
formData
2224
} = useTDBDocuments(woqlClient)
2325
const navigate = useNavigate()
2426

@@ -50,10 +52,10 @@ export const DocumentNew = () => {
5052
{showModal && <CreateChangeRequestModal showModal={showModal} type={type} setShowModal={setShowModal} updateViewMode={setChangeRequestBranch}/>}
5153
{error && <ErrorMessageReport error={error} setError={setError}/>}
5254
{currentChangeRequest && frames &&
53-
<NewDocumentComponent
55+
<NewDocumentComponent
5456
SearchComponent={DocumentSearchComponent}
5557
frames={frames}
56-
formData={{}}
58+
documentJson={formData}
5759
createDocument={callCreateDocument}
5860
type={type}
5961
closeButtonClick={closeButtonClick}

packages/tdb-dashboard/src/pages/DocumentView.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {CreateChangeRequestModal} from '../components/CreateChangeRequestModal'
1010
import {ErrorMessageReport} from "../components/ErrorMessageReport"
1111
import '@terminusdb/terminusdb-documents-ui/dist/css/terminusdb__darkly.css'
1212

13+
1314
export const DocumentView = () => {
1415
const { branch,setChangeRequestBranch,woqlClient,currentChangeRequest} = WOQLClientObj()
1516
const {type, docid} = useParams()
@@ -67,7 +68,7 @@ export const DocumentView = () => {
6768
<ViewDocumentComponent
6869
type={type}
6970
getDocumentById={getDocumentById}
70-
selectedDocument={selectedDocument}
71+
documentJson={selectedDocument}
7172
frames={frames}
7273
closeButtonClick={()=>navigate(-1)}
7374
documentID={documentID}

packages/tdb-documents-ui-template/src/EditDocumentComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const EditDocumentComponent = ({type,updateDocument,documentJson,frames,c
4343
<FrameViewer frame={frames}
4444
type={type}
4545
mode={CONST.EDIT_DOCUMENT}
46-
onSubmit={updateDocument}
46+
onSubmit={updateDocument}
4747
//onChange={handleChange}
4848
language={selectedLanguage}
4949
{...onSelect}

packages/tdb-documents-ui-template/src/NewDocumentComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const NewDocumentComponent = ({type,createDocument,documentJson,frames,cl
3838
<JsonFrameViewer jsonData={{}} mode={CONST.CREATE_DOCUMENT} setExtracted={createDocument}/>
3939
}
4040
{view === CONST.FORM_VIEW &&
41-
<FrameViewer frame={frames}
41+
<FrameViewer frame={frames}
4242
type={type}
4343
formData={documentJson}
4444
mode={CONST.CREATE_DOCUMENT}

packages/tdb-documents-ui-template/src/hook/useTDBDocuments.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export const useTDBDocuments = (woqlClient) => {
2222
// bool|Object
2323
const [frames, setFrames]=useState(false)
2424

25-
25+
// store the state of formData entered by the user
26+
const [formData, setFormData]= useState()
2627

2728
//get all the Document Classes (no abstract or subdocument)
2829
//improve performance with check last commit
@@ -116,6 +117,7 @@ export const useTDBDocuments = (woqlClient) => {
116117
//return the new document id
117118
return res
118119
}catch(err){
120+
setFormData(jsonDocument)
119121
setError(err.data || {message:err.message})
120122
}finally{
121123
setLoading(false)
@@ -177,12 +179,14 @@ export const useTDBDocuments = (woqlClient) => {
177179
return true
178180
}catch(err){
179181
//display conflict
182+
setSelectedDocument(jsonDoc)
180183
setError(err.data || {message:err.message})
181184
}finally{setLoading(false)}
182185
}
183186

184187
return {
185188
setError,
189+
formData,
186190
selectedDocument,
187191
getSelectedDocument,
188192
getDocumentById,

packages/tdb-documents-ui/sandbox/README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ SDK to build UI from terminusdb documents. This package includes a ``<FrameViewe
55
## Installation
66
Install the dependancy from npm
77
```npm install @terminusdb/terminusdb-documents-ui```
8-
8+
99
## Usage
1010
Then import dependancy as shown below
1111
```import {FrameViewer} from '@terminusdb/terminusdb-documents-ui'```
12+
13+
To import css is light or dark mode
14+
15+
```import '@terminusdb/terminusdb-documents-ui/dist/css/terminusdb__darkly.css'``` or
16+
```import '@terminusdb/terminusdb-documents-ui/dist/css/terminusdb__light.css'```
1217

1318
## Run sandbox
1419

@@ -152,18 +157,31 @@ return <FrameViewer
152157
type={"Theme"}/> // type of document to display in form
153158
```
154159
### Theme Selector
155-
FrameViewer is based on [Bootswatch](https://bootswatch.com/cosmo/) Themes. Use props ``theme`` in ``<FrameViewer/>`` component to change themes at an application level.
160+
FrameViewer is based on [Bootswatch](https://bootswatch.com/cosmo/) Themes. Use props ``theme`` in ``<FrameViewer/>`` component to change themes at an application level. Note that if using ``theme`` parameter in FrameViewers the css will change at an application level. If the preference is to just alter the look & feel of the FrameViwer in a project then the ``<FrameViewer/>`` component is shipped with a dark mode and a light mode.
161+
162+
156163
```
157164
import { FrameViewer } from '@terminusdb/terminusdb-documents-ui'
158165
return <FrameViewer
159166
frame={frame} // frames
160-
mode={"View"} // mode in which to display the form
161-
onTraverse={handleTraverse} // Callback traverse links function
167+
mode={"View"} // mode in which to display the form
168+
onTraverse={handleTraverse} // Callback traverse links function
162169
formData={data} // instance data
163170
theme="darkly" // pass a bootswatch theme - like darkly/ pulse
164171
type={"Theme"}/> // type of document to display in form
165172
```
166173

174+
```
175+
import { FrameViewer } from '@terminusdb/terminusdb-documents-ui'
176+
return <FrameViewer
177+
frame={frame} // frames
178+
mode={"View"} // mode in which to display the form
179+
onTraverse={handleTraverse} // Callback traverse links function
180+
formData={data} // instance data
181+
theme="minty" // pass a bootswatch theme - like darkly/ pulse
182+
type={"Theme"}/> // type of document to display in form
183+
```
184+
167185
A Theme selector can also be enabled by passing ``showThemeSelector={true}``
168186
```
169187
import { FrameViewer } from '@terminusdb/terminusdb-documents-ui'
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React, {useState} from "react"
2+
import Stack from 'react-bootstrap/Stack'
3+
import { CREATE, EDIT, VIEW, MODE_HELP_TEXT } from "./constants"
4+
import { FrameObj } from "./frameInit"
5+
import { Card } from "react-bootstrap"
6+
7+
const RadioButtons = ({ mode, handleChange, checked }) => {
8+
return <div>
9+
<label>
10+
<input
11+
type="radio"
12+
name="letter"
13+
data-cy={`${mode}_mode`}
14+
value={mode}
15+
checked={checked === mode}
16+
onChange={handleChange}
17+
/>{" "}
18+
{mode}
19+
</label>
20+
</div>
21+
}
22+
23+
export const ModeBar = () => {
24+
25+
const [checked, setChecked]=useState(CREATE)
26+
const {
27+
mode,
28+
setMode,
29+
setData
30+
} = FrameObj()
31+
32+
function handleChange (event) {
33+
let mode = event.target.value
34+
setChecked(mode)
35+
setMode(mode)
36+
if(mode === CREATE) setData({})
37+
}
38+
39+
return <Card className="mb-3">
40+
<Card.Header>
41+
<div>{`${MODE_HELP_TEXT}. `} </div>
42+
</Card.Header>
43+
<Card.Body>
44+
<Stack direction="horizontal" gap={1} className="mb-2" >
45+
<div className="text-warning">{`${mode}`}</div>
46+
<div className="text-muted">{` mode selected.`} </div>
47+
</Stack>
48+
<Stack direction="horizontal" gap={3}>
49+
<RadioButtons mode={CREATE} handleChange={handleChange} checked={checked} />
50+
<RadioButtons mode={EDIT} handleChange={handleChange} checked={checked}/>
51+
<RadioButtons mode={VIEW} handleChange={handleChange} checked={checked}/>
52+
</Stack>
53+
54+
</Card.Body>
55+
</Card>
56+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Search } from "./SearchComponent"
1111
//import '@terminusdb/terminusdb-documents-ui/dist/css/terminusdb__darkly.css'
1212
//import '@terminusdb/terminusdb-documents-ui/dist/css/terminusdb__light.css'
1313
//import '../../src/css/terminusdb__darkly.css'
14-
//import '../../src/css/terminusdb__light.css'
14+
import '../../src/css/terminusdb__light.css'
1515

1616
export const View = () => {
1717

@@ -41,7 +41,7 @@ export const View = () => {
4141
formData={getFormData(mode, type, setData)}
4242
onTraverse={handleTraverse}
4343
onSelect={<Search/>}
44-
theme="darkly"
44+
//theme="minty"
4545
//showThemeSelector={true}
4646
onSubmit={handleSubmit}
4747
type={type}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/** Generates Frame Viewer code with current params
2+
* @param {*} uiFrames - uiFrames to alter look and feel of form
3+
* @param {*} data - instance data to view form in Edit/View Mode
4+
* @param {*} mode - mode in which form is to be displayed - Create, Edit or View
5+
* @param {*} type - type of Document being displayed in form
6+
*/
7+
export const generateFrameViewerCode = function(data, mode, type){
8+
return `
9+
10+
/***
11+
* frames - JSON frames of all document types (mandatory)
12+
* type - document type to be displayed (mandatory)
13+
* data - data to be displayed in form (mandatory for EDIT/ VIEW mode - if nothing to display pass {})
14+
* mode - the mode in which form is to be displayed - Create/ Edit or View
15+
* onTraverse - a js function which gets back the ID of a document on click
16+
*/
17+
export const Form = ({ frames, type, data, mode }) => {
18+
19+
/* Callback submit function which extracts all user input fields */
20+
function handleSubmit(data) {
21+
console.log("Data submitted from form", data)
22+
}
23+
24+
/* filled data */
25+
let fData= ${JSON.stringify(data, null, 4)}
26+
27+
if(!frames) return <>LOADING ... <>
28+
29+
return <FrameViewer
30+
frame={frames} // frames
31+
type={"${type}"} // type of document to display in form
32+
formData={fData} // instance data
33+
mode={"${mode}"} // mode in which to display the form
34+
onSubmit={handleSubmit} // Callback submit function
35+
/>
36+
}
37+
`
38+
}

0 commit comments

Comments
 (0)