From f884cfabde5aafd47427e36a526fa009b5878c22 Mon Sep 17 00:00:00 2001 From: Gift Nnko Date: Tue, 10 Sep 2024 18:13:08 +0300 Subject: [PATCH] fix: scorecard form Improvement of the data groups configuration drag and drop --- .../DataConfiguration/DataGroupArea.tsx | 2 +- .../DataGroup/components/LinkingContainer.tsx | 2 +- .../DataGroups/components/DataGroup/index.tsx | 201 +++++++++--------- .../components/DataSource/index.tsx | 3 +- .../components/DataSourceHolder/index.tsx | 2 +- .../DataSourceSelectorModal/index.tsx | 26 +-- .../components/DataGroups/index.tsx | 52 +++-- .../components/EmptyDataGroups.tsx | 6 +- .../hooks/useDataGroupLayout.ts | 11 +- .../components/DataConfiguration/index.tsx | 2 +- 10 files changed, 164 insertions(+), 143 deletions(-) diff --git a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/DataGroupArea.tsx b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/DataGroupArea.tsx index 3d01ee06a..93b69b6ba 100644 --- a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/DataGroupArea.tsx +++ b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/DataGroupArea.tsx @@ -14,7 +14,7 @@ export default function DataGroupArea() {

{i18n.t("Groups")}

-
+
diff --git a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataGroup/components/LinkingContainer.tsx b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataGroup/components/LinkingContainer.tsx index d7d5887e2..d87128e82 100644 --- a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataGroup/components/LinkingContainer.tsx +++ b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataGroup/components/LinkingContainer.tsx @@ -27,7 +27,7 @@ export function LinkingContainer({ content={i18n.t( "Click to configure, drag to rearrange" )} - key={`group-${groupIndex}-holder-${source}`} + key={`group-${groupIndex}-holder-${source.id}`} > void } ) { const { - onDataSourceDelete, onDataSourceAdd, group } = useDataGroupManage({ index }); @@ -26,102 +25,114 @@ export function DataGroup( const [openAdd, setOpenAdd] = useState(false); const summaryRef = useRef(); - return ( - - event.stopPropagation()} - square - expanded={expanded} - onChange={toggleExpansion} - > - - event.stopPropagation()} - expandIcon={ - - } - aria-controls={`${id}d-content`} - id={`${id}d--header`} - > - - - - -
- {isEmpty(dataHolders) ? ( -
+ + { + (provided) => { + + return event.stopPropagation()} + square + expanded={expanded} + onChange={toggleExpansion} + > + -

- {i18n.t("Add a data source")} -

-
- ) : ( - - - {(provided: any) => ( + event.stopPropagation()} + expandIcon={ + + } + aria-controls={`${id}d-content`} + id={`${id}d--header`} + > +
+ + +
+
+ + +
+ {isEmpty(dataHolders) ? (
- {dataHolderChunks?.map( - (chunk, i) => ( - - ) - )} - {provided.placeholder} +

+ {i18n.t("Add a data source")} +

+ ) : ( + + + {(provided: any) => ( +
+ {dataHolderChunks?.map( + (chunk, i) => ( + + ) + )} + {provided.placeholder} +
+ )} +
+
)} - - - )} -
- -
-
- {/*{openAdd && (*/} - {/* setOpenAdd(false)}*/} - {/* open={openAdd}*/} - {/* />*/} - {/*)}*/} -
- - +
+ +
+
+ {openAdd && ( + setOpenAdd(false)} + open={openAdd} + /> + )} +
+
; + } + } + + ); } diff --git a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataSource/index.tsx b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataSource/index.tsx index 5f73c835f..060c61eea 100644 --- a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataSource/index.tsx +++ b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataSource/index.tsx @@ -1,5 +1,5 @@ import i18n from "@dhis2/d2-i18n"; -import { Button } from "@dhis2/ui"; +import { Button, IconDragHandle24 } from "@dhis2/ui"; import { getDataSourceShortName } from "@scorecard/shared"; import { Avatar } from "@material-ui/core"; import { IconDelete16 } from "@dhis2/ui-icons"; @@ -13,6 +13,7 @@ export default function DataSource({ dataSource, index, onDelete }: { dataSource
+ {getDataSourceShortName(type)} diff --git a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataSourceHolder/index.tsx b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataSourceHolder/index.tsx index 20c923878..7b110cb5a 100644 --- a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataSourceHolder/index.tsx +++ b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/components/DataSourceHolder/index.tsx @@ -29,7 +29,7 @@ export default function DataSourceHolder({ }; return ( - {(provided: any) => ( + {(provided) => (
void, open: boolean; onSelect: (dataItems: SelectedDataItem[]) => void, disabled: string[] }) { + const [selectedItems, setSelectedItems] = useState([]); return ( @@ -25,7 +22,7 @@ export default function DataSourceSelectorModal({ "dataElement", "dataSet", "programIndicator", - "customFunction", + "customFunction" ]} selected={selectedItems} disabled={disabled} @@ -51,10 +48,3 @@ export default function DataSourceSelectorModal({ ); } - -DataSourceSelectorModal.propTypes = { - onClose: PropTypes.func.isRequired, - onSelect: PropTypes.func.isRequired, - disabled: PropTypes.array, - open: PropTypes.bool, -}; diff --git a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/index.tsx b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/index.tsx index 6177f3204..eb8b82486 100644 --- a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/index.tsx +++ b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/DataGroups/index.tsx @@ -1,6 +1,4 @@ import React from "react"; -import { DndContext } from "@dnd-kit/core"; -import { DataGroupDroppable } from "./components/DataGroup/components/DataGroupDroppable"; import { useDataItemSearchState } from "../../states/searchState"; import { useFieldArray } from "react-hook-form"; import { ScorecardConfig, ScorecardDataGroup } from "@hisptz/dhis2-analytics"; @@ -11,10 +9,11 @@ import i18n from "@dhis2/d2-i18n"; import { Button } from "@dhis2/ui"; import { IconAdd24 } from "@dhis2/ui-icons"; import { DataGroup } from "./components/DataGroup"; +import { DragDropContext, Droppable, DropResult } from "react-beautiful-dnd"; export default function DataGroups() { const [filteredDataGroupIds] = useDataItemSearchState(); - const { fields, append, remove } = useFieldArray({ + const { fields, append, remove, move } = useFieldArray({ name: "dataSelection.dataGroups" }); @@ -22,7 +21,7 @@ export default function DataGroups() { append({ id: uid(), dataHolders: [], - title: i18n.t("Default"), + title: `${i18n.t("Default")} ${fields.length + 1}`, style: {} } as ScorecardDataGroup); }; @@ -31,22 +30,35 @@ export default function DataGroups() { return ; } + const onDragEnd = (result: DropResult) => { + const { source, destination } = result; + if (destination) { + move(source.index, destination.index); + } + }; + return ( - - -
-
- { - fields.map((field, i) => ( - - )) - } -
-
- -
-
-
-
+ + + { + (provided) => { + + return
+
+ { + fields.map((field, i) => ( + + )) + } +
+
+ +
+ {provided.placeholder} +
; + } + } +
+
); } diff --git a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/EmptyDataGroups.tsx b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/EmptyDataGroups.tsx index 01db18f24..f392611e8 100644 --- a/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/EmptyDataGroups.tsx +++ b/packages/app/src/modules/ScorecardManagement/components/DataConfiguration/components/EmptyDataGroups.tsx @@ -4,9 +4,9 @@ import { IconAdd24 } from "@dhis2/ui-icons"; import PropTypes from "prop-types"; import React from "react"; -export default function EmptyDataGroups({ onGroupAdd }: any) { +export default function EmptyDataGroups({ onGroupAdd }: { onGroupAdd: () => void }) { return ( -
+