Skip to content

Commit

Permalink
Rename node/node.slice to palette/node.slice and add extra actions
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaCWebDeveloper committed May 22, 2024
1 parent ca4291b commit e5d65f3
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
flowActions,
selectEntityById,
} from '../../redux/modules/flow/flow.slice';
import { selectNodeById } from '../../redux/modules/node/node.slice';
import { selectNodeById } from '../../redux/modules/palette/node.slice';
import environment from '../../../environment';

const StyledEditor = styled.div`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { v4 as uuidv4 } from 'uuid';
import { useAppDispatch, useAppLogic, useAppSelector } from '../../redux/hooks';
import { SerializedGraph } from '../../redux/modules/flow/flow.logic';
import { selectAllEntities } from '../../redux/modules/flow/flow.slice';
import { NodeEntity } from '../../redux/modules/node/node.slice';
import { NodeEntity } from '../../redux/modules/palette/node.slice';
import { ItemTypes } from '../node/draggable-item-types'; // Assuming ItemTypes is defined elsewhere
import { createEngine } from './engine';
import { CustomDiagramModel } from './model';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import styled from 'styled-components';

import { useAppDispatch } from '../../redux/hooks';
import { builderActions } from '../../redux/modules/builder/builder.slice';
import { NodeEntity } from '../../redux/modules/node/node.slice';
import { NodeEntity } from '../../redux/modules/palette/node.slice';
import NodeRedNode from '../node/node-red-node';
import { CustomEngine } from './engine';
import { FlowNodeEntity } from '../../redux/modules/flow/flow.slice';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import styled from 'styled-components';
import { NodeEntity } from '../../redux/modules/node/node.slice';
import { NodeEntity } from '../../redux/modules/palette/node.slice';
import Node from './node';
import DraggableNodeWrapper from './draggable-node-wrapper'; // Import the DraggableNodeWrapper

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { useDrag } from 'react-dnd';

import { NodeEntity } from '../../redux/modules/node/node.slice';
import { NodeEntity } from '../../redux/modules/palette/node.slice';
import { ItemTypes } from '../node/draggable-item-types'; // Adjust the path as necessary

export type DraggableNodeWrapperProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import styled from 'styled-components';
import { NodeEntity } from '../../redux/modules/node/node.slice';
import { NodeEntity } from '../../redux/modules/palette/node.slice';
import Category from './category'; // Ensure this is correctly imported

export type NodeListProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import {
nodeActions,
selectFilteredNodes,
} from '../../redux/modules/node/node.slice';
} from '../../redux/modules/palette/node.slice';
import NodeList from './node-list';
import SearchBar from './search-bar';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import styled from 'styled-components';

import { NodeEntity } from '../../redux/modules/node/node.slice';
import { NodeEntity } from '../../redux/modules/palette/node.slice';
import NodeRedNode from '../node/node-red-node';

export type NodeProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from 'styled-components';

import { NodeEntity } from '../../redux/modules/node/node.slice';
import { NodeEntity } from '../../redux/modules/palette/node.slice';
import environment from '../../../environment';
import { FlowNodeEntity } from '../../redux/modules/flow/flow.slice';

Expand Down
2 changes: 1 addition & 1 deletion packages/flow-client/src/app/red/execute-script.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import environment from '../../environment';
import { FlowNodeEntity } from '../redux/modules/flow/flow.slice';
import { NodeEntity } from '../redux/modules/node/node.slice';
import { NodeEntity } from '../redux/modules/palette/node.slice';
import { JqueryContext } from './mock-jquery';
import { createMockRed } from './mock-red';

Expand Down
2 changes: 1 addition & 1 deletion packages/flow-client/src/app/redux/logic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PersistGate } from 'redux-persist/integration/react';

import { FeatureLogic } from './modules/feature/feature.logic';
import { FlowLogic } from './modules/flow/flow.logic';
import { NodeLogic } from './modules/node/node.logic';
import { NodeLogic } from './modules/palette/node.logic';
import { AppStore } from './store';

export const createLogic = () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as apiModule from '@reduxjs/toolkit/query/react';
import { MockedFunction } from 'vitest';
import { nodeActions } from '../node/node.slice';
import { nodeActions } from '../palette/node.slice';

// Mock the createApi and fetchBaseQuery functions from RTK Query
vi.mock('@reduxjs/toolkit/query/react', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-client/src/app/redux/modules/api/node.api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import environment from '../../../../environment';
import { NodeEntity, nodeActions } from '../node/node.slice';
import { NodeEntity, nodeActions } from '../palette/node.slice';
import { AppLogic } from '../../logic';

// Define a service using a base URL and expected endpoints for nodes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { MockedFunction } from 'vitest';
import '../../../../../vitest-esbuild-compat';
import { RootState } from '../../store';
import { NodeEntity, selectAllNodes, selectNodeById } from '../node/node.slice';
import {
NodeEntity,
selectAllNodes,
selectNodeById,
} from '../palette/node.slice';
import {
FlowLogic,
NodeModel,
Expand All @@ -24,7 +28,7 @@ import {

vi.mock('../node/node.slice', async importOriginal => {
const originalModule = await importOriginal<
typeof import('../node/node.slice')
typeof import('../palette/node.slice')
>();
return {
...originalModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { createSelector } from '@reduxjs/toolkit';
import { v4 as uuidv4 } from 'uuid';

import { AppDispatch, RootState } from '../../store';
import { NodeEntity, selectAllNodes, selectNodeById } from '../node/node.slice';
import {
NodeEntity,
selectAllNodes,
selectNodeById,
} from '../palette/node.slice';
import {
DirectoryEntity,
FlowEntity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { RootState } from '../../store';
import {
NODE_FEATURE_KEY,
NodeEntity,
NodeState,
nodeActions,
nodeAdapter,
nodeReducer,
selectNodeById,
PALETTE_NODE_FEATURE_KEY,
PaletteNodeEntity,
PaletteNodeState,
paletteNodeActions,
paletteNodeAdapter,
paletteNodeReducer,
selectNodesByNodeRedId,
selectPaletteNodeById,
} from './node.slice';

describe('node reducer', () => {
it('should handle initial state', () => {
const expected = nodeAdapter.getInitialState({
const expected = paletteNodeAdapter.getInitialState({
loadingStatus: 'not loaded',
error: null,
searchQuery: '',
});

expect(nodeReducer(undefined, { type: '' })).toEqual(expected);
expect(paletteNodeReducer(undefined, { type: '' })).toEqual(expected);
});

it('should handle setNodes', () => {
const initialState = nodeAdapter.getInitialState({
const initialState = paletteNodeAdapter.getInitialState({
loadingStatus: 'not loaded' as const,
error: null,
searchQuery: '',
Expand All @@ -42,7 +43,10 @@ describe('node reducer', () => {
},
];

const state = nodeReducer(initialState, nodeActions.setNodes(nodes));
const state = paletteNodeReducer(
initialState,
paletteNodeActions.setNodes(nodes)
);

expect(state).toEqual(
expect.objectContaining({
Expand All @@ -57,14 +61,14 @@ describe('node reducer', () => {
});

it('should handle updateNodeProperties', () => {
let initialState = nodeAdapter.getInitialState({
let initialState = paletteNodeAdapter.getInitialState({
loadingStatus: 'loaded' as const,
error: null,
// Assuming additional properties in the initial state
searchQuery: '',
});

initialState = nodeAdapter.setAll(initialState, [
initialState = paletteNodeAdapter.setAll(initialState, [
{
id: 'node1',
editorTemplate: '',
Expand All @@ -79,9 +83,9 @@ describe('node reducer', () => {
},
]);

const state = nodeReducer(
const state = paletteNodeReducer(
initialState,
nodeActions.updateOne({
paletteNodeActions.updateOne({
id: 'node1',
changes: {
editorTemplate: '<div>Updated</div>',
Expand Down Expand Up @@ -135,21 +139,23 @@ describe('node reducer', () => {
},
];

const initialState: NodeState = {
const initialState: PaletteNodeState = {
ids: nodes.map(node => node.id),
entities: nodes.reduce((acc, node) => {
acc[node.id] = node;
return acc;
}, {} as Record<string, NodeEntity>),
}, {} as Record<string, PaletteNodeEntity>),
loadingStatus: 'not loaded',
error: null,
searchQuery: '',
};

const state = { [NODE_FEATURE_KEY]: initialState };
const state = {
[PALETTE_NODE_FEATURE_KEY]: initialState,
} as RootState;

const selectedNode1 = selectNodeById(state, 'node1');
const selectedNode2 = selectNodeById(state, 'node2');
const selectedNode1 = selectPaletteNodeById(state, 'node1');
const selectedNode2 = selectPaletteNodeById(state, 'node2');

expect(selectedNode1).toEqual(nodes[0]);
expect(selectedNode2).toEqual(nodes[1]);
Expand All @@ -169,20 +175,25 @@ describe('node reducer', () => {
},
];

const initialState = nodeAdapter.getInitialState({
const initialState = paletteNodeAdapter.getInitialState({
ids: nodes.map(node => node.id),
entities: nodes.reduce((acc, node) => {
acc[node.id] = node;
return acc;
}, {} as Record<string, NodeEntity>),
}, {} as Record<string, PaletteNodeEntity>),
loadingStatus: 'not loaded',
error: null,
searchQuery: '',
}) as NodeState;
}) as PaletteNodeState;

const state = { [NODE_FEATURE_KEY]: initialState };
const state = {
[PALETTE_NODE_FEATURE_KEY]: initialState,
} as RootState;

const selectedNode = selectNodeById(state, 'nonExistentNodeId');
const selectedNode = selectPaletteNodeById(
state,
'nonExistentNodeId'
);

expect(selectedNode).toBeUndefined();
});
Expand All @@ -192,7 +203,7 @@ describe('node reducer', () => {
it('should return nodes that match the specified nodeRedId', () => {
// Mock state
const state = {
node: {
[PALETTE_NODE_FEATURE_KEY]: {
ids: ['node1', 'node2', 'node3'],
entities: {
node1: {
Expand Down Expand Up @@ -237,7 +248,7 @@ describe('node reducer', () => {

it('should return an empty array if no nodes match the specified nodeRedId', () => {
const state = {
node: {
[PALETTE_NODE_FEATURE_KEY]: {
ids: ['node1', 'node2', 'node3'],
entities: {
node1: {
Expand Down
Loading

0 comments on commit e5d65f3

Please sign in to comment.