Skip to content

Commit

Permalink
set default schema options and remove getFlowSchema()?.nodes calls pe…
Browse files Browse the repository at this point in the history
…r component
  • Loading branch information
jessicamcinchak committed Dec 20, 2024
1 parent 5114475 commit 867a6c2
Show file tree
Hide file tree
Showing 12 changed files with 3 additions and 44 deletions.
3 changes: 0 additions & 3 deletions editor.planx.uk/src/@planx/components/AddressInput/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export default function AddressInputComponent(props: Props): FCReturn {
validate: () => { },
});

const schema = useStore().getFlowSchema()?.nodes;

return (
<form onSubmit={formik.handleSubmit} id="modal">
<ModalSection>
Expand All @@ -58,7 +56,6 @@ export default function AddressInputComponent(props: Props): FCReturn {
</InputRow>
<DataFieldAutocomplete
required
schema={schema}
value={formik.values.fn}
onChange={(value) => formik.setFieldValue("fn", value)}
/>
Expand Down
4 changes: 0 additions & 4 deletions editor.planx.uk/src/@planx/components/Calculate/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import { Switch } from "ui/shared/Switch";

import { useStore } from "pages/FlowEditor/lib/store";
import { DataFieldAutocomplete } from "../shared/DataFieldAutocomplete";
import { ICONS } from "../shared/icons";
import type { Calculate } from "./model";
Expand Down Expand Up @@ -104,8 +103,6 @@ export default function Component(props: Props) {
}
}, [formik.values.formula]);

const schema = useStore().getFlowSchema()?.nodes;

return (
<form onSubmit={formik.handleSubmit} id="modal">
<ModalSection>
Expand All @@ -130,7 +127,6 @@ export default function Component(props: Props) {
<ModalSectionContent title="Output">
<DataFieldAutocomplete
required
schema={schema}
value={formik.values.output}
onChange={(value) => formik.setFieldValue("output", value)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import InputRow from "ui/shared/InputRow";
import { Switch } from "ui/shared/Switch";

import { DataFieldAutocomplete } from "@planx/components/shared/DataFieldAutocomplete";
import { useStore } from "pages/FlowEditor/lib/store";
import { Option, parseBaseNodeData } from "../../shared";
import { ICONS } from "../../shared/icons";
import type { Checklist } from "../model";
Expand Down Expand Up @@ -110,8 +109,6 @@ export const ChecklistEditor: React.FC<ChecklistProps> = (props) => {
}, 50);
}, []);

const schema = useStore().getFlowSchema()?.nodes;

return (
<form onSubmit={formik.handleSubmit} id="modal">
<ModalSection>
Expand Down Expand Up @@ -143,7 +140,6 @@ export const ChecklistEditor: React.FC<ChecklistProps> = (props) => {
/>
</InputRow>
<DataFieldAutocomplete
schema={schema}
value={formik.values.fn}
onChange={(value) => formik.setFieldValue("fn", value)}
/>
Expand Down
4 changes: 0 additions & 4 deletions editor.planx.uk/src/@planx/components/ContactInput/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { useStore } from "pages/FlowEditor/lib/store";
import { DataFieldAutocomplete } from "../shared/DataFieldAutocomplete";
import { ICONS } from "../shared/icons";
import { ContactInput, parseContactInput } from "./model";
Expand All @@ -30,8 +29,6 @@ export default function ContactInputComponent(props: Props): FCReturn {
validate: () => {},
});

const schema = useStore().getFlowSchema()?.nodes;

return (
<form onSubmit={formik.handleSubmit} id="modal">
<ModalSection>
Expand All @@ -58,7 +55,6 @@ export default function ContactInputComponent(props: Props): FCReturn {
</InputRow>
<DataFieldAutocomplete
required
schema={schema}
value={formik.values.fn}
onChange={(value) => formik.setFieldValue("fn", value)}
/>
Expand Down
4 changes: 0 additions & 4 deletions editor.planx.uk/src/@planx/components/DateInput/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import DateInputUi from "ui/shared/DateInput/DateInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { useStore } from "pages/FlowEditor/lib/store";
import { DataFieldAutocomplete } from "../shared/DataFieldAutocomplete";
import { ICONS } from "../shared/icons";

Expand All @@ -38,8 +37,6 @@ const DateInputComponent: React.FC<Props> = (props) => {
validationSchema: editorValidationSchema(),
});

const schema = useStore().getFlowSchema()?.nodes;

return (
<form onSubmit={formik.handleSubmit} id="modal" name="modal">
<ModalSection>
Expand All @@ -62,7 +59,6 @@ const DateInputComponent: React.FC<Props> = (props) => {
/>
</InputRow>
<DataFieldAutocomplete
schema={schema}
value={formik.values.fn}
onChange={(value) => formik.setFieldValue("fn", value)}
/>
Expand Down
4 changes: 0 additions & 4 deletions editor.planx.uk/src/@planx/components/List/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import InputRow from "ui/shared/InputRow";
import InputRowItem from "ui/shared/InputRowItem";
import InputRowLabel from "ui/shared/InputRowLabel";

import { useStore } from "pages/FlowEditor/lib/store";
import { DataFieldAutocomplete } from "../shared/DataFieldAutocomplete";
import { ICONS } from "../shared/icons";
import { EditorProps } from "../shared/types";
Expand Down Expand Up @@ -94,8 +93,6 @@ function ListComponent(props: Props) {
validateOnChange: false,
});

const dataFieldSchema = useStore().getFlowSchema()?.nodes;

return (
<form onSubmit={formik.handleSubmit} id="modal">
<ModalSection>
Expand All @@ -120,7 +117,6 @@ function ListComponent(props: Props) {
</InputRow>
<DataFieldAutocomplete
required
schema={dataFieldSchema}
value={formik.values.fn}
onChange={(value) => formik.setFieldValue("fn", value)}
/>
Expand Down
4 changes: 0 additions & 4 deletions editor.planx.uk/src/@planx/components/MapAndLabel/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import InputRowItem from "ui/shared/InputRowItem";

import { useStore } from "pages/FlowEditor/lib/store";
import { DataFieldAutocomplete } from "../shared/DataFieldAutocomplete";
import { ICONS } from "../shared/icons";
import BasicRadio from "../shared/Radio/BasicRadio";
Expand All @@ -42,8 +41,6 @@ function MapAndLabelComponent(props: Props) {
},
});

const dataFieldSchema = useStore().getFlowSchema()?.nodes;

return (
<form onSubmit={formik.handleSubmit} id="modal">
<ModalSection>
Expand Down Expand Up @@ -72,7 +69,6 @@ function MapAndLabelComponent(props: Props) {
</InputRow>
<DataFieldAutocomplete
required
schema={dataFieldSchema}
value={formik.values.fn}
onChange={(value) => formik.setFieldValue("fn", value)}
/>
Expand Down
4 changes: 0 additions & 4 deletions editor.planx.uk/src/@planx/components/NumberInput/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import InputRowItem from "ui/shared/InputRowItem";
import InputRowLabel from "ui/shared/InputRowLabel";
import { Switch } from "ui/shared/Switch";

import { useStore } from "pages/FlowEditor/lib/store";
import { DataFieldAutocomplete } from "../shared/DataFieldAutocomplete";
import { ICONS } from "../shared/icons";

Expand All @@ -31,8 +30,6 @@ export default function NumberInputComponent(props: Props): FCReturn {
validate: () => {},
});

const schema = useStore().getFlowSchema()?.nodes;

return (
<form onSubmit={formik.handleSubmit} id="modal">
<ModalSection>
Expand All @@ -58,7 +55,6 @@ export default function NumberInputComponent(props: Props): FCReturn {
/>
</InputRow>
<DataFieldAutocomplete
schema={schema}
value={formik.values.fn}
onChange={(value) => formik.setFieldValue("fn", value)}
/>
Expand Down
4 changes: 0 additions & 4 deletions editor.planx.uk/src/@planx/components/Page/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import InputRow from "ui/shared/InputRow";
import InputRowItem from "ui/shared/InputRowItem";
import InputRowLabel from "ui/shared/InputRowLabel";

import { useStore } from "pages/FlowEditor/lib/store";
import { DataFieldAutocomplete } from "../shared/DataFieldAutocomplete";
import { ICONS } from "../shared/icons";
import { EditorProps } from "../shared/types";
Expand All @@ -36,8 +35,6 @@ function PageComponent(props: Props) {
},
});

const dataFieldSchema = useStore().getFlowSchema()?.nodes;

return (
<form onSubmit={formik.handleSubmit} id="modal">
<ModalSection>
Expand All @@ -62,7 +59,6 @@ function PageComponent(props: Props) {
</InputRow>
<DataFieldAutocomplete
required
schema={dataFieldSchema}
value={formik.values.fn}
onChange={(value) => formik.setFieldValue("fn", value)}
/>
Expand Down
4 changes: 0 additions & 4 deletions editor.planx.uk/src/@planx/components/SetValue/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import ModalSectionContent from "ui/editor/ModalSectionContent";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { useStore } from "pages/FlowEditor/lib/store";
import { DataFieldAutocomplete } from "../shared/DataFieldAutocomplete";
import { parseSetValue, SetValue } from "./model";

Expand Down Expand Up @@ -94,15 +93,12 @@ function SetValueComponent(props: Props) {
formik.setFieldValue("operation", target.value);
};

const schema = useStore().getFlowSchema()?.nodes;

return (
<form onSubmit={formik.handleSubmit} id="modal">
<ModalSection>
<ModalSectionContent title="Passport field name">
<DataFieldAutocomplete
required
schema={schema}
value={formik.values.fn}
onChange={(value) => formik.setFieldValue("fn", value)}
/>
Expand Down
4 changes: 0 additions & 4 deletions editor.planx.uk/src/@planx/components/TextInput/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";

import { useStore } from "pages/FlowEditor/lib/store";
import { DataFieldAutocomplete } from "../shared/DataFieldAutocomplete";
import { ICONS } from "../shared/icons";
import { parseTextInput, TextInput } from "./model";
Expand All @@ -33,8 +32,6 @@ const TextInputComponent: React.FC<Props> = (props) => {
validate: () => { },
});

const schema = useStore().getFlowSchema()?.nodes;

const handleRadioChange = (event: React.SyntheticEvent<Element, Event>) => {
const target = event.target as HTMLInputElement;
formik.setFieldValue("type", target.value);
Expand Down Expand Up @@ -62,7 +59,6 @@ const TextInputComponent: React.FC<Props> = (props) => {
/>
</InputRow>
<DataFieldAutocomplete
schema={schema}
value={formik.values.fn}
onChange={(value) => formik.setFieldValue("fn", value)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "@mui/material/Autocomplete";
import ListItem from "@mui/material/ListItem";
import isNull from "lodash/isNull";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { useMemo } from "react";
import AutocompleteInput from "ui/shared/AutocompleteInput";
import InputRow from "ui/shared/InputRow";
Expand Down Expand Up @@ -33,7 +34,8 @@ const renderOptions: AutocompleteProps<
const filter = createFilterOptions<string>();

export const DataFieldAutocomplete: React.FC<Props> = (props) => {
const { value: initialValue, schema: options = [] } = props;
const defaultSchema = useStore().getFlowSchema()?.nodes || [];
const { value: initialValue, schema: options = defaultSchema } = props;

const value: string | undefined = useMemo(
() => options?.find((option) => option === initialValue),
Expand Down

0 comments on commit 867a6c2

Please sign in to comment.