Skip to content

Commit f879598

Browse files
briantangMarkLogic Builder
authored andcommitted
DHFPROD-7449: Scroll to respective tables when pagination is applied
1 parent e5b6bd7 commit f879598

File tree

7 files changed

+52
-7
lines changed

7 files changed

+52
-7
lines changed

marklogic-data-hub-central/ui/e2e/cypress/integration/curation/curate/relatedEntityMapping.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,16 @@ describe("Mapping", () => {
249249
//Related entity does not exist after reopening step
250250
mappingStepDetail.entityTitle("Relation (relatedTo Person)").should("not.exist");
251251
});
252+
253+
it("Verify page automically scrolls to top of table after pagination", () => {
254+
cy.waitUntil(() => mappingStepDetail.relatedFilterMenu("Person")).click();
255+
cy.waitUntil(() => mappingStepDetail.getRelatedEntityFromList("Relation (relatedTo Person)")).click();
256+
cy.get("#entityContainer").scrollTo("bottom", {ensureScrollable: false});
257+
mappingStepDetail.entityTitle("Person").should("not.be.visible");
258+
browsePage.getPaginationPageSizeOptions().then(attr => {
259+
attr[1].click();
260+
});
261+
browsePage.getPageSizeOption("10 / page").click();
262+
mappingStepDetail.entityTitle("Person").should("be.visible");
263+
});
252264
});

marklogic-data-hub-central/ui/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

marklogic-data-hub-central/ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"stompjs": "^2.3.3",
5656
"typescript": "^3.8.0",
5757
"use-deep-compare-effect": "^1.3.1",
58+
"use-dynamic-refs": "^1.0.0",
5859
"xml-formatter": "^2.4.0"
5960
},
6061
"scripts": {

marklogic-data-hub-central/ui/src/components/entities/mapping/entity-map-table/entity-map-table.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import arrayIcon from "../../../../assets/icon_array.png";
1313
import DocIcon from "../../../../assets/DocIcon.png";
1414
import {css} from "@emotion/css";
1515
import {getParentKey, getKeys, deepCopy} from "../../../../util/data-conversion";
16-
import {paginationOptions} from "../../../../config/mapping.config";
16+
import {paginationMapping} from "../../../../config/mapping.config";
1717
import {ModelingTooltips, MappingDetailsTooltips} from "../../../../config/tooltips.config";
1818
import StepsConfig from "../../../../config/steps.config";
1919

2020
interface Props {
21+
setScrollRef: any;
22+
executeScroll: any;
2123
mapResp: any;
2224
mapData: any;
2325
setMapResp: any;
@@ -215,6 +217,17 @@ const EntityMapTable: React.FC<Props> = (props) => {
215217
/* The source context is updated when mapping is saved/loaded, this function does a level order traversal of entity
216218
json and updates the sourceContext for every entity property */
217219

220+
const paginationFunction = {
221+
defaultCurrent: paginationMapping.defaultCurrent,
222+
defaultPageSize: paginationMapping.defaultPageSize,
223+
hideOnSinglePage: paginationMapping.hideOnSinglePage,
224+
pageSizeOptions: paginationMapping.pageSizeOptions,
225+
showSizeChanger: paginationMapping.showSizeChanger,
226+
size: paginationMapping.size,
227+
onChange: (e) => { props.executeScroll(`${props.entityMappingId}-ref`); },
228+
onShowSizeChange: (e) => { props.executeScroll(`${props.entityMappingId}-ref`); }
229+
};
230+
218231
const updateSourceContext = (mapExp, entityTable) => {
219232

220233
let queue: any[] = [];
@@ -1381,7 +1394,7 @@ const EntityMapTable: React.FC<Props> = (props) => {
13811394
});
13821395

13831396
return (props.entityLoaded ? (props.entityMappingId || !props.isRelatedEntity) ? (<div id={props.isRelatedEntity? "entityTableContainer" : "rootTableContainer"} data-testid={props.entityTypeTitle.split(" ")[0].toLowerCase() + "-table"}>
1384-
<div id={entityProperties.length > 0 ? "upperTable" : "upperTableEmptyProps"}>
1397+
<div id={entityProperties.length > 0 ? "upperTable" : "upperTableEmptyProps"} ref={props.setScrollRef(`${props.entityMappingId}-ref`)}>
13851398
<Table
13861399
pagination={false}
13871400
className={tableCSS}
@@ -1402,7 +1415,7 @@ const EntityMapTable: React.FC<Props> = (props) => {
14021415
{entityProperties.length > 0 ?
14031416
<div id="lowerTable">
14041417
<Table
1405-
pagination={paginationOptions}
1418+
pagination={paginationFunction}
14061419
className={tableCSS}
14071420
expandIcon={(props) => customExpandIcon(props)}
14081421
onExpand={(expanded, record) => toggleRowExpanded(expanded, record, "key")}

marklogic-data-hub-central/ui/src/components/entities/mapping/mapping-step-detail/mapping-step-detail.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,7 @@ describe("RTL Source-to-entity map tests", () => {
16461646
mockGetUris.mockResolvedValue({status: 200, data: ["/dummy/uri/person-101.json"]});
16471647
mockGetSourceDoc.mockResolvedValue({status: 200, data: data.jsonSourceDataLargeDataset});
16481648
mockGetNestedEntities.mockResolvedValue({status: 200, data: personRelatedEntityDefLargePropSet});
1649+
window.HTMLElement.prototype.scrollIntoView = function() {};
16491650

16501651
let getByText, queryByText, getByTestId, getByTitle, getAllByTitle, queryByTitle, getByLabelText, queryByTestId, getAllByText;
16511652
await act(async () => {

marklogic-data-hub-central/ui/src/components/entities/mapping/mapping-step-detail/mapping-step-detail.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import arrayIcon from "../../../../assets/icon_array.png";
2626
import relatedEntityIcon from "../../../../assets/icon_related_entities.png";
2727
import CustomPageHeader from "../../page-header/page-header";
2828
import {clearSessionStorageOnRefresh, getViewSettings, setViewSettings} from "../../../../util/user-context";
29-
import {paginationOptions, mappingColors} from "../../../../config/mapping.config";
29+
import {paginationMapping, mappingColors} from "../../../../config/mapping.config";
30+
import useDynamicRefs from "use-dynamic-refs";
3031

3132
const DEFAULT_MAPPING_STEP: MappingStep = {
3233
name: "",
@@ -145,6 +146,14 @@ const MappingStepDetail: React.FC = () => {
145146
const [sourceFormat, setSourceFormat] = useState("");
146147
const [docNotFound, setDocNotFound] = useState(false);
147148
const [mapData, setMapData] = useState<any>(DEFAULT_MAPPING_STEP);
149+
const [getRef, setRef] = useDynamicRefs();
150+
151+
const executeScroll = (refId) => {
152+
const scrollToRef : any = getRef(refId);
153+
if (scrollToRef && scrollToRef.current) {
154+
scrollToRef.current.scrollIntoView();
155+
}
156+
};
148157

149158
let tableColors = [...mappingColors];
150159

@@ -1399,7 +1408,7 @@ const MappingStepDetail: React.FC = () => {
13991408
<span className={styles.sourceCollapseButtons}><ExpandCollapse handleSelection={(id) => handleSourceExpandCollapse(id)} currentSelection={""} /></span>
14001409
</div>
14011410
<Table
1402-
pagination={paginationOptions}
1411+
pagination={paginationMapping}
14031412
expandIcon={(props) => customExpandIcon(props)}
14041413
onExpand={(expanded, record) => toggleSourceRowExpanded(expanded, record, "rowKey")}
14051414
expandedRowKeys={sourceExpandedKeys}
@@ -1431,6 +1440,8 @@ const MappingStepDetail: React.FC = () => {
14311440
<span className={styles.columnOptionsSelector}>{columnOptionsSelector}</span>
14321441
</div>
14331442
<EntityMapTable
1443+
setScrollRef = {setRef}
1444+
executeScroll = {executeScroll}
14341445
mapResp={mapResp}
14351446
mapData={mapData}
14361447
setMapResp={setMapResp}
@@ -1471,8 +1482,10 @@ const MappingStepDetail: React.FC = () => {
14711482
labelRemoved = {labelRemoved}
14721483
entityLoaded = {entityLoaded}
14731484
/>
1474-
{relatedEntityTypeProperties.map(entity => relatedEntitiesSelected.map(selectedEntity => selectedEntity.entityMappingId).includes(entity.entityMappingId) ?
1485+
{relatedEntityTypeProperties.map((entity, i) => relatedEntitiesSelected.map(selectedEntity => selectedEntity.entityMappingId).includes(entity.entityMappingId) ?
14751486
<EntityMapTable
1487+
setScrollRef = {setRef}
1488+
executeScroll = {executeScroll}
14761489
mapResp={mapResp}
14771490
mapData={mapData}
14781491
setMapResp={setMapResp}

marklogic-data-hub-central/ui/src/config/mapping.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const paginationOptions = {
1+
export const paginationMapping = {
22
defaultCurrent: 1,
33
defaultPageSize: 20,
44
hideOnSinglePage: false,

0 commit comments

Comments
 (0)