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

migrate: find+replace Calculate output prop with fn #4083

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion api.planx.uk/modules/flows/downloadSchema/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const getFlowSchema = async (flowId: string) => {
planx_variable:
nodeData.data?.fn ||
nodeData.data?.val ||
nodeData.data?.output ||
Copy link
Member Author

@jessicamcinchak jessicamcinchak Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a key benefit - we only need to account for nodeData.data?.fn when getting a flow's "schema" ✔️

nodeData.data?.dataFieldBoundary,
}),
);
Expand Down
302 changes: 151 additions & 151 deletions e2e/tests/api-driven/src/invite-to-pay/mocks/flow.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/src/mocks/flows/invite-to-pay-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const flow: FlowGraph = {
},
F9iwWG1jBQ: {
data: {
output: "application.fee.payable",
fn: "application.fee.payable",
formula: "123.45",
},
type: ComponentType.Calculate,
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/src/mocks/flows/pay-flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"KzuRf6vqc1": {
"data": {
"output": "pay.test",
"fn": "pay.test",
"formula": "10"
},
"type": 700
Expand Down
6 changes: 3 additions & 3 deletions editor.planx.uk/src/@planx/components/Calculate/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export default function Component(props: Props) {
<ModalSectionContent title="Output">
<DataFieldAutocomplete
required
value={formik.values.output}
onChange={(value) => formik.setFieldValue("output", value)}
value={formik.values.fn}
onChange={(value) => formik.setFieldValue("fn", value)}
/>
<InputRow>
<Switch
Expand Down Expand Up @@ -196,7 +196,7 @@ export default function Component(props: Props) {
<></>
)}
<p>
<strong>{formik.values.output || "<output>"}</strong> would be set
<strong>{formik.values.fn || "<output>"}</strong> would be set
to <strong>{sampleResult}</strong>
</p>
</ModalSectionContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("Calculate component", () => {
const handleSubmit = vi.fn();
setup(
<Calculate
output="testGroup"
fn="testGroup"
formula="pickRandom([1,2])"
formatOutputForAutomations={true}
defaults={{}}
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/@planx/components/Calculate/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Component(props: Props) {
props.formatOutputForAutomations
? [evaluatedResult.toString()]
: evaluatedResult,
props.output,
props.fn,
),
// don't show this component to the user, auto=true required
// for back button to skip past this component when going back
Expand Down
4 changes: 2 additions & 2 deletions editor.planx.uk/src/@planx/components/Calculate/logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const flowWithAutomation: Store.Flow = {
},
Calculate: {
data: {
output: "testGroup",
fn: "testGroup",
formula: "pickRandom([1,2])",
formatOutputForAutomations: true,
},
Expand Down Expand Up @@ -108,7 +108,7 @@ const flowWithoutAutomation: Store.Flow = {
},
Calculate: {
data: {
output: "testGroup",
fn: "testGroup",
formula: "pickRandom([1,2])",
formatOutputForAutomations: false,
},
Expand Down
4 changes: 2 additions & 2 deletions editor.planx.uk/src/@planx/components/Calculate/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BaseNodeData, parseBaseNodeData } from "../shared";

export interface Calculate extends BaseNodeData {
title?: string;
output: string;
fn: string;
defaults: Record<string, number>;
formula: string;
samples: Record<string, number>;
Expand All @@ -20,7 +20,7 @@ export const parseCalculate = (
data: Record<string, any> | undefined,
): Calculate => ({
...parseBaseNodeData(data),
output: data?.output || "",
fn: data?.fn || "",
defaults: data?.defaults || {},
formula: data?.formula || "",
samples: data?.samples || {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("Calculate component", () => {
componentType: "Calculate",
headline: "calculateOutput",
iconKey: ComponentType.Calculate,
key: "Output (data)",
key: "Data",
title: "This is a calculate component",
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ const keyFormatters: KeyMap = {
getDisplayKey: () => "Formula",
getHeadline: ({ item }) => (item.data as unknown as Calculate).formula,
},
"data.output": {
getDisplayKey: () => "Output (data)",
},
// List contains data variables nested within its schema
"data.schema.fields.data.fn": {
getDisplayKey: () => "Data",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const generalData: SearchFacets = ["data.fn", "data.val"];
const fileUploadAndLabelData: SearchFacets = ["data.fileTypes.fn"];

const calculateData: SearchFacets = [
"data.output",
Copy link
Member Author

@jessicamcinchak jessicamcinchak Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another key benefit - data.output is now simply picked up by generalData search facets ✔️

{
name: "formula",
getFn: (node: IndexedNode) => Object.keys(node.data?.defaults || {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const mockFlow: FlowGraph = {
zryBH8H7vD: {
data: {
title: "This is a calculate component",
output: "calculateOutput",
fn: "calculateOutput",
formula: "formulaOne + formulaTwo",
defaults: {
formulaOne: "1",
Expand Down Expand Up @@ -623,7 +623,7 @@ export const mockCalculateRootResult: SearchResult<IndexedNode> = {
type: 700,
data: {
title: "This is a calculate component",
output: "calculateOutput",
fn: "calculateOutput",
formula: "formulaOne + formulaTwo",
defaults: {
formulaOne: "1",
Expand All @@ -633,7 +633,7 @@ export const mockCalculateRootResult: SearchResult<IndexedNode> = {
samples: {},
},
},
key: "data.output",
key: "data.fn",
matchIndices: [[0, 14]],
refIndex: 0,
matchValue: "calculateOutput",
Expand All @@ -646,7 +646,7 @@ export const mockCalculateFormulaResult: SearchResult<IndexedNode> = {
type: 700,
data: {
title: "This is a calculate component",
output: "calculateOutput",
fn: "calculateOutput",
formula: "formulaOne + formulaTwo",
defaults: {
formulaOne: "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const flow: Store.Flow = {
Calculate: {
type: TYPES.Calculate,
data: {
output: "fee",
fn: "fee",
formula: "10",
},
},
Expand Down
1 change: 0 additions & 1 deletion editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ export const editorStore: StateCreator<
};

// TODO align to (reuse?) data facets from search
if (node.data?.output) nodes.add(node.data.output);
if (node.data?.dataFieldBoundary) nodes.add(node.data.dataFieldBoundary);

if (node.data?.val) {
Expand Down
Loading