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

[MDS-6129] project summary status: frontend #3299

Merged
merged 15 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ exports[`ReplaceDocumentModal renders correctly and matches the snapshot 1`] = `
>
<input
accept="application/pdf"
id="fileUpload"
multiple=""
name="file"
type="file"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ exports[`AddSpatialDocumentsModal renders properly 1`] = `
>
<input
accept="application/dbf,application/x-dbf,application/x-dbase,application/vnd.google-earth.kml+xml,application/vnd.google-earth.kmz,application/octet-stream,application/xml"
id="fieldName"
multiple=""
name="file"
type="file"
Expand Down
117 changes: 57 additions & 60 deletions services/common/src/components/forms/RenderFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ export const FileUpload: FC<FileUploadProps> = ({
maxFileSize = "750MB",
maxFileNameLength = null,
acceptedFileTypesMap = {},
onFileLoad = () => {},
onRemoveFile = () => {},
addFileStart = () => {},
onFileLoad = () => { },
onRemoveFile = () => { },
addFileStart = () => { },
chunkSize = 1048576, // 1MB
allowRevert = false,
allowMultiple = true,
allowReorder = false,
onProcessFiles = () => {},
onAbort = () => {},
onInit = () => {},
onProcessFiles = () => { },
onAbort = () => { },
onInit = () => { },
itemInsertLocation = "before" as ItemInsertLocationType,
labelInstruction = '<strong>Drag & Drop your files or <span class="filepond--label-action">Browse</span></strong>',
abbrevLabel = false,
beforeAddFile = () => {},
beforeDropFile = () => {},
beforeAddFile = () => { },
beforeDropFile = () => { },
labelHref,
label,
required,
Expand Down Expand Up @@ -160,9 +160,8 @@ export const FileUpload: FC<FileUploadProps> = ({
const secondLine = abbrevLabel
? `<div>We accept most common ${fileTypeDisplayString} files${fileSize}.</div>`
: `<div>Accepted filetypes: ${fileTypeDisplayString}</div>`;
return `${labelInstruction}<br>${
maxFileNameLength ? secondLineWithNamingConvention : secondLine
}`;
return `${labelInstruction}<br>${maxFileNameLength ? secondLineWithNamingConvention : secondLine
}`;
};

// Stores metadata and process function for each file, so we can manually
Expand Down Expand Up @@ -197,9 +196,8 @@ export const FileUpload: FC<FileUploadProps> = ({
)
) {
notification.error({
message: `Failed to upload ${file && file.name ? file.name : ""}: ${
errorMessage ? errorMessage : err
}`,
message: `Failed to upload ${file?.name ?? ""}: ${errorMessage ?? err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Super minor, but if the file.name is null would this not render as "Failed to upload : {errorMessage}". Noting the presence and placement of the colon.

}`,
duration: 10,
});
}
Expand Down Expand Up @@ -254,9 +252,8 @@ export const FileUpload: FC<FileUploadProps> = ({
}

notification.error({
message: `Failed to upload ${file && file.name ? file.name : ""}: ${
response.data.status
}`,
message: `Failed to upload ${file?.name ?? ""}: ${response.data.status
}`,
duration: 10,
});

Expand Down Expand Up @@ -539,6 +536,7 @@ export const FileUpload: FC<FileUploadProps> = ({
/>
)}
<Form.Item
id={input?.name}
name={input?.name}
required={required}
label={getLabel()}
Expand All @@ -551,50 +549,49 @@ export const FileUpload: FC<FileUploadProps> = ({
(meta?.warning && <span>{meta?.warning}</span>))
}
>
<>
<FilePond
ref={(ref) => (filepond = ref)}
server={server}
name="file"
beforeDropFile={beforeDropFile}
beforeAddFile={beforeAddFile}
allowRevert={allowRevert}
onremovefile={onRemoveFile}
allowMultiple={allowMultiple}
onaddfilestart={addFileStart}
allowReorder={allowReorder}
maxParallelUploads={1}
maxFileSize={maxFileSize}
minFileSize="1"
allowFileTypeValidation={acceptedFileMimeTypes.length > 0}
acceptedFileTypes={acceptedFileMimeTypes}
onaddfile={handleFileAdd}
onprocessfiles={onProcessFiles}
onprocessfileabort={onAbort}
oninit={onInit}
labelIdle={getFilePondLabel()}
itemInsertLocation={itemInsertLocation}
credits={null}
fileValidateTypeLabelExpectedTypes={getfileValidateTypeLabelExpectedTypes()}
fileValidateTypeDetectType={(source, type) =>
new Promise((resolve, reject) => {
// If the browser can't automatically detect the file's MIME type, use the one stored in the "accepted file types" map.
if (!type) {
const exts = source.name.split(".");
const ext = exts?.length > 0 && `.${exts.pop().toLowerCase()}`;

if (ext && acceptedFileTypeExtensions.includes(ext)) {
const match = acceptedFileTypesMap[ext];
type = Array.isArray(match) ? match[0] : match;
} else {
reject(type);
}
<FilePond
id={input?.name}
ref={(ref) => (filepond = ref)}
server={server}
name="file"
beforeDropFile={beforeDropFile}
beforeAddFile={beforeAddFile}
allowRevert={allowRevert}
onremovefile={onRemoveFile}
allowMultiple={allowMultiple}
onaddfilestart={addFileStart}
allowReorder={allowReorder}
maxParallelUploads={1}
maxFileSize={maxFileSize}
minFileSize="1"
allowFileTypeValidation={acceptedFileMimeTypes.length > 0}
acceptedFileTypes={acceptedFileMimeTypes}
onaddfile={handleFileAdd}
onprocessfiles={onProcessFiles}
onprocessfileabort={onAbort}
oninit={onInit}
labelIdle={getFilePondLabel()}
itemInsertLocation={itemInsertLocation}
credits={null}
fileValidateTypeLabelExpectedTypes={getfileValidateTypeLabelExpectedTypes()}
fileValidateTypeDetectType={(source, type) =>
new Promise((resolve, reject) => {
// If the browser can't automatically detect the file's MIME type, use the one stored in the "accepted file types" map.
if (!type) {
const exts = source.name.split(".");
const ext = exts?.length > 0 && `.${exts.pop().toLowerCase()}`;

if (ext && acceptedFileTypeExtensions.includes(ext)) {
const match = acceptedFileTypesMap[ext];
type = Array.isArray(match) ? match[0] : match;
} else {
reject(type);
}
resolve(type);
})
}
/>
</>
}
resolve(type);
})
}
/>
</Form.Item>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const RenderGroupCheckbox: FC<CheckboxProps> = ({
if (!isEditMode) {
return (
<Form.Item
id={input.name}
name={input.name}
label={<div className="view-item-label">{label}</div>}
getValueProps={() => ({ value: input.value })}
Expand Down
45 changes: 23 additions & 22 deletions services/common/src/components/forms/RenderOrgBookSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { BaseInputProps, getFormItemLabel } from "./BaseInput";

interface OrgBookSearchProps extends BaseInputProps {
data?: any;
isDisabled?: boolean;
setCredential: (credential: IOrgbookCredential) => void;
}

Expand All @@ -29,7 +28,7 @@ const RenderOrgBookSearch: FC<OrgBookSearchProps> = ({
input,
meta,
required,
isDisabled = false,
disabled = false,
setCredential,
}) => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -121,26 +120,28 @@ const RenderOrgBookSearch: FC<OrgBookSearchProps> = ({
required={required}
getValueProps={() => input?.value !== "" && { value: input?.value }}
>
<Select
virtual={false}
showSearch
showArrow
labelInValue
placeholder="Start typing to search OrgBook..."
notFoundContent={isSearching ? <Spin size="small" indicator={<LoadingOutlined />} /> : null}
filterOption={false}
onSearch={handleSearchDebounced}
onChange={handleChange}
onSelect={handleSelect}
style={{ width: "100%" }}
disabled={isDisabled}
value={options.length === 1 ? { key: options[0].text } : null}
>
{options.map((option) => (
<Select.Option key={option.value}>{option.text}</Select.Option>
))}
</Select>
{help && <div className={`form-item-help ${input?.name}-form-help`}>{help}</div>}
<>
<Select
virtual={false}
showSearch
showArrow
labelInValue
placeholder="Start typing to search OrgBook..."
notFoundContent={isSearching ? <Spin size="small" indicator={<LoadingOutlined />} /> : null}
filterOption={false}
onSearch={handleSearchDebounced}
onChange={handleChange}
onSelect={handleSelect}
style={{ width: "100%" }}
disabled={disabled}
value={options.length === 1 ? { key: options[0].text } : undefined}
>
{options.map((option) => (
<Select.Option key={option.value}>{option.text}</Select.Option>
))}
</Select>
{help && <div className={`form-item-help ${input?.name}-form-help`}>{help}</div>}
</>
</Form.Item>
);
};
Expand Down
29 changes: 15 additions & 14 deletions services/common/src/components/projectSummary/Agent.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import FormWrapper from "../forms/FormWrapper";
import * as MOCK from "@mds/common/tests/mocks/dataMocks";
import { Agent } from "./Agent";

const formValues = {
values: {
status_code: "DFT",
agent: {
credential_id: 1000,
party_type_code: null,
address: { address_type_code: "CAN", sub_division_code: "BC" },
},
is_agent: true,
},
};
const initialState = {
form: {
[FORM.ADD_EDIT_PROJECT_SUMMARY]: {
values: {
status_code: "DFT",
agent: {
credential_id: 1000,
party_type_code: null,
address: { address_type_code: "CAN", sub_division_code: "BC" },
},
is_agent: true,
},
},
[FORM.ADD_EDIT_PROJECT_SUMMARY]: { values: formValues },
},
[PROJECTS]: {
projectSummary: MOCK.PROJECT_SUMMARY,
Expand All @@ -38,10 +39,10 @@ describe("Agent Component", () => {
<ReduxWrapper initialState={initialState}>
<FormWrapper
name={FORM.ADD_EDIT_PROJECT_SUMMARY}
initialValues={initialState}
onSubmit={() => {}}
initialValues={formValues}
onSubmit={() => { }}
>
<Agent />
<Agent fieldsDisabled={false} />
</FormWrapper>
</ReduxWrapper>
);
Expand Down
Loading
Loading