Skip to content

Commit

Permalink
migrate: find+replace Calculate output prop with fn (#4083)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak authored Jan 8, 2025
1 parent 9ab99a3 commit bfec874
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 174 deletions.
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 ||
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",
{
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

0 comments on commit bfec874

Please sign in to comment.