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

Merge master #3223

Merged
merged 4 commits into from
Nov 20, 2023
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
10 changes: 1 addition & 9 deletions frontend/src/js/external-forms/form-components/DropzoneList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import DropzoneWithFileInput, {
DragItemFile,
} from "../../ui-components/DropzoneWithFileInput";
import Label from "../../ui-components/Label";
import Optional from "../../ui-components/Optional";

import DropzoneBetweenElements from "./DropzoneBetweenElements";

Expand Down Expand Up @@ -56,7 +55,6 @@ interface PropsT<DroppableObject> {
className?: string;
label?: ReactNode;
tooltip?: string;
optional?: boolean;
dropzoneChildren: (args: ChildArgs<DroppableObject>) => ReactNode;
items: ReactNode[];
acceptedDropTypes: string[];
Expand All @@ -78,7 +76,6 @@ const DropzoneList = <DroppableObject extends PossibleDroppableObject>(
className,
label,
tooltip,
optional,
dropzoneChildren,
items,
acceptedDropTypes,
Expand All @@ -97,12 +94,7 @@ const DropzoneList = <DroppableObject extends PossibleDroppableObject>(
return (
<div className={className}>
<Row>
{label && (
<Label>
{optional && <Optional />}
{label}
</Label>
)}
{label && <Label>{label}</Label>}
{tooltip && <InfoTooltip text={tooltip} />}
</Row>
{items && items.length > 0 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ interface Props {
tooltip?: string;
newValue: FormConceptGroupT;
isSingle?: boolean;
optional?: boolean;
disallowMultipleColumns?: boolean;
blocklistedTables?: string[];
allowlistedTables?: string[];
Expand Down Expand Up @@ -190,7 +189,6 @@ const FormConceptGroup = (props: Props) => {
<DropzoneList /* TODO: ADD GENERIC TYPE <ConceptQueryNodeType> */
ref={dropzoneRef}
tooltip={props.tooltip}
optional={props.optional}
label={
<>
{props.label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { DragItemQuery } from "../../standard-query-editor/types";
import InfoTooltip from "../../tooltip/InfoTooltip";
import Dropzone from "../../ui-components/Dropzone";
import Label from "../../ui-components/Label";
import Optional from "../../ui-components/Optional";

import ValidatedFormQueryResult from "./ValidatedFormQueryResult";

Expand All @@ -23,7 +22,6 @@ const DROP_TYPES = [
interface PropsT {
label: string;
tooltip?: string;
optional?: boolean;
dropzoneText: string;
className?: string;
value: DragItemQuery | null;
Expand All @@ -33,7 +31,6 @@ interface PropsT {
const FormQueryDropzone: FC<PropsT> = ({
label,
tooltip,
optional,
dropzoneText,
className,
value,
Expand All @@ -60,7 +57,6 @@ const FormQueryDropzone: FC<PropsT> = ({
return (
<div className={className}>
<Label>
{optional && <Optional />}
{label}
{exists(tooltip) && <InfoTooltip text={tooltip} />}
</Label>
Expand Down
68 changes: 16 additions & 52 deletions frontend/src/js/external-forms/form/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ import FormConceptGroup from "../form-concept-group/FormConceptGroup";
import type { FormConceptGroupT } from "../form-concept-group/formConceptGroupState";
import FormQueryDropzone from "../form-query-dropzone/FormQueryDropzone";
import FormTabNavigation from "../form-tab-navigation/FormTabNavigation";
import {
getFieldKey,
getInitialValue,
isFormField,
isOptionalField,
} from "../helper";
import { getFieldKey, getInitialValue, isFormField } from "../helper";
import { getErrorForField } from "../validators";

import type { DynamicFormValues } from "./Form";
Expand Down Expand Up @@ -165,35 +160,28 @@ const NestedFields = styled("div")`
border-radius: ${({ theme }) => theme.borderRadius};
`;

interface PropsT {
const setValueConfig = {
shouldValidate: true,
shouldDirty: true,
shouldTouch: true,
};

const Field = ({
field,
...commonProps
}: {
formType: string;
h1Index?: number;
field: GeneralField;
locale: Language;
availableDatasets: SelectOptionT[];
optional?: boolean;
register: UseFormRegister<DynamicFormValues>;
setValue: UseFormSetValue<DynamicFormValues>;
control: Control<DynamicFormValues>;
}

const setValueConfig = {
shouldValidate: true,
shouldDirty: true,
shouldTouch: true,
};

const Field = ({ field, ...commonProps }: PropsT) => {
}) => {
const datasetId = useDatasetId();
const {
formType,
h1Index,
optional,
locale,
availableDatasets,
setValue,
control,
} = commonProps;
const { formType, h1Index, locale, availableDatasets, setValue, control } =
commonProps;
const { t } = useTranslation();

const defaultValue =
Expand Down Expand Up @@ -238,7 +226,6 @@ const Field = ({ field, ...commonProps }: PropsT) => {
value={fieldProps.value as string}
onChange={(value) => setValue(field.name, value, setValueConfig)}
tooltip={field.tooltip ? field.tooltip[locale] : undefined}
optional={optional}
/>
)}
</ConnectedField>
Expand All @@ -263,7 +250,6 @@ const Field = ({ field, ...commonProps }: PropsT) => {
setValue(field.name, value, setValueConfig);
}}
tooltip={field.tooltip ? field.tooltip[locale] : undefined}
optional={optional}
/>
)}
</ConnectedField>
Expand Down Expand Up @@ -292,7 +278,6 @@ const Field = ({ field, ...commonProps }: PropsT) => {
max: field.max,
}}
tooltip={field.tooltip ? field.tooltip[locale] : undefined}
optional={optional}
/>
)}
</ConnectedField>
Expand All @@ -310,7 +295,6 @@ const Field = ({ field, ...commonProps }: PropsT) => {
inline={true}
label={field.label[locale]}
tooltip={field.tooltip ? field.tooltip[locale] : undefined}
optional={optional}
value={fieldProps.value as DateStringMinMax}
onChange={(value) =>
setValue(field.name, value, setValueConfig)
Expand All @@ -332,7 +316,6 @@ const Field = ({ field, ...commonProps }: PropsT) => {
label={field.label[locale] || ""}
dropzoneText={field.dropzoneLabel[locale] || ""}
tooltip={field.tooltip ? field.tooltip[locale] : undefined}
optional={optional}
value={fieldProps.value as DragItemQuery}
onChange={(value) => setValue(field.name, value, setValueConfig)}
/>
Expand Down Expand Up @@ -372,7 +355,6 @@ const Field = ({ field, ...commonProps }: PropsT) => {
value: option.value,
}))}
tooltip={field.tooltip ? field.tooltip[locale] : undefined}
optional={optional}
value={fieldProps.value as SelectOptionT | null}
onChange={(value) => setValue(field.name, value, setValueConfig)}
/>
Expand All @@ -397,7 +379,6 @@ const Field = ({ field, ...commonProps }: PropsT) => {
label={field.label[locale]}
options={availableDatasets}
tooltip={field.tooltip ? field.tooltip[locale] : undefined}
optional={optional}
value={fieldProps.value as SelectOptionT | null}
onChange={(value) =>
setValue(field.name, value, setValueConfig)
Expand Down Expand Up @@ -425,16 +406,8 @@ const Field = ({ field, ...commonProps }: PropsT) => {
>
{field.fields.map((f, i) => {
const key = getFieldKey(formType, f, i);
const nestedFieldOptional = isOptionalField(f);

return (
<Field
key={key}
field={f}
{...commonProps}
optional={nestedFieldOptional}
/>
);
return <Field key={key} field={f} {...commonProps} />;
})}
</Group>
</>
Expand Down Expand Up @@ -469,16 +442,8 @@ const Field = ({ field, ...commonProps }: PropsT) => {
<NestedFields>
{tabToShow.fields.map((f, i) => {
const key = getFieldKey(formType, f, i);
const nestedFieldOptional = isOptionalField(f);

return (
<Field
key={key}
field={f}
{...commonProps}
optional={nestedFieldOptional}
/>
);
return <Field key={key} field={f} {...commonProps} />;
})}
</NestedFields>
) : (
Expand Down Expand Up @@ -521,7 +486,6 @@ const Field = ({ field, ...commonProps }: PropsT) => {
blocklistedSelects={field.blocklistedSelects}
allowlistedSelects={field.allowlistedSelects}
defaults={field.defaults}
optional={optional}
isValidConcept={(item) =>
!nodeIsInvalid(
item,
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/js/external-forms/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { SelectOptionT } from "../../api/types";
import { useActiveLang } from "../../localization/useActiveLang";
import FormHeader from "../FormHeader";
import type { Form as FormType } from "../config-types";
import { getFieldKey, getH1Index, isOptionalField } from "../helper";
import { getFieldKey, getH1Index } from "../helper";

import Field from "./Field";

Expand Down Expand Up @@ -44,7 +44,6 @@ const Form = memo(({ config, datasetOptions, methods }: Props) => {
)}
{config.fields.map((field, i) => {
const key = getFieldKey(config.type, field, i);
const optional = isOptionalField(field);
const h1Index = getH1Index(config.fields, field);

return (
Expand All @@ -58,7 +57,6 @@ const Form = memo(({ config, datasetOptions, methods }: Props) => {
setValue={methods.setValue}
availableDatasets={datasetOptions}
locale={activeLang}
optional={optional}
/>
);
})}
Expand Down
9 changes: 0 additions & 9 deletions frontend/src/js/external-forms/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ export const getH1Index = (fields: GeneralField[], field: GeneralField) => {
return h1Fields.indexOf(field);
};

export const isOptionalField = (field: GeneralField) => {
return (
isFormField(field) &&
(!("validations" in field) ||
("validations" in field &&
(!field.validations || !field.validations.includes("NOT_EMPTY"))))
);
};

export const isFormField = (field: GeneralField): field is FormField => {
return !nonFormFieldTypes.has(field.type);
};
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/js/ui-components/InputDateRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import InfoTooltip from "../tooltip/InfoTooltip";
import InputDate from "./InputDate/InputDate";
import Label from "./Label";
import Labeled from "./Labeled";
import Optional from "./Optional";

const Root = styled("div")<{ center?: boolean }>`
text-align: ${({ center }) => (center ? "center" : "left")};
Expand Down Expand Up @@ -88,7 +87,6 @@ interface PropsT {
center?: boolean;
autoFocus?: boolean;
tooltip?: string;
optional?: boolean;
value: DateStringMinMax;
onChange: (value: DateStringMinMax) => void;
}
Expand All @@ -115,7 +113,6 @@ const InputDateRange: FC<PropsT> = ({
labelSuffix,
value,
onChange,
optional,
tooltip,
}) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -179,7 +176,6 @@ const InputDateRange: FC<PropsT> = ({
<StyledLabel large={large}>
<Icon icon={faCalendar} left gray />
{exists(indexPrefix) && <IndexPrefix># {indexPrefix}</IndexPrefix>}
{optional && <Optional />}
{label}
<InfoTooltip
html={
Expand All @@ -197,7 +193,7 @@ const InputDateRange: FC<PropsT> = ({
{labelSuffix && labelSuffix}
</StyledLabel>
);
}, [t, label, labelSuffix, large, optional, tooltip, indexPrefix]);
}, [t, label, labelSuffix, large, tooltip, indexPrefix]);

return (
<Root center={center}>
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/js/ui-components/InputPlain/InputPlain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const SxBaseInput = styled(BaseInput)<{ fullWidth?: boolean }>`
interface Props {
label: string;
indexPrefix?: number;
optional?: boolean;
inputType?: string;
money?: boolean;
className?: string;
Expand All @@ -44,7 +43,6 @@ const InputPlain = forwardRef<HTMLInputElement, Props>(
large,
indexPrefix,
tooltip,
optional,
inputType = "text",
money,
placeholder,
Expand All @@ -65,7 +63,6 @@ const InputPlain = forwardRef<HTMLInputElement, Props>(
largeLabel={large}
indexPrefix={indexPrefix}
tooltip={tooltip}
optional={optional}
>
<SxBaseInput
ref={ref}
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/js/ui-components/InputSelect/InputSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const InputSelect = ({
clearable,
className,
value,
optional,
smallMenu,
onChange,
sortOptions,
Expand All @@ -67,7 +66,6 @@ const InputSelect = ({
className?: string;
dataTestId?: string;
value: SelectOptionT | null;
optional?: boolean;
onChange: (value: SelectOptionT | null) => void;
sortOptions?: (a: SelectOptionT, b: SelectOptionT, query: string) => number;
}) => {
Expand Down Expand Up @@ -347,7 +345,6 @@ const InputSelect = ({
}
indexPrefix={indexPrefix}
className={className}
optional={optional}
>
{Select}
</Labeled>
Expand Down
Loading
Loading