mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 15:06:20 +00:00
wired-tools(store): hoist variable-key records (selectedInspectionVariableKeys, selectedVariableKeys)
Move the last two `Record<...Type, string>` useStates out of
WiredCreatorToolsView into useWiredCreatorToolsUiStore. Both writers
were already using the `prev => ({ ...prev, [key]: value })` updater
shape, so the new store setters expose `Updater<Record<...>>` to keep
existing call sites verbatim.
Initial values default to empty strings; the existing
`variableDefinitionsByType` sync effect at WiredCreatorToolsView.tsx
:1543-1574 already populates valid keys on first render and reconciles
whenever the server-side definitions change. Closing/reopening the panel
now preserves the active picker key instead of resetting it.
Tests: 4 new cases on the store (updater shape, single-key patch
preserving siblings, direct-record write path, panel-lifecycle
persistence). Suite: 197/197 (was 193/193).
This commit is contained in:
@@ -28,7 +28,9 @@ const INITIAL = {
|
||||
editingVariable: null,
|
||||
editingValue: '',
|
||||
editingManagedHolderVariableId: 0,
|
||||
editingManagedHolderValue: ''
|
||||
editingManagedHolderValue: '',
|
||||
selectedInspectionVariableKeys: { furni: '', user: '', global: '' },
|
||||
selectedVariableKeys: { furni: '', user: '', global: '', context: '' }
|
||||
};
|
||||
|
||||
describe('useWiredCreatorToolsUiStore', () =>
|
||||
@@ -68,6 +70,8 @@ describe('useWiredCreatorToolsUiStore', () =>
|
||||
expect(state.editingValue).toBe('');
|
||||
expect(state.editingManagedHolderVariableId).toBe(0);
|
||||
expect(state.editingManagedHolderValue).toBe('');
|
||||
expect(state.selectedInspectionVariableKeys).toEqual({ furni: '', user: '', global: '' });
|
||||
expect(state.selectedVariableKeys).toEqual({ furni: '', user: '', global: '', context: '' });
|
||||
});
|
||||
|
||||
describe('setIsVisible', () =>
|
||||
@@ -404,4 +408,54 @@ describe('useWiredCreatorToolsUiStore', () =>
|
||||
expect(useWiredCreatorToolsUiStore.getState().editingManagedHolderValue).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('variable-key records', () =>
|
||||
{
|
||||
it('setSelectedInspectionVariableKeys accepts the updater shape used by give/remove handlers', () =>
|
||||
{
|
||||
useWiredCreatorToolsUiStore.getState().setSelectedInspectionVariableKeys(prev => ({ ...prev, furni: '@state' }));
|
||||
expect(useWiredCreatorToolsUiStore.getState().selectedInspectionVariableKeys).toEqual({ furni: '@state', user: '', global: '' });
|
||||
|
||||
useWiredCreatorToolsUiStore.getState().setSelectedInspectionVariableKeys(prev => ({ ...prev, user: 'username' }));
|
||||
expect(useWiredCreatorToolsUiStore.getState().selectedInspectionVariableKeys).toEqual({ furni: '@state', user: 'username', global: '' });
|
||||
});
|
||||
|
||||
it('setSelectedVariableKeys preserves untouched keys when patching a single type', () =>
|
||||
{
|
||||
useWiredCreatorToolsUiStore.getState().setSelectedVariableKeys(prev => ({ ...prev, furni: '@state', user: 'level' }));
|
||||
useWiredCreatorToolsUiStore.getState().setSelectedVariableKeys(prev => ({ ...prev, context: 'hotel.uptime' }));
|
||||
|
||||
expect(useWiredCreatorToolsUiStore.getState().selectedVariableKeys).toEqual({
|
||||
furni: '@state',
|
||||
user: 'level',
|
||||
global: '',
|
||||
context: 'hotel.uptime'
|
||||
});
|
||||
});
|
||||
|
||||
it('setSelectedVariableKeys accepts a direct record (definition-sync write path)', () =>
|
||||
{
|
||||
useWiredCreatorToolsUiStore.getState().setSelectedVariableKeys({
|
||||
furni: '~teleport.target_id',
|
||||
user: 'username',
|
||||
global: 'hotel.uptime',
|
||||
context: 'event.type'
|
||||
});
|
||||
|
||||
expect(useWiredCreatorToolsUiStore.getState().selectedVariableKeys.furni).toBe('~teleport.target_id');
|
||||
expect(useWiredCreatorToolsUiStore.getState().selectedVariableKeys.context).toBe('event.type');
|
||||
});
|
||||
|
||||
it('variable-key records persist across the panel close/reopen lifecycle', () =>
|
||||
{
|
||||
useWiredCreatorToolsUiStore.getState().setSelectedVariableKeys(prev => ({ ...prev, furni: '@state' }));
|
||||
useWiredCreatorToolsUiStore.getState().setSelectedInspectionVariableKeys(prev => ({ ...prev, user: 'level' }));
|
||||
|
||||
useWiredCreatorToolsUiStore.getState().setIsVisible(false);
|
||||
useWiredCreatorToolsUiStore.getState().setIsVisible(true);
|
||||
|
||||
expect(useWiredCreatorToolsUiStore.getState().selectedVariableKeys.furni).toBe('@state');
|
||||
expect(useWiredCreatorToolsUiStore.getState().selectedInspectionVariableKeys.user).toBe('level');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user