From 0732f3d32838bcd49ab2f7e4e50d7d58767bd782 Mon Sep 17 00:00:00 2001 From: Benjamin Paige Date: Wed, 8 Nov 2023 20:10:35 -0700 Subject: [PATCH 1/3] fix(status-filter): fix cms status filtering bug --- src/services/ui/src/components/Opensearch/utils.ts | 2 +- src/services/ui/src/pages/dashboard/Lists/spas/consts.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/ui/src/components/Opensearch/utils.ts b/src/services/ui/src/components/Opensearch/utils.ts index d394491276..a52248c7b8 100644 --- a/src/services/ui/src/components/Opensearch/utils.ts +++ b/src/services/ui/src/components/Opensearch/utils.ts @@ -60,7 +60,7 @@ export const paginationQueryBuilder = ( ) => { const from = (() => { if (!pagination.number) return 0; - return pagination.number * pagination.size - 1; + return pagination.number * pagination.size; })(); return { diff --git a/src/services/ui/src/pages/dashboard/Lists/spas/consts.tsx b/src/services/ui/src/pages/dashboard/Lists/spas/consts.tsx index 95abf69592..147db76f8e 100644 --- a/src/services/ui/src/pages/dashboard/Lists/spas/consts.tsx +++ b/src/services/ui/src/pages/dashboard/Lists/spas/consts.tsx @@ -47,7 +47,7 @@ export const TABLE_COLUMNS = (props?: { : BLANK_VALUE, }, { - field: props?.isCms ? "cmsStatus" : "stateStatus.keyword", + field: props?.isCms ? "cmsStatus.keyword" : "stateStatus.keyword", label: "Status", cell: (data) => props?.isCms && !(props.user?.["custom:cms-roles"] === UserRoles.HELPDESK) From 3a9d290de472b74bb7c834a8901f019d90b7f0a2 Mon Sep 17 00:00:00 2001 From: Walesango2 <110047743+Walesango2@users.noreply.github.com> Date: Mon, 13 Nov 2023 09:13:12 -0500 Subject: [PATCH 2/3] feat(Role based users update): update package status in all instances where applicable (#187) * feat(Role based users update): update record status * feat(Role based users update): update record status * feat(Role based users update): update record status * feat(Role based users update): update record status * feat(Role based users update): update record status --------- Co-authored-by: Adewale Sangobiyi Co-authored-by: Adewale Sangobiyi --- .../components/Opensearch/Filtering/consts.ts | 7 ++--- .../components/Opensearch/Filtering/index.tsx | 2 +- .../Opensearch/Filtering/useFilterDrawer.ts | 2 +- .../components/Opensearch/useOpensearch.ts | 26 ++++++------------- .../ui/src/components/UsaBanner/index.tsx | 6 ++--- src/services/ui/src/pages/detail/index.tsx | 14 +++++----- 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/services/ui/src/components/Opensearch/Filtering/consts.ts b/src/services/ui/src/components/Opensearch/Filtering/consts.ts index 1584be1fab..c6da029d07 100644 --- a/src/services/ui/src/components/Opensearch/Filtering/consts.ts +++ b/src/services/ui/src/components/Opensearch/Filtering/consts.ts @@ -1,5 +1,6 @@ import { OsField, OsFilterable } from "shared-types"; import { OsFilterComponentType } from "./types"; +import { UserRoles } from "shared-types"; type DrawerFilterableGroup = { label: string; @@ -16,7 +17,7 @@ type DrawerFilterableGroup = { * - value: query value */ export const FILTER_GROUPS = ( - isCms?: boolean + user?: any ): Partial> => { return { "state.keyword": { @@ -43,9 +44,9 @@ export const FILTER_GROUPS = ( type: "terms", value: [], }, - [isCms ? "cmsStatus.keyword" : "stateStatus.keyword"]: { + [(user?.isCms && !user.user?.["custom:cms-roles"].includes(UserRoles.HELPDESK)) ? "cmsStatus.keyword" : "stateStatus.keyword"]: { label: "Status", - field: isCms ? "cmsStatus.keyword" : "stateStatus.keyword", + field: (user?.isCms && !user.user?.["custom:cms-roles"].includes(UserRoles.HELPDESK)) ? "cmsStatus.keyword" : "stateStatus.keyword", component: "multiCheck", prefix: "must", type: "terms", diff --git a/src/services/ui/src/components/Opensearch/Filtering/index.tsx b/src/services/ui/src/components/Opensearch/Filtering/index.tsx index 4fb5d81302..223a77fa32 100644 --- a/src/services/ui/src/components/Opensearch/Filtering/index.tsx +++ b/src/services/ui/src/components/Opensearch/Filtering/index.tsx @@ -69,7 +69,7 @@ export const OsFiltering: FC<{ { name: "Status", transform(data) { - if (user.data?.isCms) { + if (user?.data?.isCms && !user?.data?.user) { if (data.cmsStatus) { return data.cmsStatus; } diff --git a/src/services/ui/src/components/Opensearch/Filtering/useFilterDrawer.ts b/src/services/ui/src/components/Opensearch/Filtering/useFilterDrawer.ts index 48f70a699a..2ff772e4c9 100644 --- a/src/services/ui/src/components/Opensearch/Filtering/useFilterDrawer.ts +++ b/src/services/ui/src/components/Opensearch/Filtering/useFilterDrawer.ts @@ -10,7 +10,7 @@ import { useGetUser } from "@/api/useGetUser"; export const useFilterDrawer = () => { const { drawerOpen, setDrawerState } = useFilterDrawerContext(); const { data: user } = useGetUser(); - const [filters, setFilters] = useState(Consts.FILTER_GROUPS(user?.isCms)); + const [filters, setFilters] = useState(Consts.FILTER_GROUPS(user)); const [accordionValues, setAccordionValues] = useState([]); const params = useOsParams(); const labelMap = useLabelMapping(); diff --git a/src/services/ui/src/components/Opensearch/useOpensearch.ts b/src/services/ui/src/components/Opensearch/useOpensearch.ts index 6a2650d436..728fc6de06 100644 --- a/src/services/ui/src/components/Opensearch/useOpensearch.ts +++ b/src/services/ui/src/components/Opensearch/useOpensearch.ts @@ -5,9 +5,7 @@ import { OsQueryState, SearchData, UserRoles } from "shared-types"; import { createSearchFilterable } from "./utils"; import { useQuery } from "@tanstack/react-query"; import { useGetUser } from "@/api/useGetUser"; - export type OsTab = "waivers" | "spas"; - export const DEFAULT_FILTERS: Record> = { spas: { filters: [ @@ -30,20 +28,18 @@ export const DEFAULT_FILTERS: Record> = { ], }, }; - /** * - * @summary - * use with main - * Comments - * - TODO: add index scope - * - FIX: Initial render fires useEffect twice - 2 os requests +@summary +use with main +Comments +- TODO: add index scope +- FIX: Initial render fires useEffect twice - 2 os requests */ export const useOsQuery = () => { const params = useOsParams(); const [data, setData] = useState(); const { mutateAsync, isLoading, error } = useOsSearch(); - const onRequest = async (query: OsQueryState, options?: any) => { try { await mutateAsync( @@ -62,14 +58,11 @@ export const useOsQuery = () => { console.error("Error occurred during search:", error); } }; - useEffect(() => { onRequest(params.state); }, [params.queryString]); - return { data, isLoading, error, ...params }; }; - export const useOsAggregate = () => { const { data: user } = useGetUser(); const { state } = useOsParams(); @@ -98,8 +91,8 @@ export const useOsAggregate = () => { size: 10, }, { - field: user?.isCms ? "cmsStatus.keyword" : "stateStatus.keyword", - name: user?.isCms ? "cmsStatus.keyword" : "stateStatus.keyword", + field: (user?.isCms && !user.user?.["custom:cms-roles"].includes(UserRoles.HELPDESK)) ? "cmsStatus.keyword" : "stateStatus.keyword", + name: (user?.isCms && !user.user?.["custom:cms-roles"].includes(UserRoles.HELPDESK)) ? "cmsStatus.keyword" : "stateStatus.keyword", type: "terms", size: 10, }, @@ -115,12 +108,9 @@ export const useOsAggregate = () => { }); }, }); - return aggs.data?.aggregations; }; - export type OsParamsState = OsQueryState & { tab: OsTab }; - export const useOsParams = () => { return useParams({ key: "os", @@ -132,4 +122,4 @@ export const useOsParams = () => { sort: { field: "changedDate", order: "desc" }, }, }); -}; +}; \ No newline at end of file diff --git a/src/services/ui/src/components/UsaBanner/index.tsx b/src/services/ui/src/components/UsaBanner/index.tsx index 0da55d29c2..da0572429c 100644 --- a/src/services/ui/src/components/UsaBanner/index.tsx +++ b/src/services/ui/src/components/UsaBanner/index.tsx @@ -75,16 +75,16 @@ export const UsaBanner = () => { {hasRole && (

- You do not have access to view the application + You do not have access to view the entire application.{" "} Please visit IDM {" "} - to request the appropriate user role(s) - FAIL + to request the appropriate user role(s).

)} diff --git a/src/services/ui/src/pages/detail/index.tsx b/src/services/ui/src/pages/detail/index.tsx index e733d2c7e7..45713b7747 100644 --- a/src/services/ui/src/pages/detail/index.tsx +++ b/src/services/ui/src/pages/detail/index.tsx @@ -10,7 +10,7 @@ import { SubmissionInfo, } from "@/components"; import { useGetUser } from "@/api/useGetUser"; -import { ItemResult } from "shared-types"; +import { ItemResult, UserRoles } from "shared-types"; import { useQuery } from "@/hooks"; import { useGetItem } from "@/api"; import { BreadCrumbs } from "@/components/BreadCrumb"; @@ -33,12 +33,10 @@ const DetailCardWrapper = ({ ); -const StatusCard = ({ isCms, data }: { isCms: boolean; data: ItemResult }) => ( +const StatusCard = ({ status }: { status: string }) => (
-

- {isCms ? data._source.cmsStatus : data._source.stateStatus} -

+

{status}

); @@ -73,6 +71,10 @@ const PackageActionsCard = ({ id }: { id: string }) => { export const DetailsContent = ({ data }: { data?: ItemResult }) => { const { data: user } = useGetUser(); if (!data?._source) return ; + const status = + user?.isCms && !user.user?.["custom:cms-roles"].includes(UserRoles.HELPDESK) + ? data._source.cmsStatus + : data._source.stateStatus; return (