From 0631de7c051d522157ef711b76398ae353f88ca1 Mon Sep 17 00:00:00 2001 From: ibolton336 Date: Tue, 26 Sep 2023 10:17:26 -0400 Subject: [PATCH] :ghost: Remove shared app filter and unused menuActions Signed-off-by: ibolton336 --- client/src/app/components/MenuActions.tsx | 42 ---- client/src/app/components/PageHeader.tsx | 8 - .../app/components/tests/MenuActions.test.tsx | 45 ---- .../app/components/tests/PageHeader.test.tsx | 10 - .../__snapshots__/MenuActions.test.tsx.snap | 128 ---------- .../pages/applications/applicationsFilter.ts | 225 ------------------ .../manage-imports-details.tsx | 1 - .../manage-imports/manage-imports.tsx | 1 - .../components/assessment-page-header.tsx | 1 - client/src/app/pages/review/review-page.tsx | 2 - 10 files changed, 463 deletions(-) delete mode 100644 client/src/app/components/MenuActions.tsx delete mode 100644 client/src/app/components/tests/MenuActions.test.tsx delete mode 100644 client/src/app/components/tests/__snapshots__/MenuActions.test.tsx.snap delete mode 100644 client/src/app/pages/applications/applicationsFilter.ts diff --git a/client/src/app/components/MenuActions.tsx b/client/src/app/components/MenuActions.tsx deleted file mode 100644 index 3a40c86f9e..0000000000 --- a/client/src/app/components/MenuActions.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import React, { useState } from "react"; -import { - Dropdown, - DropdownItem, - DropdownList, - MenuToggle, -} from "@patternfly/react-core"; - -export interface MenuActionsProps { - actions: { label: string; callback: () => void }[]; -} - -export const MenuActions: React.FC = ({ actions }) => { - const [isOpen, setIsOpen] = useState(false); - - return ( - { - setIsOpen(false); - }} - toggle={(toggleRef) => ( - setIsOpen(!isOpen)} - isExpanded={isOpen} - > - Actions - - )} - shouldFocusToggleOnSelect - > - - {actions.map((item, index) => ( - - {item.label} - - ))} - - - ); -}; diff --git a/client/src/app/components/PageHeader.tsx b/client/src/app/components/PageHeader.tsx index 548b602088..25a12c7680 100644 --- a/client/src/app/components/PageHeader.tsx +++ b/client/src/app/components/PageHeader.tsx @@ -8,7 +8,6 @@ import { Text, } from "@patternfly/react-core"; import { BreadCrumbPath } from "./BreadCrumbPath"; -import { MenuActions } from "./MenuActions"; import { HorizontalNav } from "./HorizontalNav"; export interface PageHeaderProps { @@ -16,7 +15,6 @@ export interface PageHeaderProps { description?: React.ReactNode; breadcrumbs: { title: string; path: string | (() => void) }[]; btnActions?: React.ReactNode; - menuActions: { label: string; callback: () => void }[]; navItems?: { title: string; path: string }[]; } @@ -25,7 +23,6 @@ export const PageHeader: React.FC = ({ description, breadcrumbs, btnActions, - menuActions, navItems, }) => { return ( @@ -42,11 +39,6 @@ export const PageHeader: React.FC = ({ {btnActions && {btnActions}} - {menuActions.length > 0 && ( - - - - )} {navItems && ( diff --git a/client/src/app/components/tests/MenuActions.test.tsx b/client/src/app/components/tests/MenuActions.test.tsx deleted file mode 100644 index 1fca580f9f..0000000000 --- a/client/src/app/components/tests/MenuActions.test.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import React from "react"; -import { MenuActions } from "../MenuActions"; -import { render, screen, fireEvent } from "@app/test-config/test-utils"; - -describe("MenuActions", () => { - it("Renders without crashing", () => { - const wrapper = render( - - ); - expect(wrapper).toMatchSnapshot(); - }); - - it("Executes callback", () => { - const callback1Mock = jest.fn(); - const callback2Mock = jest.fn(); - - render( - - ); - - const actionsButton = screen.getByText(/Actions/i); - fireEvent.click(actionsButton); - - const action1Button = screen.getByText(/Action1/i); - fireEvent.click(action1Button); - - expect(callback1Mock).toHaveBeenCalledTimes(1); - - fireEvent.click(actionsButton); - const action2Button = screen.getByText(/Action2/i); - fireEvent.click(action2Button); - - expect(callback2Mock).toHaveBeenCalledTimes(1); - }); -}); diff --git a/client/src/app/components/tests/PageHeader.test.tsx b/client/src/app/components/tests/PageHeader.test.tsx index 2a298a3126..3eac4b1fd0 100644 --- a/client/src/app/components/tests/PageHeader.test.tsx +++ b/client/src/app/components/tests/PageHeader.test.tsx @@ -21,16 +21,6 @@ describe("PageHeader", () => { }, ]} btnActions={} - menuActions={[ - { - label: "Edit", - callback: jest.fn(), - }, - { - label: "Delete", - callback: jest.fn(), - }, - ]} navItems={[ { title: "Overview", diff --git a/client/src/app/components/tests/__snapshots__/MenuActions.test.tsx.snap b/client/src/app/components/tests/__snapshots__/MenuActions.test.tsx.snap deleted file mode 100644 index 13f8df57e7..0000000000 --- a/client/src/app/components/tests/__snapshots__/MenuActions.test.tsx.snap +++ /dev/null @@ -1,128 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`MenuActions Renders without crashing 1`] = ` -{ - "asFragment": [Function], - "baseElement": -
- -
- , - "container":
- -
, - "debug": [Function], - "findAllByAltText": [Function], - "findAllByDisplayValue": [Function], - "findAllByLabelText": [Function], - "findAllByPlaceholderText": [Function], - "findAllByRole": [Function], - "findAllByTestId": [Function], - "findAllByText": [Function], - "findAllByTitle": [Function], - "findByAltText": [Function], - "findByDisplayValue": [Function], - "findByLabelText": [Function], - "findByPlaceholderText": [Function], - "findByRole": [Function], - "findByTestId": [Function], - "findByText": [Function], - "findByTitle": [Function], - "getAllByAltText": [Function], - "getAllByDisplayValue": [Function], - "getAllByLabelText": [Function], - "getAllByPlaceholderText": [Function], - "getAllByRole": [Function], - "getAllByTestId": [Function], - "getAllByText": [Function], - "getAllByTitle": [Function], - "getByAltText": [Function], - "getByDisplayValue": [Function], - "getByLabelText": [Function], - "getByPlaceholderText": [Function], - "getByRole": [Function], - "getByTestId": [Function], - "getByText": [Function], - "getByTitle": [Function], - "queryAllByAltText": [Function], - "queryAllByDisplayValue": [Function], - "queryAllByLabelText": [Function], - "queryAllByPlaceholderText": [Function], - "queryAllByRole": [Function], - "queryAllByTestId": [Function], - "queryAllByText": [Function], - "queryAllByTitle": [Function], - "queryByAltText": [Function], - "queryByDisplayValue": [Function], - "queryByLabelText": [Function], - "queryByPlaceholderText": [Function], - "queryByRole": [Function], - "queryByTestId": [Function], - "queryByText": [Function], - "queryByTitle": [Function], - "rerender": [Function], - "unmount": [Function], -} -`; diff --git a/client/src/app/pages/applications/applicationsFilter.ts b/client/src/app/pages/applications/applicationsFilter.ts deleted file mode 100644 index e891ea20ab..0000000000 --- a/client/src/app/pages/applications/applicationsFilter.ts +++ /dev/null @@ -1,225 +0,0 @@ -import * as React from "react"; - -import { useTranslation } from "react-i18next"; - -import { Application } from "@app/api/models"; -import { useFetchIdentities } from "@app/queries/identities"; -import { useFetchTagCategories } from "@app/queries/tags"; -import { - FilterCategory, - FilterType, -} from "@app/components/FilterToolbar/FilterToolbar"; -import { useLegacyFilterState } from "@app/hooks/useLegacyFilterState"; -import { useLegacyPaginationState } from "@app/hooks/useLegacyPaginationState"; -import { useLegacySortState } from "@app/hooks/useLegacySortState"; -import { dedupeFunction } from "@app/utils/utils"; -import { useSelectionState } from "@migtools/lib-ui"; -export enum ApplicationTableType { - Assessment = "assessment", - Analysis = "analysis", -} -export const useApplicationsFilterValues = ( - tableType: string, - applications: Application[] = [] -) => { - const { identities } = useFetchIdentities(); - - const { t } = useTranslation(); - - const { tagCategories: tagCategories } = useFetchTagCategories(); - - const filterCategories: FilterCategory< - Application, - | "name" - | "description" - | "businessService" - | "identities" - | "repository" - | "binary" - | "tags" - >[] = [ - { - key: "name", - title: t("terms.name"), - type: FilterType.search, - placeholderText: - t("actions.filterBy", { - what: t("terms.name").toLowerCase(), - }) + "...", - getItemValue: (item) => item?.name || "", - }, - { - key: "description", - title: t("terms.description"), - type: FilterType.search, - placeholderText: - t("actions.filterBy", { - what: t("terms.description").toLowerCase(), - }) + "...", - getItemValue: (item) => item.description || "", - }, - { - key: "businessService", - title: t("terms.businessService"), - placeholderText: - t("actions.filterBy", { - what: t("terms.businessService").toLowerCase(), - }) + "...", - type: FilterType.select, - selectOptions: dedupeFunction( - applications - .filter((app) => !!app.businessService?.name) - .map((app) => app.businessService?.name) - .map((name) => ({ key: name, value: name })) - ), - getItemValue: (item) => item.businessService?.name || "", - }, - { - key: "identities", - title: t("terms.credentialType"), - placeholderText: - t("actions.filterBy", { - what: t("terms.credentialType").toLowerCase(), - }) + "...", - type: FilterType.multiselect, - selectOptions: [ - { key: "source", value: "Source" }, - { key: "maven", value: "Maven" }, - { key: "proxy", value: "Proxy" }, - ], - getItemValue: (item) => { - const searchStringArr: string[] = []; - item.identities?.forEach((appIdentity) => { - const matchingIdentity = identities.find( - (identity) => identity.id === appIdentity.id - ); - searchStringArr.push(matchingIdentity?.kind || ""); - }); - const searchString = searchStringArr.join(""); - return searchString; - }, - }, - { - key: "repository", - title: t("terms.repositoryType"), - placeholderText: - t("actions.filterBy", { - what: t("terms.repositoryType").toLowerCase(), - }) + "...", - type: FilterType.select, - selectOptions: [ - { key: "git", value: "Git" }, - { key: "subversion", value: "Subversion" }, - ], - getItemValue: (item) => item?.repository?.kind || "", - }, - { - key: "binary", - title: t("terms.artifact"), - placeholderText: - t("actions.filterBy", { - what: t("terms.artifact").toLowerCase(), - }) + "...", - type: FilterType.select, - selectOptions: [ - { key: "binary", value: t("terms.artifactAssociated") }, - { key: "none", value: t("terms.artifactNotAssociated") }, - ], - getItemValue: (item) => { - const hasBinary = - item.binary !== "::" && item.binary?.match(/.+:.+:.+/) - ? "binary" - : "none"; - - return hasBinary; - }, - }, - { - key: "tags", - title: t("terms.tags"), - type: FilterType.multiselect, - placeholderText: - t("actions.filterBy", { - what: t("terms.tagName").toLowerCase(), - }) + "...", - getItemValue: (item) => { - let tagNames = item?.tags?.map((tag) => tag.name).join(""); - return tagNames || ""; - }, - selectOptions: dedupeFunction( - tagCategories - ?.map((tagCategory) => tagCategory?.tags) - .flat() - .filter((tag) => tag && tag.name) - .map((tag) => ({ key: tag?.name, value: tag?.name })) - ), - }, - ]; - - const { filterValues, setFilterValues, filteredItems } = useLegacyFilterState( - applications || [], - filterCategories, - "applicationsFilter" - ); - - const handleOnClearAllFilters = () => { - setFilterValues({}); - }; - - const getSortValues = (item: Application) => [ - "", - item?.name || "", - "", - item.businessService?.name || "", - "", - ...(tableType === ApplicationTableType.Assessment ? [""] : []), - item.tags?.length || 0, - "", // Action column - ]; - - const { sortBy, onSort, sortedItems } = useLegacySortState( - filteredItems, - getSortValues - ); - - //Bulk selection - const { - isItemSelected: isRowSelected, - toggleItemSelected: toggleRowSelected, - selectAll, - selectMultiple, - areAllSelected, - selectedItems: selectedRows, - } = useSelectionState({ - items: filteredItems || [], - isEqual: (a, b) => a.id === b.id, - }); - - const { currentPageItems, setPageNumber, paginationProps } = - useLegacyPaginationState(sortedItems, 10); - - const [activeAppInDetailDrawer, openDetailDrawer] = - React.useState(null); - const closeDetailDrawer = () => openDetailDrawer(null); - - return { - currentPageItems, - paginationProps, - sortBy, - onSort, - filterCategories, - filterValues, - setFilterValues, - handleOnClearAllFilters, - isRowSelected, - toggleRowSelected, - selectAll, - selectMultiple, - areAllSelected, - selectedRows, - openDetailDrawer, - closeDetailDrawer, - activeAppInDetailDrawer, - setPageNumber, - }; -}; diff --git a/client/src/app/pages/applications/manage-imports-details/manage-imports-details.tsx b/client/src/app/pages/applications/manage-imports-details/manage-imports-details.tsx index 1ccf437a79..2aba12f003 100644 --- a/client/src/app/pages/applications/manage-imports-details/manage-imports-details.tsx +++ b/client/src/app/pages/applications/manage-imports-details/manage-imports-details.tsx @@ -151,7 +151,6 @@ export const ManageImportsDetails: React.FC = () => { path: "", }, ]} - menuActions={[]} /> diff --git a/client/src/app/pages/applications/manage-imports/manage-imports.tsx b/client/src/app/pages/applications/manage-imports/manage-imports.tsx index 69a89f3dcd..e32788867e 100644 --- a/client/src/app/pages/applications/manage-imports/manage-imports.tsx +++ b/client/src/app/pages/applications/manage-imports/manage-imports.tsx @@ -303,7 +303,6 @@ export const ManageImports: React.FC = () => { path: "", }, ]} - menuActions={[]} /> diff --git a/client/src/app/pages/assessment/components/assessment-page-header.tsx b/client/src/app/pages/assessment/components/assessment-page-header.tsx index 6644d0e3f8..4e3d89740c 100644 --- a/client/src/app/pages/assessment/components/assessment-page-header.tsx +++ b/client/src/app/pages/assessment/components/assessment-page-header.tsx @@ -66,7 +66,6 @@ export const AssessmentPageHeader: React.FC = ({ )} } - menuActions={[]} /> { {t("message.reviewInstructions")} } breadcrumbs={breadcrumbs} - menuActions={[]} /> @@ -97,7 +96,6 @@ const ReviewPage: React.FC = () => { {t("message.reviewInstructions")} } breadcrumbs={breadcrumbs} - menuActions={[]} />