From 0e00b275611b957a6f0d9df90260f286063c2002 Mon Sep 17 00:00:00 2001 From: Joshua Carter Date: Tue, 21 May 2024 19:52:49 -0700 Subject: [PATCH] Update flow.slice selectors --- .../app/redux/modules/flow/flow.slice.spec.ts | 38 +++++++++++++++++-- .../src/app/redux/modules/flow/flow.slice.ts | 16 +++++--- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/packages/flow-client/src/app/redux/modules/flow/flow.slice.spec.ts b/packages/flow-client/src/app/redux/modules/flow/flow.slice.spec.ts index 4f79712..69ffd1f 100644 --- a/packages/flow-client/src/app/redux/modules/flow/flow.slice.spec.ts +++ b/packages/flow-client/src/app/redux/modules/flow/flow.slice.spec.ts @@ -13,13 +13,16 @@ import { selectAllFlows, selectAllSubflows, selectDirectoryById, + selectDirectoryEntities, selectDirectoryIds, - selectFlowDirectoryEntities, + selectFlowDirectoryEntityState, selectFlowEntities, selectFlowEntityById, selectFlowEntityIds, + selectFlowEntityState, selectFlowNodeById, selectFlowNodeEntities, + selectFlowNodeEntityState, selectFlowNodeIds, selectFlowNodesByFlowId, selectFlowState, @@ -976,7 +979,7 @@ describe('Flow Slice', () => { }, }; - expect(selectFlowEntities(customState)).toEqual( + expect(selectFlowEntityState(customState)).toEqual( customState.flow.flowEntities ); }); @@ -1008,7 +1011,7 @@ describe('Flow Slice', () => { }, }; - expect(selectFlowNodeEntities(customState)).toEqual( + expect(selectFlowNodeEntityState(customState)).toEqual( customState.flow.flowNodes ); }); @@ -1032,7 +1035,7 @@ describe('Flow Slice', () => { }, }; - expect(selectFlowDirectoryEntities(customState)).toEqual( + expect(selectFlowDirectoryEntityState(customState)).toEqual( customState.flow.directories ); }); @@ -1089,6 +1092,15 @@ describe('Flow Slice', () => { expect(ids).toEqual(['flow1', 'subflow1']); }); + it('selectFlowEntities()', () => { + const entities = selectFlowEntities(state); + expect(Object.keys(entities).length).toEqual(2); + expect(Object.values(entities)).toEqual([ + state.flow.flowEntities.entities['flow1'], + state.flow.flowEntities.entities['subflow1'], + ]); + }); + it('selectAllFlows()', () => { const flows = selectAllFlows(state); expect(flows.length).toEqual(1); @@ -1166,6 +1178,15 @@ describe('Flow Slice', () => { expect(ids).toEqual(['node1', 'node2']); }); + it('selectFlowNodeEntities()', () => { + const entities = selectFlowNodeEntities(state); + expect(Object.keys(entities).length).toEqual(2); + expect(Object.values(entities)).toEqual([ + state.flow.flowNodes.entities['node1'], + state.flow.flowNodes.entities['node2'], + ]); + }); + it('selectFlowNodesByFlowId()', () => { const nodes = selectFlowNodesByFlowId(state, 'flow1'); expect(nodes.length).toEqual(1); @@ -1218,5 +1239,14 @@ describe('Flow Slice', () => { const ids = selectDirectoryIds(state); expect(ids).toEqual(['dir1', 'dir2']); }); + + it('selectDirectoryEntities()', () => { + const entities = selectDirectoryEntities(state); + expect(Object.keys(entities).length).toEqual(2); + expect(Object.values(entities)).toEqual([ + state.flow.directories.entities['dir1'], + state.flow.directories.entities['dir2'], + ]); + }); }); }); diff --git a/packages/flow-client/src/app/redux/modules/flow/flow.slice.ts b/packages/flow-client/src/app/redux/modules/flow/flow.slice.ts index 73467e5..bd7a214 100644 --- a/packages/flow-client/src/app/redux/modules/flow/flow.slice.ts +++ b/packages/flow-client/src/app/redux/modules/flow/flow.slice.ts @@ -224,15 +224,15 @@ export const flowActions = flowSlice.actions; export const selectFlowState = (state: RootState) => state[FLOW_FEATURE_KEY]; // entities -export const selectFlowEntities = createSelector( +export const selectFlowEntityState = createSelector( selectFlowState, state => state.flowEntities ); -export const selectFlowNodeEntities = createSelector( +export const selectFlowNodeEntityState = createSelector( selectFlowState, state => state.flowNodes ); -export const selectFlowDirectoryEntities = createSelector( +export const selectFlowDirectoryEntityState = createSelector( selectFlowState, state => state.directories ); @@ -242,20 +242,24 @@ export const { selectAll: selectAllFlowEntities, selectById: selectFlowEntityById, selectIds: selectFlowEntityIds, -} = flowAdapter.getSelectors(selectFlowEntities); + selectEntities: selectFlowEntities, +} = flowAdapter.getSelectors(selectFlowEntityState); export const { selectAll: selectAllFlowNodes, selectById: selectFlowNodeById, selectIds: selectFlowNodeIds, -} = nodeAdapter.getSelectors(selectFlowNodeEntities); + selectEntities: selectFlowNodeEntities, +} = nodeAdapter.getSelectors(selectFlowNodeEntityState); export const { selectAll: selectAllDirectories, selectById: selectDirectoryById, selectIds: selectDirectoryIds, -} = directoryAdapter.getSelectors(selectFlowDirectoryEntities); + selectEntities: selectDirectoryEntities, +} = directoryAdapter.getSelectors(selectFlowDirectoryEntityState); +// additional selectors export const selectAllFlows = createSelector( selectAllFlowEntities, entities =>