Skip to content

Commit e08f2a2

Browse files
briantangMarkLogic Builder
authored andcommitted
DHFPROD-8111: Modeling graph UI fixes
1 parent b1283a0 commit e08f2a2

File tree

4 files changed

+99
-5
lines changed

4 files changed

+99
-5
lines changed

marklogic-data-hub-central/ui/src/components/modeling/graph-view/graph-view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ const GraphView: React.FC<Props> = (props) => {
270270
pane2Style={splitPaneStyles.pane2}
271271
split="vertical"
272272
primary="first"
273-
defaultSize="70%"
273+
defaultSize="66%"
274274
onDragFinished={handleSplitPaneResize}
275275
>
276276
{graphViewMainPanel}

marklogic-data-hub-central/ui/src/components/modeling/property-table/property-table.module.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@
112112
display: inline-block;
113113
}
114114

115+
.addPropertyButton {
116+
line-height: normal;
117+
padding: 1.5px 8px !important;
118+
}
119+
115120
.disabledButton {
116121
cursor: not-allowed;
117122
}

marklogic-data-hub-central/ui/src/components/modeling/property-table/property-table.test.tsx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {render, screen, fireEvent, within, cleanup} from "@testing-library/react
33
import {waitFor} from "@testing-library/dom";
44
import userEvent from "@testing-library/user-event";
55
import PropertyTable from "./property-table";
6-
6+
import {onClosestTableRow} from "../../../util/test-utils";
77
import {entityReferences, primaryEntityTypes} from "../../../api/modeling";
88
import curateData from "../../../assets/mock-data/curation/flows.data";
99
import {ConfirmationType} from "../../../types/common-types";
@@ -220,6 +220,53 @@ describe("Entity Modeling Property Table Component", () => {
220220
expect(getAllByText("string")).toHaveLength(10);
221221
});
222222

223+
test("Expand/Collapse all works in Property table side panel view", async () => {
224+
let entityName = propertyTableEntities[2].entityName;
225+
let definitions = propertyTableEntities[2].model.definitions;
226+
const {queryByText, getByTestId, getAllByText} = render(
227+
<PropertyTable
228+
canReadEntityModel={true}
229+
canWriteEntityModel={false}
230+
entityName={entityName}
231+
definitions={definitions}
232+
sidePanelView={true}
233+
updateSavedEntity={jest.fn()}
234+
/>
235+
);
236+
237+
//properties under Address and Billing structured properties should be hidden by default
238+
expect(queryByText("street")).not.toBeInTheDocument();
239+
expect(queryByText("state")).not.toBeInTheDocument();
240+
expect(queryByText("fiveDigit")).not.toBeInTheDocument();
241+
expect(queryByText("plusFour")).not.toBeInTheDocument();
242+
243+
//verify expand all
244+
fireEvent.click(getByTestId("expandBtn"));
245+
246+
//all nested properties should be present
247+
expect(getAllByText("street")).toHaveLength(2);
248+
expect(getAllByText("state")).toHaveLength(2);
249+
expect(getAllByText("fiveDigit")).toHaveLength(2);
250+
expect(getAllByText("plusFour")).toHaveLength(2);
251+
252+
//verify collapse all
253+
fireEvent.click(getByTestId("collapseBtn"));
254+
255+
//all nested properties should be present
256+
257+
//address
258+
expect(onClosestTableRow(getAllByText("street")[0])?.style.display).toBe("none");
259+
expect(onClosestTableRow(getAllByText("state")[0])?.style.display).toBe("none");
260+
expect(onClosestTableRow(getAllByText("fiveDigit")[0])?.style.display).toBe("none");
261+
expect(onClosestTableRow(getAllByText("plusFour")[0])?.style.display).toBe("none");
262+
//billing
263+
expect(onClosestTableRow(getAllByText("street")[1])?.style.display).toBe("none");
264+
expect(onClosestTableRow(getAllByText("state")[1])?.style.display).toBe("none");
265+
expect(onClosestTableRow(getAllByText("fiveDigit")[1])?.style.display).toBe("none");
266+
expect(onClosestTableRow(getAllByText("plusFour")[1])?.style.display).toBe("none");
267+
});
268+
269+
223270
test("Property Table renders and shows messaging when entity name does not match a definition", async () => {
224271
let entityName = propertyTableEntities[2].entityName + "-different";
225272
let definitions = propertyTableEntities[2].model.definitions;

marklogic-data-hub-central/ui/src/components/modeling/property-table/property-table.tsx

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ const PropertyTable: React.FC<Props> = (props) => {
103103
const [expandedRows, setExpandedRows] = useState<string[]>(expandedRowStorage ? expandedRowStorage : []);
104104
const [newRowKey, setNewRowKey] = useState("");
105105

106+
const [sourceExpandedKeys, setSourceExpandedKeys] = useState<any[]>([]);
107+
const [expandedSourceFlag, setExpandedSourceFlag] = useState(false);
108+
106109
useEffect(() => {
107110
updateEntityDefinitionsAndRenderTable(props.definitions);
108111
}, [props.definitions]);
@@ -895,8 +898,47 @@ const PropertyTable: React.FC<Props> = (props) => {
895898
}
896899
};
897900

898-
const handleSourceExpandCollapse = (option) => {
901+
//Collapse all-Expand All button
902+
903+
const toggleSourceRowExpanded = (expanded, record, rowKey) => {
904+
if (!sourceExpandedKeys.includes(record.rowKey)) {
905+
setSourceExpandedKeys(prevState => {
906+
let finalKeys = prevState.concat([record["key"]]);
907+
setExpandedSourceFlag(true);
908+
return finalKeys;
909+
});
910+
911+
} else {
912+
setSourceExpandedKeys(prevState => {
913+
let finalKeys = prevState.filter(item => item !== record["key"]);
914+
setExpandedSourceFlag(false);
915+
return finalKeys;
916+
});
917+
}
918+
};
899919

920+
const getKeysToExpandFromTable = (dataArr, rowKey, allKeysToExpand: any = [], expanded?) => {
921+
922+
dataArr.forEach(obj => {
923+
if (obj.hasOwnProperty("children")) {
924+
allKeysToExpand.push(obj[rowKey]);
925+
if (rowKey === "key" && (!expandedSourceFlag || expanded)) {
926+
getKeysToExpandFromTable(obj["children"], rowKey, allKeysToExpand);
927+
}
928+
}
929+
});
930+
return allKeysToExpand;
931+
};
932+
933+
const handleSourceExpandCollapse = (option) => {
934+
let keys = getKeysToExpandFromTable(tableData, "key", [], true);
935+
if (option === "collapse") {
936+
setSourceExpandedKeys([]);
937+
setExpandedSourceFlag(false);
938+
} else {
939+
setSourceExpandedKeys([...keys]);
940+
setExpandedSourceFlag(true);
941+
}
900942
};
901943

902944
// Check if entity name has no matching definition
@@ -958,8 +1000,8 @@ const PropertyTable: React.FC<Props> = (props) => {
9581000
locale={{emptyText: " "}}
9591001
columns={headerColumns}
9601002
dataSource={tableData}
961-
onExpand={onExpand}
962-
expandedRowKeys={expandedRows}
1003+
onExpand={props.sidePanelView ? (expanded, record) => toggleSourceRowExpanded(expanded, record, "key") : onExpand}
1004+
expandedRowKeys={props.sidePanelView ? sourceExpandedKeys : expandedRows}
9631005
pagination={false}
9641006
/>
9651007
}

0 commit comments

Comments
 (0)