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

psp-6864 missing fields required message. #3492

Merged
merged 2 commits into from
Sep 27, 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
2 changes: 1 addition & 1 deletion .github/workflows/retag-test-to-uat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
TAG_DEV: "dev"
TAG_TEST: "test"
TAG_PROD: "prod"
INSTANCE: "-test"
INSTANCE: "-uat"
NAMESPACE_OVERRIDE: "3cd915-test"
RELEASE_TAG: "test"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const AddLeaseContainer: React.FunctionComponent<
isOkDisabled={formikRef.current?.isSubmitting || bcaLoading}
onSave={handleSave}
onCancel={handleCancel}
isValid={isValid}
displayRequiredFieldError={isValid === false}
/>
}
showCloseButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { FilePropertyRouter } from './router/FilePropertyRouter';

export interface IAcquisitionViewProps {
onClose: (() => void) | undefined;
onSave: () => void;
onSave: () => Promise<void>;
onCancel: () => void;
onMenuChange: (selectedIndex: number) => void;
onShowPropertySelector: () => void;
Expand Down Expand Up @@ -137,7 +137,7 @@ export const AcquisitionView: React.FunctionComponent<IAcquisitionViewProps> = (
isOkDisabled={formikRef?.current?.isSubmitting}
onSave={onSave}
onCancel={onCancel}
isValid={isFormValid}
displayRequiredFieldError={isFormValid === false}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const AddAcquisitionContainer: React.FC<IAddAcquisitionContainerProps> =
isOkDisabled={helper.loading}
onSave={handleSave}
onCancel={close}
isValid={isValid}
displayRequiredFieldError={isValid === false}
/>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ const UpdateCompensationRequisitionForm: React.FC<CompensationRequisitionFormPro
}}
isOkDisabled={formikProps.isSubmitting || !formikProps.dirty}
onCancel={() => cancelFunc(formikProps.resetForm, formikProps.dirty)}
isValid={isValid}
displayRequiredFieldError={isValid === false}
/>
</StyledFooter>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export const UpdateForm8Form: React.FC<IForm8FormProps> = ({
onSave={() => formikProps.submitForm()}
isOkDisabled={formikProps.isSubmitting || !formikProps.dirty}
onCancel={() => cancelFunc(formikProps.resetForm, formikProps.dirty)}
displayRequiredFieldError={
formikProps.isValid === false && !!formikProps.submitCount
}
/>
</StyledFooter>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
isOkDisabled={formikRef?.current?.isSubmitting}
onSave={handleSaveClick}
onCancel={handleCancelClick}
isValid={isValid}
displayRequiredFieldError={isValid === false && !!formikRef.current?.submitCount}

Check warning on line 219 in source/frontend/src/features/mapSideBar/lease/LeaseContainer.tsx

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/lease/LeaseContainer.tsx#L219

Added line #L219 was not covered by tests
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface IProjectContainerViewProps {
onClose: () => void;
onSetProject: (project: Api_Project) => void;
onSuccess: () => void;
setIsValid: (value: boolean) => void;
displayRequiredFieldsError: boolean;
}

export interface IProjectContainerProps {
Expand Down Expand Up @@ -74,6 +76,8 @@ const ProjectContainer: React.FunctionComponent<
getProject: { execute: getProject, loading: loadingProject },
} = useProjectProvider();

const [isValid, setIsValid] = useState<boolean>(false);

const [containerState, setContainerState] = useReducer(
(prevState: ProjectContainerState, newState: Partial<ProjectContainerState>) => ({
...prevState,
Expand Down Expand Up @@ -117,6 +121,8 @@ const ProjectContainer: React.FunctionComponent<
onSetProject={setProject}
onClose={onClose}
onSuccess={onSuccess}
setIsValid={setIsValid}
displayRequiredFieldsError={containerState.isSubmitting && !isValid}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const mockProps: IProjectContainerViewProps = {
onSetProject: jest.fn(),
onSetContainerState: jest.fn(),
onSuccess: jest.fn(),
setIsValid: jest.fn(),
displayRequiredFieldsError: false,
};

describe('ProjectSummaryView component', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@
activeTab,
isEditing,
showConfirmModal,
isSubmitting,
displayRequiredFieldsError,
onClose,
onSetProject,
onSetContainerState,
onSuccess,
setIsValid,
}) => {
const close = useCallback(() => onClose && onClose(), [onClose]);

const handleSaveClick = () => {
if (formikRef !== undefined) {
setIsValid(formikRef.current?.isValid ?? false);

Check warning on line 33 in source/frontend/src/features/mapSideBar/project/ProjectContainerView.tsx

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/project/ProjectContainerView.tsx#L33

Added line #L33 was not covered by tests
onSetContainerState({ isSubmitting: true });
formikRef.current?.setSubmitting(true);
formikRef.current?.submitForm();
return formikRef.current?.submitForm() ?? Promise.resolve();

Check warning on line 36 in source/frontend/src/features/mapSideBar/project/ProjectContainerView.tsx

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/project/ProjectContainerView.tsx#L36

Added line #L36 was not covered by tests
}
return Promise.resolve();

Check warning on line 38 in source/frontend/src/features/mapSideBar/project/ProjectContainerView.tsx

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/project/ProjectContainerView.tsx#L38

Added line #L38 was not covered by tests
};

const formikRef = useRef<FormikProps<any>>(null);
Expand Down Expand Up @@ -77,6 +80,7 @@
isOkDisabled={false}
onSave={handleSaveClick}
onCancel={handleCancelClick}
displayRequiredFieldError={displayRequiredFieldsError}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const AddProjectContainer: React.FC<React.PropsWithChildren<IAddProjectContainer
const [businessFunctions, setBusinessFunctions] = useState<Api_FinancialCode[]>([]);
const [costTypes, setCostTypes] = useState<Api_FinancialCode[]>([]);
const [workActivities, setWorkActivities] = useState<Api_FinancialCode[]>([]);
const [isValid, setIsValid] = useState<boolean>(true);

useEffect(() => {
async function fetchBusinessFunctions() {
Expand Down Expand Up @@ -76,8 +77,10 @@ const AddProjectContainer: React.FC<React.PropsWithChildren<IAddProjectContainer

const close = useCallback(() => onClose && onClose(), [onClose]);

const handleSave = () => {
formikRef.current?.submitForm();
const handleSave = async () => {
var result = await (formikRef.current?.submitForm() ?? Promise.resolve());
setIsValid(formikRef.current?.isValid ?? false);
return result;
};

const onSuccess = async (proj: Api_Project) => {
Expand All @@ -93,7 +96,9 @@ const AddProjectContainer: React.FC<React.PropsWithChildren<IAddProjectContainer
title="Create Project"
icon={<FaBriefcase className="mr-2 mb-2" size={32} />}
onClose={close}
footer={<SidebarFooter onSave={handleSave} onCancel={close} />}
footer={
<SidebarFooter onSave={handleSave} onCancel={close} displayRequiredFieldError={!isValid} />
}
>
<AddProjectForm
ref={formikRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ const AddProjectForm = React.forwardRef<FormikProps<ProjectForm>, IAddProjectFor
} = props;

const handleSubmit = async (values: ProjectForm, formikHelpers: FormikHelpers<ProjectForm>) => {
await onSubmit(values, formikHelpers);
var result = await onSubmit(values, formikHelpers);
formikHelpers.setSubmitting(false);
return result;
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ exports[`AddProjectContainer component renders as expected 1`] = `
</div>
</div>
</div>
.c2.btn {
.c1.btn {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
Expand Down Expand Up @@ -710,49 +710,49 @@ exports[`AddProjectContainer component renders as expected 1`] = `
cursor: pointer;
}

.c2.btn:hover {
.c1.btn:hover {
-webkit-text-decoration: underline;
text-decoration: underline;
opacity: 0.8;
}

.c2.btn:focus {
.c1.btn:focus {
outline-width: 0.4rem;
outline-style: solid;
outline-offset: 1px;
box-shadow: none;
}

.c2.btn.btn-primary {
.c1.btn.btn-primary {
border: none;
}

.c2.btn.btn-secondary {
.c1.btn.btn-secondary {
background: none;
}

.c2.btn.btn-info {
.c1.btn.btn-info {
border: none;
background: none;
padding-left: 0.6rem;
padding-right: 0.6rem;
}

.c2.btn.btn-info:hover,
.c2.btn.btn-info:active,
.c2.btn.btn-info:focus {
.c1.btn.btn-info:hover,
.c1.btn.btn-info:active,
.c1.btn.btn-info:focus {
background: none;
}

.c2.btn.btn-light {
.c1.btn.btn-light {
border: none;
}

.c2.btn.btn-dark {
.c1.btn.btn-dark {
border: none;
}

.c2.btn.btn-link {
.c1.btn.btn-link {
font-size: 1.6rem;
font-weight: 400;
background: none;
Expand All @@ -773,9 +773,9 @@ exports[`AddProjectContainer component renders as expected 1`] = `
padding: 0;
}

.c2.btn.btn-link:hover,
.c2.btn.btn-link:active,
.c2.btn.btn-link:focus {
.c1.btn.btn-link:hover,
.c1.btn.btn-link:active,
.c1.btn.btn-link:focus {
-webkit-text-decoration: underline;
text-decoration: underline;
border: none;
Expand All @@ -784,14 +784,14 @@ exports[`AddProjectContainer component renders as expected 1`] = `
outline: none;
}

.c2.btn.btn-link:disabled,
.c2.btn.btn-link.disabled {
.c1.btn.btn-link:disabled,
.c1.btn.btn-link.disabled {
background: none;
pointer-events: none;
}

.c2.btn:disabled,
.c2.btn:disabled:hover {
.c1.btn:disabled,
.c1.btn:disabled:hover {
box-shadow: none;
-webkit-user-select: none;
-moz-user-select: none;
Expand All @@ -802,15 +802,15 @@ exports[`AddProjectContainer component renders as expected 1`] = `
opacity: 0.65;
}

.c2.Button .Button__icon {
.c1.Button .Button__icon {
margin-right: 1.6rem;
}

.c2.Button--icon-only:focus {
.c1.Button--icon-only:focus {
outline: none;
}

.c2.Button--icon-only .Button__icon {
.c1.Button--icon-only .Button__icon {
margin-right: 0;
}

Expand All @@ -823,11 +823,6 @@ exports[`AddProjectContainer component renders as expected 1`] = `
z-index: 10;
}

.c1 {
padding-top: 0.7rem;
color: red;
}

<div
class=""
>
Expand All @@ -836,18 +831,12 @@ exports[`AddProjectContainer component renders as expected 1`] = `
>
<div
class="pr-3 col-auto"
>
<div
class="c1"
>
Please check the required fields.
</div>
</div>
/>
<div
class="pr-4 col-auto"
>
<button
class="c2 Button btn btn-secondary"
class="c1 Button btn btn-secondary"
type="button"
>
<div
Expand All @@ -861,7 +850,7 @@ exports[`AddProjectContainer component renders as expected 1`] = `
class="col-auto"
>
<button
class="c2 Button btn btn-primary"
class="c1 Button btn btn-primary"
type="button"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
const [showCancelConfirmModal, setShowCancelConfirmModal] = useState<boolean>(false);

const [isEditing, setIsEditing] = useState<boolean>(false);
const [isValid, setIsValid] = useState<boolean>(true);

const mapMachine = useMapStateMachine();

Expand Down Expand Up @@ -57,7 +58,8 @@
const handleSaveClick = async () => {
if (formikRef !== undefined) {
formikRef.current?.setSubmitting(true);
formikRef.current?.submitForm();
await formikRef.current?.submitForm();
setIsValid(formikRef.current?.isValid ?? false);

Check warning on line 62 in source/frontend/src/features/mapSideBar/property/MotiInventoryContainer.tsx

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/property/MotiInventoryContainer.tsx#L61-L62

Added lines #L61 - L62 were not covered by tests
Comment on lines +61 to +62
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see other places doing:

var result = await (formikRef.current?.submitForm() ?? Promise.resolve());
setIsValid(...)

why not use the same pattern here (awaiting the promise)?

}
};

Expand Down Expand Up @@ -108,6 +110,7 @@
isOkDisabled={formikRef?.current?.isSubmitting}
onSave={handleSaveClick}
onCancel={handleCancelClick}
displayRequiredFieldError={!isValid}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
const [selectedMenuIndex, setSelectedMenuIndex] = useState<number>(0);
const [isEditing, setIsEditing] = useState<boolean>(false);
const [editKey, setEditKey] = useState(FormKeys.none);
const [isValid, setIsValid] = useState<boolean>(true);

const [isShowingPropertySelector, setIsShowingPropertySelector] = useState<boolean>(false);

Expand Down Expand Up @@ -117,6 +118,7 @@
if (formikRef !== undefined) {
formikRef.current?.setSubmitting(true);
formikRef.current?.submitForm();
setIsValid(formikRef.current?.isValid || false);

Check warning on line 121 in source/frontend/src/features/mapSideBar/research/ResearchContainer.tsx

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/research/ResearchContainer.tsx#L121

Added line #L121 was not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other code awaits the result of submitForm() but this one doesn't. Would it make sense to apply the same pattern here?

}
};

Expand Down Expand Up @@ -183,6 +185,7 @@
isOkDisabled={formikRef?.current?.isSubmitting}
onSave={handleSaveClick}
onCancel={handleCancelClick}
displayRequiredFieldError={!isValid}
/>
)
}
Expand Down
Loading
Loading