@evenicanpm/portal-table-ui 1.5.0 → 1.7.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 (67) hide show
  1. package/package.json +6 -5
  2. package/src/auth/auth-context.tsx +92 -0
  3. package/src/features/table/components/dashboard/table/bulk-action-button.tsx +77 -0
  4. package/src/features/table/components/dashboard/table/data-mask-map.ts +26 -0
  5. package/src/features/table/components/dashboard/table/details/details.tsx +185 -0
  6. package/src/features/table/components/dashboard/table/details/label.tsx +26 -0
  7. package/src/features/table/components/dashboard/table/details/rows/downloads.tsx +25 -0
  8. package/src/features/table/components/dashboard/table/details/rows/primitive.tsx +25 -0
  9. package/src/features/table/components/dashboard/table/details/rows/table.tsx +73 -0
  10. package/{dist/features/table/components/dashboard/table/details/styles.d.ts → src/features/table/components/dashboard/table/details/styles.ts} +10 -2
  11. package/src/features/table/components/dashboard/table/details/templates/invoice-details.tsx +407 -0
  12. package/src/features/table/components/dashboard/table/details/templates/template-registry.ts +36 -0
  13. package/src/features/table/components/dashboard/table/filter-render-map.tsx +10 -0
  14. package/src/features/table/components/dashboard/table/filters/date-filter.tsx +31 -0
  15. package/src/features/table/components/dashboard/table/filters/status-filter.tsx +36 -0
  16. package/src/features/table/components/dashboard/table/no-results.tsx +26 -0
  17. package/src/features/table/components/dashboard/table/status-pill.tsx +18 -0
  18. package/src/features/table/components/dashboard/table/table-header.tsx +98 -0
  19. package/src/features/table/components/dashboard/table/table-input.tsx +94 -0
  20. package/src/features/table/components/dashboard/table/table-row/action-button.tsx +47 -0
  21. package/src/features/table/components/dashboard/table/table-row/table-row.tsx +144 -0
  22. package/src/features/table/components/dashboard/table/table-row-skeleton.tsx +35 -0
  23. package/src/features/table/components/dashboard/table/table.tsx +361 -0
  24. package/src/features/table/components/dashboard/table/use-select-rows.ts +53 -0
  25. package/src/features/table/components/dashboard/table-dashboard.tsx +71 -0
  26. package/{dist/features/table/index.d.ts → src/features/table/index.ts} +7 -1
  27. package/src/features/table/logic/resolvers.ts +111 -0
  28. package/src/features/table/logic/transformers.ts +56 -0
  29. package/src/features/table/logic/types.ts +8 -0
  30. package/{dist/features/table/types/handlers.d.ts → src/features/table/types/handlers.ts} +30 -12
  31. package/{dist/features/table/types/index.d.ts → src/features/table/types/index.ts} +1 -0
  32. package/{dist/features/table/types/queries.d.ts → src/features/table/types/queries.ts} +10 -3
  33. package/src/features/table/types/schemas.ts +89 -0
  34. package/{dist/index.d.ts → src/index.ts} +2 -1
  35. package/src/portal.tsx +68 -0
  36. package/dist/auth/auth-context.d.ts +0 -36
  37. package/dist/features/settings/index.d.ts +0 -2
  38. package/dist/features/table/components/dashboard/table/actions.d.ts +0 -14
  39. package/dist/features/table/components/dashboard/table/data-mask-map.d.ts +0 -2
  40. package/dist/features/table/components/dashboard/table/details/details.d.ts +0 -27
  41. package/dist/features/table/components/dashboard/table/details/label.d.ts +0 -5
  42. package/dist/features/table/components/dashboard/table/details/rows/downloads.d.ts +0 -6
  43. package/dist/features/table/components/dashboard/table/details/rows/primitive.d.ts +0 -6
  44. package/dist/features/table/components/dashboard/table/details/rows/table.d.ts +0 -17
  45. package/dist/features/table/components/dashboard/table/filter-render-map.d.ts +0 -2
  46. package/dist/features/table/components/dashboard/table/filters/date-filter.d.ts +0 -2
  47. package/dist/features/table/components/dashboard/table/filters/status-filter.d.ts +0 -2
  48. package/dist/features/table/components/dashboard/table/no-results.d.ts +0 -2
  49. package/dist/features/table/components/dashboard/table/status-pill.d.ts +0 -8
  50. package/dist/features/table/components/dashboard/table/table-header.d.ts +0 -16
  51. package/dist/features/table/components/dashboard/table/table-input.d.ts +0 -11
  52. package/dist/features/table/components/dashboard/table/table-row/action-button.d.ts +0 -8
  53. package/dist/features/table/components/dashboard/table/table-row/table-row.d.ts +0 -32
  54. package/dist/features/table/components/dashboard/table/table-row-skeleton.d.ts +0 -6
  55. package/dist/features/table/components/dashboard/table/table.d.ts +0 -18
  56. package/dist/features/table/components/dashboard/table-dashboard.d.ts +0 -22
  57. package/dist/features/table/logic/resolvers.d.ts +0 -21
  58. package/dist/features/table/logic/transformers.d.ts +0 -35
  59. package/dist/features/table/logic/types.d.ts +0 -8
  60. package/dist/features/table/types/schemas.d.ts +0 -31
  61. package/dist/portal.d.ts +0 -38
  62. package/dist/tsconfig.tsbuildinfo +0 -1
  63. /package/{dist/features/table/components/dashboard/index.d.ts → src/features/table/components/dashboard/index.tsx} +0 -0
  64. /package/{dist/features/table/components/dashboard/table/details/index.d.ts → src/features/table/components/dashboard/table/details/index.ts} +0 -0
  65. /package/{dist/features/table/components/dashboard/table/details/rows/index.d.ts → src/features/table/components/dashboard/table/details/rows/index.ts} +0 -0
  66. /package/{dist/features/table/components/dashboard/table/index.d.ts → src/features/table/components/dashboard/table/index.ts} +0 -0
  67. /package/{dist/features/table/logic/index.d.ts → src/features/table/logic/index.ts} +0 -0
@@ -0,0 +1,53 @@
1
+ import { useState } from "react";
2
+
3
+ type Id = string | number;
4
+
5
+ type Input = {
6
+ currentPageIds: Id[];
7
+ };
8
+
9
+ export const useSelectRows = (input: Input) => {
10
+ const { currentPageIds } = input;
11
+
12
+ const [selectedIds, setSelectedIds] = useState<Set<Id>>(new Set());
13
+
14
+ const clearSelection = () => setSelectedIds(new Set());
15
+
16
+ const toggleOne = (id: Id) => {
17
+ setSelectedIds((prev) => {
18
+ const next = new Set(prev);
19
+ if (next.has(id)) next.delete(id);
20
+ else next.add(id);
21
+ return next;
22
+ });
23
+ };
24
+
25
+ const isAllOnPageSelected =
26
+ currentPageIds.length > 0 &&
27
+ currentPageIds.every((id) => selectedIds.has(id));
28
+
29
+ const isSomeOnPageSelected =
30
+ currentPageIds.some((id) => selectedIds.has(id)) && !isAllOnPageSelected;
31
+
32
+ const toggleAllOnPage = (checked: boolean) => {
33
+ setSelectedIds((prev) => {
34
+ const next = new Set(prev);
35
+ if (checked) {
36
+ for (const id of currentPageIds) next.add(id);
37
+ } else {
38
+ for (const id of currentPageIds) next.delete(id);
39
+ }
40
+ return next;
41
+ });
42
+ };
43
+
44
+ return {
45
+ selectedIds,
46
+ setSelectedIds,
47
+ clearSelection,
48
+ toggleOne,
49
+ toggleAllOnPage,
50
+ isAllOnPageSelected,
51
+ isSomeOnPageSelected,
52
+ };
53
+ };
@@ -0,0 +1,71 @@
1
+ import TabContext from "@mui/lab/TabContext";
2
+ import TabList from "@mui/lab/TabList";
3
+ import TabPanel from "@mui/lab/TabPanel";
4
+ import Box from "@mui/material/Box";
5
+ import Tab from "@mui/material/Tab";
6
+ import type { QueryKey } from "@tanstack/react-query";
7
+ import { type SyntheticEvent, useState } from "react";
8
+ import type * as Types from "../../types";
9
+ import { Table } from "./table";
10
+
11
+ /**
12
+ * The main props for top-level table entry-point
13
+ *
14
+ *
15
+ */
16
+ export interface TableProps {
17
+ viewConfigQuery?: (resourceName: string) => {
18
+ queryKey: QueryKey;
19
+ queryFn: () => Promise<Types.Queries.TableConfig>;
20
+ };
21
+ resources: Types.Schemas.Resource[];
22
+ }
23
+
24
+ /**
25
+ *
26
+ * The TableDashboard is the main view component for the table feature.
27
+ * Holds state for the tabs and global pagination for all tables.
28
+ *
29
+ * @params props
30
+ */
31
+ export const TableDashboard = ({ resources, viewConfigQuery }: TableProps) => {
32
+ const [value, setValue] = useState(resources[0]?.name);
33
+ const [pageSize, setPageSize] = useState(5); // better if this is global to not reset when switching tables
34
+
35
+ const handleChange = (_event: SyntheticEvent, newValue: string) => {
36
+ setValue(newValue);
37
+ };
38
+
39
+ return (
40
+ <Box sx={{ width: "100%", minHeight: "70vh" }}>
41
+ <TabContext value={value}>
42
+ <Box sx={{ borderBottom: 1, borderColor: "divider" }}>
43
+ <TabList onChange={handleChange}>
44
+ {resources?.map((resource, i) => (
45
+ <Tab
46
+ key={resource?.name + String(i)}
47
+ label={resource?.label}
48
+ value={resource?.name}
49
+ />
50
+ ))}
51
+ </TabList>
52
+ </Box>
53
+ {resources?.map((resource, i) => (
54
+ <Box key={resource.name + String(i)}>
55
+ <TabPanel
56
+ value={resource?.name}
57
+ sx={{ padding: "25px 0", margin: 0 }}
58
+ >
59
+ <Table
60
+ viewConfigQuery={viewConfigQuery}
61
+ resource={resource}
62
+ pageSize={pageSize}
63
+ setPageSize={setPageSize}
64
+ />
65
+ </TabPanel>
66
+ </Box>
67
+ ))}
68
+ </TabContext>
69
+ </Box>
70
+ );
71
+ };
@@ -3,6 +3,12 @@
3
3
 
4
4
  * @packageDocumentation
5
5
  */
6
+
6
7
  export type { DocumentTableProps } from "./components/dashboard/table/table";
7
- export { TableDashboard, type TableProps, } from "./components/dashboard/table-dashboard";
8
+ export {
9
+ TableDashboard,
10
+ type TableProps,
11
+ } from "./components/dashboard/table-dashboard";
12
+
13
+ // SCHEMAS
8
14
  export * as Table from "./types";
@@ -0,0 +1,111 @@
1
+ import { method, multi } from "@arrows/multimethod";
2
+ import type { Column } from "@evenicanpm/portal-types-schemas";
3
+ import type * as Types from "../types";
4
+ import type { TableConfig } from "../types/queries";
5
+ import type { UIAction, UIBulkAction } from "../types/schemas";
6
+ import type { FilterRequest } from "./types";
7
+
8
+ /** MULTIMETHOD FOR FILTERS
9
+ * Allows multiple implementations
10
+ * based on multiple column properties.
11
+ * Priotizes column name, but also can
12
+ * use data type
13
+ * @internal
14
+ */
15
+ export const resolveFilterUI = multi(
16
+ (req: FilterRequest, handlers: Types.Handlers.FilterRenderMap) => {
17
+ if (handlers?.[req.filterName]) return "BY_NAME";
18
+ if (handlers?.[req.filterType]) return "BY_TYPE";
19
+ return "NONE";
20
+ },
21
+ method(
22
+ "BY_NAME",
23
+ (req: FilterRequest, handlers: Types.Handlers.FilterRenderMap) =>
24
+ handlers[req.filterName],
25
+ ),
26
+ method(
27
+ "BY_TYPE",
28
+ (req: FilterRequest, handlers: Types.Handlers.FilterRenderMap) =>
29
+ handlers[req.filterType],
30
+ ),
31
+ method("NONE", () => () => null),
32
+ );
33
+
34
+ /**
35
+ * Dispatch identifies which properties are
36
+ * in handler, then provides corresponding method
37
+ * @internal
38
+ */
39
+ export const resolveDataMask = multi(
40
+ (col: Column, handlers: Types.Handlers.DataMaskMap) => {
41
+ if (!col?.DataMask) return "SKIP";
42
+ if (handlers?.[col?.DataType]) return "BY_TYPE";
43
+ if (handlers?.[col?.Data]) return "BY_NAME";
44
+ return "SKIP";
45
+ },
46
+ method(
47
+ "BY_TYPE",
48
+ (col: Column, handlers: Types.Handlers.DataMaskMap) =>
49
+ handlers?.[col?.DataType],
50
+ ),
51
+ method(
52
+ "BY_NAME",
53
+ (col: Column, handlers: Types.Handlers.DataMaskMap) =>
54
+ handlers?.[col?.Data],
55
+ ),
56
+ method("SKIP", () => (value: string | number) => value),
57
+ );
58
+
59
+ /**
60
+ * Simpler, doesn't need multimethod cause only dispatches on column name
61
+ * @internal
62
+ */
63
+ export const resolveCellUI = (
64
+ col: Column,
65
+ handlers: Types.Handlers.CellRenderMap,
66
+ ) => {
67
+ if (Object.hasOwn(handlers, col.Data)) return handlers?.[col?.Data];
68
+
69
+ return (value: string | number) => value;
70
+ };
71
+
72
+ export function resolveActions(
73
+ configActions: TableConfig["Actions"] | undefined,
74
+ registry: Record<string, UIAction> | undefined,
75
+ ): UIAction[] {
76
+ if (!configActions || !registry) return [];
77
+
78
+ return configActions
79
+ .filter((a) => a.IsEnabled)
80
+ .flatMap((a) => {
81
+ const action = registry[a.Type];
82
+ if (!action) {
83
+ console.warn(`Unknown action type: ${a.Type}`);
84
+ return [];
85
+ }
86
+ return [
87
+ {
88
+ ...action,
89
+ label: a.Name,
90
+ },
91
+ ];
92
+ });
93
+ }
94
+
95
+ export function resolveBulkActions(
96
+ configBulkActions: TableConfig["BulkActions"] | undefined,
97
+ registry: Record<string, UIBulkAction> | undefined,
98
+ ): UIBulkAction[] {
99
+ if (!configBulkActions || !registry) return [];
100
+
101
+ return configBulkActions
102
+ .filter((a) => a.IsEnabled)
103
+ .flatMap((a) => {
104
+ const action = registry[a.Type] as UIBulkAction;
105
+ if (!action) {
106
+ console.warn(`Unknown bulk action type: ${a.Type}`);
107
+ return [];
108
+ }
109
+ return [{ ...action, label: a.Name }];
110
+ });
111
+ }
@@ -0,0 +1,56 @@
1
+ import type { Column } from "@evenicanpm/portal-types-schemas";
2
+
3
+ /**
4
+ * These are pure static functions that include business rules
5
+ * and data manipulation to get the data into the correct
6
+ * form for rendering.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+
11
+ /**
12
+ * Gets filters and returns an array of the
13
+ * active filters and corresponding options
14
+ * in FilterRequest
15
+ */
16
+ export const getActiveFilters = (columns: Column[] | undefined) => {
17
+ return columns
18
+ ?.filter((c) => c?.IsFilterable)
19
+ ?.flatMap((c) =>
20
+ c?.Filters?.map((f) => ({
21
+ filterName: c.Data,
22
+ filterOptions: f.FilterOptions,
23
+ filterType: f.FilterType ?? c.DataType,
24
+ })),
25
+ );
26
+ };
27
+
28
+ /**
29
+ * Filters and sorts visible cols
30
+ */
31
+ export const getVisibleColumns = (columns: Column[] | undefined) =>
32
+ columns
33
+ ?.filter(
34
+ (column): column is Column & { ColumnOrder: number } =>
35
+ typeof column.ColumnOrder === "number",
36
+ )
37
+ .sort((a, b) => a.ColumnOrder - b.ColumnOrder);
38
+
39
+ /**
40
+ *
41
+ */
42
+ export const getVisibleDetails = (columns: Column[] | undefined) =>
43
+ columns
44
+ ?.filter((col) => col.DisplayOrder)
45
+ ?.sort((a, b) => {
46
+ if (a?.DisplayOrder && b?.DisplayOrder) {
47
+ return a?.DisplayOrder - b?.DisplayOrder;
48
+ }
49
+ return -1;
50
+ });
51
+
52
+ /**
53
+ * Filters and sorts visible cols
54
+ */
55
+ export const getSearchableColumns = (columns: Column[] | undefined) =>
56
+ columns?.filter((column) => column?.IsSearchable);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * FILTER REQUEST to RESOLVER
3
+ */
4
+ export interface FilterRequest {
5
+ filterName: string;
6
+ filterOptions: string[];
7
+ filterType: string;
8
+ }
@@ -1,10 +1,15 @@
1
1
  import type { FilterOption } from "@evenicanpm/portal-types-schemas";
2
+
2
3
  /**
3
4
  *
4
5
  * @group View Handlers
5
6
  */
6
7
  export type DataMaskMap = Record<string, MaskingFunction>;
7
- export type MaskingFunction = (value: string | number, dataMask: string) => string;
8
+ export type MaskingFunction = (
9
+ value: string | number,
10
+ dataMask: string,
11
+ ) => string;
12
+
8
13
  /**
9
14
  * Uses column names as keys and maps out
10
15
  * value with specific JSX for specific column names.
@@ -15,15 +20,19 @@ export type MaskingFunction = (value: string | number, dataMask: string) => stri
15
20
  * @group View Handlers
16
21
  */
17
22
  export interface CellRenderMap {
18
- [ColumnName: string]: (value: string | number | string[]) => React.ReactElement;
23
+ [ColumnName: string]: (
24
+ value: string | number | string[],
25
+ ) => React.ReactElement;
19
26
  }
27
+
20
28
  export interface FilterProps {
21
- filterName: string;
22
- filterOptions: FilterOption[];
23
- value: Record<string, string>;
24
- setValue: React.Dispatch<React.SetStateAction<Record<string, string>>>;
25
- resetPagination: () => void;
29
+ filterName: string;
30
+ filterOptions: FilterOption[];
31
+ value: Record<string, string>;
32
+ setValue: React.Dispatch<React.SetStateAction<Record<string, string>>>;
33
+ resetPagination: () => void;
26
34
  }
35
+
27
36
  /**
28
37
  *
29
38
  * Provides render methods for particular filter
@@ -36,18 +45,27 @@ export interface FilterProps {
36
45
  * @group View Handlers
37
46
  */
38
47
  export interface FilterRenderMap {
39
- [ColumnName: string]: (props: FilterProps) => React.ReactElement;
48
+ [ColumnName: string]: (props: FilterProps) => React.ReactElement;
40
49
  }
50
+
41
51
  /**
42
52
  *
43
53
  * @group View Handlers
44
54
  */
45
55
  export interface EmptyStateProps {
46
- label: string;
56
+ label: string;
47
57
  }
58
+
48
59
  export type NoResultsComponent = (props: EmptyStateProps) => React.ReactElement;
60
+
49
61
  export interface DetailsRenderMap {
50
- [columnName: string]: (props: {
51
- [columnName: string]: string | number | object | string[] | number[] | object[];
52
- }) => React.ReactNode;
62
+ [columnName: string]: (props: {
63
+ [columnName: string]:
64
+ | string
65
+ | number
66
+ | object
67
+ | string[]
68
+ | number[]
69
+ | object[];
70
+ }) => React.ReactNode;
53
71
  }
@@ -64,6 +64,7 @@
64
64
  *
65
65
  * @packageDocumentation
66
66
  */
67
+
67
68
  export * as Handlers from "./handlers";
68
69
  export * as Queries from "./queries";
69
70
  export * as Schemas from "./schemas";
@@ -1,24 +1,31 @@
1
1
  import type { ViewConfig } from "@evenicanpm/portal-types-schemas";
2
+
2
3
  /**
3
4
  *
4
5
  * These are data types returned from API Backend
5
6
  *
6
7
  */
8
+
7
9
  /**
8
10
  *
9
11
  * A single row in the data table response object.
10
12
  *
11
13
  */
12
- export type Row = Record<string, string | number | string[] | Record<string, string>[] | unknown>;
14
+ export type Row = Record<
15
+ string,
16
+ string | number | string[] | Record<string, string>[] | unknown
17
+ >;
18
+
13
19
  /**
14
20
  *
15
21
  * The response type defined in TDD for row data.
16
22
  *
17
23
  */
18
24
  export interface TableRows {
19
- items: number;
20
- data: Row[];
25
+ items: number;
26
+ data: Row[];
21
27
  }
28
+
22
29
  /**
23
30
  *
24
31
  * Response type of data from table config
@@ -0,0 +1,89 @@
1
+ import type { TableViewParams } from "@evenicanpm/portal-types-schemas";
2
+ import type { SvgIconComponent } from "@mui/icons-material";
3
+ import type { UseMutationOptions } from "@tanstack/react-query";
4
+ import type { Table } from "..";
5
+ import type { DetailsTemplateKey } from "../components/dashboard/table/details/templates/template-registry";
6
+ import type {
7
+ CellRenderMap,
8
+ DataMaskMap,
9
+ DetailsRenderMap,
10
+ FilterRenderMap,
11
+ NoResultsComponent,
12
+ } from "./handlers";
13
+ import type { TableRows } from "./queries";
14
+
15
+ /**
16
+ * These are primary domain models and the source of truth for table system.
17
+ */
18
+
19
+ /**
20
+ * Status maps
21
+ */
22
+ export type StatusTextMap = Record<number | string, string>;
23
+
24
+ export type StatusColor = "success" | "primary" | "warning" | "error";
25
+
26
+ export type StatusColorMap = Record<number | string, StatusColor>;
27
+
28
+ type BaseAction = {
29
+ label?: string;
30
+ icon?: SvgIconComponent;
31
+ };
32
+
33
+ export type UIAction = BaseAction & {
34
+ isEnabled?: (row: Record<string, unknown>) => boolean;
35
+ mutation: (args: {
36
+ resourceName: string;
37
+ docId: string | number;
38
+ }) => UseMutationOptions<any, any, any, any>;
39
+ };
40
+
41
+ export type UIBulkAction = BaseAction & {
42
+ isAllowed?: (rows: Record<string, unknown>[]) => boolean;
43
+ mutation: (args: {
44
+ resourceName: string;
45
+ selectedIds: (string | number)[];
46
+ }) => UseMutationOptions<any, any, any, any>;
47
+ };
48
+
49
+ /**
50
+ * Resource Definition
51
+ */
52
+ export interface Resource {
53
+ name: string;
54
+ label: string;
55
+ idField: string;
56
+
57
+ // Data Handlers
58
+ rowsQueryFn: (displaySettings: TableViewParams) => {
59
+ queryKey: readonly unknown[];
60
+ queryFn: () => Promise<TableRows>;
61
+ };
62
+
63
+ // UI Renderers & Mappings
64
+ cellRenderMap?: CellRenderMap;
65
+ dataMaskMap?: DataMaskMap;
66
+ filterRenderMap?: FilterRenderMap;
67
+ noResultsComponent?: NoResultsComponent;
68
+
69
+ // Optional Details view
70
+ detailsRenderMap?: DetailsRenderMap;
71
+
72
+ detailsQueryFn?: (id: string) => {
73
+ queryKey: readonly unknown[];
74
+ queryFn: () => Promise<unknown>;
75
+ };
76
+
77
+ detailsTemplate?: DetailsTemplateKey;
78
+
79
+ // State Visuals
80
+ statusTextMap: StatusTextMap;
81
+ statusColorMap: StatusColorMap;
82
+
83
+ // View Config Value
84
+ viewConfig?: Table.Queries.TableConfig;
85
+
86
+ // Actions and Bulk Actions
87
+ actions?: Record<string, UIAction>;
88
+ bulkActions?: Record<string, UIBulkAction>;
89
+ }
@@ -58,6 +58,7 @@
58
58
  * ```
59
59
  * @module e4 Portal
60
60
  */
61
+
61
62
  export type { Session } from "./auth/auth-context";
62
- export { Portal, type PortalProps } from "./portal";
63
63
  export { Table } from "./features/table";
64
+ export { Portal, type PortalProps } from "./portal";
package/src/portal.tsx ADDED
@@ -0,0 +1,68 @@
1
+ import { FlexBox } from "@evenicanpm/ui";
2
+ import type { PropsWithChildren } from "react";
3
+ import {
4
+ type AuthProviderProps,
5
+ PortalAuthProvider,
6
+ } from "./auth/auth-context";
7
+ import { TableDashboard } from "./features/table/components/dashboard/table-dashboard";
8
+
9
+ /**
10
+ * Main Entry point properties into portal package
11
+ *
12
+ *
13
+ */
14
+ interface PortalProps extends AuthProviderProps {
15
+ // Add Portal Specific Properties Here
16
+ // ie. roles
17
+ }
18
+
19
+ /**
20
+ * The main **e4Portal** entry point.
21
+ * * This is a React Functional Component that provides the core context
22
+ * and layout for the application. It is required to wrap all components
23
+ * that use the library's hooks or sub-components.
24
+ *
25
+ *
26
+ * @param props - The properties passed to the Portal component.
27
+ * @returns A React Element rendering the main application structure.
28
+ */
29
+ const Portal = ({
30
+ session,
31
+ logout,
32
+ children,
33
+ }: PropsWithChildren<PortalProps>) => {
34
+ // Not Logged In
35
+ if (!session?.email) {
36
+ return (
37
+ <FlexBox mt={5} width="100%" justifyContent="center">
38
+ Please login to view the portal.
39
+ </FlexBox>
40
+ );
41
+ }
42
+
43
+ // Logged In yes
44
+ return (
45
+ <PortalAuthProvider session={session} logout={logout}>
46
+ {children}
47
+ </PortalAuthProvider>
48
+ );
49
+ };
50
+
51
+ /**
52
+ *
53
+ * # Feature: Table
54
+ * This is the table feature component.
55
+ * @params props
56
+ *
57
+ */
58
+ Portal.Table = TableDashboard;
59
+
60
+ /**
61
+ *
62
+ * # Feature: Settings
63
+ * This is the table feature component.
64
+ * @params props
65
+ *
66
+ */
67
+
68
+ export { Portal, type PortalProps };
@@ -1,36 +0,0 @@
1
- import { type PropsWithChildren } from "react";
2
- /**
3
- * Powers the auth provider that portal is wrapped in
4
- * Aggregates user and session related data that is needed
5
- * within the portal
6
- */
7
- interface AuthProviderProps {
8
- /** The user details returned from auth framework eg. next-auth **/
9
- session: Session;
10
- /** how to handle logout **/
11
- logout: () => void;
12
- }
13
- /**
14
- * The context value
15
- */
16
- interface AuthContext {
17
- session: Session | null;
18
- /** how to handle logout **/
19
- logout: (() => void) | null;
20
- isAuthenticated: boolean | null;
21
- }
22
- interface Session {
23
- email: string | null | undefined;
24
- name: string | null | undefined;
25
- token: string | null | undefined;
26
- }
27
- declare const AuthContext: import("react").Context<AuthContext>;
28
- /**
29
- * Used to access auth details and callback handlers within the portal auth context
30
- */
31
- declare const useAuth: () => AuthContext;
32
- /**
33
- *
34
- */
35
- declare const PortalAuthProvider: ({ session, logout, children, }: PropsWithChildren<AuthProviderProps>) => import("react").JSX.Element;
36
- export { PortalAuthProvider, useAuth, type AuthProviderProps, AuthContext, type Session, };
@@ -1,2 +0,0 @@
1
- declare const PortalSettings: () => import("react").JSX.Element;
2
- export { PortalSettings };
@@ -1,14 +0,0 @@
1
- import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
2
- import { UseMutationOptions } from "@tanstack/react-query";
3
- /**
4
- *
5
- * Map of action types -> MUI Icons
6
- *
7
- */
8
- export declare const actionIconMap: Record<string, typeof FileDownloadOutlinedIcon>;
9
- type MutationFactory = (resourceName: string, docId: string) => UseMutationOptions<any, any, any, any>;
10
- /**
11
- *
12
- */
13
- export declare const actionMutationMap: Record<string, MutationFactory>;
14
- export {};
@@ -1,2 +0,0 @@
1
- import * as Table from "../../../types/";
2
- export declare const dataMaskMap: Table.Handlers.DataMaskMap;
@@ -1,27 +0,0 @@
1
- import type { Column } from "@evenicanpm/portal-types-schemas";
2
- import type * as Types from "../../../../types";
3
- import type { StatusColorMap, StatusTextMap } from "../../../../types/schemas";
4
- interface DetailsProps {
5
- /** What do we do when use clicks back button? */
6
- handleBack: () => void;
7
- /** What is the id field name */
8
- id: string | number;
9
- /** The actual pojo of data from the API */
10
- documentData: Types.Queries.Row;
11
- documentTypeLabel: string;
12
- /** Special instructions for how to render certain properties */
13
- detailsRenderMap?: Types.Handlers.DetailsRenderMap;
14
- /** Data mask map */
15
- dataMaskMap: Types.Handlers.DataMaskMap;
16
- /** Table columns **/
17
- columns: Column[];
18
- /** */
19
- statusColorMap: StatusColorMap;
20
- /** */
21
- statusTextMap: StatusTextMap;
22
- }
23
- /**
24
- * The Details Page
25
- */
26
- declare const Details: ({ id, documentTypeLabel, documentData, handleBack, columns, dataMaskMap, statusColorMap, statusTextMap, }: DetailsProps) => import("react").JSX.Element;
27
- export { Details };