Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
AruSeito committed Jan 29, 2024
2 parents 26095e2 + 7aad4b0 commit 6cd4bb4
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 40 deletions.
2 changes: 1 addition & 1 deletion apps/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"author": "ILLA Cloud <[email protected]>",
"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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -142,38 +151,40 @@ const ColumnSetter: FC<ColumnSetterProps> = (props) => {
items={mixedColumns.map((item) => item.field)}
>
{mixedColumns.length > 0 ? (
mixedColumns.map((config, index) => (
<Column
onDelete={(id) => {
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 : (
<Column
onDelete={(id) => {
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,
},
})
}}
/>
),
)
) : (
<ColumnEmpty />
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -11,21 +13,33 @@ export function dealRawData2ArrayData(rawData: unknown): object[] {
return []
} else {
if (isObject(rawData[0])) {
return rawData
return rawData.map((item) => {
return {
[UNIQUE_ID_NAME]: v4(),
...item,
}
})
} else {
return rawData.map((item) => {
return {
[UNIQUE_ID_NAME]: v4(),
field: item,
}
})
}
}
} else {
if (isObject(rawData)) {
return [rawData]
return [
{
[UNIQUE_ID_NAME]: v4(),
...rawData,
},
]
} else {
return [
{
[UNIQUE_ID_NAME]: v4(),
field: rawData,
},
]
Expand Down
1 change: 1 addition & 0 deletions apps/builder/src/widgetLibrary/DataGridWidget/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const UNIQUE_ID_NAME = "$uniqueID"
18 changes: 14 additions & 4 deletions apps/builder/src/widgetLibrary/DataGridWidget/dataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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<BaseDataGridProps> = (props) => {
Expand Down Expand Up @@ -218,7 +218,8 @@ export const DataGridWidget: FC<BaseDataGridProps> = (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(
Expand All @@ -232,6 +233,12 @@ export const DataGridWidget: FC<BaseDataGridProps> = (props) => {
)
: getColumnFromType(safeColumn, triggerEventHandler)
})
const uniqueId = {
field: UNIQUE_ID_NAME,
headerName: "",
type: "string",
}
return [uniqueId, ...currentColumns]
}, [arrayData, columns, triggerEventHandler])

const aggregationModel = useMemo(() => {
Expand Down Expand Up @@ -262,7 +269,7 @@ export const DataGridWidget: FC<BaseDataGridProps> = (props) => {
primaryKey === "—" ||
!(primaryKey in row)
) {
return v4()
return get(row, UNIQUE_ID_NAME)
} else {
return get(row, primaryKey)
}
Expand Down Expand Up @@ -303,7 +310,10 @@ export const DataGridWidget: FC<BaseDataGridProps> = (props) => {
])
triggerEventHandler("onColumnVisibilityModelChange")
}}
columnVisibilityModel={columnVisibilityModel}
columnVisibilityModel={{
[UNIQUE_ID_NAME]: false,
...columnVisibilityModel,
}}
onRowSelectionModelChange={(model) => {
handleUpdateMultiExecutionResult([
{
Expand Down

0 comments on commit 6cd4bb4

Please sign in to comment.