Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into finsoup
  • Loading branch information
pkim-gswell committed Nov 14, 2023
2 parents fb73ca6 + 0414968 commit 1333188
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 36 deletions.
7 changes: 4 additions & 3 deletions src/services/ui/src/components/Opensearch/Filtering/consts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OsField, OsFilterable } from "shared-types";
import { OsFilterComponentType } from "./types";
import { UserRoles } from "shared-types";

type DrawerFilterableGroup = {
label: string;
Expand All @@ -16,7 +17,7 @@ type DrawerFilterableGroup = {
* - value: query value
*/
export const FILTER_GROUPS = (
isCms?: boolean
user?: any
): Partial<Record<OsField, OsFilterable & DrawerFilterableGroup>> => {
return {
"state.keyword": {
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>([]);
const params = useOsParams();
const labelMap = useLabelMapping();
Expand Down
26 changes: 8 additions & 18 deletions src/services/ui/src/components/Opensearch/useOpensearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OsTab, Partial<OsParamsState>> = {
spas: {
filters: [
Expand All @@ -30,20 +28,18 @@ export const DEFAULT_FILTERS: Record<OsTab, Partial<OsParamsState>> = {
],
},
};

/**
*
* @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<SearchData>();
const { mutateAsync, isLoading, error } = useOsSearch();

const onRequest = async (query: OsQueryState, options?: any) => {
try {
await mutateAsync(
Expand All @@ -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();
Expand Down Expand Up @@ -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,
},
Expand All @@ -115,12 +108,9 @@ export const useOsAggregate = () => {
});
},
});

return aggs.data?.aggregations;
};

export type OsParamsState = OsQueryState & { tab: OsTab };

export const useOsParams = () => {
return useParams<OsParamsState>({
key: "os",
Expand All @@ -132,4 +122,4 @@ export const useOsParams = () => {
sort: { field: "changedDate", order: "desc" },
},
});
};
};
2 changes: 1 addition & 1 deletion src/services/ui/src/components/Opensearch/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions src/services/ui/src/components/Pagination/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import type { Props } from "./types";
import { pageStateResolver } from "./utils";
import { cn } from "@/lib/utils";

const maxRecordCount = 10000;

export const Pagination: FC<Props> = (props) => {
const count = props.count > maxRecordCount ? maxRecordCount : props.count;
const state = pageStateResolver({
pageNumber: props.pageNumber,
pageSize: props.pageSize,
count: props.count,
count,
});

return (
Expand Down Expand Up @@ -40,7 +43,7 @@ export const Pagination: FC<Props> = (props) => {
<span className="font-bold">{state.lowerBoundValue}</span>-
<span className="font-bold">{state.upperBoundValue}</span>
of
<span className="font-bold">{props.count}</span>
<span className="font-bold">{count}</span>
records
</p>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/services/ui/src/components/UsaBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ export const UsaBanner = () => {
{hasRole && (
<div className="w-full px-4 py-1 lg:px-8 text-xs mx-auto flex gap-2 items-center justify-center bg-red-200 ">
<p className="text-center text-base">
You do not have access to view the application
You do not have access to view the entire application.{" "}
<a
rel="noreferrer"
href="https://home.idm.cms.gov/signin/login.html"
href="https://test.home.idm.cms.gov/"
target="_blank"
className="text-blue-600 inline no-underline"
>
Please visit IDM
</a>{" "}
to request the appropriate user role(s) - FAIL
to request the appropriate user role(s).
</p>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/services/ui/src/pages/dashboard/Lists/spas/consts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions src/services/ui/src/pages/detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -33,12 +33,10 @@ const DetailCardWrapper = ({
</div>
</CardWithTopBorder>
);
const StatusCard = ({ isCms, data }: { isCms: boolean; data: ItemResult }) => (
const StatusCard = ({ status }: { status: string }) => (
<DetailCardWrapper title={"Status"}>
<div>
<h2 className="text-xl font-semibold">
{isCms ? data._source.cmsStatus : data._source.stateStatus}
</h2>
<h2 className="text-xl font-semibold">{status}</h2>
</div>
</DetailCardWrapper>
);
Expand Down Expand Up @@ -73,6 +71,10 @@ const PackageActionsCard = ({ id }: { id: string }) => {
export const DetailsContent = ({ data }: { data?: ItemResult }) => {
const { data: user } = useGetUser();
if (!data?._source) return <LoadingSpinner />;
const status =
user?.isCms && !user.user?.["custom:cms-roles"].includes(UserRoles.HELPDESK)
? data._source.cmsStatus
: data._source.stateStatus;
return (
<div className="block md:flex">
<aside className="flex-none font-bold hidden md:block pr-8">
Expand All @@ -99,7 +101,7 @@ export const DetailsContent = ({ data }: { data?: ItemResult }) => {
id="package-overview"
className="sm:flex lg:grid lg:grid-cols-2 gap-4 my-6"
>
<StatusCard isCms={user?.isCms || false} data={data} />
<StatusCard status={status} />
<PackageActionsCard id={data._id} />
</section>
<DetailsSection id="package-details" title="Package Details">
Expand Down

0 comments on commit 1333188

Please sign in to comment.