Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
EVG-19904: Augment user subscription table features (#1873)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad authored Jun 7, 2023
1 parent 7933971 commit 4ee6c94
Show file tree
Hide file tree
Showing 18 changed files with 458 additions and 180 deletions.
54 changes: 51 additions & 3 deletions cypress/integration/preferences/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,65 @@ describe("global subscription settings", () => {
});

describe("user subscriptions table", () => {
it("shows all of a user's subscriptions and expands with details", () => {
beforeEach(() => {
cy.visit(pageRoute);
});

it("shows all of a user's subscriptions and expands with details", () => {
cy.dataCy("subscription-row").should("have.length", 3);

cy.dataCy("regex-selectors").should("not.be.visible");
cy.dataCy("trigger-data").should("not.be.visible");
cy.get("tr button").first().click();
cy.dataCy("subscription-row")
.eq(0)
.within(() => {
cy.get("button").first().click();
});
cy.dataCy("regex-selectors").should("be.visible");
cy.dataCy("trigger-data").should("not.be.visible");
cy.get("tr button").last().click();
cy.dataCy("subscription-row")
.eq(2)
.within(() => {
cy.get("button").first().click();
});
cy.dataCy("regex-selectors").should("be.visible");
cy.dataCy("trigger-data").should("be.visible");
});

it("Shows the selected count in the 'Delete' button", () => {
cy.dataCy("subscription-row")
.eq(0)
.within(() => {
cy.get("input[type=checkbox]").check({ force: true });
});
cy.dataCy("delete-some-button").contains("Delete (1)");

cy.get("thead").within(() => {
cy.get("input[type=checkbox]").check({ force: true });
});
cy.dataCy("delete-some-button").contains("Delete (3)");

cy.get("thead").within(() => {
cy.get("input[type=checkbox]").uncheck({ force: true });
});
cy.dataCy("delete-some-button").contains("Delete");
cy.dataCy("delete-some-button").should(
"have.attr",
"aria-disabled",
"true"
);
});

describe("Deleting subscriptions", { testIsolation: false }, () => {
it("Deletes a single subscription", () => {
cy.dataCy("subscription-row")
.eq(0)
.within(() => {
cy.get("input[type=checkbox]").check({ force: true });
});
cy.dataCy("delete-some-button").click();
cy.validateToast("success", "Deleted 1 subscription.");
cy.dataCy("subscription-row").should("have.length", 2);
});
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@leafygreen-ui/menu": "20.0.0",
"@leafygreen-ui/modal": "14.0.1",
"@leafygreen-ui/number-input": "1.0.4",
"@leafygreen-ui/pagination": "1.0.7",
"@leafygreen-ui/palette": "3.4.4",
"@leafygreen-ui/popover": "11.0.1",
"@leafygreen-ui/radio-box-group": "12.0.1",
Expand Down
51 changes: 51 additions & 0 deletions src/components/Table/BaseTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
Cell,
ExpandedContent,
flexRender,
HeaderCell,
HeaderRow,
type LGRowData,
Row,
Table,
TableBody,
type TableProps,
TableHead,
} from "@leafygreen-ui/table/new";

type SpruceTableProps = {
"data-cy-row"?: string;
"data-cy-table"?: string;
};

export const BaseTable = <T extends LGRowData>({
"data-cy-row": dataCyRow,
"data-cy-table": dataCyTable,
table,
...args
}: SpruceTableProps & TableProps<T>) => (
<Table data-cy={dataCyTable} table={table} {...args}>
<TableHead>
{table.getHeaderGroups().map((headerGroup) => (
<HeaderRow key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<HeaderCell key={header.id} header={header}>
{flexRender(header.column.columnDef.header, header.getContext())}
</HeaderCell>
))}
</HeaderRow>
))}
</TableHead>
<TableBody>
{table.getRowModel().rows.map((row) => (
<Row key={row.id} row={row} data-cy={dataCyRow}>
{row.getVisibleCells().map((cell) => (
<Cell key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</Cell>
))}
{row.original.renderExpandedContent && <ExpandedContent row={row} />}
</Row>
))}
</TableBody>
</Table>
);
46 changes: 46 additions & 0 deletions src/components/Table/LGFilters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { LeafyGreenTableRow } from "@leafygreen-ui/table/new";
import { TableFilterPopover } from "components/TablePopover";
import { TreeDataEntry } from "components/TreeSelect";

type TreeSelectFilterProps = {
"data-cy"?: string;
tData: TreeDataEntry[];
title: React.ReactNode;
};

export const getColumnTreeSelectFilterProps = ({
"data-cy": dataCy,
tData,
title,
}: TreeSelectFilterProps) => ({
header: ({ column }) => {
// Only present options that appear in the table
const options = tData.filter(
({ value }) => !!column.getFacetedUniqueValues().get(value)
);
return (
<>
{title}
<TableFilterPopover
value={column?.getFilterValue() ?? []}
options={options}
onConfirm={(value) => {
column.setFilterValue(value);
}}
data-cy={dataCy}
/>
</>
);
},
filterFn: (
row: LeafyGreenTableRow<any>,
columnId: string,
filterValue: string[]
) => {
// If no filter is specified, show all rows
if (!filterValue.length) {
return true;
}
return filterValue.includes(row.getValue(columnId));
},
});
24 changes: 11 additions & 13 deletions src/components/TreeSelect/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ const renderCheckboxesHelper = ({
state: string[];
tData: TreeDataEntry[];
}): void => {
const ParentCheckboxWrapper = getCheckboxWrapper(0);
// push parent
const onChangeFn = (): void =>
handleOnChange({ state, value: data.value, onChange, tData });
rows.push(
<ParentCheckboxWrapper key={data.key}>
<CheckboxWrapper key={data.key} level={0} isAll={data.value === ALL_VALUE}>
<Checkbox
className="cy-checkbox"
onChange={onChangeFn}
Expand All @@ -150,16 +149,19 @@ const renderCheckboxesHelper = ({
bold={false}
data-cy="checkbox"
/>
</ParentCheckboxWrapper>
</CheckboxWrapper>
);
// then examine children
const ChildCheckboxWrapper = getCheckboxWrapper(1);
if (data.children) {
data.children.forEach((child) => {
const onChangeChildFn = (): void =>
handleOnChange({ state, value: child.value, onChange, tData });
rows.push(
<ChildCheckboxWrapper key={`${data.key}-${child.key}`}>
<CheckboxWrapper
key={`${data.key}-${child.key}`}
level={1}
isAll={child.value === ALL_VALUE}
>
<Checkbox
className="cy-checkbox"
onChange={onChangeChildFn}
Expand All @@ -168,7 +170,7 @@ const renderCheckboxesHelper = ({
bold={false}
data-cy="checkbox"
/>
</ChildCheckboxWrapper>
</CheckboxWrapper>
);
});
}
Expand Down Expand Up @@ -317,15 +319,11 @@ const getAllValues = (tData: TreeDataEntry[]): string[] =>
return accum.concat([currNode.value]).concat(childrenValues);
}, []);

const getCheckboxWrapper = (
level: number
): React.VFC<{ children: React.ReactNode }> => styled.div`
padding-left: ${level}em;
const CheckboxWrapper = styled.div<{ level: number; isAll: boolean }>`
padding-left: ${({ level }) => `${level}em`};
padding-top: ${size.xxs};
padding-bottom: ${size.xxs};
:first-of-type {
border-bottom: 1px solid ${gray.light2};
}
${({ isAll }) => isAll && `border-bottom: 1px solid ${gray.light2};`}
`;

const OptionsWrapper = styled.div`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`storybook Storyshots components/TreeSelect Default 1`] = `
data-cy="tree-select-options"
>
<div
class="css-u0wfkk-getCheckboxWrapper e1mpj03z3"
class="css-j2ntgf-CheckboxWrapper e1mpj03z3"
>
<div
class="leafygreen-ui-55kazc cy-checkbox"
Expand Down Expand Up @@ -60,7 +60,7 @@ exports[`storybook Storyshots components/TreeSelect Default 1`] = `
</div>
</div>
<div
class="css-u0wfkk-getCheckboxWrapper e1mpj03z3"
class="css-6y9iv7-CheckboxWrapper e1mpj03z3"
>
<div
class="leafygreen-ui-55kazc cy-checkbox"
Expand Down Expand Up @@ -113,7 +113,7 @@ exports[`storybook Storyshots components/TreeSelect Default 1`] = `
</div>
</div>
<div
class="css-1i6181l-getCheckboxWrapper e1mpj03z3"
class="css-154o89o-CheckboxWrapper e1mpj03z3"
>
<div
class="leafygreen-ui-55kazc cy-checkbox"
Expand Down Expand Up @@ -166,7 +166,7 @@ exports[`storybook Storyshots components/TreeSelect Default 1`] = `
</div>
</div>
<div
class="css-1i6181l-getCheckboxWrapper e1mpj03z3"
class="css-154o89o-CheckboxWrapper e1mpj03z3"
>
<div
class="leafygreen-ui-55kazc cy-checkbox"
Expand Down Expand Up @@ -219,7 +219,7 @@ exports[`storybook Storyshots components/TreeSelect Default 1`] = `
</div>
</div>
<div
class="css-1i6181l-getCheckboxWrapper e1mpj03z3"
class="css-154o89o-CheckboxWrapper e1mpj03z3"
>
<div
class="leafygreen-ui-55kazc cy-checkbox"
Expand Down Expand Up @@ -272,7 +272,7 @@ exports[`storybook Storyshots components/TreeSelect Default 1`] = `
</div>
</div>
<div
class="css-u0wfkk-getCheckboxWrapper e1mpj03z3"
class="css-6y9iv7-CheckboxWrapper e1mpj03z3"
>
<div
class="leafygreen-ui-55kazc cy-checkbox"
Expand Down Expand Up @@ -325,7 +325,7 @@ exports[`storybook Storyshots components/TreeSelect Default 1`] = `
</div>
</div>
<div
class="css-u0wfkk-getCheckboxWrapper e1mpj03z3"
class="css-6y9iv7-CheckboxWrapper e1mpj03z3"
>
<div
class="leafygreen-ui-55kazc cy-checkbox"
Expand Down Expand Up @@ -378,7 +378,7 @@ exports[`storybook Storyshots components/TreeSelect Default 1`] = `
</div>
</div>
<div
class="css-u0wfkk-getCheckboxWrapper e1mpj03z3"
class="css-6y9iv7-CheckboxWrapper e1mpj03z3"
>
<div
class="leafygreen-ui-55kazc cy-checkbox"
Expand Down Expand Up @@ -431,7 +431,7 @@ exports[`storybook Storyshots components/TreeSelect Default 1`] = `
</div>
</div>
<div
class="css-u0wfkk-getCheckboxWrapper e1mpj03z3"
class="css-6y9iv7-CheckboxWrapper e1mpj03z3"
>
<div
class="leafygreen-ui-55kazc cy-checkbox"
Expand Down
5 changes: 3 additions & 2 deletions src/components/styles/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { size } from "constants/tokens";
const { white, gray } = palette;

export const PopoverContainer = styled.div`
background-color: ${white};
border-radius: ${size.s};
box-shadow: 0px 2px 4px -1px ${gray.base};
display: flex;
flex-direction: column;
background-color: ${white};
padding: ${size.s};
box-shadow: 0px 2px 4px -1px ${gray.base};
`;
Loading

0 comments on commit 4ee6c94

Please sign in to comment.