Skip to content

Commit 30c368d

Browse files
authored
feat: add filter tags to data dictionary (#529) (#536)
1 parent d189f5f commit 30c368d

30 files changed

Lines changed: 398 additions & 60 deletions

File tree

src/components/DataDictionary/components/Entities/constants.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { ComponentProps } from "react";
33
import { NoResults } from "../../../NoResults/noResults";
44
import { StyledRoundedPaper } from "./entities.styles";
55

6-
export const ENTITIES_ROW_GAP = 8;
7-
86
export const GRID_PROPS: GridProps = {
97
container: true,
108
direction: "column",
119
flexWrap: "nowrap",
12-
rowGap: ENTITIES_ROW_GAP,
10+
rowGap: 8,
1311
};
1412

1513
export const NO_RESULTS_PROPS: ComponentProps<typeof NoResults> = {

src/components/DataDictionary/components/Entity/entity.styles.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
import styled from "@emotion/styled";
22
import { Typography } from "@mui/material";
33
import { LayoutSpacing } from "../../hooks/UseLayoutSpacing/types";
4-
import { ENTITIES_ROW_GAP } from "../Entities/constants";
5-
import { LAYOUT_SPACING } from "../Layout/constants";
6-
7-
const TOP =
8-
ENTITIES_ROW_GAP +
9-
LAYOUT_SPACING.TITLE_HEIGHT +
10-
LAYOUT_SPACING.FILTERS_HEIGHT +
11-
LAYOUT_SPACING.FILTERS_PADDING_TOP +
12-
LAYOUT_SPACING.CONTENT_PADDING_TOP;
134

145
export const StyledTypography = styled(Typography)<Partial<LayoutSpacing>>`
15-
scroll-margin-top: ${({ top = 0 }) => top + TOP}px;
6+
scroll-margin-top: ${({ top = 0 }) => top}px;
167
178
&:hover a {
189
opacity: 1;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import styled from "@emotion/styled";
2+
import { Grid } from "@mui/material";
3+
4+
export const StyledGrid = styled(Grid)`
5+
.MuiChip-root:last-of-type {
6+
margin-right: 8px;
7+
}
8+
`;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Button } from "@mui/material";
2+
import { RowData } from "@tanstack/react-table";
3+
import React from "react";
4+
import { Attribute } from "../../../../../../common/entities";
5+
import { BUTTON_PROPS } from "../../../../../../styles/common/mui/button";
6+
import { ColumnFilterTag } from "../../../../../Table/components/TableFeatures/ColumnFilter/components/ColumnFilterTag/columnFilterTag";
7+
import { StyledGrid } from "./columnFilterTags.styles";
8+
import { GRID_PROPS } from "./constants";
9+
import { ColumnFilterTagsProps } from "./types";
10+
11+
export const ColumnFilterTags = <T extends RowData = Attribute>({
12+
className,
13+
table,
14+
}: ColumnFilterTagsProps<T>): JSX.Element | null => {
15+
const { getAllColumns, resetColumnFilters } = table;
16+
const columns = getAllColumns().filter((column) => column.getIsFiltered());
17+
18+
if (columns.length === 0) return null;
19+
20+
return (
21+
<StyledGrid className={className} {...GRID_PROPS}>
22+
{columns.map((column) => (
23+
<ColumnFilterTag key={column.id} column={column} />
24+
))}
25+
<Button
26+
onClick={() => resetColumnFilters(true)}
27+
variant={BUTTON_PROPS.VARIANT.TEXT}
28+
>
29+
Clear all
30+
</Button>
31+
</StyledGrid>
32+
);
33+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { GridProps } from "@mui/material";
2+
3+
export const GRID_PROPS: GridProps = {
4+
container: true,
5+
direction: "row",
6+
spacing: 2,
7+
wrap: "wrap",
8+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { RowData, Table } from "@tanstack/react-table";
2+
import { Attribute } from "../../../../../../common/entities";
3+
import { BaseComponentProps } from "../../../../../types";
4+
5+
export interface ColumnFilterTagsProps<T extends RowData = Attribute>
6+
extends BaseComponentProps {
7+
table: Table<T>;
8+
}

src/components/DataDictionary/components/Filters/stories/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { fn } from "@storybook/test";
12
import { PartialColumn } from "./types";
23

34
export const BIONETWORK: PartialColumn = {
@@ -10,7 +11,9 @@ export const BIONETWORK: PartialColumn = {
1011
["Brain", 2],
1112
["Lung", 1],
1213
]),
14+
getFilterValue: () => ["Nervous System", "Brain"],
1315
id: "bioNetwork",
16+
setFilterValue: fn(),
1417
};
1518

1619
export const DESCRIPTION: PartialColumn = {

src/components/DataDictionary/components/Layout/components/EntitiesLayout/entitiesLayout.styles.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ import { LAYOUT_SPACING } from "../../constants";
55

66
const PB = LAYOUT_SPACING.CONTENT_PADDING_BOTTOM; /* bottom padding */
77
const PT = LAYOUT_SPACING.CONTENT_PADDING_TOP; /* top padding */
8-
const FILTERS_HEIGHT =
9-
LAYOUT_SPACING.FILTERS_HEIGHT +
10-
LAYOUT_SPACING.FILTERS_PADDING_TOP; /* filters height */
11-
const TITLE_HEIGHT = LAYOUT_SPACING.TITLE_HEIGHT; /* title height */
128

139
export const Layout = styled("div")<LayoutSpacing>`
1410
grid-column: 2;
1511
grid-row: 1;
1612
padding-bottom: ${PB}px;
17-
padding-top: ${({ top }) => top + TITLE_HEIGHT + FILTERS_HEIGHT + PT}px;
13+
padding-top: ${({ top }) => top}px;
1814
z-index: 1; /* not required, but helpful in that the entities are always on top */
1915
2016
${mediaTabletDown} {
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import React from "react";
1+
import React, { forwardRef } from "react";
22
import { Layout } from "./entitiesLayout.styles";
33
import { EntitiesLayoutProps } from "./types";
44

5-
export const EntitiesLayout = ({
6-
children,
7-
...props
8-
}: EntitiesLayoutProps): JSX.Element => {
9-
return <Layout {...props}>{children}</Layout>;
10-
};
5+
export const EntitiesLayout = forwardRef<HTMLDivElement, EntitiesLayoutProps>(
6+
function EntitiesLayout(
7+
{ children, spacing, ...props }: EntitiesLayoutProps,
8+
ref
9+
): JSX.Element {
10+
return (
11+
<Layout ref={ref} {...spacing} {...props}>
12+
{children}
13+
</Layout>
14+
);
15+
}
16+
);
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { ReactNode } from "react";
1+
import { CSSProperties, ReactNode } from "react";
22
import { LayoutSpacing } from "../../../../hooks/UseLayoutSpacing/types";
33

4-
export interface EntitiesLayoutProps extends LayoutSpacing {
4+
export interface EntitiesLayoutProps {
55
children: ReactNode;
6+
spacing: LayoutSpacing;
7+
style?: CSSProperties; // Required for Fade component. See https://mui.com/material-ui/transitions/#child-requirement.
68
}

0 commit comments

Comments
 (0)