Skip to content

Commit

Permalink
Merge pull request #372 from ConductionNL/fix/missing-fields
Browse files Browse the repository at this point in the history
Many missing fields added
  • Loading branch information
remko48 authored Jun 3, 2024
2 parents f4e5fce + 7ec883d commit 9835d39
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CodeEditor } from "../../../components/codeEditor/CodeEditor";
import { translateDate } from "../../../services/dateFormat";
import { StatusTag } from "../../../components/statusTag/StatusTag";
import { formatDateTime } from "../../../services/dateTime";
import { useUser } from "../../../hooks/user";

export const formId: string = "action-form";

Expand All @@ -44,6 +45,9 @@ export const ActionFormTemplate: React.FC<ActionFormTemplateProps> = ({ action }
const _useCronjob = useCronjob(queryClient);
const getCronjobs = _useCronjob.getAll();

const _useUsers = useUser(queryClient);
const getUsers = _useUsers.getAll();

const {
register,
handleSubmit,
Expand Down Expand Up @@ -81,6 +85,7 @@ export const ActionFormTemplate: React.FC<ActionFormTemplateProps> = ({ action }
listens: data.listens?.map((listener: any) => listener.value),
throws: data.throws?.map((_throw: any) => _throw.value),
class: data.class.value,
userId: data.userId?.value ?? null,
conditions: actionConditionsFieldValue ? JSON.parse(actionConditionsFieldValue) : [],
configuration: {},
};
Expand All @@ -96,13 +101,28 @@ export const ActionFormTemplate: React.FC<ActionFormTemplateProps> = ({ action }
};

const handleSetFormValues = (): void => {
const basicFields: string[] = ["reference", "name", "description", "priority", "async", "isLockable", "isEnabled"];
const basicFields: string[] = [
"reference",
"version",
"name",
"description",
"priority",
"async",
"isLockable",
"isEnabled",
];
basicFields.forEach((field) => setValue(field, action[field]));

setActionConditionsFieldValue(JSON.stringify(action["conditions"], null, 2));

setValue("class", { label: action.class, value: action.class });

for (const [key, value] of Object.entries(getUsers?.data)) {
if (value?.id === action?.userId) {
setValue("userId", { label: setUserIdLabel(value), value: value.id });
}
}

setValue(
"listens",
action["listens"].map((listen: any) => ({ label: listen, value: listen })),
Expand Down Expand Up @@ -131,6 +151,10 @@ export const ActionFormTemplate: React.FC<ActionFormTemplateProps> = ({ action }
}
};

const setUserIdLabel = (user: any): string => {
return user.name + (" - " + user?.organization?.name);
};

React.useEffect(() => {
action && handleSetFormValues();
}, [action]);
Expand Down Expand Up @@ -166,6 +190,19 @@ export const ActionFormTemplate: React.FC<ActionFormTemplateProps> = ({ action }
</FormFieldInput>
</FormField>

<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Version")}</FormFieldLabel>
<InputText
{...{ register, errors }}
name="version"
disabled={isLoading.actionForm}
defaultValue={action?.version ?? "0.0.0"}
ariaLabel={t("Enter version")}
/>
</FormFieldInput>
</FormField>

<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Name")}</FormFieldLabel>
Expand Down Expand Up @@ -261,6 +298,28 @@ export const ActionFormTemplate: React.FC<ActionFormTemplateProps> = ({ action }
</FormFieldInput>
</FormField>

<FormField>
<FormFieldInput>
<FormFieldLabel>{t("User ID")}</FormFieldLabel>

{getUsers.isLoading && <Skeleton height="50px" />}

{getUsers.isSuccess && (
<SelectSingle
options={getUsers.data.map((user: any) => ({
label: setUserIdLabel(user),
value: user.id,
}))}
name="userId"
{...{ register, errors, control }}
disabled={isLoading.actionForm}
ariaLabel={t("Select an user as userId")}
isClearable={true}
/>
)}
</FormFieldInput>
</FormField>

<FormField>
<FormFieldInput>
<FormFieldLabel>{t("async")}</FormFieldLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ export const ApplicationsFormTemplate: React.FC<ApplicationFormTemplateProps> =
/>
</FormFieldInput>
</FormField>
<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Version")}</FormFieldLabel>
<InputText
{...{ register, errors }}
name="version"
disabled={isLoading.applicationForm}
defaultValue={application?.version ?? "0.0.0"}
ariaLabel={t("Enter version")}
/>
</FormFieldInput>
</FormField>

<FormField>
<FormFieldInput>
Expand All @@ -124,18 +136,6 @@ export const ApplicationsFormTemplate: React.FC<ApplicationFormTemplateProps> =
/>
</FormFieldInput>
</FormField>
<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Version")}</FormFieldLabel>
<InputText
{...{ register, errors }}
name="version"
disabled={isLoading.applicationForm}
defaultValue={application?.version ?? "0.0.0"}
ariaLabel={t("Enter version")}
/>
</FormFieldInput>
</FormField>
<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Domains")}</FormFieldLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { useCronjob } from "../../../hooks/cronjob";
import { validateStringAsCronTab } from "../../../services/stringValidations";
import { predefinedSubscriberEvents } from "../../../data/predefinedSubscriberEvents";
import Skeleton from "react-loading-skeleton";
import { SelectCreate } from "@conduction/components/lib/components/formFields/select/select";
import { SelectCreate, SelectSingle } from "@conduction/components/lib/components/formFields/select/select";
import { useIsLoadingContext } from "../../../context/isLoading";
import { enrichValidation } from "../../../services/enrichReactHookFormValidation";
import { useUser } from "../../../hooks/user";

interface CronjobFormTemplateProps {
cronjob?: any;
Expand All @@ -28,6 +29,9 @@ export const CronjobFormTemplate: React.FC<CronjobFormTemplateProps> = ({ cronjo
const _useCronjobs = useCronjob(queryClient);
const createOrEditCronjob = _useCronjobs.createOrEdit(cronjob?.id);

const _useUsers = useUser(queryClient);
const getUsers = _useUsers.getAll();

const {
register,
handleSubmit,
Expand All @@ -54,15 +58,25 @@ export const CronjobFormTemplate: React.FC<CronjobFormTemplateProps> = ({ cronjo
};

const handleSetFormValues = (): void => {
const basicFields: string[] = ["name", "description", "crontab", "isEnabled"];
const basicFields: string[] = ["reference", "version", "name", "description", "crontab", "isEnabled"];
basicFields.forEach((field) => setValue(field, cronjob[field]));

for (const [key, value] of Object.entries(getUsers?.data)) {
if (value?.id === cronjob?.userId) {
setValue("userId", { label: setUserIdLabel(value), value: value.id });
}
}

setValue(
"throws",
cronjob["throws"]?.map((_throw: any) => ({ label: _throw, value: _throw })),
);
};

const setUserIdLabel = (user: any): string => {
return user.name + (" - " + user?.organization?.name);
};

React.useEffect(() => {
cronjob && handleSetFormValues();
}, [cronjob]);
Expand All @@ -72,6 +86,30 @@ export const CronjobFormTemplate: React.FC<CronjobFormTemplateProps> = ({ cronjo
<form onSubmit={handleSubmit(onSubmit)} id={formId}>
<div className={styles.gridContainer}>
<div className={styles.grid}>
<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Reference")}</FormFieldLabel>
<InputText
{...{ register, errors }}
name="reference"
disabled={isLoading.cronjobForm}
ariaLabel={t("Enter reference")}
/>
</FormFieldInput>
</FormField>

<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Version")}</FormFieldLabel>
<InputText
{...{ register, errors }}
name="version"
disabled={isLoading.cronjobForm}
defaultValue={cronjob?.version ?? "0.0.0"}
ariaLabel={t("Enter version")}
/>
</FormFieldInput>
</FormField>
<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Name")}</FormFieldLabel>
Expand Down Expand Up @@ -128,6 +166,28 @@ export const CronjobFormTemplate: React.FC<CronjobFormTemplateProps> = ({ cronjo
</FormFieldInput>
</FormField>

<FormField>
<FormFieldInput>
<FormFieldLabel>{t("User ID")}</FormFieldLabel>

{getUsers.isLoading && <Skeleton height="50px" />}

{getUsers.isSuccess && (
<SelectSingle
options={getUsers.data.map((user: any) => ({
label: setUserIdLabel(user),
value: user.id,
}))}
name="userId"
{...{ register, errors, control }}
disabled={isLoading.actionForm}
ariaLabel={t("Select an user as userId")}
isClearable={true}
/>
)}
</FormFieldInput>
</FormField>

<FormField>
<FormFieldInput>
<FormFieldLabel>{t("isEnabled")}</FormFieldLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const EndpointFormTemplate: React.FC<EndpointFormTemplateProps> = ({ endp
};

const handleSetFormValues = (): void => {
const basicFields: string[] = ["name", "description", "pathRegex", "tag"];
const basicFields: string[] = ["reference", "version", "name", "description", "pathRegex", "tag"];
basicFields.forEach((field) => setValue(field, endpoint[field]));

setValue("path", endpoint.path && endpoint.path.join("/"));
Expand Down Expand Up @@ -113,6 +113,30 @@ export const EndpointFormTemplate: React.FC<EndpointFormTemplateProps> = ({ endp
<form onSubmit={handleSubmit(onSubmit)} id={formId}>
<div className={styles.gridContainer}>
<div className={styles.grid}>
<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Reference")}</FormFieldLabel>
<InputText
{...{ register, errors }}
name="reference"
disabled={isLoading.endpointForm}
ariaLabel={t("Enter reference")}
/>
</FormFieldInput>
</FormField>

<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Version")}</FormFieldLabel>
<InputText
{...{ register, errors }}
name="version"
disabled={isLoading.endpointForm}
defaultValue={endpoint?.version ?? "0.0.0"}
ariaLabel={t("Enter version")}
/>
</FormFieldInput>
</FormField>
<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Name")}</FormFieldLabel>
Expand Down
23 changes: 11 additions & 12 deletions pwa/src/templates/templateParts/mappingForm/MappingFormTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,42 +105,41 @@ export const MappingFormTemplate: React.FC<MappingFormTemplateProps> = ({ mappin
<div className={styles.grid}>
<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Name")}</FormFieldLabel>
<FormFieldLabel>{t("Reference")}</FormFieldLabel>
<InputText
{...{ register, errors }}
name="name"
validation={enrichValidation({ required: true })}
name="reference"
disabled={isLoading.mappingForm}
ariaLabel={t("Enter name")}
ariaLabel={t("Enter reference")}
/>
</FormFieldInput>
</FormField>

<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Reference")}</FormFieldLabel>
<FormFieldLabel>{t("Version")}</FormFieldLabel>
<InputText
{...{ register, errors }}
name="reference"
name="version"
disabled={isLoading.mappingForm}
ariaLabel={t("Enter reference")}
ariaLabel={t("Enter version")}
/>
</FormFieldInput>
</FormField>
<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Version")}</FormFieldLabel>
<FormFieldLabel>{t("Name")}</FormFieldLabel>
<InputText
{...{ register, errors }}
name="version"
name="name"
validation={enrichValidation({ required: true })}
disabled={isLoading.mappingForm}
ariaLabel={t("Enter version")}
ariaLabel={t("Enter name")}
/>
</FormFieldInput>
</FormField>
<FormField>
<FormFieldInput>
<FormFieldLabel>{t("Pass Through")}</FormFieldLabel>
<FormFieldLabel>{t("Pass through")}</FormFieldLabel>
<InputCheckbox {...{ register, errors }} label="on" name="passTrough" disabled={isLoading.mappingForm} />
</FormFieldInput>
</FormField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ export const EditPropertyFormTemplate: React.FC<EditPropertyFormTemplateProps> =
{...{ register, errors, control }}
name="format"
options={formatSelectOptions}
isClearable={true}
disabled={loading || isImmutable}
ariaLabel={t("Select format")}
/>
Expand Down
Loading

0 comments on commit 9835d39

Please sign in to comment.