Skip to content

Commit

Permalink
[MDS-6304] - Clean up some document bugs on MMA (#3350)
Browse files Browse the repository at this point in the history
* fix flow with mma. Fix bug with archiving versioned files. Make action menu prettier on MS at least

* actions on documents tab

* take out replacing of archived files
  • Loading branch information
taraepp authored Dec 17, 2024
1 parent 87b6f89 commit 5d9fa5b
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 198 deletions.
12 changes: 7 additions & 5 deletions services/common/src/components/common/ActionMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, ReactNode } from "react";
import { Button, Dropdown, Modal } from "antd";
import { Button, ButtonProps, Dropdown, Modal } from "antd";
import CaretDownOutlined from "@ant-design/icons/CaretDownOutlined";
import DownOutlined from "@ant-design/icons/DownOutlined";
import { ITableAction } from "@mds/common/components/common/CoreTableCommonColumns";
Expand All @@ -25,7 +25,7 @@ export const generateActionMenuItems = (actionItems: ITableAction[], record) =>
<button
type="button"
disabled={action.disabled}
className={`full actions-dropdown-button`}
className={`full actions-dropdown-button menu-item-button`}
data-testid={`action-button-${action.key}`}
onClick={(event) => action.clickFunction(event, record)}
>
Expand All @@ -43,15 +43,17 @@ export interface IHeaderAction {
clickFunction: () => void | Promise<void>;
}
// Looks like a button, intended for page-scope, not record-scope in the actions
export const ActionMenuButton: FC<{ buttonText?: string; actions: IHeaderAction[] }> = ({
export const ActionMenuButton: FC<{ buttonText?: string; actions: IHeaderAction[], disabled?: boolean, buttonProps?: ButtonProps }> = ({
actions,
buttonText = "Action",
buttonProps,
disabled = false
}) => {
const items = generateActionMenuItems((actions as unknown) as ITableAction[], null);

return (
<Dropdown menu={{ items }} placement="bottomLeft">
<Button type="ghost" className="actions-dropdown-button">
<Dropdown menu={{ items }} placement="bottomLeft" disabled={disabled}>
<Button type="ghost" className="actions-dropdown-button" {...buttonProps}>
{buttonText}
<DownOutlined />
</Button>
Expand Down
74 changes: 25 additions & 49 deletions services/common/src/components/documents/DocumentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import ArchiveDocumentModal from "./ArchiveDocumentModal";
import DeleteDocumentModal from "./DeleteDocumentModal";
import ReplaceDocumentModal from "./ReplaceDocumentModal";
import { downloadFileFromDocumentManager } from "@mds/common/redux/utils/actionlessNetworkCalls";
import { ActionMenuButton } from "../common/ActionMenu";

export const DocumentTable: FC<DocumentTableProps> = ({
isViewOnly = false,
Expand Down Expand Up @@ -108,9 +109,8 @@ export const DocumentTable: FC<DocumentTableProps> = ({
setDocuments(parseDocuments(props.documents ?? []));
}, [props.documents]);

const openArchiveModal = (event, docs: MineDocument[]) => {
const openArchiveModal = (docs: MineDocument[]) => {
const mineGuid = docs[0].mine_guid;
event.preventDefault();
dispatch(
openModal({
props: {
Expand Down Expand Up @@ -197,7 +197,7 @@ export const DocumentTable: FC<DocumentTableProps> = ({
key: "archive",
label: FileOperations.Archive,
icon: <InboxOutlined />,
clickFunction: (event, record: MineDocument) => openArchiveModal(event, [record]),
clickFunction: (_event, record: MineDocument) => openArchiveModal([record]),
},
{
key: "delete",
Expand Down Expand Up @@ -275,43 +275,25 @@ export const DocumentTable: FC<DocumentTableProps> = ({
? { size: "small" as SizeType, rowClassName: "ant-table-row-minimal" }
: null;

const bulkItems: MenuProps["items"] = [
const bulkItems = [
{
key: FileOperations.Download,
icon: <DownloadOutlined />,
label: (
<button
type="button"
className="full add-permit-dropdown-button"
onClick={() => {
setIsCompressionModal(true);
}}
>
<div>Download File(s)</div>
</button>
),
label: "Download File(s)",
clickFunction: () => setIsCompressionModal(true)
},
{
key: FileOperations.Archive,
icon: <InboxOutlined />,
label: (
<button
type="button"
className="full add-permit-dropdown-button"
onClick={(e) => {
openArchiveModal(e, rowSelection);
}}
>
<div>Archive File(s)</div>
</button>
),
},
label: "Archive File(s)",
clickFunction: () => openArchiveModal(rowSelection)
}
].filter((a) => allowedTableActions[a.key]);

const renderBulkActions = () => {
let element = (
<Button
className="ant-btn ant-btn-primary"
type="primary"
disabled={rowSelection.length === 0 || isCompressionInProgress}
onClick={() => {
setIsCompressionModal(true);
Expand All @@ -322,16 +304,10 @@ export const DocumentTable: FC<DocumentTableProps> = ({
);
if (documentsCanBulkDropDown) {
element = (
<Dropdown
menu={{ items: bulkItems }}
placement="bottomLeft"
<ActionMenuButton actions={bulkItems}
disabled={rowSelection.length === 0 || isCompressionInProgress}
>
<Button className="ant-btn ant-btn-primary">
Action
<DownOutlined />
</Button>
</Dropdown>
buttonProps={{ type: "primary", }}
/>
);
}

Expand All @@ -350,22 +326,22 @@ export const DocumentTable: FC<DocumentTableProps> = ({

const bulkActionsProps = enableBulkActions
? {
rowSelection: {
type: "checkbox",
...rowSelectionObject,
},
}
rowSelection: {
type: "checkbox",
...rowSelectionObject,
},
}
: {};

const versionProps = showVersionHistory
? {
expandProps: {
childrenColumnName: "versions",
matchChildColumnsToParent: true,
recordDescription: "version history",
rowExpandable: (record) => record.number_prev_versions > 0,
},
}
expandProps: {
childrenColumnName: "versions",
matchChildColumnsToParent: true,
recordDescription: "version history",
rowExpandable: (record) => record.number_prev_versions > 0,
},
}
: {};

const coreTableProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ interface ArchivedDocumentsSectionProps {
titleLevel?: 1 | 2 | 3 | 4 | 5;
href?: string;
showCategory?: boolean;
canReplace?: boolean;
}

const ArchivedDocumentsSection: FC<ArchivedDocumentsSectionProps> = ({
titleLevel = 4,
href = "archived-documents",
documents,
showCategory = true,
canReplace = true,
}) => {
const { isFeatureEnabled } = useFeatureFlag();

Expand All @@ -45,7 +43,7 @@ const ArchivedDocumentsSection: FC<ArchivedDocumentsSectionProps> = ({
<DocumentTable
documents={documents}
showVersionHistory={true}
canReplaceDocuments={canReplace}
canReplaceDocuments={false}
additionalColumns={additionalColumns}
/>
</div>
Expand Down
25 changes: 13 additions & 12 deletions services/common/src/components/projects/ProjectDocumentsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { fetchMineDocuments } from "@mds/common/redux/actionCreators/mineActionC
import { MineDocument } from "@mds/common/models/documents/document";
import Loading from "../common/Loading";
import { getProjectSummaryDocumentTypesHash } from "@mds/common/redux/selectors/staticContentSelectors";
import { areDocumentFieldsDisabled } from "./projectUtils";

interface ProjectDocumentsTabProps {
project: IProject;
Expand All @@ -35,10 +36,6 @@ const ProjectDocumentsTab: FC<ProjectDocumentsTabProps> = ({ project }) => {
const systemFlag = useSelector(getSystemFlag);
const isCore = systemFlag === SystemFlagEnum.core;
const [isLoaded, setIsLoaded] = useState(true);
const statusesToDisableReplaceFor = ["UNR", "WDN", "OHD"];
const canReplace = isCore
? true
: !statusesToDisableReplaceFor.includes(project?.project_summary?.status_code);

const refreshData = async () => {
setIsLoaded(false);
Expand Down Expand Up @@ -86,6 +83,9 @@ const ProjectDocumentsTab: FC<ProjectDocumentsTabProps> = ({ project }) => {
.toLowerCase();
};

const canModifySummaryDocs = areDocumentFieldsDisabled(systemFlag, project?.project_summary?.status_code);
const canModifyMmaDocs = areDocumentFieldsDisabled(systemFlag, project?.major_mine_application?.status_code);

const projectSummaryDocs =
project?.project_summary?.documents?.map(
(d) =>
Expand Down Expand Up @@ -163,8 +163,7 @@ const ProjectDocumentsTab: FC<ProjectDocumentsTabProps> = ({ project }) => {
title={titleText}
key={auth.project_summary_authorization_guid}
canArchive={false}
canReplace={canReplace}
onArchivedDocuments={refreshData}
canReplace={canModifySummaryDocs}
documents={auth.amendment_documents.map(
(d) =>
new MineDocument({
Expand Down Expand Up @@ -195,7 +194,8 @@ const ProjectDocumentsTab: FC<ProjectDocumentsTabProps> = ({ project }) => {
title="Supporting Documents"
documents={pdSupportingDocuments}
onArchivedDocuments={refreshData}
canReplace={canReplace}
canReplace={canModifySummaryDocs}
canArchive={canModifySummaryDocs}
/>
),
},
Expand All @@ -206,7 +206,6 @@ const ProjectDocumentsTab: FC<ProjectDocumentsTabProps> = ({ project }) => {
id="information-requirements-table"
key="information-requirements-table"
titleLevel={3}
onArchivedDocuments={refreshData}
documents={irtDocuments}
canReplace={false}
canArchive={false}
Expand All @@ -233,7 +232,8 @@ const ProjectDocumentsTab: FC<ProjectDocumentsTabProps> = ({ project }) => {
key="primary-document"
onArchivedDocuments={refreshData}
documents={primaryDocuments}
canReplace={canReplace}
canReplace={canModifyMmaDocs}
canArchive={canModifyMmaDocs}
/>
),
},
Expand All @@ -259,7 +259,8 @@ const ProjectDocumentsTab: FC<ProjectDocumentsTabProps> = ({ project }) => {
key="supporting-documents"
onArchivedDocuments={refreshData}
documents={mmaSupportingDocuments}
canReplace={canReplace}
canReplace={canModifyMmaDocs}
canArchive={canModifyMmaDocs}
/>
),
},
Expand All @@ -271,7 +272,8 @@ const ProjectDocumentsTab: FC<ProjectDocumentsTabProps> = ({ project }) => {
key="ministry-decision-documentation"
onArchivedDocuments={refreshData}
documents={ministryDecisionDocuments}
canReplace={canReplace}
canReplace={canModifyMmaDocs}
canArchive={canModifyMmaDocs}
/>
),
},
Expand All @@ -281,7 +283,6 @@ const ProjectDocumentsTab: FC<ProjectDocumentsTabProps> = ({ project }) => {
<ArchivedDocumentsSection
documents={mineDocuments}
showCategory={false}
canReplace={canReplace}
/>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface ProjectDocumentsTabSectionProps {
title?: string;
titleLevel?: 1 | 2 | 3 | 4 | 5;
documents: MineDocument[];
onArchivedDocuments: () => Promise<void>;
onArchivedDocuments?: () => Promise<void>;
canArchive?: boolean;
canReplace?: boolean;
infoText?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ exports[`ProjectDocumentsTab renders properly 1`] = `
style="float: right;"
>
<button
class="ant-btn ant-btn-default ant-dropdown-trigger ant-btn ant-btn-primary"
class="ant-btn ant-btn-primary ant-dropdown-trigger actions-dropdown-button"
disabled=""
type="button"
>
Expand Down Expand Up @@ -1891,7 +1891,7 @@ exports[`ProjectDocumentsTab renders properly 1`] = `
style="float: right;"
>
<button
class="ant-btn ant-btn-default ant-dropdown-trigger ant-btn ant-btn-primary"
class="ant-btn ant-btn-primary ant-dropdown-trigger actions-dropdown-button"
disabled=""
type="button"
>
Expand Down Expand Up @@ -2302,7 +2302,7 @@ exports[`ProjectDocumentsTab renders properly 1`] = `
style="float: right;"
>
<button
class="ant-btn ant-btn-default ant-dropdown-trigger ant-btn ant-btn-primary"
class="ant-btn ant-btn-primary ant-dropdown-trigger actions-dropdown-button"
disabled=""
type="button"
>
Expand Down Expand Up @@ -3282,7 +3282,7 @@ exports[`ProjectDocumentsTab renders properly 1`] = `
style="float: right;"
>
<button
class="ant-btn ant-btn-default ant-dropdown-trigger ant-btn ant-btn-primary"
class="ant-btn ant-btn-primary ant-dropdown-trigger actions-dropdown-button"
disabled=""
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports[`ProjectDocumentsTab renders properly 1`] = `
style="float: right;"
>
<button
class="ant-btn ant-btn-default ant-dropdown-trigger ant-btn ant-btn-primary"
class="ant-btn ant-btn-primary ant-dropdown-trigger actions-dropdown-button"
disabled=""
type="button"
>
Expand Down
1 change: 1 addition & 0 deletions services/common/src/models/documents/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class MineDocument implements IMineDocument {
this.makeChild(
{
...version,
mine_guid: jsonObject.mine_guid,
is_latest_version: false,
mine_document_guid: this.mine_document_guid,
document_manager_guid: this.document_manager_guid,
Expand Down
Loading

0 comments on commit 5d9fa5b

Please sign in to comment.