@databiosphere/findable-ui 21.1.1 → 21.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +14 -0
  3. package/lib/common/entities.d.ts +33 -0
  4. package/lib/components/DataDictionary/common/utils.d.ts +38 -0
  5. package/lib/components/DataDictionary/common/utils.js +122 -0
  6. package/lib/components/DataDictionary/components/Tooltip/components/Title/constants.d.ts +3 -0
  7. package/lib/components/DataDictionary/components/Tooltip/components/Title/constants.js +8 -0
  8. package/lib/components/DataDictionary/components/Tooltip/components/Title/title.d.ts +3 -0
  9. package/lib/components/DataDictionary/components/Tooltip/components/Title/title.js +9 -0
  10. package/lib/components/DataDictionary/components/Tooltip/components/Title/types.d.ts +5 -0
  11. package/lib/components/DataDictionary/components/Tooltip/components/Title/types.js +1 -0
  12. package/lib/components/DataDictionary/components/Tooltip/constants.d.ts +2 -0
  13. package/lib/components/DataDictionary/components/Tooltip/constants.js +24 -0
  14. package/lib/components/DataDictionary/components/Tooltip/tooltip.d.ts +4 -0
  15. package/lib/components/DataDictionary/components/Tooltip/tooltip.js +8 -0
  16. package/lib/components/DataDictionary/components/Tooltip/types.d.ts +5 -0
  17. package/lib/components/DataDictionary/components/Tooltip/types.js +1 -0
  18. package/lib/components/Filter/components/Filter/filter.js +1 -1
  19. package/lib/components/Filter/components/FilterLabel/filterLabel.d.ts +3 -1
  20. package/lib/components/Filter/components/FilterLabel/filterLabel.js +4 -2
  21. package/lib/components/Index/components/Tabs/common/utils.js +2 -1
  22. package/lib/components/Table/components/TableHead/tableHead.js +4 -1
  23. package/lib/components/common/Tabs/tabs.d.ts +2 -0
  24. package/lib/components/common/Tabs/tabs.js +14 -1
  25. package/lib/config/entities.d.ts +5 -1
  26. package/lib/hooks/useCategoryFilter.js +1 -0
  27. package/lib/providers/config.js +9 -2
  28. package/package.json +1 -1
  29. package/src/common/entities.ts +37 -0
  30. package/src/components/DataDictionary/common/utils.ts +160 -0
  31. package/src/components/DataDictionary/components/Tooltip/components/Title/constants.ts +11 -0
  32. package/src/components/DataDictionary/components/Tooltip/components/Title/title.tsx +19 -0
  33. package/src/components/DataDictionary/components/Tooltip/components/Title/types.ts +6 -0
  34. package/src/components/DataDictionary/components/Tooltip/constants.ts +26 -0
  35. package/src/components/DataDictionary/components/Tooltip/tooltip.tsx +26 -0
  36. package/src/components/DataDictionary/components/Tooltip/types.ts +10 -0
  37. package/src/components/Filter/components/Filter/filter.tsx +1 -0
  38. package/src/components/Filter/components/FilterLabel/filterLabel.tsx +16 -10
  39. package/src/components/Index/components/Tabs/common/utils.ts +2 -0
  40. package/src/components/Table/components/TableHead/tableHead.tsx +26 -15
  41. package/src/components/common/Tabs/tabs.tsx +33 -3
  42. package/src/config/entities.ts +10 -1
  43. package/src/hooks/useCategoryFilter.ts +1 -0
  44. package/src/providers/config.tsx +10 -2
  45. package/tests/dataDictionary_utils.test.ts +153 -0
  46. package/types/data-explorer-ui.d.ts +2 -0
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "21.1.1"
2
+ ".": "21.3.0"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [21.3.0](https://github.com/DataBiosphere/findable-ui/compare/v21.2.0...v21.3.0) (2025-02-14)
4
+
5
+
6
+ ### Features
7
+
8
+ * add data dictionary tooltip support [#4131](https://github.com/DataBiosphere/findable-ui/issues/4131) ([#320](https://github.com/DataBiosphere/findable-ui/issues/320)) ([849e5cf](https://github.com/DataBiosphere/findable-ui/commit/849e5cf5898f71be210436863c9b10baf85a8427))
9
+
10
+ ## [21.2.0](https://github.com/DataBiosphere/findable-ui/compare/v21.1.1...v21.2.0) (2025-02-12)
11
+
12
+
13
+ ### Features
14
+
15
+ * create data dictionary tooltip component ([#317](https://github.com/DataBiosphere/findable-ui/issues/317)) ([#318](https://github.com/DataBiosphere/findable-ui/issues/318)) ([be4fd30](https://github.com/DataBiosphere/findable-ui/commit/be4fd30bcc2d04db230f0beefbae5ff3f7998d0b))
16
+
3
17
  ## [21.1.1](https://github.com/DataBiosphere/findable-ui/compare/v21.1.0...v21.1.1) (2025-01-31)
4
18
 
5
19
 
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Model of a value of a metadata class.
3
+ */
4
+ export interface Attribute {
5
+ description: string;
6
+ key: string;
7
+ label: string;
8
+ }
1
9
  /**
2
10
  * Filterable metadata keys.
3
11
  */
@@ -10,10 +18,34 @@ export interface CategoryTag {
10
18
  onRemove: () => void;
11
19
  superseded: boolean;
12
20
  }
21
+ /**
22
+ * Model of a metadata class, to be specified manually or built from LinkML schema.
23
+ */
24
+ export interface Class {
25
+ attributes: Attribute[];
26
+ description: string;
27
+ key: string;
28
+ label: string;
29
+ name: string;
30
+ }
13
31
  /**
14
32
  * Category values to be used as keys. For example, "Homo sapiens" or "10X 3' v2 sequencing".
15
33
  */
16
34
  export type CategoryValueKey = unknown;
35
+ /**
36
+ * Model of a metadata dictionary containing a set of classes and their definitions.
37
+ */
38
+ export interface DataDictionary {
39
+ classes: Class[];
40
+ }
41
+ /**
42
+ * Label and description values from a data dictionary that are added to a site
43
+ * config value.
44
+ */
45
+ export interface DataDictionaryAnnotation {
46
+ description: string;
47
+ label: string;
48
+ }
17
49
  /**
18
50
  * Set of selected category values.
19
51
  */
@@ -63,6 +95,7 @@ export interface SelectCategoryValueView {
63
95
  * View model of category, for multiselect categories.
64
96
  */
65
97
  export interface SelectCategoryView {
98
+ annotation?: DataDictionaryAnnotation;
66
99
  isDisabled?: boolean;
67
100
  key: CategoryKey;
68
101
  label: string;
@@ -0,0 +1,38 @@
1
+ import { DataDictionaryAnnotation } from "../../../common/entities";
2
+ import { SiteConfig } from "../../../config/entities";
3
+ /**
4
+ * Annotate each entity column configuration with data dictionary values. Specifically,
5
+ * look up label and description for each column key.
6
+ * @param siteConfig - Site configuration to annotate.
7
+ * @param annotationsByKey - Data dictionary annotations keyed by key.
8
+ */
9
+ export declare function annotateColumnConfig(siteConfig: SiteConfig, annotationsByKey: Record<string, DataDictionaryAnnotation>): void;
10
+ /**
11
+ * Annotate filter and colummn configuration with data dictionary values. Note this
12
+ * functionality mutates the site config. A possible future improvement would be to
13
+ * create either a specific "raw" or "annotated" type to indicate clearly the point
14
+ * at which the config has been annotated.
15
+ * @param siteConfig - The site configuration to annotate.
16
+ */
17
+ export declare function annotateSiteConfig(siteConfig: SiteConfig): void;
18
+ /**
19
+ * Annotate entity configuration with data dictionary values. Specifically, look
20
+ * up label and description for each entity key.
21
+ * @param siteConfig - The site configuration to annotate.
22
+ * @param annotationsByKey - Data dictionary annotations keyed by key.
23
+ */
24
+ export declare function annotateEntityConfig(siteConfig: SiteConfig, annotationsByKey: Record<string, DataDictionaryAnnotation>): void;
25
+ /**
26
+ * Annotate top-level (app-wide) category config with data dictionary values.
27
+ * Specifically, look up label and description for each filter key.
28
+ * @param siteConfig - Site configuration to annotate.
29
+ * @param annotationsByKey - Data dictionary annotations keyed by key.
30
+ */
31
+ export declare function annotateDefaultCategoryConfig(siteConfig: SiteConfig, annotationsByKey: Record<string, DataDictionaryAnnotation>): void;
32
+ /**
33
+ * Annotate entity-specific category config with data dictionary values. Specifically,
34
+ * look up label and description for each category key.
35
+ * @param siteConfig - Site configuration to annotate.
36
+ * @param annotationsByKey - Data dictionary annotations keyed by key.
37
+ */
38
+ export declare function annotateEntityCategoryConfig(siteConfig: SiteConfig, annotationsByKey: Record<string, DataDictionaryAnnotation>): void;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Annotate each entity column configuration with data dictionary values. Specifically,
3
+ * look up label and description for each column key.
4
+ * @param siteConfig - Site configuration to annotate.
5
+ * @param annotationsByKey - Data dictionary annotations keyed by key.
6
+ */
7
+ export function annotateColumnConfig(siteConfig, annotationsByKey) {
8
+ // Annotate every column in every entity.
9
+ siteConfig.entities.forEach((entity) => {
10
+ entity.list.columns.forEach((columnConfig) => {
11
+ // Find the annotation for the column key.
12
+ const annotation = annotationsByKey[columnConfig.id];
13
+ if (!annotation) {
14
+ return;
15
+ }
16
+ if (!columnConfig.meta) {
17
+ columnConfig.meta = {};
18
+ }
19
+ columnConfig.meta.annotation = annotation;
20
+ });
21
+ });
22
+ }
23
+ /**
24
+ * Annotate filter and colummn configuration with data dictionary values. Note this
25
+ * functionality mutates the site config. A possible future improvement would be to
26
+ * create either a specific "raw" or "annotated" type to indicate clearly the point
27
+ * at which the config has been annotated.
28
+ * @param siteConfig - The site configuration to annotate.
29
+ */
30
+ export function annotateSiteConfig(siteConfig) {
31
+ // Build and map data dictionary annotations by key.
32
+ const { dataDictionary } = siteConfig;
33
+ if (!dataDictionary) {
34
+ return;
35
+ }
36
+ const annotationsByKey = keyAnnotationsByKey(dataDictionary);
37
+ // Annotate elements of site config.
38
+ annotateEntityConfig(siteConfig, annotationsByKey);
39
+ annotateDefaultCategoryConfig(siteConfig, annotationsByKey);
40
+ annotateEntityCategoryConfig(siteConfig, annotationsByKey);
41
+ annotateColumnConfig(siteConfig, annotationsByKey);
42
+ }
43
+ /**
44
+ * Annotate entity configuration with data dictionary values. Specifically, look
45
+ * up label and description for each entity key.
46
+ * @param siteConfig - The site configuration to annotate.
47
+ * @param annotationsByKey - Data dictionary annotations keyed by key.
48
+ */
49
+ export function annotateEntityConfig(siteConfig, annotationsByKey) {
50
+ // Annotate every entity.
51
+ siteConfig.entities.forEach((entityConfig) => {
52
+ // Check entity for a data dictionary key.
53
+ const { key } = entityConfig;
54
+ if (!key) {
55
+ return;
56
+ }
57
+ // Find corresponding annotation for the key and set on entity config.
58
+ entityConfig.annotation = annotationsByKey[key];
59
+ });
60
+ }
61
+ /**
62
+ * Annotate top-level (app-wide) category config with data dictionary values.
63
+ * Specifically, look up label and description for each filter key.
64
+ * @param siteConfig - Site configuration to annotate.
65
+ * @param annotationsByKey - Data dictionary annotations keyed by key.
66
+ */
67
+ export function annotateDefaultCategoryConfig(siteConfig, annotationsByKey) {
68
+ const { categoryGroupConfig } = siteConfig;
69
+ if (categoryGroupConfig) {
70
+ annotateCategoryGroupConfig(categoryGroupConfig, annotationsByKey);
71
+ }
72
+ }
73
+ /**
74
+ * Annotate entity-specific category config with data dictionary values. Specifically,
75
+ * look up label and description for each category key.
76
+ * @param siteConfig - Site configuration to annotate.
77
+ * @param annotationsByKey - Data dictionary annotations keyed by key.
78
+ */
79
+ export function annotateEntityCategoryConfig(siteConfig, annotationsByKey) {
80
+ // Annotate every category in every entity.
81
+ siteConfig.entities.forEach((entityConfig) => {
82
+ const { categoryGroupConfig } = entityConfig;
83
+ if (categoryGroupConfig) {
84
+ annotateCategoryGroupConfig(categoryGroupConfig, annotationsByKey);
85
+ }
86
+ });
87
+ }
88
+ /**
89
+ * Annonate category group configuration with data dictionary values.
90
+ * @param categoryGroupConfig - Category group to annotate.
91
+ * @param annotationsByKey - Data dictionary annotations keyed by key.
92
+ */
93
+ function annotateCategoryGroupConfig(categoryGroupConfig, annotationsByKey) {
94
+ categoryGroupConfig.categoryGroups.forEach((categoryGroup) => {
95
+ categoryGroup.categoryConfigs.forEach((categorConfig) => {
96
+ categorConfig.annotation = annotationsByKey[categorConfig.key];
97
+ });
98
+ });
99
+ }
100
+ /**
101
+ * Transform a data dictionary into a key-annotation map. Build annotations for both
102
+ * classes and attributes and add to map.
103
+ * @param dataDictionary - Data dictionary to transform into a key-annotation map.
104
+ * @returns Key-annotation map.
105
+ */
106
+ function keyAnnotationsByKey(dataDictionary) {
107
+ return dataDictionary.classes.reduce((acc, cls) => {
108
+ // Add class to map.
109
+ acc[cls.key] = {
110
+ description: cls.description,
111
+ label: cls.label,
112
+ };
113
+ // Add each class attribute to the map.
114
+ cls.attributes.forEach((attribute) => {
115
+ acc[attribute.key] = {
116
+ description: attribute.description,
117
+ label: attribute.label,
118
+ };
119
+ });
120
+ return acc;
121
+ }, {});
122
+ }
@@ -0,0 +1,3 @@
1
+ import { StackProps, TypographyProps } from "@mui/material";
2
+ export declare const STACK_PROPS: StackProps;
3
+ export declare const TYPOGRAPHY_PROPS: TypographyProps;
@@ -0,0 +1,8 @@
1
+ export const STACK_PROPS = {
2
+ spacing: 2,
3
+ useFlexGap: true,
4
+ };
5
+ export const TYPOGRAPHY_PROPS = {
6
+ color: "ink.light",
7
+ component: "div",
8
+ };
@@ -0,0 +1,3 @@
1
+ import { BaseComponentProps } from "../../../../../types";
2
+ import { TitleProps } from "./types";
3
+ export declare const Title: ({ className, description, title, }: BaseComponentProps & Required<TitleProps>) => JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { Stack, Typography } from "@mui/material";
2
+ import React from "react";
3
+ import { TEXT_BODY_LARGE_500 } from "../../../../../../theme/common/typography";
4
+ import { STACK_PROPS, TYPOGRAPHY_PROPS } from "./constants";
5
+ export const Title = ({ className, description, title, }) => {
6
+ return (React.createElement(Stack, { ...STACK_PROPS, className: className },
7
+ React.createElement(Typography, { variant: TEXT_BODY_LARGE_500 }, title),
8
+ React.createElement(Typography, { ...TYPOGRAPHY_PROPS }, description)));
9
+ };
@@ -0,0 +1,5 @@
1
+ import { ReactNode } from "react";
2
+ export interface TitleProps {
3
+ description?: ReactNode;
4
+ title: ReactNode;
5
+ }
@@ -0,0 +1,2 @@
1
+ import { TooltipProps } from "@mui/material";
2
+ export declare const TOOLTIP_PROPS: Omit<TooltipProps, "children" | "title">;
@@ -0,0 +1,24 @@
1
+ import { TEXT_BODY_SMALL_400_2_LINES } from "../../../../theme/common/typography";
2
+ export const TOOLTIP_PROPS = {
3
+ arrow: true,
4
+ disableInteractive: true,
5
+ enterNextDelay: 250,
6
+ slotProps: {
7
+ arrow: { sx: (theme) => ({ color: theme.palette.common.white }) },
8
+ popper: {
9
+ modifiers: [
10
+ { name: "offset", options: { offset: [0, 2] } },
11
+ { name: "preventOverflow", options: { padding: 8 } },
12
+ ],
13
+ },
14
+ tooltip: {
15
+ sx: (theme) => ({
16
+ ...theme.typography[TEXT_BODY_SMALL_400_2_LINES],
17
+ backgroundColor: theme.palette.common.white,
18
+ borderRadius: 2,
19
+ color: theme.palette.ink.main,
20
+ padding: 4,
21
+ }),
22
+ },
23
+ },
24
+ };
@@ -0,0 +1,4 @@
1
+ import { BaseComponentProps } from "../../../types";
2
+ import { TitleProps } from "./components/Title/types";
3
+ import { TooltipProps } from "./types";
4
+ export declare const Tooltip: ({ children, className, description, title, ...props }: BaseComponentProps & TitleProps & TooltipProps) => JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { Tooltip as MTooltip } from "@mui/material";
2
+ import React from "react";
3
+ import { Title } from "./components/Title/title";
4
+ import { TOOLTIP_PROPS } from "./constants";
5
+ export const Tooltip = ({ children, className, description, title, ...props }) => {
6
+ return (React.createElement(MTooltip, { ...TOOLTIP_PROPS, className: className, title: description && React.createElement(Title, { description: description, title: title }), ...props },
7
+ React.createElement("span", null, children)));
8
+ };
@@ -0,0 +1,5 @@
1
+ import { TooltipProps as MTooltipProps } from "@mui/material";
2
+ import { ReactNode } from "react";
3
+ export type TooltipProps = Omit<MTooltipProps, "children"> & {
4
+ children: ReactNode;
5
+ };
@@ -48,7 +48,7 @@ export const Filter = ({ categorySection, categoryView, closeAncestor, isFilterD
48
48
  trackFilterOpened?.({ category: categoryView.key });
49
49
  };
50
50
  return (React.createElement(React.Fragment, null,
51
- React.createElement(FilterLabel, { count: categoryView.values.length, disabled: categoryView.isDisabled, isOpen: isOpen, label: categoryView.label, onClick: onOpenFilter }),
51
+ React.createElement(FilterLabel, { annotation: categoryView.annotation, count: categoryView.values.length, disabled: categoryView.isDisabled, isOpen: isOpen, label: categoryView.label, onClick: onOpenFilter }),
52
52
  React.createElement(FilterPopover, { anchorPosition: anchorPosition, anchorReference: "anchorPosition", marginThreshold: 0, onClose: onCloseFilters, open: isOpen, slotProps: slotProps, TransitionComponent: TransitionComponent, transitionDuration: TransitionDuration },
53
53
  isOpen && isFilterDrawer && (React.createElement(IconButton, { Icon: CloseRounded, onClick: onCloseFilters, size: "medium" })),
54
54
  React.createElement(FilterMenu, { categorySection: categorySection, categoryKey: categoryView.key, categoryLabel: categoryView.label, isFilterDrawer: isFilterDrawer, onFilter: onFilter, onCloseFilter: onCloseFilter, values: categoryView.values })),
@@ -1,9 +1,11 @@
1
1
  import { MouseEvent } from "react";
2
+ import { DataDictionaryAnnotation } from "../../../../common/entities";
2
3
  export interface FilterLabelProps {
4
+ annotation?: DataDictionaryAnnotation;
3
5
  count?: number;
4
6
  disabled?: boolean;
5
7
  isOpen: boolean;
6
8
  label: string;
7
9
  onClick: (event: MouseEvent<HTMLButtonElement>) => void;
8
10
  }
9
- export declare const FilterLabel: ({ count, disabled, isOpen, label, onClick, }: FilterLabelProps) => JSX.Element;
11
+ export declare const FilterLabel: ({ annotation, count, disabled, isOpen, label, onClick, }: FilterLabelProps) => JSX.Element;
@@ -1,7 +1,9 @@
1
1
  import ArrowDropDownRoundedIcon from "@mui/icons-material/ArrowDropDownRounded";
2
2
  import React from "react";
3
+ import { Tooltip } from "../../../DataDictionary/components/Tooltip/tooltip";
3
4
  import { FilterLabel as Label } from "./filterLabel.styles";
4
- export const FilterLabel = ({ count, disabled = false, isOpen, label, onClick, }) => {
5
+ export const FilterLabel = ({ annotation, count, disabled = false, isOpen, label, onClick, }) => {
5
6
  const filterLabel = count ? `${label}\xa0(${count})` : label; // When the count is present, a non-breaking space is used to prevent it from being on its own line
6
- return (React.createElement(Label, { color: "inherit", disabled: disabled, endIcon: React.createElement(ArrowDropDownRoundedIcon, { fontSize: "small" }), fullWidth: true, isOpen: isOpen, onClick: onClick }, filterLabel));
7
+ return (React.createElement(Tooltip, { description: annotation?.description, title: annotation?.label },
8
+ React.createElement(Label, { color: "inherit", disabled: disabled, endIcon: React.createElement(ArrowDropDownRoundedIcon, { fontSize: "small" }), fullWidth: true, isOpen: isOpen, onClick: onClick }, filterLabel)));
7
9
  };
@@ -4,9 +4,10 @@
4
4
  * @returns tabs list.
5
5
  */
6
6
  export function getEntityListTabs(entities) {
7
- return entities.reduce((acc, { label, listView: { enableTab = true } = {}, route, tabIcon: icon, tabIconPosition: iconPosition, }) => {
7
+ return entities.reduce((acc, { annotation, label, listView: { enableTab = true } = {}, route, tabIcon: icon, tabIconPosition: iconPosition, }) => {
8
8
  if (enableTab) {
9
9
  acc.push({
10
+ annotation,
10
11
  icon,
11
12
  iconPosition,
12
13
  label,
@@ -2,6 +2,7 @@ import SouthRoundedIcon from "@mui/icons-material/SouthRounded";
2
2
  import { TableHead as MTableHead, TableRow as MTableRow, TableCell, TableSortLabel, } from "@mui/material";
3
3
  import { flexRender } from "@tanstack/react-table";
4
4
  import React, { Fragment } from "react";
5
+ import { Tooltip } from "../../../DataDictionary/components/Tooltip/tooltip";
5
6
  import { ROW_DIRECTION } from "../../common/entities";
6
7
  import { getTableCellAlign, getTableCellPadding, } from "../TableCell/common/utils";
7
8
  import { handleToggleSorting } from "../TableFeatures/RowSorting/utils";
@@ -11,6 +12,8 @@ export const TableHead = ({ rowDirection, tableInstance, }) => {
11
12
  tableInstance.getHeaderGroups().map((headerGroup) => (React.createElement(MTableHead, { key: headerGroup.id },
12
13
  React.createElement(MTableRow, null, headerGroup.headers.map(({ column, getContext, id }) => {
13
14
  const { columnDef, getIsGrouped, getIsSorted } = column;
14
- return getIsGrouped() ? null : (React.createElement(TableCell, { key: id, align: getTableCellAlign(column), padding: getTableCellPadding(id) }, shouldSortColumn(tableInstance, column) ? (React.createElement(TableSortLabel, { IconComponent: SouthRoundedIcon, active: Boolean(getIsSorted()), direction: getIsSorted() || undefined, disabled: isSortDisabled(tableInstance), onClick: (mouseEvent) => handleToggleSorting(mouseEvent, tableInstance, column) }, flexRender(columnDef.header, getContext()))) : (flexRender(columnDef.header, getContext()))));
15
+ const annotation = columnDef.meta?.annotation;
16
+ return getIsGrouped() ? null : (React.createElement(TableCell, { key: id, align: getTableCellAlign(column), padding: getTableCellPadding(id) },
17
+ React.createElement(Tooltip, { description: annotation?.description, title: annotation?.label }, shouldSortColumn(tableInstance, column) ? (React.createElement(TableSortLabel, { IconComponent: SouthRoundedIcon, active: Boolean(getIsSorted()), direction: getIsSorted() || undefined, disabled: isSortDisabled(tableInstance), onClick: (mouseEvent) => handleToggleSorting(mouseEvent, tableInstance, column) }, flexRender(columnDef.header, getContext()))) : (flexRender(columnDef.header, getContext())))));
15
18
  })))))));
16
19
  };
@@ -1,9 +1,11 @@
1
1
  import { TabProps as MTabProps, TabsProps as MTabsProps } from "@mui/material";
2
2
  import { ReactNode } from "react";
3
+ import { DataDictionaryAnnotation } from "../../../common/entities";
3
4
  export type TabsValue = MTabsProps["value"];
4
5
  export type TabValue = MTabProps["value"];
5
6
  export type OnTabChangeFn = (tabValue: TabValue) => void;
6
7
  export interface Tab {
8
+ annotation?: DataDictionaryAnnotation;
7
9
  count?: string;
8
10
  icon?: MTabProps["icon"];
9
11
  iconPosition?: MTabProps["iconPosition"];
@@ -1,6 +1,19 @@
1
1
  import { Tabs as MTabs, } from "@mui/material";
2
2
  import React from "react";
3
+ import { Tooltip } from "../../DataDictionary/components/Tooltip/tooltip";
3
4
  import { Tab, TabScrollFuzz } from "./tabs.styles";
4
5
  export const Tabs = ({ className, onTabChange, tabs, value, }) => {
5
- return (React.createElement(MTabs, { allowScrollButtonsMobile: true, className: className, onChange: (_, tabValue) => onTabChange(tabValue), ScrollButtonComponent: TabScrollFuzz, value: value }, tabs.map(({ count, icon, iconPosition = "start", label, value: tabValue }, t) => (React.createElement(Tab, { icon: icon, iconPosition: icon ? iconPosition : undefined, key: `${label}${t}`, label: count ? `${label} (${count})` : label, value: tabValue })))));
6
+ return (React.createElement(MTabs, { allowScrollButtonsMobile: true, className: className, onChange: (_, tabValue) => onTabChange(tabValue), ScrollButtonComponent: TabScrollFuzz, value: value }, tabs.map(({ annotation, count, icon, iconPosition = "start", label, value: tabValue, }, t) => (React.createElement(Tab, { icon: icon, iconPosition: icon ? iconPosition : undefined, key: `${label}${t}`, label: buildTabLabel(label, count, annotation), value: tabValue })))));
6
7
  };
8
+ /**
9
+ * Build a tab value from a tab config. Specifically, display the tab label
10
+ * with a tooltip annotation if necessary.
11
+ * @param label - Tab display value.
12
+ * @param count - Optional count to display next to the tab label.
13
+ * @param annotation - Data dictionary annotation.
14
+ * @returns Tab label with optional count and tooltip.
15
+ */
16
+ function buildTabLabel(label, count, annotation) {
17
+ return (React.createElement(Tooltip, { description: annotation?.description, title: annotation?.label },
18
+ React.createElement("span", null, count ? `${label} (${count})` : label)));
19
+ }
@@ -1,7 +1,7 @@
1
1
  import { TabProps as MTabProps, Theme, ThemeOptions } from "@mui/material";
2
2
  import { CellContext, ColumnDef, ColumnMeta, ColumnSort, GroupingState, RowData, Table, TableOptions } from "@tanstack/react-table";
3
3
  import { JSXElementConstructor, ReactNode } from "react";
4
- import { SelectCategoryValueView, SelectedFilter } from "../common/entities";
4
+ import { DataDictionary, DataDictionaryAnnotation, SelectCategoryValueView, SelectedFilter } from "../common/entities";
5
5
  import { HeroTitle } from "../components/common/Title/title";
6
6
  import { FooterProps } from "../components/Layout/components/Footer/footer";
7
7
  import { HeaderProps } from "../components/Layout/components/Header/header";
@@ -70,6 +70,7 @@ export interface CategoryGroup {
70
70
  * Model of category configured in site config.
71
71
  */
72
72
  export interface CategoryConfig {
73
+ annotation?: DataDictionaryAnnotation;
73
74
  key: string;
74
75
  label: string;
75
76
  mapSelectCategoryValue?: (selectCategoryValue: SelectCategoryValueView) => SelectCategoryValueView;
@@ -127,6 +128,7 @@ export type EntityPath = string;
127
128
  * the detail and the list page configuration.
128
129
  */
129
130
  export interface EntityConfig<T = any, I = any> extends TabConfig {
131
+ annotation?: DataDictionaryAnnotation;
130
132
  apiPath?: EntityPath;
131
133
  categoryGroupConfig?: CategoryGroupConfig;
132
134
  detail: BackPageConfig;
@@ -137,6 +139,7 @@ export interface EntityConfig<T = any, I = any> extends TabConfig {
137
139
  getId?: GetIdFunction<T>;
138
140
  getTitle?: GetTitleFunction<T>;
139
141
  hideTabs?: boolean;
142
+ key?: string;
140
143
  list: ListConfig<T>;
141
144
  listView?: ListViewConfig;
142
145
  options?: Options;
@@ -295,6 +298,7 @@ export interface SiteConfig {
295
298
  categoryGroupConfig?: CategoryGroupConfig;
296
299
  contentDir?: string;
297
300
  contentThemeOptionsFn?: ThemeOptionsFn;
301
+ dataDictionary?: DataDictionary;
298
302
  dataSource: DataSourceConfig;
299
303
  entities: EntityConfig[];
300
304
  explorerTitle: HeroTitle;
@@ -27,6 +27,7 @@ function buildCategoryView(category, categoryValueViews, categoryConfigs) {
27
27
  const categoryConfig = findCategoryConfig(category.key, categoryConfigs);
28
28
  const mapSelectCategoryValue = categoryConfig?.mapSelectCategoryValue || getSelectCategoryValue;
29
29
  return {
30
+ annotation: categoryConfig?.annotation,
30
31
  isDisabled: false,
31
32
  key: category.key,
32
33
  label: getCategoryLabel(category.key, categoryConfig),
@@ -1,4 +1,5 @@
1
- import React, { createContext } from "react";
1
+ import React, { createContext, useState } from "react";
2
+ import { annotateSiteConfig } from "../components/DataDictionary/common/utils";
2
3
  import { getDefaultConfig, getDefaultEntityConfig, getEntityConfig, } from "../config/utils";
3
4
  export const ConfigContext = createContext({
4
5
  config: getDefaultConfig(),
@@ -7,7 +8,13 @@ export const ConfigContext = createContext({
7
8
  entityListType: "",
8
9
  });
9
10
  export function ConfigProvider({ children, config, entityListType = "", }) {
10
- const { entities } = config;
11
+ // Annote config on init. Note config is mutated but using state here to
12
+ // ensure annotated config is calculated once and is used rather than the raw config.
13
+ const [annotatedConfig] = useState(() => {
14
+ annotateSiteConfig(config);
15
+ return config;
16
+ });
17
+ const { entities } = annotatedConfig;
11
18
  const defaultEntityListType = config.redirectRootToPath.slice(1);
12
19
  const entityName = entityListType || defaultEntityListType;
13
20
  const entityConfig = getEntityConfig(entities, entityName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@databiosphere/findable-ui",
3
- "version": "21.1.1",
3
+ "version": "21.3.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Model of a value of a metadata class.
3
+ */
4
+ export interface Attribute {
5
+ description: string;
6
+ key: string;
7
+ label: string;
8
+ }
9
+
1
10
  /**
2
11
  * Filterable metadata keys.
3
12
  */
@@ -12,11 +21,38 @@ export interface CategoryTag {
12
21
  superseded: boolean;
13
22
  }
14
23
 
24
+ /**
25
+ * Model of a metadata class, to be specified manually or built from LinkML schema.
26
+ */
27
+ export interface Class {
28
+ attributes: Attribute[];
29
+ description: string;
30
+ key: string;
31
+ label: string;
32
+ name: string;
33
+ }
34
+
15
35
  /**
16
36
  * Category values to be used as keys. For example, "Homo sapiens" or "10X 3' v2 sequencing".
17
37
  */
18
38
  export type CategoryValueKey = unknown;
19
39
 
40
+ /**
41
+ * Model of a metadata dictionary containing a set of classes and their definitions.
42
+ */
43
+ export interface DataDictionary {
44
+ classes: Class[];
45
+ }
46
+
47
+ /**
48
+ * Label and description values from a data dictionary that are added to a site
49
+ * config value.
50
+ */
51
+ export interface DataDictionaryAnnotation {
52
+ description: string;
53
+ label: string;
54
+ }
55
+
20
56
  /**
21
57
  * Set of selected category values.
22
58
  */
@@ -72,6 +108,7 @@ export interface SelectCategoryValueView {
72
108
  * View model of category, for multiselect categories.
73
109
  */
74
110
  export interface SelectCategoryView {
111
+ annotation?: DataDictionaryAnnotation;
75
112
  isDisabled?: boolean;
76
113
  key: CategoryKey;
77
114
  label: string;