Skip to content

Commit

Permalink
Bulkedit workgroup reset (#1594)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt authored Oct 21, 2024
2 parents 7896e87 + 4967846 commit cef17ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/client/cypress/e2e/mainPage/bulkedit.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ describe("Test the borehole bulk edit feature.", () => {
cy.get(".MuiAccordionSummary-expandIconWrapper").click({ multiple: true, force: true });
setInput("custom.project_name", "new name");
setSelect("workgroup", 1);
setSelect("restriction", 3);
setSelect("national_interest", 1);
setSelect("restriction", 2);
setSelect("national_interest", 0);

let visibleCount = 0;

Expand Down
4 changes: 3 additions & 1 deletion src/client/src/components/form/formSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface FormSelectProps {
sx?: SxProps;
className?: string;
onUpdate?: (value: number | boolean | null) => void;
canReset?: boolean;
}

export interface FormSelectValue {
Expand All @@ -41,12 +42,13 @@ export const FormSelect: FC<FormSelectProps> = ({
sx,
className,
onUpdate,
canReset = true, // option to disable reset in dropdown without using the required rule and error display
}) => {
const { t } = useTranslation();
const { control } = useFormContext();

const menuItems: FormSelectMenuItem[] = [];
if (!required) {
if (!required && canReset) {
menuItems.push({ key: 0, value: undefined, label: t("reset"), italic: true });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ export const BulkEditForm = ({ selected, loadBoreholes }: BulkEditFormProps) =>
(field: BulkEditFormField, newValue: BulkEditFormValue) => {
const fieldName = field.api ?? field.fieldName;
let updatedValue: BulkEditFormValue = newValue;
if (field.type === FormValueType.Boolean) {
updatedValue = newValue === 1 ? true : newValue === 0 ? false : undefined;
}
if (field.type === FormValueType.Number) {
updatedValue = parseFloat(newValue as string);
}
Expand Down Expand Up @@ -131,9 +128,10 @@ export const BulkEditForm = ({ selected, loadBoreholes }: BulkEditFormProps) =>
const entryIndex = fieldsToUpdate.findIndex(([key]) => key === fieldName);
if (entryIndex !== -1) {
setFieldsToUpdate([...fieldsToUpdate.filter(f => f[0] !== fieldName)]);
formMethods.resetField(fieldName);
if (fieldName === "workgroup") {
setWorkgroupId(null);
} else {
formMethods.resetField(fieldName);
}
}
};
Expand All @@ -155,6 +153,7 @@ export const BulkEditForm = ({ selected, loadBoreholes }: BulkEditFormProps) =>
if (field.type === FormValueType.Domain) {
return (
<FormDomainSelect
canReset={false}
fieldName={field.api ?? field.fieldName}
label={field.fieldName}
schemaName={field?.domain ?? field.api ?? field.fieldName}
Expand All @@ -168,6 +167,7 @@ export const BulkEditForm = ({ selected, loadBoreholes }: BulkEditFormProps) =>
if (field.type === FormValueType.Boolean) {
return (
<FormBooleanSelect
canReset={false}
fieldName={field.api ?? field.fieldName}
label={field.fieldName}
onUpdate={e => {
Expand Down

0 comments on commit cef17ce

Please sign in to comment.