Skip to content

Commit f3fa731

Browse files
authored
feat!: create data dictionary chip (#451) (#467)
1 parent 70644d1 commit f3fa731

6 files changed

Lines changed: 58 additions & 17 deletions

File tree

src/common/entities.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ColumnDef } from "@tanstack/react-table";
2+
import { GridTrackSize } from "../config/entities";
23

34
/**
45
* Model of a value of a metadata class.
@@ -21,7 +22,7 @@ export interface Attribute {
2122
/**
2223
* Model of attribute key types; used mostly when building data dictionary column definitions.
2324
*/
24-
export type AttributeValueTypes = string | boolean;
25+
export type AttributeValueTypes<TValue = unknown> = TValue;
2526

2627
/**
2728
* Filterable metadata keys.
@@ -76,13 +77,17 @@ export interface DataDictionary {
7677
* Display model of a data dictionary column.
7778
*/
7879
export interface DataDictionaryColumnDef {
80+
attributeAccessorFnName?: string; // Name of accessor function to map to.
81+
attributeCellName?: string; // Name of cell renderer component to map to.
7982
attributeDisplayName: string;
8083
attributeSlotName: string;
8184
// Adding width here for now; possibly revisit separating column def and UI.
82-
width: {
83-
max: string;
84-
min: string;
85-
};
85+
width:
86+
| Omit<GridTrackSize, "GridTrackMinMax">
87+
| {
88+
max: string;
89+
min: string;
90+
};
8691
}
8792

8893
/**
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { Typography } from "@mui/material";
2-
import React from "react";
2+
import { CellContext, RowData } from "@tanstack/react-table";
3+
import React, { ReactNode } from "react";
34
import { TYPOGRAPHY_PROPS } from "../../../../../../styles/common/mui/typography";
4-
import { BasicCellProps } from "./types";
55

6-
export const BasicCell = ({ getValue }: BasicCellProps): JSX.Element => {
6+
export const BasicCell = <T extends RowData, TValue>({
7+
getValue,
8+
}: CellContext<T, TValue>): JSX.Element | null => {
9+
const value = getValue();
10+
if (value === undefined || value === null) return null;
711
return (
812
<Typography variant={TYPOGRAPHY_PROPS.VARIANT.INHERIT}>
9-
{getValue()}
13+
{value as ReactNode}
1014
</Typography>
1115
);
1216
};

src/components/DataDictionary/components/Table/components/BasicCell/types.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { RowData } from "@tanstack/react-table";
2+
3+
/**
4+
* Type guard to check if a row has a specific key.
5+
* Useful for generic accessor functions.
6+
* @param row - The row to check.
7+
* @param key - The key to check.
8+
* @returns True if the row has the specified key, false otherwise.
9+
*/
10+
export function rowHasKey<T extends RowData, K extends PropertyKey, TValue>(
11+
row: T,
12+
key: K
13+
): row is T & Record<K, TValue> {
14+
return row != null && typeof row === "object" && key in row;
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Chip } from "@mui/material";
2+
import { CellContext, RowData } from "@tanstack/react-table";
3+
import React from "react";
4+
5+
export const ChipCell = <T extends RowData, TValue>({
6+
getValue,
7+
}: CellContext<T, TValue>): JSX.Element | null => {
8+
const props = getValue();
9+
if (!props) return null;
10+
return <Chip {...props} />;
11+
};

src/theme/common/components.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,14 @@ export const MuiChip = (theme: Theme): Components["MuiChip"] => {
410410
},
411411
label: {
412412
...theme.typography[TEXT_BODY_SMALL_400],
413+
variants: [
414+
{
415+
props: { variant: "status" },
416+
style: {
417+
...theme.typography[TEXT_BODY_SMALL_500],
418+
},
419+
},
420+
],
413421
},
414422
},
415423
variants: [
@@ -489,13 +497,18 @@ export const MuiChip = (theme: Theme): Components["MuiChip"] => {
489497
{
490498
props: { variant: "status" },
491499
style: {
492-
...theme.typography[TEXT_BODY_SMALL_500],
493500
boxShadow: `0 0 0 2px ${PALETTE.COMMON_WHITE}`,
494501
height: 20,
495502
maxWidth: "fit-content",
496503
minWidth: 0,
497504
},
498505
},
506+
{
507+
props: { color: "default", variant: "status" },
508+
style: {
509+
color: PALETTE.INK_LIGHT,
510+
},
511+
},
499512
],
500513
};
501514
};

0 commit comments

Comments
 (0)