wired-tools(store): hoist inspection give pickers (inspectionGiveVariableItemId, inspectionGiveValue)

Move the Inspection-tab Give-variable popover picker pair into the
Zustand store. Both writers use direct assignments (no updater shape),
so the store setters are plain `(next: number) => void` /
`(next: string) => void`. Defaults `0` / `'0'` match the existing
"sentinel = not selected" convention used by the reset effects at
WiredCreatorToolsView.tsx:3026-3042.

Tests: 2 new cases (set+read pair, sentinel-reset). Suite: 199/199.
This commit is contained in:
simoleo89
2026-05-18 20:38:02 +02:00
parent ba77806f52
commit 8894fcc959
3 changed files with 52 additions and 4 deletions
@@ -58,8 +58,10 @@ export const WiredCreatorToolsView: FC<{}> = () =>
const setSelectedInspectionVariableKeys = useWiredCreatorToolsUiStore(s => s.setSelectedInspectionVariableKeys);
const isInspectionGiveOpen = useWiredCreatorToolsUiStore(s => s.isInspectionGiveOpen);
const setIsInspectionGiveOpen = useWiredCreatorToolsUiStore(s => s.setIsInspectionGiveOpen);
const [ inspectionGiveVariableItemId, setInspectionGiveVariableItemId ] = useState(0);
const [ inspectionGiveValue, setInspectionGiveValue ] = useState('0');
const inspectionGiveVariableItemId = useWiredCreatorToolsUiStore(s => s.inspectionGiveVariableItemId);
const setInspectionGiveVariableItemId = useWiredCreatorToolsUiStore(s => s.setInspectionGiveVariableItemId);
const inspectionGiveValue = useWiredCreatorToolsUiStore(s => s.inspectionGiveValue);
const setInspectionGiveValue = useWiredCreatorToolsUiStore(s => s.setInspectionGiveValue);
const isVariableManageOpen = useWiredCreatorToolsUiStore(s => s.isVariableManageOpen);
const setIsVariableManageOpen = useWiredCreatorToolsUiStore(s => s.setIsVariableManageOpen);
const variableManageTypeFilter = useWiredCreatorToolsUiStore(s => s.variableManageTypeFilter);
@@ -30,7 +30,9 @@ const INITIAL = {
editingManagedHolderVariableId: 0,
editingManagedHolderValue: '',
selectedInspectionVariableKeys: { furni: '', user: '', global: '' },
selectedVariableKeys: { furni: '', user: '', global: '', context: '' }
selectedVariableKeys: { furni: '', user: '', global: '', context: '' },
inspectionGiveVariableItemId: 0,
inspectionGiveValue: '0'
};
describe('useWiredCreatorToolsUiStore', () =>
@@ -72,6 +74,8 @@ describe('useWiredCreatorToolsUiStore', () =>
expect(state.editingManagedHolderValue).toBe('');
expect(state.selectedInspectionVariableKeys).toEqual({ furni: '', user: '', global: '' });
expect(state.selectedVariableKeys).toEqual({ furni: '', user: '', global: '', context: '' });
expect(state.inspectionGiveVariableItemId).toBe(0);
expect(state.inspectionGiveValue).toBe('0');
});
describe('setIsVisible', () =>
@@ -458,4 +462,28 @@ describe('useWiredCreatorToolsUiStore', () =>
expect(useWiredCreatorToolsUiStore.getState().selectedInspectionVariableKeys.user).toBe('level');
});
});
describe('inspection give pickers', () =>
{
it('setInspectionGiveVariableItemId / setInspectionGiveValue write the picker pair', () =>
{
useWiredCreatorToolsUiStore.getState().setInspectionGiveVariableItemId(42);
useWiredCreatorToolsUiStore.getState().setInspectionGiveValue('150');
expect(useWiredCreatorToolsUiStore.getState().inspectionGiveVariableItemId).toBe(42);
expect(useWiredCreatorToolsUiStore.getState().inspectionGiveValue).toBe('150');
});
it('reset path uses 0 / "0" as the sentinel-empty pair (post-action and target-change paths)', () =>
{
useWiredCreatorToolsUiStore.getState().setInspectionGiveVariableItemId(42);
useWiredCreatorToolsUiStore.getState().setInspectionGiveValue('150');
useWiredCreatorToolsUiStore.getState().setInspectionGiveVariableItemId(0);
useWiredCreatorToolsUiStore.getState().setInspectionGiveValue('0');
expect(useWiredCreatorToolsUiStore.getState().inspectionGiveVariableItemId).toBe(0);
expect(useWiredCreatorToolsUiStore.getState().inspectionGiveValue).toBe('0');
});
});
});
@@ -91,6 +91,15 @@ interface WiredCreatorToolsUiState
selectedInspectionVariableKeys: Record<InspectionElementType, string>;
selectedVariableKeys: Record<VariablesElementType, string>;
/**
* Inspection-tab "Give variable" popover state. `itemId` is the
* picked variable definition id (0 = none); `value` is the in-flight
* value text. Both reset to their defaults whenever the inspection
* target changes (sync effect in WiredCreatorToolsView).
*/
inspectionGiveVariableItemId: number;
inspectionGiveValue: string;
setIsVisible: (next: Updater<boolean>) => void;
setActiveTab: (next: WiredToolsTab) => void;
setInspectionType: (next: InspectionElementType) => void;
@@ -128,6 +137,9 @@ interface WiredCreatorToolsUiState
setSelectedInspectionVariableKeys: (next: Updater<Record<InspectionElementType, string>>) => void;
setSelectedVariableKeys: (next: Updater<Record<VariablesElementType, string>>) => void;
setInspectionGiveVariableItemId: (next: number) => void;
setInspectionGiveValue: (next: string) => void;
}
export const useWiredCreatorToolsUiStore = createNitroStore<WiredCreatorToolsUiState>()((set) => ({
@@ -168,6 +180,9 @@ export const useWiredCreatorToolsUiStore = createNitroStore<WiredCreatorToolsUiS
selectedInspectionVariableKeys: { furni: '', user: '', global: '' },
selectedVariableKeys: { furni: '', user: '', global: '', context: '' },
inspectionGiveVariableItemId: 0,
inspectionGiveValue: '0',
setIsVisible: (next) => set(state => ({ isVisible: apply(state.isVisible, next) })),
setActiveTab: (next) => set({ activeTab: next }),
setInspectionType: (next) => set({ inspectionType: next }),
@@ -204,5 +219,8 @@ export const useWiredCreatorToolsUiStore = createNitroStore<WiredCreatorToolsUiS
setEditingManagedHolderValue: (next) => set({ editingManagedHolderValue: next }),
setSelectedInspectionVariableKeys: (next) => set(state => ({ selectedInspectionVariableKeys: apply(state.selectedInspectionVariableKeys, next) })),
setSelectedVariableKeys: (next) => set(state => ({ selectedVariableKeys: apply(state.selectedVariableKeys, next) }))
setSelectedVariableKeys: (next) => set(state => ({ selectedVariableKeys: apply(state.selectedVariableKeys, next) })),
setInspectionGiveVariableItemId: (next) => set({ inspectionGiveVariableItemId: next }),
setInspectionGiveValue: (next) => set({ inspectionGiveValue: next })
}));