@databiosphere/findable-ui 2.1.0 → 3.0.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 (135) hide show
  1. package/lib/components/Detail/components/DetailViewTable/detailViewTable.js +1 -1
  2. package/lib/components/Filter/components/FilterLabel/filterLabel.styles.d.ts +1 -1
  3. package/lib/components/Filter/components/Filters/filters.d.ts +1 -1
  4. package/lib/components/Filter/components/Filters/filters.styles.js +1 -1
  5. package/lib/components/Filter/components/VariableSizeListItem/variableSizeListItem.js +2 -1
  6. package/lib/components/Index/index.d.ts +2 -1
  7. package/lib/components/Index/index.js +2 -2
  8. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/components/AuthenticationMenu/authenticationMenu.styles.d.ts +3 -3
  9. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/components/RequestAuthentication/requestAuthentication.styles.d.ts +1 -1
  10. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Search/components/SearchBar/searchBar.styles.d.ts +1 -1
  11. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Search/components/SearchButton/searchButton.styles.d.ts +1 -1
  12. package/lib/components/Layout/components/Outline/components/ContentsTab/contentsTab.styles.d.ts +1 -1
  13. package/lib/components/Layout/components/Outline/outline.styles.d.ts +1 -1
  14. package/lib/components/Table/common/utils.d.ts +6 -0
  15. package/lib/components/Table/common/utils.js +12 -1
  16. package/lib/components/Table/components/CheckboxMenu/checkboxMenu.js +2 -2
  17. package/lib/components/Table/components/CheckboxMenu/checkboxMenu.styles.d.ts +1 -1
  18. package/lib/components/Table/components/CheckboxMenu/checkboxMenu.styles.js +3 -3
  19. package/lib/components/Table/components/TableCell/common/utils.d.ts +8 -0
  20. package/lib/components/Table/components/TableCell/common/utils.js +15 -0
  21. package/lib/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.d.ts +6 -0
  22. package/lib/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.js +15 -0
  23. package/lib/components/Table/components/TableHead/components/HeadSelectionCell/headSelectionCell.d.ts +6 -0
  24. package/lib/components/Table/components/TableHead/components/HeadSelectionCell/headSelectionCell.js +16 -0
  25. package/lib/components/Table/components/TableHead/tableHead.js +2 -2
  26. package/lib/components/Table/components/TableRows/tableRows.js +2 -3
  27. package/lib/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.d.ts +10 -0
  28. package/lib/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.js +37 -0
  29. package/lib/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.styles.d.ts +3 -0
  30. package/lib/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.styles.js +13 -0
  31. package/lib/components/Table/components/TableToolbar/components/RowSelection/rowSelection.d.ts +9 -0
  32. package/lib/components/Table/components/TableToolbar/components/RowSelection/rowSelection.js +19 -0
  33. package/lib/components/Table/components/TableToolbar/components/RowSelection/rowSelection.styles.d.ts +5 -0
  34. package/lib/components/Table/components/TableToolbar/components/RowSelection/rowSelection.styles.js +13 -0
  35. package/lib/components/Table/components/TableToolbar/tableToolbar.js +5 -5
  36. package/lib/components/Table/components/TableToolbar/tableToolbar.styles.d.ts +1 -5
  37. package/lib/components/Table/components/TableToolbar/tableToolbar.styles.js +10 -7
  38. package/lib/components/Table/table.d.ts +5 -2
  39. package/lib/components/Table/table.js +13 -2
  40. package/lib/components/TableCreator/common/constants.d.ts +6 -0
  41. package/lib/components/TableCreator/common/constants.js +22 -0
  42. package/lib/components/TableCreator/common/entities.d.ts +5 -0
  43. package/lib/components/TableCreator/common/entities.js +2 -0
  44. package/lib/components/TableCreator/common/utils.d.ts +8 -0
  45. package/lib/components/TableCreator/common/utils.js +24 -0
  46. package/lib/components/TableCreator/tableCreator.d.ts +3 -1
  47. package/lib/components/TableCreator/tableCreator.js +19 -34
  48. package/lib/components/common/Alert/components/AlertText/alertText.styles.d.ts +5 -0
  49. package/lib/components/common/Alert/components/AlertText/alertText.styles.js +25 -0
  50. package/lib/components/common/Button/components/DropdownButton/dropdownButton.d.ts +4 -2
  51. package/lib/components/common/Button/components/DropdownButton/dropdownButton.js +2 -2
  52. package/lib/components/common/Button/components/DropdownButton/dropdownButton.styles.d.ts +5 -1
  53. package/lib/components/common/Button/components/DropdownButton/dropdownButton.styles.js +24 -1
  54. package/lib/components/common/CustomIcon/components/IndeterminateIcon/indeterminateIcon.d.ts +6 -0
  55. package/lib/components/common/CustomIcon/components/IndeterminateIcon/indeterminateIcon.js +29 -0
  56. package/lib/components/common/Dialog/dialog.d.ts +7 -0
  57. package/lib/components/common/Dialog/dialog.js +24 -0
  58. package/lib/components/common/DropdownMenu/common/constants.d.ts +2 -0
  59. package/lib/components/common/DropdownMenu/common/constants.js +8 -0
  60. package/lib/components/common/DropdownMenu/common/entities.d.ts +10 -0
  61. package/lib/components/common/DropdownMenu/common/entities.js +2 -0
  62. package/lib/components/common/DropdownMenu/components/MenuItem/menuItem.d.ts +7 -0
  63. package/lib/components/common/DropdownMenu/components/MenuItem/menuItem.js +25 -0
  64. package/lib/components/common/DropdownMenu/dropdownMenu.d.ts +9 -0
  65. package/lib/components/common/DropdownMenu/dropdownMenu.js +49 -0
  66. package/lib/components/common/DropdownMenu/dropdownMenu.styles.d.ts +3 -0
  67. package/lib/components/common/DropdownMenu/dropdownMenu.styles.js +13 -0
  68. package/lib/components/common/IconButton/iconButton.d.ts +4 -3
  69. package/lib/components/common/IconButton/iconButton.js +4 -4
  70. package/lib/components/common/IconButton/iconButton.styles.d.ts +34 -0
  71. package/lib/components/common/IconButton/iconButton.styles.js +27 -1
  72. package/lib/components/common/Tabs/tabs.styles.d.ts +1 -1
  73. package/lib/config/entities.d.ts +9 -1
  74. package/lib/providers/exploreState/constants.d.ts +3 -3
  75. package/lib/providers/exploreState/constants.js +3 -26
  76. package/lib/providers/exploreState/entities.d.ts +16 -5
  77. package/lib/providers/exploreState/initializer/constants.js +2 -0
  78. package/lib/providers/exploreState/initializer/utils.js +77 -5
  79. package/lib/providers/exploreState/payloads/entities.d.ts +32 -6
  80. package/lib/providers/exploreState/utils.d.ts +65 -11
  81. package/lib/providers/exploreState/utils.js +126 -15
  82. package/lib/providers/exploreState.d.ts +39 -7
  83. package/lib/providers/exploreState.js +58 -11
  84. package/lib/theme/common/components.js +4 -0
  85. package/lib/views/ExploreView/exploreView.d.ts +3 -1
  86. package/lib/views/ExploreView/exploreView.js +17 -11
  87. package/package.json +1 -1
  88. package/src/components/Detail/components/DetailViewTable/detailViewTable.tsx +2 -2
  89. package/src/components/Filter/components/Filters/filters.styles.ts +1 -1
  90. package/src/components/Filter/components/Filters/filters.tsx +1 -1
  91. package/src/components/Filter/components/VariableSizeListItem/variableSizeListItem.tsx +6 -3
  92. package/src/components/Index/index.tsx +3 -1
  93. package/src/components/Table/common/utils.ts +17 -0
  94. package/src/components/Table/components/CheckboxMenu/checkboxMenu.styles.ts +3 -3
  95. package/src/components/Table/components/CheckboxMenu/checkboxMenu.tsx +4 -2
  96. package/src/components/Table/components/TableCell/common/utils.ts +16 -0
  97. package/src/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.tsx +24 -0
  98. package/src/components/Table/components/TableHead/components/HeadSelectionCell/headSelectionCell.tsx +31 -0
  99. package/src/components/Table/components/TableHead/tableHead.tsx +18 -7
  100. package/src/components/Table/components/TableRows/tableRows.tsx +10 -8
  101. package/src/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.styles.ts +8 -0
  102. package/src/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.tsx +50 -0
  103. package/src/components/Table/components/TableToolbar/components/RowSelection/rowSelection.styles.ts +8 -0
  104. package/src/components/Table/components/TableToolbar/components/RowSelection/rowSelection.tsx +30 -0
  105. package/src/components/Table/components/TableToolbar/tableToolbar.styles.ts +10 -7
  106. package/src/components/Table/components/TableToolbar/tableToolbar.tsx +11 -8
  107. package/src/components/Table/table.tsx +18 -1
  108. package/src/components/TableCreator/common/constants.ts +26 -0
  109. package/src/components/TableCreator/common/entities.ts +6 -0
  110. package/src/components/TableCreator/common/utils.ts +33 -0
  111. package/src/components/TableCreator/tableCreator.tsx +38 -17
  112. package/src/components/common/Alert/components/AlertText/alertText.styles.ts +20 -0
  113. package/src/components/common/Button/components/DropdownButton/dropdownButton.styles.ts +15 -1
  114. package/src/components/common/Button/components/DropdownButton/dropdownButton.tsx +10 -2
  115. package/src/components/common/CustomIcon/components/IndeterminateIcon/indeterminateIcon.tsx +23 -0
  116. package/src/components/common/Dialog/dialog.tsx +21 -0
  117. package/src/components/common/DropdownMenu/common/constants.ts +7 -0
  118. package/src/components/common/DropdownMenu/common/entities.ts +11 -0
  119. package/src/components/common/DropdownMenu/components/MenuItem/menuItem.tsx +24 -0
  120. package/src/components/common/DropdownMenu/dropdownMenu.styles.ts +8 -0
  121. package/src/components/common/DropdownMenu/dropdownMenu.tsx +48 -0
  122. package/src/components/common/IconButton/iconButton.styles.ts +18 -0
  123. package/src/components/common/IconButton/iconButton.tsx +10 -11
  124. package/src/config/entities.ts +13 -1
  125. package/src/providers/exploreState/constants.ts +3 -0
  126. package/src/providers/exploreState/entities.ts +28 -4
  127. package/src/providers/exploreState/initializer/constants.ts +2 -0
  128. package/src/providers/exploreState/initializer/utils.ts +94 -3
  129. package/src/providers/exploreState/payloads/entities.ts +41 -7
  130. package/src/providers/exploreState/utils.ts +185 -21
  131. package/src/providers/exploreState.tsx +155 -21
  132. package/src/theme/common/components.ts +4 -0
  133. package/src/views/ExploreView/exploreView.tsx +22 -10
  134. package/types/data-explorer-ui.d.ts +10 -0
  135. package/src/components/Table/components/EntityViewToggle/entityViewToggle.tsx +0 -36
@@ -1,11 +1,25 @@
1
+ import { css } from "@emotion/react";
1
2
  import styled from "@emotion/styled";
3
+ import { smokeLightest } from "../../../../../styles/common/mixins/colors";
2
4
  import { ButtonSecondary } from "../ButtonSecondary/buttonSecondary";
3
5
 
6
+ interface Props {
7
+ open: boolean;
8
+ }
9
+
4
10
  // Dropdown button with "secondary" styles.
5
- export const DropdownButton = styled(ButtonSecondary)`
11
+ export const DropdownButton = styled(ButtonSecondary, {
12
+ shouldForwardProp: (prop) => prop !== "open",
13
+ })<Props>`
6
14
  padding-right: 8px;
7
15
 
8
16
  .MuiButton-endIcon {
9
17
  margin-left: -6px;
10
18
  }
19
+
20
+ ${({ open, ...props }) =>
21
+ open &&
22
+ css`
23
+ background-color: ${smokeLightest(props)};
24
+ `}
11
25
  `;
@@ -3,15 +3,23 @@ import React from "react";
3
3
  import { ButtonProps } from "../../button";
4
4
  import { DropdownButton as Button } from "./dropdownButton.styles";
5
5
 
6
- export type DropdownButtonProps = Exclude<ButtonProps, "StartIcon">;
6
+ export interface DropdownButtonProps extends Exclude<ButtonProps, "StartIcon"> {
7
+ open?: boolean;
8
+ }
7
9
 
8
10
  export const DropdownButton = ({
9
11
  children,
10
12
  disabled = false,
13
+ open = false,
11
14
  ...props /* Spread props to allow for Mui ButtonProps specific prop overrides e.g. "onClick". */
12
15
  }: DropdownButtonProps): JSX.Element => {
13
16
  return (
14
- <Button disabled={disabled} EndIcon={ArrowDropDownRoundedIcon} {...props}>
17
+ <Button
18
+ disabled={disabled}
19
+ EndIcon={ArrowDropDownRoundedIcon}
20
+ open={open}
21
+ {...props}
22
+ >
15
23
  {children}
16
24
  </Button>
17
25
  );
@@ -0,0 +1,23 @@
1
+ import { SvgIcon } from "@mui/material";
2
+ import React from "react";
3
+ import { CustomSVGIconProps } from "../../common/entities";
4
+
5
+ /**
6
+ * Custom indeterminate icon.
7
+ */
8
+
9
+ export const IndeterminateIcon = ({
10
+ fontSize = "xsmall",
11
+ viewBox = "0 0 18 18",
12
+ ...props /* Spread props to allow for Mui SvgIconProps specific prop overrides e.g. "htmlColor". */
13
+ }: CustomSVGIconProps): JSX.Element => {
14
+ return (
15
+ <SvgIcon fontSize={fontSize} viewBox={viewBox} {...props}>
16
+ <path
17
+ d="M0 4C0 1.79086 1.79086 0 4 0H14C16.2091 0 18 1.79086 18 4V14C18 16.2091 16.2091 18 14 18H4C1.79086 18 0 16.2091 0 14V4Z"
18
+ fill="currentColor"
19
+ />
20
+ <rect x="5" y="8" width="8" height="2" rx="1" fill="white" />
21
+ </SvgIcon>
22
+ );
23
+ };
@@ -0,0 +1,21 @@
1
+ import { Dialog as MDialog, DialogProps as MDialogProps } from "@mui/material";
2
+ import React, { ReactNode } from "react";
3
+
4
+ export interface DialogProps extends MDialogProps {
5
+ children: ReactNode | ReactNode[];
6
+ className?: string;
7
+ }
8
+
9
+ export const Dialog = ({
10
+ children,
11
+ className,
12
+ onClose,
13
+ open,
14
+ ...props /* Spread props to allow for Mui Dialog specific prop overrides e.g. "fullWidth". */
15
+ }: DialogProps): JSX.Element => {
16
+ return (
17
+ <MDialog className={className} onClose={onClose} open={open} {...props}>
18
+ {children}
19
+ </MDialog>
20
+ );
21
+ };
@@ -0,0 +1,7 @@
1
+ import { MenuProps as MMenuProps } from "@mui/material";
2
+
3
+ export const DEFAULT_DROPDOWN_MENU_PROPS: Partial<MMenuProps> = {
4
+ anchorOrigin: { horizontal: "right", vertical: "bottom" },
5
+ slotProps: { paper: { variant: "menu" } },
6
+ transformOrigin: { horizontal: "right", vertical: "top" },
7
+ };
@@ -0,0 +1,11 @@
1
+ import {
2
+ ButtonProps as MButtonProps,
3
+ IconButtonProps as MIconButtonProps,
4
+ } from "@mui/material";
5
+
6
+ export interface DropdownMenuItemProps {
7
+ closeMenu: () => void;
8
+ }
9
+
10
+ export type DropdownMenuButtonProps = MButtonProps & { open?: boolean };
11
+ export type DropdownMenuIconButtonProps = MIconButtonProps & { open?: boolean };
@@ -0,0 +1,24 @@
1
+ import {
2
+ ListItemText as MListItemText,
3
+ MenuItem as MMenuItem,
4
+ MenuItemProps as MMenuItemProps,
5
+ } from "@mui/material";
6
+ import React, { ReactNode } from "react";
7
+
8
+ export interface MenuItemProps extends MMenuItemProps {
9
+ children: ReactNode;
10
+ className?: string;
11
+ }
12
+
13
+ export const MenuItem = ({
14
+ children,
15
+ className,
16
+ onClick,
17
+ ...props /* Spread props to allow for Mui MenuItem specific prop overrides e.g. "disableGutters". */
18
+ }: MenuItemProps): JSX.Element => {
19
+ return (
20
+ <MMenuItem className={className} onClick={onClick} {...props}>
21
+ <MListItemText disableTypography>{children}</MListItemText>
22
+ </MMenuItem>
23
+ );
24
+ };
@@ -0,0 +1,8 @@
1
+ import styled from "@emotion/styled";
2
+ import { Menu as MMenu } from "@mui/material";
3
+
4
+ export const Menu = styled(MMenu)`
5
+ .MuiPaper-menu {
6
+ margin: 4px 0;
7
+ }
8
+ `;
@@ -0,0 +1,48 @@
1
+ import { MenuProps as MMenuProps } from "@mui/material";
2
+ import React, { ElementType, Fragment, MouseEvent, useState } from "react";
3
+ import { DEFAULT_DROPDOWN_MENU_PROPS } from "./common/constants";
4
+ import {
5
+ DropdownMenuButtonProps,
6
+ DropdownMenuIconButtonProps,
7
+ DropdownMenuItemProps,
8
+ } from "./common/entities";
9
+ import { Menu } from "./dropdownMenu.styles";
10
+
11
+ export interface DropdownMenuProps
12
+ extends Omit<MMenuProps, "children" | "open"> {
13
+ Button:
14
+ | ElementType<DropdownMenuButtonProps>
15
+ | ElementType<DropdownMenuIconButtonProps>;
16
+ children?: ({ closeMenu }: DropdownMenuItemProps) => JSX.Element[];
17
+ className?: string;
18
+ }
19
+
20
+ export const DropdownMenu = ({
21
+ Button,
22
+ children,
23
+ className,
24
+ ...props /* Spread props to allow for Mui Menu specific prop overrides e.g. "anchorOrigin". */
25
+ }: DropdownMenuProps): JSX.Element => {
26
+ const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
27
+ const closeMenu = (): void => setAnchorEl(null);
28
+ return (
29
+ <Fragment>
30
+ <Button
31
+ onClick={(event: MouseEvent<HTMLButtonElement>): void =>
32
+ setAnchorEl(event.currentTarget)
33
+ }
34
+ open={Boolean(anchorEl)}
35
+ />
36
+ <Menu
37
+ {...DEFAULT_DROPDOWN_MENU_PROPS}
38
+ anchorEl={anchorEl}
39
+ className={className}
40
+ onClose={closeMenu}
41
+ open={Boolean(anchorEl)}
42
+ {...props}
43
+ >
44
+ {children ? children({ closeMenu }) : null}
45
+ </Menu>
46
+ </Fragment>
47
+ );
48
+ };
@@ -1,7 +1,25 @@
1
+ import { css } from "@emotion/react";
1
2
  import styled from "@emotion/styled";
2
3
  import { IconButton as MIconButton } from "@mui/material";
4
+ import { smokeLightest } from "../../../styles/common/mixins/colors";
3
5
  import { IconButton } from "./iconButton";
4
6
 
7
+ interface Props {
8
+ open: boolean;
9
+ }
10
+
11
+ export const Button = styled(MIconButton, {
12
+ shouldForwardProp: (prop) => prop !== "open",
13
+ })<Props>`
14
+ ${({ open, ...props }) =>
15
+ open &&
16
+ css`
17
+ &.MuiIconButton-root {
18
+ background-color: ${smokeLightest(props)};
19
+ }
20
+ `}
21
+ `;
22
+
5
23
  // Primary icon button.
6
24
  export const IconButtonPrimary = styled(IconButton)`
7
25
  background-color: ${({ theme }) => theme.palette.primary.main};
@@ -1,8 +1,9 @@
1
1
  import {
2
- IconButton as MIconButton,
3
2
  IconButtonProps as MIconButtonProps,
3
+ IconProps as MIconProps,
4
4
  } from "@mui/material";
5
5
  import React, { ElementType } from "react";
6
+ import { Button } from "./iconButton.styles";
6
7
 
7
8
  /**
8
9
  * Basic icon button component.
@@ -11,24 +12,22 @@ import React, { ElementType } from "react";
11
12
 
12
13
  export interface IconButtonProps extends MIconButtonProps {
13
14
  className?: string;
14
- disabled?: boolean;
15
15
  Icon: ElementType;
16
+ iconProps?: MIconProps;
17
+ open?: boolean;
16
18
  }
17
19
 
18
20
  export const IconButton = ({
19
21
  className,
20
- disabled = false,
21
22
  Icon,
23
+ iconProps = { fontSize: "small" },
24
+ open = false,
25
+ size = "large",
22
26
  ...props /* Spread props to allow for Mui IconButtonProps specific prop overrides e.g. "onClick". */
23
27
  }: IconButtonProps): JSX.Element => {
24
28
  return (
25
- <MIconButton
26
- className={className}
27
- disabled={disabled}
28
- size="large"
29
- {...props}
30
- >
31
- <Icon fontSize="small" />
32
- </MIconButton>
29
+ <Button className={className} open={open} size={size} {...props}>
30
+ <Icon {...iconProps} />
31
+ </Button>
33
32
  );
34
33
  };
@@ -1,7 +1,11 @@
1
1
  import { TabProps as MTabProps, Theme, ThemeOptions } from "@mui/material";
2
2
  import { ColumnSort } from "@tanstack/react-table";
3
3
  import { JSXElementConstructor, ReactNode } from "react";
4
- import { CategoryKey, SelectedFilterValue } from "../common/entities";
4
+ import {
5
+ CategoryKey,
6
+ SelectedFilter,
7
+ SelectedFilterValue,
8
+ } from "../common/entities";
5
9
  import { HeroTitle } from "../components/common/Title/title";
6
10
  import { FooterProps } from "../components/Layout/components/Footer/footer";
7
11
  import { HeaderProps } from "../components/Layout/components/Header/header";
@@ -56,6 +60,7 @@ export interface BackPageTabConfig extends TabConfig {
56
60
  export interface CategoryGroupConfig {
57
61
  categoryGroups: CategoryGroup[];
58
62
  key: string;
63
+ savedFilters?: SavedFilter[];
59
64
  }
60
65
 
61
66
  /**
@@ -256,8 +261,10 @@ export interface ListConfig<T = any> {
256
261
  export interface ListViewConfig {
257
262
  disablePagination?: boolean;
258
263
  enableDownload?: boolean;
264
+ enableRowSelection?: boolean;
259
265
  listHero?: ComponentsConfig;
260
266
  relatedView?: RelatedViewConfig;
267
+ rowSelectionView?: ComponentsConfig;
261
268
  subTitleHero?: ComponentsConfig;
262
269
  }
263
270
 
@@ -302,6 +309,11 @@ type RelatedSearchFunction = (
302
309
  selectedCategoryValues: SelectedFilterValue | undefined
303
310
  ) => Promise<RelatedSearchResult | undefined>;
304
311
 
312
+ export interface SavedFilter {
313
+ filters: SelectedFilter[];
314
+ sort?: ColumnSort;
315
+ title: string;
316
+ }
305
317
  /**
306
318
  * Filter applied tracking payload
307
319
  */
@@ -0,0 +1,3 @@
1
+ export const SELECT_CATEGORY_KEY = {
2
+ SAVED_FILTERS: "savedFilters",
3
+ };
@@ -1,15 +1,24 @@
1
- import { ColumnSort } from "@tanstack/react-table";
2
- import { SelectCategory, SelectedFilter } from "../../common/entities";
1
+ import { ColumnSort, RowSelectionState } from "@tanstack/react-table";
2
+ import { VisibilityState } from "@tanstack/table-core/src/features/Visibility";
3
+ import {
4
+ CategoryValueKey,
5
+ SelectCategory,
6
+ SelectCategoryView,
7
+ SelectedFilter,
8
+ } from "../../common/entities";
3
9
  import {
4
10
  CategoryConfig,
5
11
  CategoryGroup,
6
12
  CategoryGroupConfig,
7
13
  EntityPath,
14
+ SavedFilter,
8
15
  } from "../../config/entities";
9
16
 
10
17
  export interface EntityPageState {
11
18
  categoryGroupConfigKey: CategoryGroupConfigKey;
12
- columnsVisibility: Record<string, boolean>;
19
+ columnsVisibility: VisibilityState;
20
+ enableRowSelection: boolean;
21
+ rowSelection: RowSelectionState;
13
22
  sorting: ColumnSort[];
14
23
  }
15
24
 
@@ -20,8 +29,11 @@ export interface EntityPageStateMapper {
20
29
  export interface EntityState {
21
30
  categoryConfigs?: CategoryConfig[];
22
31
  categoryGroups?: CategoryGroup[];
23
- categoryViews: SelectCategory[];
32
+ categoryViews: SelectCategoryView[];
24
33
  filterState: SelectedFilter[];
34
+ savedFilterByCategoryValueKey?: SavedFilterByCategoryValueKey;
35
+ savedFilterState: SelectedFilter[];
36
+ savedSelectCategories: SelectCategory[];
25
37
  }
26
38
 
27
39
  export type EntityStateByCategoryGroupConfigKey = Map<
@@ -30,3 +42,15 @@ export type EntityStateByCategoryGroupConfigKey = Map<
30
42
  >;
31
43
 
32
44
  export type CategoryGroupConfigKey = CategoryGroupConfig["key"];
45
+
46
+ export interface EntityStateSavedFilter extends Omit<SavedFilter, "sort"> {
47
+ sorting?: ColumnSort[];
48
+ }
49
+
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO revisit when adding react query or similar
51
+ export type ListItem = any;
52
+
53
+ export type SavedFilterByCategoryValueKey = Map<
54
+ CategoryValueKey,
55
+ EntityStateSavedFilter
56
+ >;
@@ -4,6 +4,8 @@ import { EntityState } from "../entities";
4
4
  export const DEFAULT_ENTITY_STATE: EntityState = {
5
5
  categoryViews: [],
6
6
  filterState: [],
7
+ savedFilterState: [],
8
+ savedSelectCategories: [],
7
9
  };
8
10
 
9
11
  export const DEFAULT_PAGINATION_STATE: PaginationState = {
@@ -1,22 +1,88 @@
1
- import { SelectedFilter } from "../../../common/entities";
1
+ import { VisibilityState } from "@tanstack/table-core/src/features/Visibility";
2
+ import { SelectCategory, SelectedFilter } from "../../../common/entities";
2
3
  import { getInitialTableColumnVisibility } from "../../../components/Table/common/utils";
4
+ import { ACCESSOR_KEYS } from "../../../components/TableCreator/common/constants";
3
5
  import {
4
6
  CategoryConfig,
5
7
  CategoryGroup,
6
8
  CategoryGroupConfig,
7
9
  EntityConfig,
10
+ SavedFilter,
8
11
  SiteConfig,
9
12
  } from "../../../config/entities";
10
13
  import { getDefaultSorting } from "../../../config/utils";
11
14
  import { ExploreState } from "../../exploreState";
15
+ import { SELECT_CATEGORY_KEY } from "../constants";
12
16
  import {
13
17
  CategoryGroupConfigKey,
14
18
  EntityPageStateMapper,
15
19
  EntityStateByCategoryGroupConfigKey,
20
+ SavedFilterByCategoryValueKey,
16
21
  } from "../entities";
17
22
  import { getEntityCategoryGroupConfigKey, getFilterCount } from "../utils";
18
23
  import { DEFAULT_ENTITY_STATE, INITIAL_STATE } from "./constants";
19
24
 
25
+ /**
26
+ * Builds category groups from the given category group config (adds the saved filters category to the category groups).
27
+ * @param categoryGroupConfig - Category group config.
28
+ * @returns category groups with saved filters category.
29
+ */
30
+ function buildCategoryGroups(
31
+ categoryGroupConfig: CategoryGroupConfig
32
+ ): CategoryGroup[] {
33
+ const { categoryGroups, savedFilters } = categoryGroupConfig;
34
+ if (!savedFilters) return categoryGroups;
35
+ const clonedCategoryGroups = [...categoryGroups];
36
+ const savedFiltersCategoryGroup: CategoryGroup = {
37
+ categoryConfigs: [
38
+ { key: SELECT_CATEGORY_KEY.SAVED_FILTERS, label: "Saved Filters" },
39
+ ],
40
+ };
41
+ clonedCategoryGroups.unshift(savedFiltersCategoryGroup);
42
+ return clonedCategoryGroups;
43
+ }
44
+
45
+ /**
46
+ * Returns the saved filters as select categories.
47
+ * @param savedFilters - Saved filters.
48
+ * @returns select categories.
49
+ */
50
+ function buildSavedSelectCategories(
51
+ savedFilters?: SavedFilter[]
52
+ ): SelectCategory[] {
53
+ if (!savedFilters) return [];
54
+ return [
55
+ {
56
+ key: SELECT_CATEGORY_KEY.SAVED_FILTERS,
57
+ label: "", // Label is applied in filter hook where it has access to the config.
58
+ values: savedFilters.map(({ title }) => ({
59
+ count: 1,
60
+ key: title,
61
+ label: title,
62
+ selected: false, // Selected state updated in filter hook.
63
+ })),
64
+ },
65
+ ];
66
+ }
67
+
68
+ /**
69
+ * Builds saved filter by category value key.
70
+ * @param savedFilters - Saved filters.
71
+ * @returns saved filter by category value key.
72
+ */
73
+ function buildSavedFilterByCategoryValueKey(
74
+ savedFilters?: SavedFilter[]
75
+ ): SavedFilterByCategoryValueKey | undefined {
76
+ if (!savedFilters) return;
77
+ const savedFilterByCategoryValueKey: SavedFilterByCategoryValueKey =
78
+ new Map();
79
+ for (const { filters, sort, title } of savedFilters) {
80
+ const sorting = sort ? [sort] : undefined;
81
+ savedFilterByCategoryValueKey.set(title, { filters, sorting, title });
82
+ }
83
+ return savedFilterByCategoryValueKey;
84
+ }
85
+
20
86
  /**
21
87
  * Returns entity related configured category group config where entity config takes precedence over site config.
22
88
  * @param siteConfig - Site config.
@@ -74,6 +140,22 @@ function initCategoryGroups(
74
140
  ?.categoryGroups;
75
141
  }
76
142
 
143
+ /**
144
+ * Initializes column visibility for the given entity.
145
+ * @param entityConfig - Entity config.
146
+ * @returns column visibility.
147
+ */
148
+ function initColumnVisibility(entityConfig: EntityConfig): VisibilityState {
149
+ const {
150
+ list: { columns },
151
+ listView: { enableRowSelection = false } = {},
152
+ } = entityConfig;
153
+ return {
154
+ [ACCESSOR_KEYS.SELECT]: enableRowSelection,
155
+ ...getInitialTableColumnVisibility(columns),
156
+ };
157
+ }
158
+
77
159
  /**
78
160
  * Initializes entity page state.
79
161
  * @param config - Site config.
@@ -85,7 +167,9 @@ function initEntityPageState(config: SiteConfig): EntityPageStateMapper {
85
167
  ...acc,
86
168
  [entity.route]: {
87
169
  categoryGroupConfigKey: initCategoryGroupConfigKey(config, entity),
88
- columnsVisibility: getInitialTableColumnVisibility(entity.list.columns),
170
+ columnsVisibility: initColumnVisibility(entity),
171
+ enableRowSelection: Boolean(entity.listView?.enableRowSelection),
172
+ rowSelection: {},
89
173
  sorting: getDefaultSorting(entity),
90
174
  },
91
175
  };
@@ -109,13 +193,20 @@ function initEntityStateByCategoryGroupConfigKey(
109
193
  for (const entity of config.entities) {
110
194
  const categoryGroupConfig = getEntityCategoryGroupConfig(config, entity);
111
195
  if (!categoryGroupConfig) continue;
112
- const { categoryGroups, key } = categoryGroupConfig;
196
+ const { key, savedFilters } = categoryGroupConfig;
113
197
  if (entityStateByCategoryGroupConfigKey.has(key)) continue;
198
+ const categoryGroups = buildCategoryGroups(categoryGroupConfig);
199
+ const savedSelectCategories: SelectCategory[] =
200
+ buildSavedSelectCategories(savedFilters);
201
+ const savedFilterByCategoryValueKey =
202
+ buildSavedFilterByCategoryValueKey(savedFilters);
114
203
  entityStateByCategoryGroupConfigKey.set(key, {
115
204
  ...DEFAULT_ENTITY_STATE,
116
205
  categoryConfigs: flattenCategoryGroups(categoryGroups),
117
206
  categoryGroups,
118
207
  filterState: key === categoryGroupConfigKey ? filterState : [],
208
+ savedFilterByCategoryValueKey,
209
+ savedSelectCategories,
119
210
  });
120
211
  }
121
212
  return entityStateByCategoryGroupConfigKey;
@@ -1,4 +1,8 @@
1
- import { ColumnSort } from "@tanstack/react-table";
1
+ import {
2
+ ColumnSort,
3
+ RowSelectionState,
4
+ VisibilityState,
5
+ } from "@tanstack/react-table";
2
6
  import {
3
7
  CategoryKey,
4
8
  CategoryValueKey,
@@ -11,6 +15,29 @@ import {
11
15
  PaginationResponse,
12
16
  RelatedListItems,
13
17
  } from "../../exploreState";
18
+ import { ListItem } from "../entities";
19
+
20
+ /**
21
+ * Apply saved filter payload.
22
+ */
23
+ export interface ApplySavedFilterPayload {
24
+ categoryKey: CategoryKey;
25
+ selected: boolean;
26
+ selectedValue: CategoryValueKey;
27
+ }
28
+
29
+ /**
30
+ * Paginate table payload.
31
+ */
32
+ export type PaginateTablePayload = PaginationDirectionType;
33
+
34
+ /**
35
+ * Patch explore response payload.
36
+ */
37
+ export interface PatchExploreResponsePayload {
38
+ listItemKey: keyof ListItem;
39
+ updatedListItems: ListItems;
40
+ }
14
41
 
15
42
  /**
16
43
  * Process explore response payload.
@@ -29,11 +56,6 @@ export interface ProcessRelatedResponsePayload {
29
56
  relatedListItems: RelatedListItems;
30
57
  }
31
58
 
32
- /**
33
- * Paginate table payload.
34
- */
35
- export type PaginateTablePayload = PaginationDirectionType;
36
-
37
59
  /**
38
60
  * Reset explore response payload.
39
61
  */
@@ -47,7 +69,14 @@ export type ToggleEntityViewPayload = ENTITY_VIEW;
47
69
  /**
48
70
  * Update column visibility payload.
49
71
  */
50
- export type UpdateColumnVisibilityPayload = Record<string, boolean>;
72
+ export type UpdateColumnVisibilityPayload = VisibilityState;
73
+
74
+ /**
75
+ * Update entity view access payload.
76
+ */
77
+ export interface UpdateEntityViewAccessPayload {
78
+ canEdit: boolean;
79
+ }
51
80
 
52
81
  /**
53
82
  * Update filter payload.
@@ -58,6 +87,11 @@ export interface UpdateFilterPayload {
58
87
  selectedValue: CategoryValueKey;
59
88
  }
60
89
 
90
+ /**
91
+ * Update row selection payload.
92
+ */
93
+ export type UpdateRowSelectionPayload = RowSelectionState;
94
+
61
95
  /**
62
96
  * Update sorting payload.
63
97
  */