From 37f57e57e9d35eaf37172a1402dd3e0e8c3f0bee Mon Sep 17 00:00:00 2001 From: Scenery <1507337624@qq.com> Date: Mon, 29 Jan 2024 18:40:21 +0800 Subject: [PATCH 1/4] fix: data grid filter bug --- .../DataGridSetter/ColumnSetter/index.tsx | 77 +++++++++++-------- .../PanelSetters/DataGridSetter/utils.ts | 18 ++++- .../widgetLibrary/DataGridWidget/constants.ts | 1 + .../widgetLibrary/DataGridWidget/dataGrid.tsx | 18 ++++- 4 files changed, 75 insertions(+), 39 deletions(-) create mode 100644 apps/builder/src/widgetLibrary/DataGridWidget/constants.ts diff --git a/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/ColumnSetter/index.tsx b/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/ColumnSetter/index.tsx index cc742980e2..87979b234f 100644 --- a/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/ColumnSetter/index.tsx +++ b/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/ColumnSetter/index.tsx @@ -8,6 +8,7 @@ import { ColumnContainer } from "@/page/App/components/InspectPanel/PanelSetters import { getExecutionResult } from "@/redux/currentApp/executionTree/executionSelector" import { RootState } from "@/store" import { getColumnTypeFromValue } from "@/widgetLibrary/DataGridWidget/columnDeal" +import { UNIQUE_ID_NAME } from "@/widgetLibrary/DataGridWidget/constants" import { getColumnsTypeSetter } from "@/widgetLibrary/DataGridWidget/panelConfig" import { Column } from "../../DragMoveComponent/Column" import { ColumnEmpty } from "../../DragMoveComponent/Empty" @@ -18,8 +19,16 @@ function generateCalcColumnConfig( isCalc: boolean, randomKey: boolean, ): ColumnConfig { + let field + if (key === UNIQUE_ID_NAME) { + field = UNIQUE_ID_NAME + } else if (randomKey) { + field = v4() + } else { + field = `${key}` + } return { - field: randomKey ? v4() : `${key}`, + field, headerName: `${key}`, width: 170, isCalc: isCalc, @@ -142,38 +151,40 @@ const ColumnSetter: FC = (props) => { items={mixedColumns.map((item) => item.field)} > {mixedColumns.length > 0 ? ( - mixedColumns.map((config, index) => ( - { - const finalColumns = mixedColumns.filter( - (item) => item.field !== id, - ) - handleUpdateMultiAttrDSL?.({ - [attrName]: finalColumns, - }) - }} - childrenSetter={getColumnsTypeSetter( - config.columnType, - getColumnTypeFromValue(get(arrayData[0], config.field)), - )} - showDelete={!config.isCalc} - attrPath={`${attrName}.${index}`} - widgetDisplayName={widgetDisplayName} - key={config.field} - id={config.field} - showVisible={true} - label={config.headerName ?? config.field} - visibility={columnVisibilityModel?.[config.field] ?? true} - onVisibilityChange={(visibility) => { - handleUpdateMultiAttrDSL?.({ - ["columnVisibilityModel"]: { - ...columnVisibilityModel, - [config.field]: visibility, - }, - }) - }} - /> - )) + mixedColumns.map((config, index) => + config.field === UNIQUE_ID_NAME ? null : ( + { + const finalColumns = mixedColumns.filter( + (item) => item.field !== id, + ) + handleUpdateMultiAttrDSL?.({ + [attrName]: finalColumns, + }) + }} + childrenSetter={getColumnsTypeSetter( + config.columnType, + getColumnTypeFromValue(get(arrayData[0], config.field)), + )} + showDelete={!config.isCalc} + attrPath={`${attrName}.${index}`} + widgetDisplayName={widgetDisplayName} + key={config.field} + id={config.field} + showVisible={true} + label={config.headerName ?? config.field} + visibility={columnVisibilityModel?.[config.field] ?? true} + onVisibilityChange={(visibility) => { + handleUpdateMultiAttrDSL?.({ + ["columnVisibilityModel"]: { + ...columnVisibilityModel, + [config.field]: visibility, + }, + }) + }} + /> + ), + ) ) : ( )} diff --git a/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/utils.ts b/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/utils.ts index e3b85a05a5..c742c64a15 100644 --- a/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/utils.ts +++ b/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/utils.ts @@ -1,6 +1,8 @@ import { isObject, isString } from "lodash-es" +import { v4 } from "uuid" import { isNumber } from "@illa-design/react" import { JSToString, stringToJS } from "@/utils/evaluateDynamicString/utils" +import { UNIQUE_ID_NAME } from "@/widgetLibrary/DataGridWidget/constants" export function dealRawData2ArrayData(rawData: unknown): object[] { if (rawData === undefined || rawData === "" || rawData === null) { @@ -11,22 +13,34 @@ export function dealRawData2ArrayData(rawData: unknown): object[] { return [] } else { if (isObject(rawData[0])) { - return rawData + return rawData.map((item) => { + return { + ...item, + [UNIQUE_ID_NAME]: v4(), + } + }) } else { return rawData.map((item) => { return { field: item, + [UNIQUE_ID_NAME]: v4(), } }) } } } else { if (isObject(rawData)) { - return [rawData] + return [ + { + ...rawData, + [UNIQUE_ID_NAME]: v4(), + }, + ] } else { return [ { field: rawData, + [UNIQUE_ID_NAME]: v4(), }, ] } diff --git a/apps/builder/src/widgetLibrary/DataGridWidget/constants.ts b/apps/builder/src/widgetLibrary/DataGridWidget/constants.ts new file mode 100644 index 0000000000..8aea997c18 --- /dev/null +++ b/apps/builder/src/widgetLibrary/DataGridWidget/constants.ts @@ -0,0 +1 @@ +export const UNIQUE_ID_NAME = "$uniqueID" diff --git a/apps/builder/src/widgetLibrary/DataGridWidget/dataGrid.tsx b/apps/builder/src/widgetLibrary/DataGridWidget/dataGrid.tsx index 2c51a9d8fd..be0fdd552a 100644 --- a/apps/builder/src/widgetLibrary/DataGridWidget/dataGrid.tsx +++ b/apps/builder/src/widgetLibrary/DataGridWidget/dataGrid.tsx @@ -15,7 +15,6 @@ import { useRef, } from "react" import { useDispatch } from "react-redux" -import { v4 } from "uuid" import { getColor } from "@illa-design/react" import { dealRawData2ArrayData } from "@/page/App/components/InspectPanel/PanelSetters/DataGridSetter/utils" import { executionActions } from "@/redux/currentApp/executionTree/executionSlice" @@ -25,6 +24,7 @@ import { getSafeColumn, } from "@/widgetLibrary/DataGridWidget/columnDeal" import { Toolbar } from "./Toolbar" +import { UNIQUE_ID_NAME } from "./constants" import { BaseDataGridProps } from "./interface" export const DataGridWidget: FC = (props) => { @@ -218,7 +218,8 @@ export const DataGridWidget: FC = (props) => { ]) const renderColumns = useMemo(() => { - return columns?.map((column) => { + if (!columns) return [] + const currentColumns: GridColDef[] = columns.map((column) => { const safeColumn = getSafeColumn(column) return safeColumn.columnType === "auto" ? getColumnFromType( @@ -232,6 +233,12 @@ export const DataGridWidget: FC = (props) => { ) : getColumnFromType(safeColumn, triggerEventHandler) }) + const uniqueId = { + field: UNIQUE_ID_NAME, + headerName: "", + type: "string", + } + return [uniqueId, ...currentColumns] }, [arrayData, columns, triggerEventHandler]) const aggregationModel = useMemo(() => { @@ -262,7 +269,7 @@ export const DataGridWidget: FC = (props) => { primaryKey === "—" || !(primaryKey in row) ) { - return v4() + return get(row, UNIQUE_ID_NAME) } else { return get(row, primaryKey) } @@ -303,7 +310,10 @@ export const DataGridWidget: FC = (props) => { ]) triggerEventHandler("onColumnVisibilityModelChange") }} - columnVisibilityModel={columnVisibilityModel} + columnVisibilityModel={{ + [UNIQUE_ID_NAME]: false, + ...columnVisibilityModel, + }} onRowSelectionModelChange={(model) => { handleUpdateMultiExecutionResult([ { From d2101219cc19e0720c1c00950b810bbffd8f3bfa Mon Sep 17 00:00:00 2001 From: Scenery <1507337624@qq.com> Date: Mon, 29 Jan 2024 18:57:17 +0800 Subject: [PATCH 2/4] fix: data grid filter bug --- .../InspectPanel/PanelSetters/DataGridSetter/utils.ts | 8 ++++---- packages/illa-design | 2 +- packages/illa-public-component | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/utils.ts b/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/utils.ts index c742c64a15..e764b665e1 100644 --- a/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/utils.ts +++ b/apps/builder/src/page/App/components/InspectPanel/PanelSetters/DataGridSetter/utils.ts @@ -15,15 +15,15 @@ export function dealRawData2ArrayData(rawData: unknown): object[] { if (isObject(rawData[0])) { return rawData.map((item) => { return { - ...item, [UNIQUE_ID_NAME]: v4(), + ...item, } }) } else { return rawData.map((item) => { return { - field: item, [UNIQUE_ID_NAME]: v4(), + field: item, } }) } @@ -32,15 +32,15 @@ export function dealRawData2ArrayData(rawData: unknown): object[] { if (isObject(rawData)) { return [ { - ...rawData, [UNIQUE_ID_NAME]: v4(), + ...rawData, }, ] } else { return [ { - field: rawData, [UNIQUE_ID_NAME]: v4(), + field: rawData, }, ] } diff --git a/packages/illa-design b/packages/illa-design index 72f3e1e933..75dee71ddd 160000 --- a/packages/illa-design +++ b/packages/illa-design @@ -1 +1 @@ -Subproject commit 72f3e1e933a0550720d45045b5af38fa458f0912 +Subproject commit 75dee71ddd8e042681700398c95ce3858eb4b9bb diff --git a/packages/illa-public-component b/packages/illa-public-component index f5f5000e80..46c1bd5b52 160000 --- a/packages/illa-public-component +++ b/packages/illa-public-component @@ -1 +1 @@ -Subproject commit f5f5000e80065733d0e7c33c08f5333404b77ffb +Subproject commit 46c1bd5b52e498f1307c5b9095e436df787c72e7 From d2a49bb011017ddfcd7537d35f742b4ef55e9405 Mon Sep 17 00:00:00 2001 From: Scenery <1507337624@qq.com> Date: Mon, 29 Jan 2024 18:59:14 +0800 Subject: [PATCH 3/4] chore: update submodule to beta --- packages/illa-design | 2 +- packages/illa-public-component | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/illa-design b/packages/illa-design index 75dee71ddd..72f3e1e933 160000 --- a/packages/illa-design +++ b/packages/illa-design @@ -1 +1 @@ -Subproject commit 75dee71ddd8e042681700398c95ce3858eb4b9bb +Subproject commit 72f3e1e933a0550720d45045b5af38fa458f0912 diff --git a/packages/illa-public-component b/packages/illa-public-component index 46c1bd5b52..f5f5000e80 160000 --- a/packages/illa-public-component +++ b/packages/illa-public-component @@ -1 +1 @@ -Subproject commit 46c1bd5b52e498f1307c5b9095e436df787c72e7 +Subproject commit f5f5000e80065733d0e7c33c08f5333404b77ffb From 7aad4b07ae2e5819f0235e46abf252ab6cdc5dbb Mon Sep 17 00:00:00 2001 From: Scenery <1507337624@qq.com> Date: Mon, 29 Jan 2024 19:00:50 +0800 Subject: [PATCH 4/4] [ci skip] Update package.json --- apps/builder/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/builder/package.json b/apps/builder/package.json index f10b39bd8c..bf42b8173c 100644 --- a/apps/builder/package.json +++ b/apps/builder/package.json @@ -5,7 +5,7 @@ "private": true, "author": "ILLA Cloud ", "license": "Apache-2.0", - "version": "4.3.7", + "version": "4.4.0", "scripts": { "dev": "vite --strictPort --force", "build-cloud": "NODE_OPTIONS=--max-old-space-size=12288 vite build --mode cloud",