Skip to content

Commit

Permalink
Merge branch 'fix/bugs_0228' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
AruSeito committed Feb 28, 2024
2 parents dfd0f96 + 49900c2 commit ef84511
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const OptionListSetter: FC<OptionListSetterProps> = (props) => {
widgetDisplayName,
childrenSetter,
handleUpdateMultiAttrDSL,
itemName,
itemName = "Option",
} = props

const execResult = useSelector(getExecutionResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ async function handleStartExecution(
const isAddAction =
action.type.startsWith("components/add") ||
action.type.startsWith("action/add") ||
action.type.startsWith("action/batchAdd")

action.type.startsWith("action/batchAdd") ||
componentsActions.batchUpdateMultiComponentSlicePropsReducer.match(
action,
) ||
actionActions.batchUpdateMultiActionSlicePropsReducer.match(action)
const executionResult = executionTree.updateTree(
rawTree,
isDeleteAction,
Expand Down
14 changes: 10 additions & 4 deletions apps/builder/src/utils/executionTreeHelper/executionTreeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { RawTreeShape } from "@/utils/executionTreeHelper/interface"
import {
extractReferencesFromScript,
getImmediateParentsOfPropertyPaths,
getObjectPaths,
isAction,
isWidget,
removeParentPath,
Expand Down Expand Up @@ -133,6 +134,7 @@ export class ExecutionTreeFactory {
getContainerListDisplayNameMappedChildrenNodeDisplayName(
store.getState(),
)

const listWidgetDisplayNames = Object.keys(listWidgets)
let currentListDisplayName = ""
for (let i = 0; i < listWidgetDisplayNames.length; i++) {
Expand All @@ -141,11 +143,13 @@ export class ExecutionTreeFactory {
break
}
}

if (isObject(validationPaths)) {
Object.keys(validationPaths).forEach((validationPath) => {
const validationType = validationPaths[
validationPath
] as VALIDATION_TYPES
getObjectPaths(validationPaths).forEach((validationPath) => {
const validationType = get(
validationPaths,
validationPath,
) as VALIDATION_TYPES
const fullPath = `${displayName}.${validationPath}`
const validationFunc = validationFactory[validationType]
const value = get(widgetOrAction, validationPath)
Expand Down Expand Up @@ -377,6 +381,7 @@ export class ExecutionTreeFactory {
this.oldRawTree = klona(currentRawTree)
const updatePaths = this.getUpdatePathFromDifferences(differences)
const walkedPath = new Set<string>()

let currentExecution = this.updateExecutionTreeByUpdatePaths(
updatePaths,
this.executedTree,
Expand All @@ -401,6 +406,7 @@ export class ExecutionTreeFactory {
path,
-1,
)

this.mergeErrorTree(errorTree, [...updatePaths, ...path], isDeleteAction)
this.mergeDebugDataTree(
debuggerData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const generateRawWidget = (widget: WidgetShape) => {
panelConfig,
widget,
)

return {
...widget,
$validationPaths: validationPaths,
Expand Down
22 changes: 22 additions & 0 deletions apps/builder/src/utils/executionTreeHelper/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,25 @@ export const removeWidgetOrActionMethods = (
{},
)
}

export function getObjectPaths(obj: Record<string, unknown>, currentPath = "") {
let paths: string[] = []

if (typeof obj === "object" && obj !== null) {
Object.keys(obj).forEach((key) => {
const value = obj[key]
const newPath = Array.isArray(obj)
? `${currentPath}.${key}`
: `${currentPath ? currentPath + "." : ""}${key}`
if (typeof value === "object" && value !== null) {
paths = paths.concat(
getObjectPaths(value as Record<string, unknown>, newPath),
)
} else {
paths.push(newPath)
}
})
}

return paths.map((path) => (path.startsWith(".") ? path.substr(1) : path))
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { convertPathToString } from "@illa-public/dynamic-string"
import { get, toPath } from "lodash-es"
import { get, set, toPath } from "lodash-es"
import {
PanelConfig,
PanelFieldGroupConfig,
Expand All @@ -23,21 +23,21 @@ export const generateAllTypePathsFromWidgetConfig = (
const expectedType = filedConfig.expectedType
if (Array.isArray(expectedType)) {
attrPath.forEach((path, i) => {
configValidationPaths[path] = expectedType[i]
set(configValidationPaths, path, expectedType[i])
})
} else if (expectedType) {
attrPath.forEach((path) => {
configValidationPaths[path] = expectedType
set(configValidationPaths, path, expectedType)
})
}
} else {
if (filedConfig.expectedType) {
const expectedType = filedConfig.expectedType

if (Array.isArray(expectedType)) {
configValidationPaths[attrPath] = expectedType[0]
set(configValidationPaths, attrPath, expectedType[0])
} else if (expectedType) {
configValidationPaths[attrPath] = expectedType
set(configValidationPaths, attrPath, expectedType)
}
}
}
Expand All @@ -56,35 +56,43 @@ export const generateAllTypePathsFromWidgetConfig = (
if (Array.isArray(childAttrPath)) {
if (Array.isArray(expectedType)) {
childAttrPath.forEach((path, i) => {
configValidationPaths[
set(
configValidationPaths,
convertPathToString(
toPath(`${objectIndexPropertyPath}.${path}`),
)
] = expectedType[i]
),
expectedType[i],
)
})
} else if (expectedType) {
childAttrPath.forEach((path) => {
configValidationPaths[
set(
configValidationPaths,
convertPathToString(
toPath(`${objectIndexPropertyPath}.${path}`),
)
] = expectedType
),
expectedType,
)
})
}
} else {
if (expectedType) {
if (Array.isArray(expectedType)) {
configValidationPaths[
set(
configValidationPaths,
convertPathToString(
toPath(`${objectIndexPropertyPath}.${childAttrPath}`),
)
] = expectedType[0]
),
expectedType[0],
)
} else if (expectedType) {
configValidationPaths[
set(
configValidationPaths,
convertPathToString(
toPath(`${objectIndexPropertyPath}.${childAttrPath}`),
)
] = expectedType
),
expectedType,
)
}
}
}
Expand All @@ -99,7 +107,11 @@ export const generateAllTypePathsFromWidgetConfig = (
filedConfig.childrenSetter?.forEach((childConfig) => {
const expectedType = childConfig.expectedType
if (!Array.isArray(expectedType) && expectedType) {
configValidationPaths[objectIndexPropertyPath] = expectedType
set(
configValidationPaths,
objectIndexPropertyPath,
expectedType,
)
}
})
})
Expand Down
5 changes: 3 additions & 2 deletions apps/builder/src/widgetLibrary/PC/GridListWidget/gridList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getRawTree,
} from "@/redux/currentApp/executionTree/executionSelector"
import { evaluateDynamicString } from "@/utils/evaluateDynamicString"
import { getObjectPaths } from "@/utils/executionTreeHelper/utils"
import { isObject } from "@/utils/typeHelper"
import { VALIDATION_TYPES, validationFactory } from "@/utils/validationFactory"
import ListWidgetWithAutoPagination from "./components/ListWidgetWithAutoPagination"
Expand Down Expand Up @@ -85,7 +86,7 @@ export const GridListWidget: FC<GridListWidgetProps> = (props) => {
const rawWidget = rawTree[displayName]
if (rawWidget && isObject(rawWidget.$validationPaths)) {
const validationPaths = rawWidget.$validationPaths
const validationType = validationPaths[finalPath]
const validationType = get(validationPaths, finalPath)
if (validationType === VALIDATION_TYPES.ARRAY) {
const validationFunc = validationFactory[validationType]
const res = validationFunc?.(evalResult, "")
Expand Down Expand Up @@ -121,7 +122,7 @@ export const GridListWidget: FC<GridListWidgetProps> = (props) => {
const rawWidget = rawTree[realDisplayName as string]
const validationPaths = rawWidget.$validationPaths
if (isObject(validationPaths)) {
Object.keys(validationPaths).forEach((path) => {
getObjectPaths(validationPaths).forEach((path) => {
const validationType = validationPaths[path] as VALIDATION_TYPES
const validationFunc = validationFactory[validationType]
const currentValue = get(item, `props.${path}`, "")
Expand Down
10 changes: 7 additions & 3 deletions apps/builder/src/widgetLibrary/PC/ListWidget/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getRawTree,
} from "@/redux/currentApp/executionTree/executionSelector"
import { evaluateDynamicString } from "@/utils/evaluateDynamicString"
import { getObjectPaths } from "@/utils/executionTreeHelper/utils"
import { isObject } from "@/utils/typeHelper"
import { VALIDATION_TYPES, validationFactory } from "@/utils/validationFactory"
import { ListWidgetProps } from "@/widgetLibrary/PC/ListWidget/interface"
Expand Down Expand Up @@ -86,7 +87,7 @@ export const ListWidget: FC<ListWidgetProps> = (props) => {
const rawWidget = rawTree[displayName]
if (rawWidget && isObject(rawWidget.$validationPaths)) {
const validationPaths = rawWidget.$validationPaths
const validationType = validationPaths[finalPath]
const validationType = get(validationPaths, finalPath)
if (validationType === VALIDATION_TYPES.ARRAY) {
const validationFunc = validationFactory[validationType]
const res = validationFunc?.(evalResult, "")
Expand Down Expand Up @@ -122,8 +123,11 @@ export const ListWidget: FC<ListWidgetProps> = (props) => {
const rawWidget = rawTree[realDisplayName as string]
const validationPaths = rawWidget.$validationPaths
if (isObject(validationPaths)) {
Object.keys(validationPaths).forEach((path) => {
const validationType = validationPaths[path] as VALIDATION_TYPES
getObjectPaths(validationPaths).forEach((path) => {
const validationType = get(
validationPaths,
path,
) as VALIDATION_TYPES
const validationFunc = validationFactory[validationType]
const currentValue = get(item, `props.${path}`, "")
const res = validationFunc?.(currentValue, "")
Expand Down

0 comments on commit ef84511

Please sign in to comment.