Skip to content

Commit 0bb16ab

Browse files
Merge pull request #261 from terminusdb/doc-ui-fix
making subdoc collapsible only on view mode
2 parents 360ad1c + ac813bb commit 0bb16ab

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

packages/tdb-documents-ui/src/Viewer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const SelectedLanguage = ({ language }) => {
1515
}
1616

1717

18+
1819
export const Viewer = ({ display, message, mode, type, onSubmit, readOnly, data, setData, documentation, language }) => {
1920

2021
return <div className="tdb__frame__viewer ">

packages/tdb-documents-ui/src/components/DescriptionComponent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { AiOutlineLink } from "react-icons/ai"
44

55
// description field for document links
66
// shows to which document a property is linked
7-
export function getLinkedDescription (linked) {
7+
export function getLinkedDescription (linked, type) {
88
return <Stack direction="horizontal" gap={2} className="fw-bold">
99
<AiOutlineLink className="text-warning h6 mt-1"/>
1010
<small className="fst-italic text-muted">
11-
{`Linked to document: `}
11+
{`Linked to ${type ? type : "document"}: `}
1212
<span className="text-warning fw-bold">{linked}</span>
1313
</small>
1414
</Stack>

packages/tdb-documents-ui/src/widgets/subDocumentWidget.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { DisplayDocumentation } from "../templates"
1010
import { AiOutlineUp, AiOutlineRight } from "react-icons/ai"
1111
import { displayInternalProperties } from "../helpers/documentHelpers"
1212
import { HiddenSubDocumentWidgets } from "./hiddenWidgets"
13+
import { getLinkedDescription } from "../components/DescriptionComponent"
1314

1415
const CollapseMessage = ({ message, name, icon }) => {
1516
return <>
@@ -115,7 +116,7 @@ function getExpanded(expanded, linked_to, frame) {
115116
}
116117

117118
export const TDBSubDocument = ({ extracted, expanded, order_by, comment, props, index, hideFieldLabel, linked_to, propertyDocumentation, id, label, reference, subDocumentData, setSubDocumentData, args }) => {
118-
const [open, setOpen] = useState(args.mode === CONST.VIEW ? getExpanded(expanded, linked_to, args.fullFrame) : expanded);
119+
const [open, setOpen] = useState(args.mode === CONST.VIEW ? getExpanded(expanded, linked_to, args.fullFrame) : true);
119120
//const [open, setOpen] = useState(true);
120121
let uiFrame = args.uiFrame, mode = args.mode
121122

@@ -145,7 +146,7 @@ export const TDBSubDocument = ({ extracted, expanded, order_by, comment, props,
145146
className="tdb__label__width"
146147
hideFieldLabel={hideFieldLabel}/>
147148
<Card bg="secondary" className={`tdb__subdocument__input ${util.getBorder(uiFrame, props.name, index)} w-100`} key={id}>
148-
<Button variant={"secondary"}
149+
{mode === CONST.VIEW && <><Button variant={"secondary"}
149150
className={`text-start p-4`}
150151
data-testid={`root_subdocument_${props.name}_button`}
151152
name={`root_subdocument_${props.name}_button`}
@@ -154,8 +155,8 @@ export const TDBSubDocument = ({ extracted, expanded, order_by, comment, props,
154155
aria-expanded={open}
155156
>
156157
{/*<TDBLabel name={props.name} required={props.required} comment={comment}/>*/}
157-
{!open && <CollapseMessage message={`Click here to expand SubDocument`} name={props.name} icon={<AiOutlineRight className="text-muted"/>}/>}
158-
{open && <CollapseMessage message={`Click here to collapse SubDocument`} name={props.name} icon={<AiOutlineUp className="text-muted"/>}/>}
158+
{!open && <CollapseMessage message={`Click here to expand SubDocument`} name={linked_to} icon={<AiOutlineRight className="text-muted"/>}/>}
159+
{open && <CollapseMessage message={`Click here to collapse SubDocument`} name={linked_to} icon={<AiOutlineUp className="text-muted"/>}/>}
159160
</Button>
160161
<Collapse in={open}>
161162
<div id={`root_subdocument_${props.name}`}>
@@ -176,7 +177,30 @@ export const TDBSubDocument = ({ extracted, expanded, order_by, comment, props,
176177
linked_to={linked_to}
177178
args={args}/>}
178179
</div>
179-
</Collapse>
180+
</Collapse></>}
181+
{mode !== CONST.VIEW && <>
182+
<Card.Header>
183+
{getLinkedDescription (linked_to, `SubDocument`)}
184+
</Card.Header>
185+
<div id={`root_subdocument_${props.name}`}>
186+
{subDocumentData && linked_to === subDocumentData[CONST.TYPE] && <SubDocumentProperties properties={extracted.properties}
187+
//required={extracted.required}
188+
required={props.required}
189+
//formData={props.formData}
190+
id={id}
191+
index={index}
192+
reference={reference}
193+
order_by={order_by}
194+
props={props}
195+
subDocumentPropertyName={props.name}
196+
propertyDocumentation={propertyDocumentation}
197+
onChange={props.onChange}
198+
subDocumentData={subDocumentData}
199+
setSubDocumentData={setSubDocumentData}
200+
linked_to={linked_to}
201+
args={args}/>}
202+
</div>
203+
</>}
180204
</Card>
181205
</Stack>
182206
}

0 commit comments

Comments
 (0)