Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: undo operations to a flow #3056

Merged
merged 15 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 16 additions & 36 deletions editor.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions editor.planx.uk/src/@planx/graph/__tests__/formatOps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Update operations", () => {
];

expect(formatOps(flowWithChecklist, ops)).toEqual([
"Updated Checklist info", // shows prop name "info", without content
`Updated Checklist help text ("Why it matters")`, // shows prop name "info", without content
]);
});

Expand All @@ -46,9 +46,9 @@ describe("Update operations", () => {
];

expect(formatOps(flowWithChecklist, ops)).toEqual([
'Added Checklist fn "fruit"',
'Added Answer val "berry.blue"',
'Added Answer val "banana"',
'Added Checklist data field "fruit"',
'Added Answer data field "berry.blue"',
'Added Answer data field "banana"',
]);
});
});
Expand Down Expand Up @@ -165,7 +165,7 @@ describe("Insert operations", () => {
];

expect(formatOps(flowWithChecklist, ops)).toEqual([
`Added Checklist fn "food.fruit"`, // shows prop name "fn" and content
`Added Checklist data field "food.fruit"`, // shows prop name "fn" and content
]);
});

Expand Down
50 changes: 35 additions & 15 deletions editor.planx.uk/src/@planx/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,17 @@ export const formatOps = (graph: Graph, ops: Array<OT.Op>): string[] => {
const output: string[] = [];

// Only show full change description for simple props, omit complex or long ones like `moreInfo`, `fileTypes`, etc
const allowProps = ["title", "text", "fn", "val"];
const allowProps: string[] = ["title", "text", "fn", "val"];

// Create a simple lookup to overwrite most common component props to a more human-readable name
const propsMap: Record<string, string> = {
jessicamcinchak marked this conversation as resolved.
Show resolved Hide resolved
fn: "data field",
val: "data field",
info: `help text ("Why it matters")`,
howMeasured: `help text ("How is it defined?")`,
policyRef: `help text source links`,
definitionImg: `help text image`,
};

// Updating a node or its properties (update = delete + insert)
const handleUpdate = (node: Node, op: OT.Object.Replace) => {
Expand All @@ -531,14 +541,18 @@ export const formatOps = (graph: Graph, ops: Array<OT.Op>): string[] => {
}"`,
);
} else if (op.p.includes("data")) {
if (allowProps.includes(`${op.p?.[2]}`)) {
const prop = op.p?.[2] as string;
if (allowProps.includes(prop)) {
output.push(
`Updated ${node?.type ? TYPES[node.type] : "node"} ${op
.p?.[2]} from "${op.od}" to "${op.oi}"`,
`Updated ${node?.type ? TYPES[node.type] : "node"} ${
propsMap[prop] || prop
} from "${op.od}" to "${op.oi}"`,
);
} else {
output.push(
`Updated ${node?.type ? TYPES[node.type] : "node"} ${op.p?.[2]}`,
`Updated ${node?.type ? TYPES[node.type] : "node"} ${
propsMap[prop] || prop
}`,
);
}
} else if (op.p.includes("edges")) {
Expand Down Expand Up @@ -570,15 +584,18 @@ export const formatOps = (graph: Graph, ops: Array<OT.Op>): string[] => {
}"`,
);
} else if (op.p.includes("data")) {
if (allowProps.includes(`${op.p?.[2]}`)) {
const prop = op.p?.[2] as string;
if (allowProps.includes(prop)) {
output.push(
`Added ${node?.type ? TYPES[node?.type] : "node"} ${op.p?.[2]} "${
op.oi
}"`,
`Added ${node?.type ? TYPES[node?.type] : "node"} ${
propsMap[prop] || prop
} "${op.oi}"`,
);
} else {
output.push(
`Added ${node?.type ? TYPES[node?.type] : "node"} ${op.p?.[2]}`,
`Added ${node?.type ? TYPES[node?.type] : "node"} ${
propsMap[prop] || prop
}`,
);
}
} else if (op.p.includes("edges")) {
Expand All @@ -600,15 +617,18 @@ export const formatOps = (graph: Graph, ops: Array<OT.Op>): string[] => {
}"`,
);
} else if (op.p.includes("data")) {
if (allowProps.includes(`${op.p?.[2]}`)) {
const prop = op.p?.[2] as string;
if (allowProps.includes(prop)) {
output.push(
`Removed ${node?.type ? TYPES[node.type] : "node"} ${op.p?.[2]} "${
op.od
}"`,
`Removed ${node?.type ? TYPES[node.type] : "node"} ${
propsMap[prop] || prop
} "${op.od}"`,
);
} else {
output.push(
`Removed ${node?.type ? TYPES[node.type] : "node"} ${op.p?.[2]}`,
`Removed ${node?.type ? TYPES[node.type] : "node"} ${
propsMap[prop] || prop
}`,
);
}
} else if (op.p.includes("edges")) {
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.