From 8894fcc9596865f4b061decb2999d8b0c8822d24 Mon Sep 17 00:00:00 2001 From: simoleo89 Date: Mon, 18 May 2026 20:38:02 +0200 Subject: [PATCH] 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. --- .../wired-tools/WiredCreatorToolsView.tsx | 6 ++-- .../wiredCreatorToolsUiStore.test.ts | 30 ++++++++++++++++++- .../wired-tools/wiredCreatorToolsUiStore.ts | 20 ++++++++++++- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/components/wired-tools/WiredCreatorToolsView.tsx b/src/components/wired-tools/WiredCreatorToolsView.tsx index 97c5389..85984a8 100644 --- a/src/components/wired-tools/WiredCreatorToolsView.tsx +++ b/src/components/wired-tools/WiredCreatorToolsView.tsx @@ -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); diff --git a/src/components/wired-tools/wiredCreatorToolsUiStore.test.ts b/src/components/wired-tools/wiredCreatorToolsUiStore.test.ts index c128497..22f7f39 100644 --- a/src/components/wired-tools/wiredCreatorToolsUiStore.test.ts +++ b/src/components/wired-tools/wiredCreatorToolsUiStore.test.ts @@ -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'); + }); + }); }); diff --git a/src/components/wired-tools/wiredCreatorToolsUiStore.ts b/src/components/wired-tools/wiredCreatorToolsUiStore.ts index 3726b6f..0a5c18d 100644 --- a/src/components/wired-tools/wiredCreatorToolsUiStore.ts +++ b/src/components/wired-tools/wiredCreatorToolsUiStore.ts @@ -91,6 +91,15 @@ interface WiredCreatorToolsUiState selectedInspectionVariableKeys: Record; selectedVariableKeys: Record; + /** + * 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) => void; setActiveTab: (next: WiredToolsTab) => void; setInspectionType: (next: InspectionElementType) => void; @@ -128,6 +137,9 @@ interface WiredCreatorToolsUiState setSelectedInspectionVariableKeys: (next: Updater>) => void; setSelectedVariableKeys: (next: Updater>) => void; + + setInspectionGiveVariableItemId: (next: number) => void; + setInspectionGiveValue: (next: string) => void; } export const useWiredCreatorToolsUiStore = createNitroStore()((set) => ({ @@ -168,6 +180,9 @@ export const useWiredCreatorToolsUiStore = createNitroStore 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 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 }) }));