Skip to content

Commit a1363b1

Browse files
committed
fixed actions to match new naming conventions
1 parent f10d1f0 commit a1363b1

9 files changed

Lines changed: 169 additions & 165 deletions

File tree

client/ts/src/schematic/actions.gen.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import {
1717
handleRemoveEdge,
1818
handleRemoveNode,
1919
handleSetAuthority,
20+
handleSetConfig,
2021
handleSetEdge,
2122
handleSetLegend,
2223
handleSetNodePosition,
23-
handleSetProps,
2424
} from "@/schematic/actions";
2525
import { edgeZ, legendZ, nodeZ, type Schematic } from "@/schematic/types.gen";
2626

@@ -33,17 +33,17 @@ export const setNodePositionPayloadZ = z.object({
3333
export type SetNodePositionPayload = z.infer<typeof setNodePositionPayloadZ>;
3434

3535
/**
36-
* AddNode appends a node to the schematic. If props is non-empty it is stored
37-
* under the node's key in the schematic props map.
36+
* AddNode appends a node to the schematic. If config is non-empty it is stored
37+
* under the node's key in the schematic configs map.
3838
*/
3939
export const addNodePayloadZ = z.object({
4040
node: nodeZ,
41-
props: caseconv.preserveCase(zod.nullToUndefined(record.unknownZ())),
41+
config: caseconv.preserveCase(zod.nullToUndefined(record.unknownZ())),
4242
});
4343

4444
export type AddNodePayload = z.infer<typeof addNodePayloadZ>;
4545

46-
/** RemoveNode removes a node and any props stored under its key. */
46+
/** RemoveNode removes a node and any config stored under its key. */
4747
export const removeNodePayloadZ = z.object({
4848
key: z.string(),
4949
});
@@ -67,13 +67,13 @@ export const removeEdgePayloadZ = z.object({
6767

6868
export type RemoveEdgePayload = z.infer<typeof removeEdgePayloadZ>;
6969

70-
/** SetProps sets the props entry for the given node or edge key. */
71-
export const setPropsPayloadZ = z.object({
70+
/** SetConfig sets the config entry for the given node or edge key. */
71+
export const setConfigPayloadZ = z.object({
7272
key: z.string(),
73-
props: caseconv.preserveCase(record.nullishToEmpty()),
73+
config: caseconv.preserveCase(record.nullishToEmpty()),
7474
});
7575

76-
export type SetPropsPayload = z.infer<typeof setPropsPayloadZ>;
76+
export type SetConfigPayload = z.infer<typeof setConfigPayloadZ>;
7777

7878
/** SetAuthority sets the control authority level for this schematic. */
7979
export const setAuthorityPayloadZ = z.object({
@@ -95,7 +95,7 @@ export const ACTION_TYPES = {
9595
remove_node: "remove_node",
9696
set_edge: "set_edge",
9797
remove_edge: "remove_edge",
98-
set_props: "set_props",
98+
set_config: "set_config",
9999
set_authority: "set_authority",
100100
set_legend: "set_legend",
101101
} as const;
@@ -109,7 +109,7 @@ export const actionZ = z.discriminatedUnion("type", [
109109
z.object({ type: z.literal("remove_node"), removeNode: removeNodePayloadZ }),
110110
z.object({ type: z.literal("set_edge"), setEdge: setEdgePayloadZ }),
111111
z.object({ type: z.literal("remove_edge"), removeEdge: removeEdgePayloadZ }),
112-
z.object({ type: z.literal("set_props"), setProps: setPropsPayloadZ }),
112+
z.object({ type: z.literal("set_config"), setConfig: setConfigPayloadZ }),
113113
z.object({ type: z.literal("set_authority"), setAuthority: setAuthorityPayloadZ }),
114114
z.object({ type: z.literal("set_legend"), setLegend: setLegendPayloadZ }),
115115
]);
@@ -141,9 +141,9 @@ export const removeEdge = (payload: RemoveEdgePayload): Action => ({
141141
removeEdge: payload,
142142
});
143143

144-
export const setProps = (payload: SetPropsPayload): Action => ({
145-
type: "set_props",
146-
setProps: payload,
144+
export const setConfig = (payload: SetConfigPayload): Action => ({
145+
type: "set_config",
146+
setConfig: payload,
147147
});
148148

149149
export const setAuthority = (payload: SetAuthorityPayload): Action => ({
@@ -173,8 +173,8 @@ export const reduce = (state: Schematic, action: Action): Schematic => {
173173
case "remove_edge":
174174
handleRemoveEdge(state, action.removeEdge);
175175
break;
176-
case "set_props":
177-
handleSetProps(state, action.setProps);
176+
case "set_config":
177+
handleSetConfig(state, action.setConfig);
178178
break;
179179
case "set_authority":
180180
handleSetAuthority(state, action.setAuthority);

client/ts/src/schematic/actions.spec.ts

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import {
2020
removeEdge,
2121
removeNode,
2222
setAuthority,
23+
setConfig,
2324
setEdge,
2425
setLegend,
2526
setNodePosition,
26-
setProps,
2727
} from "@/schematic/actions.gen";
2828
import { ZERO_LEGEND } from "@/schematic/client";
2929
import { type Edge, type Node, type Schematic } from "@/schematic/types.gen";
@@ -53,7 +53,7 @@ const empty = (overrides: Partial<Schematic> = {}): Schematic => ({
5353
legend: ZERO_LEGEND,
5454
nodes: [],
5555
edges: [],
56-
props: {},
56+
configs: {},
5757
...overrides,
5858
});
5959

@@ -89,15 +89,15 @@ describe("schematic reducer", () => {
8989
const out = reduceAll(state, [addNode({ node: node("n2", 1, 2) })]);
9090
expect(out.nodes).toEqual([node("n1", 0, 0), node("n2", 1, 2)]);
9191
});
92-
it("should write props under the node's key when props is non-undefined", () => {
92+
it("should write config under the node's key when config is non-undefined", () => {
9393
const out = reduceAll(empty(), [
94-
addNode({ node: node("n1", 0, 0), props: { label: "Pump", color: "#f00" } }),
94+
addNode({ node: node("n1", 0, 0), config: { label: "Pump", color: "#f00" } }),
9595
]);
96-
expect(out.props).toEqual({ n1: { label: "Pump", color: "#f00" } });
96+
expect(out.configs).toEqual({ n1: { label: "Pump", color: "#f00" } });
9797
});
98-
it("should leave props untouched when the action's props is undefined", () => {
98+
it("should leave configs untouched when the action's config is undefined", () => {
9999
const out = reduceAll(empty(), [addNode({ node: node("n1", 0, 0) })]);
100-
expect(out.props).toEqual({});
100+
expect(out.configs).toEqual({});
101101
});
102102
it("should append a duplicate-key node, locking current behavior", () => {
103103
const state = empty({ nodes: [node("n1", 0, 0)] });
@@ -109,14 +109,14 @@ describe("schematic reducer", () => {
109109
});
110110

111111
describe("removeNode", () => {
112-
it("should remove the matching node and any props stored under its key", () => {
112+
it("should remove the matching node and any config stored under its key", () => {
113113
const state = empty({
114114
nodes: [node("n1", 0, 0), node("n2", 1, 1)],
115-
props: { n1: { label: "Pump" }, n2: { label: "Tank" } },
115+
configs: { n1: { label: "Pump" }, n2: { label: "Tank" } },
116116
});
117117
const out = reduceAll(state, [removeNode({ key: "n1" })]);
118118
expect(out.nodes).toEqual([node("n2", 1, 1)]);
119-
expect(out.props).toEqual({ n2: { label: "Tank" } });
119+
expect(out.configs).toEqual({ n2: { label: "Tank" } });
120120
});
121121
it("should leave existing edges intact even when they reference the removed node", () => {
122122
const state = empty({
@@ -130,11 +130,11 @@ describe("schematic reducer", () => {
130130
it("should be a no-op when the key does not match any node", () => {
131131
const state = empty({
132132
nodes: [node("n1", 0, 0)],
133-
props: { n1: { label: "Pump" } },
133+
configs: { n1: { label: "Pump" } },
134134
});
135135
const out = reduceAll(state, [removeNode({ key: "ghost" })]);
136136
expect(out.nodes).toEqual(state.nodes);
137-
expect(out.props).toEqual(state.props);
137+
expect(out.configs).toEqual(state.configs);
138138
});
139139
});
140140

@@ -176,21 +176,25 @@ describe("schematic reducer", () => {
176176
});
177177
});
178178

179-
describe("setProps", () => {
180-
it("should write the props entry under the given key", () => {
179+
describe("setConfig", () => {
180+
it("should write the config entry under the given key", () => {
181181
const out = reduceAll(empty(), [
182-
setProps({ key: "n1", props: { label: "Pump" } }),
182+
setConfig({ key: "n1", config: { label: "Pump" } }),
183183
]);
184-
expect(out.props).toEqual({ n1: { label: "Pump" } });
184+
expect(out.configs).toEqual({ n1: { label: "Pump" } });
185185
});
186-
it("should overwrite an existing props entry", () => {
187-
const state = empty({ props: { n1: { label: "Old" } } });
188-
const out = reduceAll(state, [setProps({ key: "n1", props: { label: "New" } })]);
189-
expect(out.props).toEqual({ n1: { label: "New" } });
186+
it("should overwrite an existing config entry", () => {
187+
const state = empty({ configs: { n1: { label: "Old" } } });
188+
const out = reduceAll(state, [
189+
setConfig({ key: "n1", config: { label: "New" } }),
190+
]);
191+
expect(out.configs).toEqual({ n1: { label: "New" } });
190192
});
191193
it("should accept a key that does not match any node or edge", () => {
192-
const out = reduceAll(empty(), [setProps({ key: "orphan", props: { data: 1 } })]);
193-
expect(out.props).toEqual({ orphan: { data: 1 } });
194+
const out = reduceAll(empty(), [
195+
setConfig({ key: "orphan", config: { data: 1 } }),
196+
]);
197+
expect(out.configs).toEqual({ orphan: { data: 1 } });
194198
});
195199
});
196200

@@ -254,30 +258,30 @@ describe("schematic reducer", () => {
254258
addNode({ node: node("tank", 200, 0) }),
255259
setEdge({ edge: edge("e1", "pump", "out", "valve", "in") }),
256260
setEdge({ edge: edge("e2", "valve", "out", "tank", "in") }),
257-
setProps({ key: "pump", props: { label: "Main Pump" } }),
258-
setProps({ key: "e1", props: { variant: "pipe" } }),
261+
setConfig({ key: "pump", config: { label: "Main Pump" } }),
262+
setConfig({ key: "e1", config: { variant: "pipe" } }),
259263
]);
260264
expect(out.nodes).toHaveLength(3);
261265
expect(out.edges).toHaveLength(2);
262-
expect(out.props).toEqual({
266+
expect(out.configs).toEqual({
263267
pump: { label: "Main Pump" },
264268
e1: { variant: "pipe" },
265269
});
266270
});
267271

268-
it("should drop props but keep dangling edges when a node is removed and re-added", () => {
272+
it("should drop config but keep dangling edges when a node is removed and re-added", () => {
269273
const state = empty({
270274
nodes: [node("n1", 0, 0), node("n2", 1, 1)],
271275
edges: [edge("e1", "n1", "o", "n2", "i")],
272-
props: { n1: { label: "v1" } },
276+
configs: { n1: { label: "v1" } },
273277
});
274278
const out = reduceAll(state, [
275279
removeNode({ key: "n1" }),
276280
addNode({ node: node("n1", 50, 50) }),
277281
]);
278282
expect(out.nodes).toHaveLength(2);
279283
expect(out.nodes[1]).toEqual(node("n1", 50, 50));
280-
expect(out.props).toEqual({});
284+
expect(out.configs).toEqual({});
281285
expect(out.edges).toHaveLength(1);
282286
expect(out.edges[0].source.node).toBe("n1");
283287
});
@@ -308,8 +312,8 @@ describe("schematic reducer", () => {
308312
}),
309313
);
310314
for (let i = 0; i < 3; i++)
311-
actions.push(setProps({ key: `n${i}`, props: { label: `node ${i}` } }));
312-
actions.push(setProps({ key: "e1", props: { variant: "electric" } }));
315+
actions.push(setConfig({ key: `n${i}`, config: { label: `node ${i}` } }));
316+
actions.push(setConfig({ key: "e1", config: { variant: "electric" } }));
313317
actions.push(setAuthority({ value: 255 }));
314318
actions.push(
315319
setLegend({
@@ -321,7 +325,7 @@ describe("schematic reducer", () => {
321325
expect(out.nodes[0].position).toEqual({ x: 0, y: 100 });
322326
expect(out.nodes[4].position).toEqual({ x: 400, y: 100 });
323327
expect(out.edges).toHaveLength(4);
324-
expect(Object.keys(out.props)).toHaveLength(4);
328+
expect(Object.keys(out.configs)).toHaveLength(4);
325329
expect(out.authority).toBe(255);
326330
expect(out.legend.visible).toBe(true);
327331
});

client/ts/src/schematic/actions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import {
1212
type RemoveEdgePayload,
1313
type RemoveNodePayload,
1414
type SetAuthorityPayload,
15+
type SetConfigPayload,
1516
type SetEdgePayload,
1617
type SetLegendPayload,
1718
type SetNodePositionPayload,
18-
type SetPropsPayload,
1919
} from "@/schematic/actions.gen";
2020
import { type Schematic } from "@/schematic/types.gen";
2121

@@ -29,7 +29,7 @@ export const handleSetNodePosition = (
2929

3030
export const handleAddNode = (state: Schematic, payload: AddNodePayload): void => {
3131
state.nodes.push(payload.node);
32-
if (payload.props != null) state.props[payload.node.key] = payload.props;
32+
if (payload.config != null) state.configs[payload.node.key] = payload.config;
3333
};
3434

3535
export const handleRemoveNode = (
@@ -38,7 +38,7 @@ export const handleRemoveNode = (
3838
): void => {
3939
const idx = state.nodes.findIndex((n) => n.key === payload.key);
4040
if (idx !== -1) state.nodes.splice(idx, 1);
41-
delete state.props[payload.key];
41+
delete state.configs[payload.key];
4242
};
4343

4444
export const handleSetEdge = (state: Schematic, payload: SetEdgePayload): void => {
@@ -55,8 +55,8 @@ export const handleRemoveEdge = (
5555
if (idx !== -1) state.edges.splice(idx, 1);
5656
};
5757

58-
export const handleSetProps = (state: Schematic, payload: SetPropsPayload): void => {
59-
state.props[payload.key] = payload.props;
58+
export const handleSetConfig = (state: Schematic, payload: SetConfigPayload): void => {
59+
state.configs[payload.key] = payload.config;
6060
};
6161

6262
export const handleSetAuthority = (

0 commit comments

Comments
 (0)