Skip to content

Commit 92435c2

Browse files
OJ423gitbook-bot
authored andcommitted
GITBOOK-137: Adding missing UI SDK page
1 parent 4c9385d commit 92435c2

File tree

1 file changed

+316
-0
lines changed
  • document-ui-sdk/use-the-document-ui-sdk/ui-sdk-data-types

1 file changed

+316
-0
lines changed
Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,318 @@
1+
---
2+
description: Understand the different data types to build data driven user interfaces
3+
---
4+
15
# UI SDK Data Types
26

7+
The TerminusDB documents user interface generates forms representing the properties or fields of document/s in your schema. For data entry, each field is one of several data types and is mandatory by default. Schema definitions enable the linking of documents and the specification of sets.
8+
9+
[**Click here to find out how to get started with the Document UI SDK**](../)
10+
11+
### Demo
12+
13+
Take a look at the [**Document UI SDK Playground**](https://documents-ui-playground.terminusdb.com/) to view the `<FrameViewier/>` demo in Create, Edit, or View mode.
14+
15+
### Data types
16+
17+
#### Basic data types
18+
19+
The table below lists the basic data types supported and their specifications.
20+
21+
| **Data type** | **Declaration** | **Example** |
22+
| ------------- | ---------------- | ----------------------------------------------- |
23+
| Boolean | `"xsd:boolean"` | `"active": "xsd:boolean"` |
24+
| Decimal | `"xsd:decimal"` | `"age": "xsd:decimal"` |
25+
| Enum | `"@type: "Enum"` | `"@values": ["red", "blue", "yellow", "green"]` |
26+
| Integer | `"xsd:integer"` | `"age": "xsd:integer"` |
27+
| Decimal | `"xsd:decimal"` | `"age": "xsd:decimal"` |
28+
| String | `"xsd:string"` | `"name": "xsd:string"` |
29+
| Temporal | `"xsd:dateTime"` | `"DOB": "xsd:dateTime"` |
30+
31+
#### Data value optionality
32+
33+
If a property in the Form is displayed with a (Required) tab, that means the property is mandatory & has to be filled in order to submit the form. To define a property as optional, use the `"@type": "Optional"` declaration meaning the property is optional.
34+
35+
A property can also be defined as an array in the following ways -
36+
37+
`"@type": "Set"` - property can hold multiple values in an unordered fashion & can be optional
38+
39+
`"@type": "List"` - property can hold multiple values in an ordered fashion & requires at least one entry
40+
41+
#### An example of all basic types
42+
43+
**Enum**
44+
45+
The `"Enum"` data type in the example below specifies the colors a person likes - `"@id": "Colors`, `"Person"`, `"likes"`. This is rendered as a dropdown menu with the colors specified in the `"@values"` list.
46+
47+
**Optional**
48+
49+
The `"age"` of a `"Person"` is declared `"Optional"`
50+
51+
```javascript
52+
let frames = {
53+
"@context": {
54+
"@base": "terminusdb:///data/",
55+
"@schema": "terminusdb:///schema#",
56+
"@type": "@context"
57+
},
58+
"Person": {
59+
"@key": {
60+
"@type": "Random"
61+
},
62+
"@type": "Class",
63+
"DOB": "xsd:dateTime",
64+
"active": "xsd:boolean",
65+
"age": {
66+
"@class": "xsd:decimal",
67+
"@type": "Optional"
68+
},
69+
"name": "xsd:string",
70+
"likes": {
71+
"@id": "Colors",
72+
"@type": "Enum",
73+
"@values": [
74+
"red",
75+
"blue",
76+
"yellow",
77+
"green"
78+
]
79+
}
80+
}
81+
}
82+
83+
let type = "Person"
84+
let mode = "Create"
85+
86+
return <FrameViewer
87+
frame = {frames}
88+
type = {type}
89+
mode = {mode}/>
90+
```
91+
92+
### Link Properties
93+
94+
Link properties enable links to other document or subdocument classes and are displayed as `Select` components.
95+
96+
#### Link Properties Example
97+
98+
The example below demonstrates:
99+
100+
* The property `work_as` linked to document class `Job`
101+
* The property `lives_in` linked to a subdocument class `Address`
102+
103+
```javascript
104+
let frames = {
105+
"@context": {
106+
"@base": "terminusdb:///data/",
107+
"@schema": "terminusdb:///schema#",
108+
"@type": "@context"
109+
},
110+
"Person": {
111+
"@key": {
112+
"@type": "Random"
113+
},
114+
"@type": "Class",
115+
"works_as": "Job", // Link to subdocument Job
116+
"lives_in": "Address" // Link to subdocument Address
117+
},
118+
"Job": {
119+
"@key": {
120+
"@type": "Random"
121+
},
122+
"@type": "Class",
123+
"title": "xsd:string"
124+
},
125+
"Address": {
126+
"@key": {
127+
"@type": "Random"
128+
},
129+
"@subdocument": [],
130+
"@type": "Class",
131+
"Address Line 1": "xsd:string",
132+
"Code": "xsd:decimal",
133+
"Country": "xsd:string"
134+
}
135+
}
136+
137+
let type = "Person"
138+
let mode = "Create"
139+
140+
return <FrameViewer
141+
frame = {frames}
142+
type = {type}
143+
mode = {mode}/>
144+
```
145+
146+
### Set properties
147+
148+
A set specifies an **unordered set** of values of a class or data type.
149+
150+
#### Set property example
151+
152+
In the example below, the document `Person` consists of several nicknames - property `"nickName"` of `"@type": "Set"`. A set consists of zero, one or multiple items.
153+
154+
```javascript
155+
let frames = {
156+
"@context": {
157+
"@base": "terminusdb:///data/",
158+
"@schema": "terminusdb:///schema#",
159+
"@type": "@context"
160+
},
161+
"Person": {
162+
"@key": {
163+
"@type": "Random"
164+
},
165+
"@type": "Class",
166+
"name": "xsd:string",
167+
"nickName": {
168+
"@class": "xsd:string",
169+
"@type": "Set"
170+
}
171+
}
172+
}
173+
174+
let type = "Person"
175+
let mode = "Create"
176+
177+
return <FrameViewer
178+
frame = {frames}
179+
type = {type}
180+
mode = {mode}/>
181+
```
182+
183+
#### Document Class Set Example
184+
185+
In the example below, a `Person` has a property `works_as` defined as a set that links to the document `Job`, representing a person with multiple jobs.
186+
187+
```javascript
188+
let frames = {
189+
"@context": {
190+
"@base": "terminusdb:///data/",
191+
"@schema": "terminusdb:///schema#",
192+
"@type": "@context"
193+
},
194+
"Person": {
195+
"@key": {
196+
"@type": "Random"
197+
},
198+
"@type": "Class",
199+
"name": "xsd:string",
200+
"works_as": {
201+
"@class": "Job",
202+
"@type": "Set"
203+
}
204+
},
205+
"Job": {
206+
"@key": {
207+
"@type": "Random"
208+
},
209+
"@type": "Class",
210+
"title": "xsd:string"
211+
}
212+
}
213+
214+
let type = "Person"
215+
let mode = "Create"
216+
217+
return <FrameViewer
218+
frame = {frames}
219+
type = {type}
220+
mode = {mode}/>
221+
```
222+
223+
#### Subdocument Class Set Example
224+
225+
In the example below, a `Person` has a property `lived` defined as a set that links to the subdocument `Address`, representing a person's address history.
226+
227+
```javascript
228+
let frames = {
229+
"@context": {
230+
"@base": "terminusdb:///data/",
231+
"@schema": "terminusdb:///schema#",
232+
"@type": "@context"
233+
},
234+
"Person": {
235+
"@key": {
236+
"@type": "Random"
237+
},
238+
"@type": "Class",
239+
"name": "xsd:string",
240+
"lived": {
241+
"@class": {
242+
"@class": "Address",
243+
"@subdocument": []
244+
},
245+
"@type": "Set"
246+
}
247+
},
248+
"Address": {
249+
"@key": {
250+
"@type": "Random"
251+
},
252+
"@subdocument": [],
253+
"@type": "Class",
254+
"Address Line 1": "xsd:string",
255+
"Code": "xsd:decimal",
256+
"Country": "xsd:string"
257+
}
258+
}
259+
260+
let type = "Person"
261+
let mode = "Create"
262+
263+
return <FrameViewer
264+
frame = {frames}
265+
type = {type}
266+
mode = {mode}/>
267+
```
268+
269+
### List Properties
270+
271+
A list specifies an **ordered collection** of values of a class or data type. An ordered collection means values are displayed in the order they are entered in the form.
272+
273+
#### List property example
274+
275+
In the example below, a `Person` has two properties, `ordered_property` (a string data type) and `has_task` (a subdocument of type `"List"`.)
276+
277+
```javascript
278+
let frames = {
279+
"@context": {
280+
"@base": "terminusdb:///data/",
281+
"@schema": "terminusdb:///schema#",
282+
"@type": "@context"
283+
},
284+
"Person": {
285+
"@key": {
286+
"@type": "Random"
287+
},
288+
"@type": "Class",
289+
"ordered_property": {
290+
"@class": "xsd:string",
291+
"@type": "List"
292+
},
293+
"has_task": {
294+
"@class": "Tasks",
295+
"@type": "List"
296+
}
297+
},
298+
"Tasks": {
299+
"@key": {
300+
"@type": "Random"
301+
},
302+
"@subdocument": [],
303+
"@type": "Class",
304+
"Address Line 1": "xsd:string",
305+
"Code": "xsd:decimal",
306+
"Country": "xsd:string"
307+
}
308+
}
309+
310+
let type = "Person"
311+
let mode = "Create"
312+
313+
// call FrameViewer
314+
return <FrameViewer
315+
frame = {frames}
316+
type = {type}
317+
mode = {mode}/>
318+
```

0 commit comments

Comments
 (0)