Skip to content

Commit

Permalink
fix: Smart Item Action selection
Browse files Browse the repository at this point in the history
  • Loading branch information
cyaiox committed Feb 27, 2025
1 parent bd88f24 commit d7a1ec9
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/admin-toolkit-ui/SmartItemsControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,18 @@ export function SmartItemsControl({

const selectedActionIndex =
state.smartItemsControl.selectedSmartItem !== undefined
? actions.findIndex(
(action) =>
action.name ===
state.smartItemsControl.smartItems.get(
smartItems[state.smartItemsControl.selectedSmartItem!]
.entity as Entity,
)?.selectedAction ||
? actions.findIndex((action) => {
const selectedSmartItem =
smartItems[state.smartItemsControl.selectedSmartItem!]
const stateSelectedAction = state.smartItemsControl.smartItems.get(
selectedSmartItem.entity as Entity,
)?.selectedAction

return (
action.name ===
smartItems[state.smartItemsControl.selectedSmartItem!]
.defaultAction,
)
(stateSelectedAction ?? selectedSmartItem.defaultAction)
)
})
: undefined

return (
Expand All @@ -362,7 +363,9 @@ export function SmartItemsControl({
engine={engine}
smartItems={smartItems}
selectedIndex={state.smartItemsControl.selectedSmartItem}
onSelect={(idx) => handleSelectSmartItem(state, smartItems, idx)}
onSelect={(idx) => {
handleSelectSmartItem(state, smartItems, idx)
}}
/>

<ActionSelector
Expand All @@ -371,12 +374,13 @@ export function SmartItemsControl({
selectedIndex={selectedActionIndex}
disabled={state.smartItemsControl.selectedSmartItem === undefined}
onChange={(idx) => {
if (state.smartItemsControl.selectedSmartItem === undefined) return
handleSelectAction(
state,
smartItems[state.smartItemsControl.selectedSmartItem],
actions[idx],
)
if (state.smartItemsControl.selectedSmartItem !== undefined) {
handleSelectAction(
state,
smartItems[state.smartItemsControl.selectedSmartItem],
actions[idx],
)
}
}}
/>

Expand Down

0 comments on commit d7a1ec9

Please sign in to comment.