Skip to content

Commit

Permalink
fix: Trigger component conditions validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoecheza committed Nov 1, 2023
1 parent d90c0f5 commit fc88ae9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,14 @@ export default withSdk<Props>(
const hasCounter = useHasComponent(entityId, Counter)

const areValidActions = useCallback(
(updatedActions: TriggerAction[]) =>
updatedActions.length > 0 && updatedActions.every((action) => action.id && action.name),
[]
(updatedActions: TriggerAction[]) => updatedActions.every((action) => action.id && action.name),
[triggers]
)

const areValidConditions = useCallback(
(updatedConditions: TriggerCondition[] | undefined) =>
updatedConditions && updatedConditions.length > 0
? updatedConditions.every((condition) => condition.id && condition.value)
: true,
[]
(updatedConditions: TriggerCondition[] = []) =>
updatedConditions.every((condition) => condition.id && condition.value),
[triggers]
)

const areValidTriggers = useCallback(
Expand All @@ -97,6 +94,7 @@ export default withSdk<Props>(
)

useEffect(() => {
console.log('trigggers', triggers)
if (areValidTriggers(triggers)) {
if (isComponentEqual({ value: triggers })) {
return
Expand Down
10 changes: 6 additions & 4 deletions packages/@dcl/inspector/src/lib/sdk/operations/add-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ export function addAsset(engine: IEngine) {
...condition,
id: mapId(condition.id)
})),
actions: trigger.actions.map((action) => ({
...action,
id: mapId(action.id)
}))
actions: trigger.actions
.filter((action) => action.id)
.map((action) => ({
...action,
id: mapId(action.id)
}))

Check warning on line 116 in packages/@dcl/inspector/src/lib/sdk/operations/add-asset.ts

View check run for this annotation

Codecov / codecov/patch

packages/@dcl/inspector/src/lib/sdk/operations/add-asset.ts#L111-L116

Added lines #L111 - L116 were not covered by tests
}))
values.set(componentName, { ...triggers, value: newValue })
break
Expand Down

0 comments on commit fc88ae9

Please sign in to comment.