Skip to content

Commit

Permalink
Merge pull request #773 from Enterprise-CMCS/main
Browse files Browse the repository at this point in the history
Release to val
  • Loading branch information
tiffanyvu authored Sep 16, 2024
2 parents 1799227 + 45c528f commit 1bda0a7
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 360 deletions.
660 changes: 325 additions & 335 deletions lib/local-constructs/clamav-scanning/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/local-constructs/clamav-scanning/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"esbuild": "^0.21.5"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.620.0",
"@aws-sdk/client-s3": "^3.635.0",
"@types/mime-types": "^2.1.4",
"file-type": "^19.3.0",
"mime-types": "^2.1.35",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { useState } from "react";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, test, beforeEach } from "vitest";
import { type OsTableColumn, VisibilityPopover } from "../index";

const MockOsFilteringWrapper = () => {
const [columns, setColumns] = useState<OsTableColumn[]>([
{
field: "state.keyword",
label: "State",
cell: () => "",
},
{
field: "authority.keyword",
label: "Authority",
cell: () => "",
},
{
field: "stateStatus.keyword",
label: "Status",
hidden: true,
cell: () => "",
},
]);

const onToggle = (field: string) => {
setColumns((state) => {
return state?.map((S) => {
if (S.field !== field) return S;
return { ...S, hidden: !S.hidden };
});
});
};

return (
<VisibilityPopover
list={columns.filter((COL) => !COL.locked || COL.field)}
onItemClick={onToggle}
hiddenColumns={columns.filter((COL) => COL.hidden === true)}
/>
);
};

describe("Visibility button", () => {
beforeEach(() => {
render(<MockOsFilteringWrapper />);
});

test("Visibility button should show number of hidden columns if any", async () => {
expect(screen.getByText("Columns (1 hidden)")).toBeInTheDocument();
await userEvent.click(screen.getByText("Columns (1 hidden)"));

const stateColumnMenuItem = screen.getByText("State");
await userEvent.click(stateColumnMenuItem);

expect(screen.getByText("Columns (2 hidden)")).toBeInTheDocument();
});

test("Visibility button text should not show number if no hidden columns", async () => {
expect(screen.getByText("Columns (1 hidden)")).toBeInTheDocument();
await userEvent.click(screen.getByText("Columns (1 hidden)"));

const statusColumnMenuItem = screen.getByText("Status");
await userEvent.click(statusColumnMenuItem);

expect(screen.getByText("Columns")).toBeInTheDocument();
});
});
14 changes: 10 additions & 4 deletions react-app/src/components/Opensearch/main/Filtering/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { useOsUrl } from "../useOpensearch";
import { useOsContext } from "../Provider";
import { OsFilterDrawer } from "./Drawer";
import { OsExportData } from "./Export";

import { VisibilityPopover } from "@/components";
export const OsFiltering: FC<{
columns: OsTableColumn[];
onToggle: (field: string) => void;
disabled?: boolean;
}> = (props) => {
}> = ({ columns, onToggle, disabled }) => {
const url = useOsUrl();
const context = useOsContext();

Expand All @@ -27,11 +28,16 @@ export const OsFiltering: FC<{
search,
}))
}
disabled={!!props.disabled}
disabled={!!disabled}
/>
<div className="flex justify-center flex-row gap-2">
<OsExportData columns={props.columns} disabled={context?.data?.total.value === 0}/>
<VisibilityPopover
list={columns.filter((COL) => COL.locked === false || COL.field)}
onItemClick={onToggle}
hiddenColumns={columns.filter((COL) => COL.hidden === true)}
/>
<OsFilterDrawer />
<OsExportData columns={columns} disabled={context?.data?.total.value === 0}/>
</div>
</div>
</div>
Expand Down
31 changes: 23 additions & 8 deletions react-app/src/components/Opensearch/main/Settings/Visibility.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,43 @@ import * as UI from "@/components";
type Props<T extends UI.OsTableColumn> = {
list: T[];
onItemClick: (field: string) => void;
hiddenColumns: T[];
};

export const VisibilityPopover = <T extends UI.OsTableColumn>(
props: Props<T>
) => {
export const VisibilityPopover = ({
list,
onItemClick,
hiddenColumns,
}: Props<UI.OsTableColumn>) => {
return (
<UI.Popover>
<UI.PopoverTrigger>
<EyeIcon className="w-6 h-6" />
<p className="sr-only">Visibility Popover Icon</p>
<UI.PopoverTrigger asChild>
<UI.Button
variant="outline"
className="w-full xs:w-fit min-w-0 whitespace-nowrap hover:bg-transparent self-center h-10 flex gap-2"
>
<span className="prose-sm">
{hiddenColumns.length
? `Columns (${hiddenColumns.length} hidden)`
: "Columns"}
</span>
</UI.Button>
</UI.PopoverTrigger>
<UI.PopoverContent className="bg-white">
<div className="flex flex-col gap-2">
<VisibilityMenu {...props} />
<VisibilityMenu
list={list}
onItemClick={onItemClick}
hiddenColumns={hiddenColumns}
/>
</div>
</UI.PopoverContent>
</UI.Popover>
);
};

export const VisiblityItem = <T extends UI.OsTableColumn>(
props: T & { onClick: () => void }
props: T & { onClick: () => void },
) => {
const eyeStyles = cn("flex flex-row gap-2 cursor-pointer", {
"text-gray-800": !props.hidden,
Expand Down
11 changes: 0 additions & 11 deletions react-app/src/components/Opensearch/main/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { FC } from "react";
import { OsTableColumn } from "./types";
import { useOsContext } from "../Provider";
import { useOsUrl, LoadingSpinner } from "@/components";
import { VisibilityPopover } from "../Settings";
import { BLANK_VALUE } from "@/consts";
import { opensearch } from "shared-types";

Expand All @@ -18,15 +17,6 @@ export const OsTable: FC<{
<UI.Table className="overflow-scroll w-full">
<UI.TableHeader className="sticky top-0 bg-white">
<UI.TableRow>
<UI.TableHead
className="w-[10px]"
icon={
<VisibilityPopover
list={props.columns.filter((COL) => !COL.locked || COL.field)}
onItemClick={props.onToggle}
/>
}
/>
{props.columns.map((TH) => {
if (TH.hidden) return null;
return (
Expand Down Expand Up @@ -79,7 +69,6 @@ export const OsTable: FC<{
)}
{context.data?.hits.map((DAT) => (
<UI.TableRow className="max-h-1" key={DAT._source.id}>
<UI.TableCell className="fixed" />
{props.columns.map((COL) => {
if (COL.hidden) return null;
return (
Expand Down
2 changes: 1 addition & 1 deletion react-app/src/components/Opensearch/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const OsMainView: FC<{

return (
<section className="flex md:items-stretch items-center flex-col h-[100vh]">
<OsFiltering columns={osColumns} />
<OsFiltering onToggle={onToggle} columns={osColumns}/>
<OsTable onToggle={onToggle} columns={osColumns} />
<Pagination
pageNumber={url.state.pagination.number}
Expand Down

0 comments on commit 1bda0a7

Please sign in to comment.