Skip to content

Commit

Permalink
Update flow.slice selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaCWebDeveloper committed May 22, 2024
1 parent 7c59f40 commit 0e00b27
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
38 changes: 34 additions & 4 deletions packages/flow-client/src/app/redux/modules/flow/flow.slice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import {
selectAllFlows,
selectAllSubflows,
selectDirectoryById,
selectDirectoryEntities,
selectDirectoryIds,
selectFlowDirectoryEntities,
selectFlowDirectoryEntityState,
selectFlowEntities,
selectFlowEntityById,
selectFlowEntityIds,
selectFlowEntityState,
selectFlowNodeById,
selectFlowNodeEntities,
selectFlowNodeEntityState,
selectFlowNodeIds,
selectFlowNodesByFlowId,
selectFlowState,
Expand Down Expand Up @@ -976,7 +979,7 @@ describe('Flow Slice', () => {
},
};

expect(selectFlowEntities(customState)).toEqual(
expect(selectFlowEntityState(customState)).toEqual(
customState.flow.flowEntities
);
});
Expand Down Expand Up @@ -1008,7 +1011,7 @@ describe('Flow Slice', () => {
},
};

expect(selectFlowNodeEntities(customState)).toEqual(
expect(selectFlowNodeEntityState(customState)).toEqual(
customState.flow.flowNodes
);
});
Expand All @@ -1032,7 +1035,7 @@ describe('Flow Slice', () => {
},
};

expect(selectFlowDirectoryEntities(customState)).toEqual(
expect(selectFlowDirectoryEntityState(customState)).toEqual(
customState.flow.directories
);
});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'],
]);
});
});
});
16 changes: 10 additions & 6 deletions packages/flow-client/src/app/redux/modules/flow/flow.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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 =>
Expand Down

0 comments on commit 0e00b27

Please sign in to comment.