Skip to content

Commit

Permalink
[MDS-6027] Edit Permit Conditions (#3342)
Browse files Browse the repository at this point in the history
* extract a form, make it form-y

* format the step, implement move up/down

* implement other functions, styles, aria labels

* fix a little bug or two, use a fancy new selector

* add tests

* missed a console log

* remove unused import

* make imports non-ambiguous

* handle backspace. Also delete a random file to up my - ratio
  • Loading branch information
taraepp authored Dec 16, 2024
1 parent 07ba185 commit 87b6f89
Show file tree
Hide file tree
Showing 33 changed files with 1,711 additions and 496 deletions.
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
"ms-azuretools.vscode-docker",
"shd101wyy.markdown-preview-enhanced",
"esbenp.prettier-vscode",
"sonarsource.sonarlint-vscode"
"sonarsource.sonarlint-vscode",
"ms-python.vscode-pylance"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ exports[`ArchiveDocumentModal renders correctly and matches the snapshot 1`] = `
class="ant-modal-footer"
>
<button
aria-label="Cancel"
class="ant-btn ant-btn-default core-btn core-btn-default"
type="button"
>
Expand All @@ -155,6 +156,7 @@ exports[`ArchiveDocumentModal renders correctly and matches the snapshot 1`] = `
</span>
</button>
<button
aria-label="Submit"
class="ant-btn ant-btn-primary"
type="submit"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ exports[`DeleteDocumentModal renders correctly and matches the snapshot 1`] = `
class="ant-modal-footer"
>
<button
aria-label="Cancel"
class="ant-btn ant-btn-default core-btn core-btn-default"
type="button"
>
Expand All @@ -155,6 +156,7 @@ exports[`DeleteDocumentModal renders correctly and matches the snapshot 1`] = `
</span>
</button>
<button
aria-label="Submit"
class="ant-btn ant-btn-primary"
type="submit"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ exports[`ReplaceDocumentModal renders correctly and matches the snapshot 1`] = `
class="ant-modal-footer"
>
<button
aria-label="Cancel"
class="ant-btn ant-btn-default core-btn core-btn-default"
type="button"
>
Expand All @@ -158,6 +159,7 @@ exports[`ReplaceDocumentModal renders correctly and matches the snapshot 1`] = `
</span>
</button>
<button
aria-label="Submit"
class="ant-btn ant-btn-primary"
disabled=""
type="submit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ exports[`AddSpatialDocumentsModal renders properly 1`] = `
class="ant-row ant-row-end"
>
<button
aria-label="Cancel"
class="ant-btn ant-btn-default core-btn core-btn-default"
type="button"
>
Expand All @@ -240,6 +241,7 @@ exports[`AddSpatialDocumentsModal renders properly 1`] = `
</span>
</button>
<button
aria-label="Submit"
class="ant-btn ant-btn-primary"
disabled=""
type="submit"
Expand Down
10 changes: 7 additions & 3 deletions services/common/src/components/forms/BaseInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,24 @@ export interface BaseInputProps extends WrappedFieldProps {
allowClear?: boolean;
help?: string;
showOptional?: boolean;
showNA?: boolean;
autoFocus?: boolean;
}

interface BaseViewInputProps {
label?: string | ReactNode;
value: string | number;
showNA?: boolean;
}
export const BaseViewInput: FC<BaseViewInputProps> = ({ label = "", value = "" }) => {
const displayValue = value ? value.toString() : EMPTY_FIELD;
export const BaseViewInput: FC<BaseViewInputProps> = ({ label = "", value = "", showNA = true }) => {
const hasValue = value !== "";
const displayValue = hasValue ? value.toString() : EMPTY_FIELD;
return (
<div className="view-item ant-form-item">
{label && label !== "" && (
<Typography.Paragraph className="view-item-label">{label}</Typography.Paragraph>
)}
<Typography.Paragraph className="view-item-value">{displayValue}</Typography.Paragraph>
{(hasValue || showNA) && (<Typography.Paragraph className="view-item-value">{displayValue}</Typography.Paragraph>)}
</div>
);
};
Expand Down
10 changes: 6 additions & 4 deletions services/common/src/components/forms/RenderAutoSizeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const RenderAutoSizeField: FC<AutoSizeProps> = ({
if (!value.isEditMode) {
return <BaseViewInput value={props.input.value} label={label} />;
}
const showHelp = help || maximumCharacters !== undefined;
return (
<Form.Item
name={props.input.name}
Expand All @@ -51,8 +52,9 @@ const RenderAutoSizeField: FC<AutoSizeProps> = ({
{...props.input}
autoSize={{ minRows: minRows }}
placeholder={props.placeholder}
autoFocus={props.autoFocus}
/>
<Row
{showHelp && <Row
justify="space-between"
className={`form-item-help ${props.input.name}-form-help`}
>
Expand All @@ -61,9 +63,9 @@ const RenderAutoSizeField: FC<AutoSizeProps> = ({
) : (
<span>{`Maximum ${maximumCharacters} characters`}</span>
)}
<span className="flex-end">{`${maximumCharacters -
props.input.value.length} / ${maximumCharacters}`}</span>
</Row>
{<span className="flex-end">{`${maximumCharacters -
props.input.value.length} / ${maximumCharacters}`}</span>}
</Row>}
</>
</Form.Item>
);
Expand Down
23 changes: 13 additions & 10 deletions services/common/src/components/forms/RenderCancelButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export const cancelConfirmWrapper = (
return !isFormDirty
? cancelFunction()
: Modal.confirm(
modalProps ?? {
title: "Discard changes?",
content: "All changes made will not be saved.",
onOk: cancelFunction,
cancelText: "Continue Editing",
okText: "Discard",
}
);
modalProps ?? {
title: "Discard changes?",
content: "All changes made will not be saved.",
onOk: cancelFunction,
cancelText: "Continue Editing",
okText: "Discard",
}
);
};

interface RenderCancelButtonProps {
Expand All @@ -31,6 +31,7 @@ interface RenderCancelButtonProps {
buttonProps?: BaseButtonProps;
cancelFunction?: () => void | Promise<void>;
cancelModalProps?: ModalFuncProps;
iconButton?: boolean;
}

/**
Expand All @@ -47,6 +48,7 @@ const RenderCancelButton: FC<RenderCancelButtonProps> = ({
buttonProps = { type: "default" },
cancelFunction,
cancelModalProps,
iconButton = false
}) => {
const dispatch = useDispatch();
const { formName, isModal, isEditMode } = useContext(FormContext);
Expand All @@ -66,9 +68,10 @@ const RenderCancelButton: FC<RenderCancelButtonProps> = ({
: handleCancel;

const buttonType = buttonProps?.type ?? "default";
const buttonLabel = isEditMode ? buttonText : viewButtonText;
return (
<CoreButton {...buttonProps} type={buttonType} onClick={() => buttonCancelFunction()}>
{isEditMode ? buttonText : viewButtonText}
<CoreButton aria-label="Cancel" {...buttonProps} type={buttonType} onClick={() => buttonCancelFunction()}>
{!iconButton && buttonLabel}
</CoreButton>
);
};
Expand Down
3 changes: 2 additions & 1 deletion services/common/src/components/forms/RenderField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ const RenderField: FC<BaseInputProps> = ({
id,
placeholder,
allowClear,
showNA,
}) => {
return (
<FormConsumer>
{(value) => {
if (!value.isEditMode) {
return <BaseViewInput label={label} value={input?.value} />;
return <BaseViewInput label={label} value={input?.value} showNA={showNA} />;
}
const labelString = (label || input.name) instanceof String ? (String)(label || input.name) : input.name;
return (
Expand Down
5 changes: 4 additions & 1 deletion services/common/src/components/forms/RenderSubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ interface RenderSubmitButtonProps {
buttonText?: string | ReactNode;
buttonProps?: ButtonProps & React.RefAttributes<HTMLElement>;
disableOnClean?: boolean;
iconButton?: boolean;
}

const RenderSubmitButton: FC<RenderSubmitButtonProps> = ({
buttonText = "Save Changes",
buttonProps,
disableOnClean = true,
iconButton = false,
}) => {
const { formName, isEditMode } = useContext(FormContext);
const submitting = useSelector(isSubmitting(formName));
Expand All @@ -29,9 +31,10 @@ const RenderSubmitButton: FC<RenderSubmitButtonProps> = ({
disabled={disabled}
loading={submitting}
htmlType="submit"
aria-label="Submit"
{...buttonProps}
>
{buttonText}
{!iconButton && buttonText}
</Button>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`RenderCancelButton component renders properly, does not show confirm on
>
<button
ant-click-animating-without-extra-node="false"
aria-label="Cancel"
class="ant-btn ant-btn-default core-btn core-btn-default"
type="button"
>
Expand Down
1 change: 1 addition & 0 deletions services/common/src/constants/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum FORM {
REQUEST_REPORT = "REQUEST_REPORT",
ADD_REPORT_TO_PERMIT_CONDITION = "ADD_REPORT_TO_PERMIT_CONDITION",
ADD_PERMIT_CONDITION_CATEGORY = "ADD_PERMIT_CONDITION_CATEGORY",
EDIT_PERMIT_CONDITION = "EDIT_PERMIT_CONDITION",
// tailings
ADD_TAILINGS = "ADD_TAILINGS",
// documents
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { IMineReportPermitRequirement } from "@mds/common/interfaces";

export interface IPermitConditionCategory {
condition_category_code: string;
description: string;
display_order: number;
step: string;
}
export interface IPermitCondition {
permit_condition_id: number;
permit_amendment_id: number;
Expand All @@ -20,3 +14,11 @@ export interface IPermitCondition {
display_order: number;
mineReportPermitRequirement?: IMineReportPermitRequirement;
}

export interface IPermitConditionCategory {
condition_category_code: string;
description: string;
display_order: number;
step: string;
conditions?: IPermitCondition[]
}
17 changes: 17 additions & 0 deletions services/common/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,20 @@ export const formatProjectPayload = (valuesFromForm: any, params: any) => {
delete payloadValues.authorizationTypes;
return payloadValues;
};

export const parsePermitConditionStep = (step: string) => {
if (step?.length > 0) {
return step.replace(".", "");
}
return step;
}

export const formatPermitConditionStep = (step: string) => {
if (step?.length > 0) {
if (step.endsWith(".")) {
return step;
}
return `${step}.`
}
return "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,10 @@ def step(self):
# and is used to determine the display format of the step.
# If not set (for manually added condtitions), we auto-generate the step
if self._step:
# Format the first level with a trailing dot - A. B. C. and the rest with () - (a), (i), (ii)
if depth == 0:
return f"{self._step}."
return f"({self._step})"
if self._step == "":
return ""

return self._step
if self._step == '':
return ''

step_format = depth % 3
if step_format == 0:
return str(self.display_order) + "."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ exports[`UpdateStatusForm renders properly 1`] = `
</div>
</div>
<button
aria-label="Submit"
class="ant-btn ant-btn-primary"
disabled=""
type="submit"
Expand Down
59 changes: 0 additions & 59 deletions services/core-web/src/components/common/FilePicker.js

This file was deleted.

Loading

0 comments on commit 87b6f89

Please sign in to comment.