@contember/create 1.4.0-rc.4 → 1.4.0-rc.5
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.
- package/dist/src/commands/WorkspaceCreateCommand.d.ts +4 -3
- package/dist/src/commands/WorkspaceCreateCommand.d.ts.map +1 -1
- package/dist/src/commands/WorkspaceCreateCommand.js +10 -4
- package/dist/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/src/lib/FileSystem.d.ts +14 -0
- package/dist/src/lib/FileSystem.d.ts.map +1 -0
- package/dist/src/lib/FileSystem.js +54 -0
- package/dist/src/lib/FileSystem.js.map +1 -0
- package/dist/src/lib/PackageDownloader.d.ts +7 -0
- package/dist/src/lib/PackageDownloader.d.ts.map +1 -0
- package/dist/src/lib/PackageDownloader.js +32 -0
- package/dist/src/lib/PackageDownloader.js.map +1 -0
- package/dist/src/lib/TemplateInstaller.d.ts +13 -0
- package/dist/src/lib/TemplateInstaller.d.ts.map +1 -0
- package/dist/src/lib/TemplateInstaller.js +75 -0
- package/dist/src/lib/TemplateInstaller.js.map +1 -0
- package/dist/src/lib/pathUtils.d.ts +3 -0
- package/dist/src/lib/pathUtils.d.ts.map +1 -0
- package/dist/src/lib/pathUtils.js +7 -0
- package/dist/src/lib/pathUtils.js.map +1 -0
- package/dist/src/run.js +7 -3
- package/dist/src/run.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -3
- package/resources/templates/template-workspace/.gitignore.dist +3 -0
- package/resources/templates/template-workspace/admin/.env.development +3 -0
- package/resources/templates/template-workspace/admin/.env.production +3 -0
- package/resources/templates/template-workspace/admin/app/components/layout.tsx +32 -0
- package/resources/templates/template-workspace/admin/app/components/logo.tsx +16 -0
- package/resources/templates/template-workspace/admin/app/components/navigation.tsx +1 -0
- package/resources/templates/template-workspace/admin/app/config.ts +27 -0
- package/resources/templates/template-workspace/admin/app/index.html +15 -0
- package/resources/templates/template-workspace/admin/app/index.tsx +40 -0
- package/resources/templates/template-workspace/admin/app/pages/index.tsx +5 -0
- package/resources/templates/template-workspace/admin/index.css +53 -0
- package/resources/templates/template-workspace/admin/index.html +13 -0
- package/resources/templates/template-workspace/admin/index.tsx +268 -0
- package/resources/templates/template-workspace/admin/lib/binding/binding.tsx +45 -0
- package/resources/templates/template-workspace/admin/lib/binding/delete.tsx +43 -0
- package/resources/templates/template-workspace/admin/lib/binding/hooks.tsx +71 -0
- package/resources/templates/template-workspace/admin/lib/binding/identity.tsx +19 -0
- package/resources/templates/template-workspace/admin/lib/binding/index.ts +5 -0
- package/resources/templates/template-workspace/admin/lib/binding/persist.tsx +70 -0
- package/resources/templates/template-workspace/admin/lib/block-repeater/block-repeater.tsx +224 -0
- package/resources/templates/template-workspace/admin/lib/block-repeater/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/board/board.tsx +240 -0
- package/resources/templates/template-workspace/admin/lib/board/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/buttons/back-button.tsx +20 -0
- package/resources/templates/template-workspace/admin/lib/buttons/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/buttons/link-back-button.tsx +21 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/cells.tsx +64 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/column-header.tsx +65 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/columns.tsx +166 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/elements.tsx +42 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/empty.tsx +8 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/export.tsx +17 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/boolean.tsx +76 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/common.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/date.tsx +153 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/enum.tsx +115 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/index.ts +7 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/mobile.tsx +19 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/number.tsx +100 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/relation.tsx +180 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/text.tsx +121 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/grid.tsx +61 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/index.ts +16 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/layout-switcher.tsx +32 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/loader.tsx +10 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/pagination.tsx +103 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/table.tsx +69 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/tiles.tsx +24 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +66 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/ui.tsx +153 -0
- package/resources/templates/template-workspace/admin/lib/dev/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/dev/login-panel.tsx +56 -0
- package/resources/templates/template-workspace/admin/lib/dev/todo.tsx +14 -0
- package/resources/templates/template-workspace/admin/lib/dict.ts +324 -0
- package/resources/templates/template-workspace/admin/lib/dimensions/dimensions.tsx +135 -0
- package/resources/templates/template-workspace/admin/lib/dimensions/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/editor/block-editor.tsx +111 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/baseEditorPlugins.tsx +66 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/buttons.tsx +83 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-block-toolbar.tsx +17 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-canvas.tsx +30 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-editable-canvas.tsx +50 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-inline-toolbar.tsx +63 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/AnchorRenderer.tsx +36 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/BlockElement.tsx +48 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/HeadingRenderer.tsx +48 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/HorizontalRuleRenderer.tsx +28 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/ListItemRenderer.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/OrderedListRenderer.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/ParagraphRenderer.tsx +15 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/ScrollTargetRenderer.tsx +30 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableCellElementRenderer.tsx +20 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableElementRenderer.tsx +96 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableRowElementRenderer.tsx +15 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/UnorderedListRenderer.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/index.ts +6 -0
- package/resources/templates/template-workspace/admin/lib/editor/editor-block.tsx +96 -0
- package/resources/templates/template-workspace/admin/lib/editor/index.ts +5 -0
- package/resources/templates/template-workspace/admin/lib/editor/plugins.tsx +36 -0
- package/resources/templates/template-workspace/admin/lib/editor/rich-text.tsx +54 -0
- package/resources/templates/template-workspace/admin/lib/editor/sortable-block.tsx +51 -0
- package/resources/templates/template-workspace/admin/lib/errors/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/errors/use-error-formatter.ts +26 -0
- package/resources/templates/template-workspace/admin/lib/form/container.tsx +63 -0
- package/resources/templates/template-workspace/admin/lib/form/index.ts +5 -0
- package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +99 -0
- package/resources/templates/template-workspace/admin/lib/form/select.tsx +123 -0
- package/resources/templates/template-workspace/admin/lib/form/ui.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/form/upload.tsx +243 -0
- package/resources/templates/template-workspace/admin/lib/formatting/formatting.ts +62 -0
- package/resources/templates/template-workspace/admin/lib/formatting/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/images/formatImageResizeUrl.ts +23 -0
- package/resources/templates/template-workspace/admin/lib/images/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/layout/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/layout/layout.tsx +167 -0
- package/resources/templates/template-workspace/admin/lib/layout/slots.tsx +24 -0
- package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/outdated-application-dialog.tsx +41 -0
- package/resources/templates/template-workspace/admin/lib/repeater/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/repeater/repeater.tsx +142 -0
- package/resources/templates/template-workspace/admin/lib/select/create-new.tsx +34 -0
- package/resources/templates/template-workspace/admin/lib/select/filter.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/select/highlight.tsx +16 -0
- package/resources/templates/template-workspace/admin/lib/select/index.ts +7 -0
- package/resources/templates/template-workspace/admin/lib/select/list.tsx +49 -0
- package/resources/templates/template-workspace/admin/lib/select/multi-select.tsx +95 -0
- package/resources/templates/template-workspace/admin/lib/select/pagination.tsx +48 -0
- package/resources/templates/template-workspace/admin/lib/select/select.tsx +87 -0
- package/resources/templates/template-workspace/admin/lib/select/sortable-select.tsx +129 -0
- package/resources/templates/template-workspace/admin/lib/select/ui.tsx +80 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/change-my-password.tsx +40 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/common.tsx +94 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/create-api-key.tsx +39 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/index.ts +8 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/invite.tsx +46 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/login.tsx +52 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/memberships-control.tsx +128 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset-request.tsx +31 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset.tsx +44 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/update-project-member.tsx +32 -0
- package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInvite.ts +28 -0
- package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInviteUser.tsx +45 -0
- package/resources/templates/template-workspace/admin/lib/tenant/index.ts +3 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/api-key-list.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/index.ts +4 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/member-delete-dialog.tsx +38 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/member-list.tsx +147 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/person-list.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/tenant/otp/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/tenant/otp/otp-setup.tsx +146 -0
- package/resources/templates/template-workspace/admin/lib/toast/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/toast/toast.tsx +112 -0
- package/resources/templates/template-workspace/admin/lib/toast/toaster.tsx +104 -0
- package/resources/templates/template-workspace/admin/lib/ui/alert-dialog.tsx +59 -0
- package/resources/templates/template-workspace/admin/lib/ui/button.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/ui/card.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/ui/dialog.tsx +51 -0
- package/resources/templates/template-workspace/admin/lib/ui/divider.tsx +11 -0
- package/resources/templates/template-workspace/admin/lib/ui/dropdown.tsx +108 -0
- package/resources/templates/template-workspace/admin/lib/ui/input.tsx +62 -0
- package/resources/templates/template-workspace/admin/lib/ui/label.tsx +7 -0
- package/resources/templates/template-workspace/admin/lib/ui/loader.tsx +30 -0
- package/resources/templates/template-workspace/admin/lib/ui/menu.tsx +103 -0
- package/resources/templates/template-workspace/admin/lib/ui/overlay.tsx +33 -0
- package/resources/templates/template-workspace/admin/lib/ui/popover.tsx +31 -0
- package/resources/templates/template-workspace/admin/lib/ui/progress.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/ui/scroll-area.tsx +45 -0
- package/resources/templates/template-workspace/admin/lib/ui/sheet.tsx +67 -0
- package/resources/templates/template-workspace/admin/lib/ui/sortable.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/ui/switch.tsx +10 -0
- package/resources/templates/template-workspace/admin/lib/ui/table.tsx +46 -0
- package/resources/templates/template-workspace/admin/lib/ui/textarea.tsx +18 -0
- package/resources/templates/template-workspace/admin/lib/ui/toggle-group.tsx +44 -0
- package/resources/templates/template-workspace/admin/lib/ui/toggle.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/ui/tooltip.tsx +24 -0
- package/resources/templates/template-workspace/admin/lib/upload/dropzone.tsx +21 -0
- package/resources/templates/template-workspace/admin/lib/upload/index.ts +3 -0
- package/resources/templates/template-workspace/admin/lib/upload/repeater.tsx +12 -0
- package/resources/templates/template-workspace/admin/lib/upload/ui.tsx +57 -0
- package/resources/templates/template-workspace/admin/lib/upload/upload-progress.tsx +130 -0
- package/resources/templates/template-workspace/admin/lib/upload/view.tsx +219 -0
- package/resources/templates/template-workspace/admin/lib/utils/cn.ts +4 -0
- package/resources/templates/template-workspace/admin/lib/utils/dict-format.tsx +3 -0
- package/resources/templates/template-workspace/admin/lib/utils/format-image-resize-url.ts +17 -0
- package/resources/templates/template-workspace/admin/lib/utils/formatting.ts +60 -0
- package/resources/templates/template-workspace/admin/lib/utils/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/utils/uic.tsx +79 -0
- package/resources/templates/template-workspace/admin/package.json +63 -0
- package/resources/templates/template-workspace/admin/postcss.config.js +6 -0
- package/resources/templates/template-workspace/admin/public/favicon.png +0 -0
- package/resources/templates/template-workspace/admin/tailwind.config.js +73 -0
- package/resources/templates/template-workspace/admin/tsconfig.json +23 -0
- package/resources/templates/template-workspace/admin/vite-env.d.ts +7 -0
- package/resources/templates/template-workspace/admin/vite.config.ts +39 -0
- package/resources/templates/template-workspace/api/index.ts +7 -0
- package/resources/templates/template-workspace/api/migrations/.gitkeep +1 -0
- package/resources/templates/template-workspace/api/model/index.ts +1 -0
- package/resources/templates/template-workspace/api/package.json +16 -0
- package/resources/templates/template-workspace/api/tsconfig.json +10 -0
- package/resources/templates/template-workspace/biome.json +45 -0
- package/resources/templates/template-workspace/client/package.json +16 -0
- package/resources/templates/template-workspace/client/src/index.ts +1 -0
- package/resources/templates/template-workspace/client/tsconfig.json +9 -0
- package/resources/templates/template-workspace/contember.template.yaml +7 -0
- package/resources/templates/template-workspace/docker-compose.yaml +124 -0
- package/resources/templates/template-workspace/package.json +32 -0
- package/resources/templates/template-workspace/scripts/generate-client.sh +8 -0
- package/resources/templates/template-workspace/tsconfig.json +9 -0
- package/resources/templates/template-workspace/tsconfig.settings.json +15 -0
- package/src/commands/WorkspaceCreateCommand.ts +15 -6
- package/src/lib/FileSystem.ts +24 -0
- package/src/lib/PackageDownloader.ts +33 -0
- package/src/lib/TemplateInstaller.ts +102 -0
- package/src/lib/pathUtils.ts +4 -0
- package/src/run.ts +14 -5
- package/tsconfig.settings.json +5 -1
- package/types/download-tarball/index.d.ts +7 -0
- package/types/get-package-json-from-registry/index.d.ts +3 -0
- package/types/registry-info/index.d.ts +7 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { Component, Field } from '@contember/interface'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { ReactNode } from 'react'
|
|
4
|
+
import { TableCell, TableHead } from '../ui/table'
|
|
5
|
+
import { DataGridColumnHeader } from './column-header'
|
|
6
|
+
import { DataViewElement } from '@contember/react-dataview'
|
|
7
|
+
import { formatBoolean, formatDate, formatNumber } from '../formatting'
|
|
8
|
+
import { DataGridEnumCell, DataGridHasManyCell, DataGridHasManyCellProps, DataGridHasOneCell, DataGridHasOneCellProps } from './cells'
|
|
9
|
+
|
|
10
|
+
export const DataGridActionColumn = Component<{ children: ReactNode }>(({ children }) => (
|
|
11
|
+
<DataGridColumnLeaf
|
|
12
|
+
header={<TableHead className="w-0"></TableHead>}
|
|
13
|
+
cell={<TableCell className="w-0">{children}</TableCell>}
|
|
14
|
+
/>
|
|
15
|
+
))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export type DataGridTextColumnProps = {
|
|
19
|
+
field: string
|
|
20
|
+
header: ReactNode
|
|
21
|
+
children?: ReactNode
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const DataGridTextColumn = Component<DataGridTextColumnProps>(({ field, header, children }) => (
|
|
25
|
+
<DataGridColumn
|
|
26
|
+
header={header}
|
|
27
|
+
sortingField={field}
|
|
28
|
+
name={field}
|
|
29
|
+
children={children ?? <Field field={field} />}
|
|
30
|
+
/>
|
|
31
|
+
))
|
|
32
|
+
|
|
33
|
+
export type DataGridBooleanColumnProps = {
|
|
34
|
+
field: string
|
|
35
|
+
header: ReactNode
|
|
36
|
+
children?: ReactNode
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const DataGridBooleanColumn = Component<DataGridBooleanColumnProps>(({ field, header, children }) => (
|
|
40
|
+
<DataGridColumn
|
|
41
|
+
header={header}
|
|
42
|
+
sortingField={field}
|
|
43
|
+
name={field}
|
|
44
|
+
children={children ?? <Field field={field} format={formatBoolean} />}
|
|
45
|
+
/>
|
|
46
|
+
))
|
|
47
|
+
|
|
48
|
+
export type DataGridNumberColumnProps = {
|
|
49
|
+
field: string
|
|
50
|
+
header: ReactNode
|
|
51
|
+
children?: ReactNode
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const DataGridNumberColumn = Component<DataGridNumberColumnProps>(({ field, header, children }) => (
|
|
55
|
+
<DataGridColumn
|
|
56
|
+
header={header}
|
|
57
|
+
sortingField={field}
|
|
58
|
+
name={field}
|
|
59
|
+
children={children ?? <Field field={field} format={formatNumber} />}
|
|
60
|
+
/>
|
|
61
|
+
))
|
|
62
|
+
|
|
63
|
+
export type DataGridDateColumnProps = {
|
|
64
|
+
field: string
|
|
65
|
+
header: ReactNode
|
|
66
|
+
children?: ReactNode
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const DataGridDateColumn = Component<DataGridDateColumnProps>(({ field, header, children }) => (
|
|
70
|
+
<DataGridColumn
|
|
71
|
+
header={header}
|
|
72
|
+
sortingField={field}
|
|
73
|
+
name={field}
|
|
74
|
+
children={children ?? <Field field={field} format={formatDate} />}
|
|
75
|
+
/>
|
|
76
|
+
))
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
export type DataGridEnumColumnProps = {
|
|
80
|
+
field: string
|
|
81
|
+
header: ReactNode
|
|
82
|
+
options: Record<string, ReactNode>
|
|
83
|
+
children?: ReactNode
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const DataGridEnumColumn = Component<DataGridEnumColumnProps>(({ field, header, options, children }) => (
|
|
87
|
+
<DataGridColumn
|
|
88
|
+
header={header}
|
|
89
|
+
sortingField={field}
|
|
90
|
+
name={field}
|
|
91
|
+
children={children ?? <DataGridEnumCell field={field} options={options} />}
|
|
92
|
+
/>
|
|
93
|
+
))
|
|
94
|
+
|
|
95
|
+
export type DataGridHasOneColumnProps =
|
|
96
|
+
& DataGridHasOneCellProps
|
|
97
|
+
& {
|
|
98
|
+
header: ReactNode
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
export const DataGridHasOneColumn = Component<DataGridHasOneColumnProps>(({ field, header, children }) => (
|
|
103
|
+
<DataGridColumn
|
|
104
|
+
header={header}
|
|
105
|
+
name={typeof field === 'string' ? field : undefined}
|
|
106
|
+
children={<DataGridHasOneCell field={field}>{children}</DataGridHasOneCell>}
|
|
107
|
+
/>
|
|
108
|
+
))
|
|
109
|
+
|
|
110
|
+
export type DataGridHasManyColumnProps =
|
|
111
|
+
& DataGridHasManyCellProps
|
|
112
|
+
& {
|
|
113
|
+
header: ReactNode
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const DataGridHasManyColumn = Component<DataGridHasManyColumnProps>(({ field, header, children }) => (
|
|
117
|
+
<DataGridColumn
|
|
118
|
+
header={header}
|
|
119
|
+
name={typeof field === 'string' ? field : undefined}
|
|
120
|
+
children={<DataGridHasManyCell field={field}>{children}</DataGridHasManyCell>}
|
|
121
|
+
/>
|
|
122
|
+
))
|
|
123
|
+
|
|
124
|
+
export type DataGridColumnProps = {
|
|
125
|
+
children: ReactNode
|
|
126
|
+
header?: ReactNode
|
|
127
|
+
name?: string
|
|
128
|
+
hidingName?: string
|
|
129
|
+
sortingField?: string
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const DataGridColumn = Component<DataGridColumnProps>(({ children, header, name, hidingName, sortingField }) => {
|
|
133
|
+
const wrapIsVisible = (child: ReactNode) => {
|
|
134
|
+
const resolvedName = hidingName ?? name
|
|
135
|
+
return resolvedName ? <DataViewElement name={resolvedName} label={header}>{child}</DataViewElement> : child
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<DataGridColumnLeaf
|
|
140
|
+
name={name}
|
|
141
|
+
header={
|
|
142
|
+
wrapIsVisible(
|
|
143
|
+
<TableHead className={'text-center'}>
|
|
144
|
+
{header ? <DataGridColumnHeader hidingName={hidingName ?? name} sortingField={sortingField}>
|
|
145
|
+
{header}
|
|
146
|
+
</DataGridColumnHeader> : null}
|
|
147
|
+
</TableHead>,
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
cell={wrapIsVisible(<TableCell>{children}</TableCell>)}
|
|
151
|
+
/>
|
|
152
|
+
)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
export interface DataGridColumnLeafProps {
|
|
156
|
+
header: ReactNode
|
|
157
|
+
cell: ReactNode
|
|
158
|
+
name?: string
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export const DataGridColumnLeaf = Component<DataGridColumnLeafProps>(() => {
|
|
162
|
+
throw new Error('DataGridColumnLeaf is not supposed to be rendered')
|
|
163
|
+
}, ({ header, cell }) => {
|
|
164
|
+
return <>{header}{cell}</>
|
|
165
|
+
})
|
|
166
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { EyeIcon, EyeOffIcon } from 'lucide-react'
|
|
2
|
+
import { dict } from '../dict'
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { ReactNode } from 'react'
|
|
5
|
+
import { DataViewVisibilityTrigger, useDataViewElements } from '@contember/react-dataview'
|
|
6
|
+
import { ScrollArea } from '../ui/scroll-area'
|
|
7
|
+
|
|
8
|
+
export interface DataGridToolbarVisibleElementsProps {
|
|
9
|
+
elements?: {
|
|
10
|
+
name: string
|
|
11
|
+
label: ReactNode
|
|
12
|
+
}[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const DataGridToolbarVisibleElements = ({ elements }: DataGridToolbarVisibleElementsProps) => {
|
|
16
|
+
const globalElements = useDataViewElements()
|
|
17
|
+
|
|
18
|
+
const resolvedElements = elements ?? globalElements
|
|
19
|
+
if (resolvedElements.length === 0) {
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
return (
|
|
23
|
+
<div>
|
|
24
|
+
<p className="text-gray-400 text-xs font-semibold mb-1">{dict.datagrid.visibleFields}</p>
|
|
25
|
+
<div className="flex flex-col bg-gray-50 p-2 border rounded shadow-inner">
|
|
26
|
+
<ScrollArea className={'max-h-48'}>
|
|
27
|
+
<div className="flex flex-col">
|
|
28
|
+
{resolvedElements.map(element => (
|
|
29
|
+
element.name && <DataViewVisibilityTrigger key={element.name} name={element.name} value={it => !(it ?? true)}>
|
|
30
|
+
<button className={'gap-2 group text-gray-400 data-[current]:text-black text-left inline-flex items-center p-0.5 text-sm rounded hover:bg-white'}>
|
|
31
|
+
<EyeIcon className={'w-3 h-3 hidden group-data-[current]:block'} />
|
|
32
|
+
<EyeOffIcon className={'w-3 h-3 block group-data-[current]:hidden'} />
|
|
33
|
+
<span>{element.label}</span>
|
|
34
|
+
</button>
|
|
35
|
+
</DataViewVisibilityTrigger>
|
|
36
|
+
))}
|
|
37
|
+
</div>
|
|
38
|
+
</ScrollArea>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Button } from '../ui/button'
|
|
2
|
+
import { DownloadIcon } from 'lucide-react'
|
|
3
|
+
import { DataViewExportTrigger } from '@contember/react-dataview'
|
|
4
|
+
import * as React from 'react'
|
|
5
|
+
import { ReactNode, useMemo } from 'react'
|
|
6
|
+
import { dict } from '../dict'
|
|
7
|
+
|
|
8
|
+
export const DataGridAutoExport = ({ fields }: { fields?: ReactNode }) => {
|
|
9
|
+
return (
|
|
10
|
+
<DataViewExportTrigger fields={fields}>
|
|
11
|
+
<Button variant={'outline'} size={'sm'} className={'gap-2'}>
|
|
12
|
+
<DownloadIcon className={'w-4 h-4'} />
|
|
13
|
+
{dict.datagrid.export}
|
|
14
|
+
</Button>
|
|
15
|
+
</DataViewExportTrigger>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
3
|
+
import { DataViewBooleanFilter, DataViewBooleanFilterProps, DataViewBooleanFilterTrigger, DataViewNullFilterTrigger } from '@contember/react-dataview'
|
|
4
|
+
import { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover'
|
|
5
|
+
import { DataGridActiveFilterUI, DataGridFilterSelectTriggerUI, DataGridSingleFilterUI } from '../ui'
|
|
6
|
+
import { DataGridNullFilter } from './common'
|
|
7
|
+
import { formatBoolean } from '../../formatting'
|
|
8
|
+
import { Button } from '../../ui/button'
|
|
9
|
+
import { dict } from '../../dict'
|
|
10
|
+
import { Component } from '@contember/interface'
|
|
11
|
+
import { DataGridFilterMobileHiding } from './mobile'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
type DataGridBooleanFilterProps =
|
|
15
|
+
& Omit<DataViewBooleanFilterProps, 'children'>
|
|
16
|
+
& {
|
|
17
|
+
label: ReactNode
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const DataGridBooleanFilter = Component(({ label, ...props }: DataGridBooleanFilterProps) => (
|
|
21
|
+
<DataViewBooleanFilter {...props}>
|
|
22
|
+
<DataGridFilterMobileHiding>
|
|
23
|
+
<DataGridSingleFilterUI>
|
|
24
|
+
<DataGridBooleanFilterSelect label={label} />
|
|
25
|
+
<DataGridBooleanFilterList />
|
|
26
|
+
</DataGridSingleFilterUI>
|
|
27
|
+
</DataGridFilterMobileHiding>
|
|
28
|
+
</DataViewBooleanFilter>
|
|
29
|
+
))
|
|
30
|
+
|
|
31
|
+
export const DataGridBooleanFilterList = () => (
|
|
32
|
+
<>
|
|
33
|
+
{[true, false].map(value => (
|
|
34
|
+
<DataViewBooleanFilterTrigger action={'unset'} value={value} key={value.toString()}>
|
|
35
|
+
<DataGridActiveFilterUI className={'data-[current=none]:hidden'}>
|
|
36
|
+
{formatBoolean(value)}
|
|
37
|
+
</DataGridActiveFilterUI>
|
|
38
|
+
</DataViewBooleanFilterTrigger>
|
|
39
|
+
))}
|
|
40
|
+
|
|
41
|
+
<DataViewNullFilterTrigger action={'unset'}>
|
|
42
|
+
<DataGridActiveFilterUI>
|
|
43
|
+
<span className={'italic'}>{dict.datagrid.na}</span>
|
|
44
|
+
</DataGridActiveFilterUI>
|
|
45
|
+
</DataViewNullFilterTrigger>
|
|
46
|
+
</>
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
export const DataGridBooleanFilterSelect = ({ label }: {
|
|
51
|
+
label?: ReactNode
|
|
52
|
+
}) => (
|
|
53
|
+
<Popover>
|
|
54
|
+
<PopoverTrigger asChild>
|
|
55
|
+
<DataGridFilterSelectTriggerUI>{label}</DataGridFilterSelectTriggerUI>
|
|
56
|
+
</PopoverTrigger>
|
|
57
|
+
<PopoverContent className={'w-52'}>
|
|
58
|
+
<div className={'relative flex flex-col gap-2'}>
|
|
59
|
+
<div className={'flex gap-2'}>
|
|
60
|
+
{[true, false].map(it => (
|
|
61
|
+
<DataViewBooleanFilterTrigger action={'toggle'} value={it} key={it.toString()}>
|
|
62
|
+
<Button size={'lg'} className={'w-full data-[active]:shadow-inner data-[active]:text-blue-500'}
|
|
63
|
+
variant={'outline'}>
|
|
64
|
+
|
|
65
|
+
<span className={'text-xs font-semibold'}>
|
|
66
|
+
{formatBoolean(it)}
|
|
67
|
+
</span>
|
|
68
|
+
</Button>
|
|
69
|
+
</DataViewBooleanFilterTrigger>
|
|
70
|
+
))}
|
|
71
|
+
</div>
|
|
72
|
+
<DataGridNullFilter />
|
|
73
|
+
</div>
|
|
74
|
+
</PopoverContent>
|
|
75
|
+
</Popover>
|
|
76
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useCallback } from 'react'
|
|
3
|
+
import { useDataViewFilterName, useDataViewNullFilter } from '@contember/react-dataview'
|
|
4
|
+
import { DataGridFilterSelectItemUI } from '../ui'
|
|
5
|
+
import { dict } from '../../dict'
|
|
6
|
+
|
|
7
|
+
export const DataGridNullFilter = ({ name }: {
|
|
8
|
+
name?: string
|
|
9
|
+
}) => {
|
|
10
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
11
|
+
name ??= useDataViewFilterName()
|
|
12
|
+
const [nullFilter, setNullFilter] = useDataViewNullFilter(name)
|
|
13
|
+
const toggleExcludeNull = useCallback(() => setNullFilter('toggleExclude'), [setNullFilter])
|
|
14
|
+
const toggleIncludeNull = useCallback(() => setNullFilter('toggleInclude'), [setNullFilter])
|
|
15
|
+
|
|
16
|
+
return <>
|
|
17
|
+
<DataGridFilterSelectItemUI
|
|
18
|
+
onExclude={toggleExcludeNull}
|
|
19
|
+
onInclude={toggleIncludeNull}
|
|
20
|
+
isExcluded={nullFilter === 'exclude'}
|
|
21
|
+
isIncluded={nullFilter === 'include'}
|
|
22
|
+
>
|
|
23
|
+
<span className={'italic'}>
|
|
24
|
+
{dict.datagrid.na}
|
|
25
|
+
</span>
|
|
26
|
+
</DataGridFilterSelectItemUI>
|
|
27
|
+
</>
|
|
28
|
+
}
|
|
29
|
+
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ReactNode, useId } from 'react'
|
|
3
|
+
import { DataViewDateFilter, DataViewDateFilterInput, DataViewDateFilterProps, DataViewDateFilterResetTrigger, DataViewNullFilterTrigger, DateRangeFilterArtifacts, useDataViewFilter, useDataViewFilterName } from '@contember/react-dataview'
|
|
4
|
+
import { Component } from '@contember/interface'
|
|
5
|
+
import { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover'
|
|
6
|
+
import { DataGridActiveFilterUI, DataGridFilterSelectTriggerUI, DataGridSingleFilterUI } from '../ui'
|
|
7
|
+
import { Input } from '../../ui/input'
|
|
8
|
+
import { formatDate } from '../../formatting/formatting'
|
|
9
|
+
import { dict } from '../../dict'
|
|
10
|
+
import { DataGridNullFilter } from './common'
|
|
11
|
+
import { DataGridFilterMobileHiding } from './mobile'
|
|
12
|
+
import { Button } from '../../ui/button'
|
|
13
|
+
import { Label } from '../../ui/label'
|
|
14
|
+
import { XIcon } from 'lucide-react'
|
|
15
|
+
|
|
16
|
+
export type DataGridDateFilterProps =
|
|
17
|
+
& Omit<DataViewDateFilterProps, 'children'>
|
|
18
|
+
& {
|
|
19
|
+
label: ReactNode
|
|
20
|
+
ranges?: DataGridPredefinedDateRange[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const DataGridDateFilter = Component(({ label, ranges, ...props }: DataGridDateFilterProps) => (
|
|
24
|
+
<DataViewDateFilter {...props}>
|
|
25
|
+
<DataGridFilterMobileHiding>
|
|
26
|
+
<DataGridSingleFilterUI>
|
|
27
|
+
<DataGridDateFilterSelect label={label} ranges={ranges} />
|
|
28
|
+
<DataGridDateFilterList />
|
|
29
|
+
</DataGridSingleFilterUI>
|
|
30
|
+
</DataGridFilterMobileHiding>
|
|
31
|
+
</DataViewDateFilter>
|
|
32
|
+
))
|
|
33
|
+
|
|
34
|
+
const DataGridDateFilterRange = () => {
|
|
35
|
+
const [artifact] = useDataViewFilter<DateRangeFilterArtifacts>(useDataViewFilterName())
|
|
36
|
+
if (!artifact) {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
const { start, end } = artifact
|
|
40
|
+
const startFormatted = start ? formatDate(start) : undefined
|
|
41
|
+
const endFormatted = end ? formatDate(end) : undefined
|
|
42
|
+
if (startFormatted !== undefined && endFormatted !== undefined) {
|
|
43
|
+
return `${startFormatted} – ${endFormatted}`
|
|
44
|
+
}
|
|
45
|
+
if (startFormatted !== undefined) {
|
|
46
|
+
return `≥ ${startFormatted}`
|
|
47
|
+
}
|
|
48
|
+
if (endFormatted !== undefined) {
|
|
49
|
+
return `≤ ${endFormatted}`
|
|
50
|
+
}
|
|
51
|
+
return undefined
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
const DataGridDateFilterList = () => (
|
|
57
|
+
<>
|
|
58
|
+
<DataViewDateFilterResetTrigger>
|
|
59
|
+
<DataGridActiveFilterUI>
|
|
60
|
+
<DataGridDateFilterRange />
|
|
61
|
+
</DataGridActiveFilterUI>
|
|
62
|
+
</DataViewDateFilterResetTrigger>
|
|
63
|
+
|
|
64
|
+
<DataViewNullFilterTrigger action={'unset'}>
|
|
65
|
+
<DataGridActiveFilterUI>
|
|
66
|
+
<span className={'italic'}>{dict.datagrid.na}</span>
|
|
67
|
+
</DataGridActiveFilterUI>
|
|
68
|
+
</DataViewNullFilterTrigger>
|
|
69
|
+
</>
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
export const createDataGridDateRange = (label: ReactNode, dayDeltaStart: number, dayDeltaEnd: number): DataGridPredefinedDateRange => {
|
|
73
|
+
const start = new Date(new Date().setDate(new Date().getDate() + dayDeltaStart))
|
|
74
|
+
const end = new Date(new Date().setDate(new Date().getDate() + dayDeltaEnd))
|
|
75
|
+
return {
|
|
76
|
+
label,
|
|
77
|
+
start: `${start.getFullYear()}-${String(start.getMonth() + 1).padStart(2, '0')}-${String(start.getDate()).padStart(2, '0')}`,
|
|
78
|
+
end: `${end.getFullYear()}-${String(end.getMonth() + 1).padStart(2, '0')}-${String(end.getDate()).padStart(2, '0')}`,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const defaultRanges = [createDataGridDateRange(dict.datagrid.today, 0, 0)]
|
|
83
|
+
|
|
84
|
+
const DataGridDateFilterSelect = ({ label, ranges = defaultRanges }: {
|
|
85
|
+
label?: ReactNode
|
|
86
|
+
ranges?: DataGridPredefinedDateRange[]
|
|
87
|
+
}) => {
|
|
88
|
+
const id = useId()
|
|
89
|
+
return (
|
|
90
|
+
<Popover>
|
|
91
|
+
<PopoverTrigger asChild>
|
|
92
|
+
<DataGridFilterSelectTriggerUI>{label}</DataGridFilterSelectTriggerUI>
|
|
93
|
+
</PopoverTrigger>
|
|
94
|
+
<PopoverContent className="p-0">
|
|
95
|
+
<div className="flex">
|
|
96
|
+
{ranges?.length > 0 && <div className="flex flex-col gap-2 bg-gray-50 p-4 border-r">
|
|
97
|
+
{ranges.map(({ start, end, label }) => (
|
|
98
|
+
<DataGridRangeFilter start={start} end={end} label={label} key={`${start}-${end}`} />
|
|
99
|
+
))}
|
|
100
|
+
</div>}
|
|
101
|
+
<div className={'relative flex flex-col'}>
|
|
102
|
+
<div className={!ranges?.length ? 'flex gap-4 px-4 py-2' : 'flex flex-col px-4 py-2 gap-2'}>
|
|
103
|
+
<div className="space-y-2">
|
|
104
|
+
<div className="flex justify-between items-end h-5">
|
|
105
|
+
<Label htmlFor={`${id}-start`}>
|
|
106
|
+
{dict.datagrid.dateStart}:
|
|
107
|
+
</Label>
|
|
108
|
+
<DataViewDateFilterResetTrigger type="start">
|
|
109
|
+
<span className="text-sm text-gray-500 cursor-pointer hover:bg-gray-100 rounded p-0.5"><XIcon className="w-3 h-3" /></span>
|
|
110
|
+
</DataViewDateFilterResetTrigger>
|
|
111
|
+
</div>
|
|
112
|
+
<DataViewDateFilterInput type={'start'}>
|
|
113
|
+
<Input inputSize={'sm'} placeholder={dict.datagrid.dateStart} type={'date'} id={`${id}-start`} />
|
|
114
|
+
</DataViewDateFilterInput>
|
|
115
|
+
</div>
|
|
116
|
+
<div className="space-y-2">
|
|
117
|
+
<div className="flex justify-between items-end h-5">
|
|
118
|
+
<Label htmlFor={`${id}-end`}>
|
|
119
|
+
{dict.datagrid.dateEnd}:
|
|
120
|
+
</Label>
|
|
121
|
+
<DataViewDateFilterResetTrigger type="end">
|
|
122
|
+
<span className="text-sm text-gray-500 cursor-pointer hover:bg-gray-100 rounded p-0.5"><XIcon className="w-3 h-3" /></span>
|
|
123
|
+
</DataViewDateFilterResetTrigger>
|
|
124
|
+
</div>
|
|
125
|
+
<DataViewDateFilterInput type={'end'}>
|
|
126
|
+
<Input inputSize={'sm'} placeholder={dict.datagrid.dateEnd} type={'date'} id={`${id}-end`} />
|
|
127
|
+
</DataViewDateFilterInput>
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
<div className="mt-auto p-2 border-t">
|
|
131
|
+
<DataGridNullFilter />
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
</div>
|
|
135
|
+
</PopoverContent>
|
|
136
|
+
</Popover>
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export type DataGridPredefinedDateRange = { start: string, end: string, label: ReactNode }
|
|
141
|
+
const DataGridRangeFilter = ({ start, end, label }: DataGridPredefinedDateRange) => {
|
|
142
|
+
const name = useDataViewFilterName()
|
|
143
|
+
const [filter, setFilter] = useDataViewFilter<DateRangeFilterArtifacts>(name)
|
|
144
|
+
const isActive = filter?.start === start && filter?.end === end
|
|
145
|
+
return (
|
|
146
|
+
<Button variant="outline" size="sm" className={isActive ? 'shadow-inner bg-gray-100' : ''} onClick={() => {
|
|
147
|
+
setFilter({
|
|
148
|
+
start,
|
|
149
|
+
end,
|
|
150
|
+
})
|
|
151
|
+
}}>{label}</Button>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ReactNode, useCallback } from 'react'
|
|
3
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../ui/tooltip'
|
|
4
|
+
import { DataViewEnumFilter, DataViewEnumFilterProps, DataViewEnumFilterTrigger, DataViewNullFilterTrigger, UseDataViewEnumFilter, useDataViewEnumFilterFactory, useDataViewFilterName } from '@contember/react-dataview'
|
|
5
|
+
import { Component } from '@contember/interface'
|
|
6
|
+
import { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover'
|
|
7
|
+
import { DataGridActiveFilterUI, DataGridExcludeActionButtonUI, DataGridFilterActionButtonUI, DataGridFilterSelectItemUI, DataGridFilterSelectTriggerUI, DataGridSingleFilterUI } from '../ui'
|
|
8
|
+
import { DataGridNullFilter } from './common'
|
|
9
|
+
import { dict } from '../../dict'
|
|
10
|
+
import { DataGridFilterMobileHiding } from './mobile'
|
|
11
|
+
|
|
12
|
+
export type DataGridEnumFilterProps =
|
|
13
|
+
& Omit<DataViewEnumFilterProps, 'children'>
|
|
14
|
+
& {
|
|
15
|
+
options: Record<string, ReactNode>
|
|
16
|
+
label: ReactNode
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const DataGridEnumFilter = Component(({ options, label, ...props }: DataGridEnumFilterProps) =>
|
|
20
|
+
(
|
|
21
|
+
<DataViewEnumFilter {...props}>
|
|
22
|
+
<DataGridFilterMobileHiding>
|
|
23
|
+
<DataGridSingleFilterUI>
|
|
24
|
+
<DataGridEnumFilterSelect options={options} label={label} />
|
|
25
|
+
<DataGridEnumFilterList options={options} />
|
|
26
|
+
</DataGridSingleFilterUI>
|
|
27
|
+
</DataGridFilterMobileHiding>
|
|
28
|
+
</DataViewEnumFilter>
|
|
29
|
+
))
|
|
30
|
+
|
|
31
|
+
export const DataGridEnumFieldTooltip = ({ children, actions, value, ...props }: Omit<DataViewEnumFilterProps, 'children'> & { children: ReactNode, value: string, actions?: ReactNode }) => (
|
|
32
|
+
<DataViewEnumFilter {...props}>
|
|
33
|
+
<TooltipProvider>
|
|
34
|
+
<Tooltip>
|
|
35
|
+
<TooltipTrigger asChild>
|
|
36
|
+
{children}
|
|
37
|
+
</TooltipTrigger>
|
|
38
|
+
<TooltipContent variant={'blurred'}>
|
|
39
|
+
<div className={'flex gap-1'}>
|
|
40
|
+
<DataViewEnumFilterTrigger action={'toggleInclude'} value={value}>
|
|
41
|
+
<DataGridFilterActionButtonUI />
|
|
42
|
+
</DataViewEnumFilterTrigger>
|
|
43
|
+
<DataViewEnumFilterTrigger action={'toggleExclude'} value={value}>
|
|
44
|
+
<DataGridExcludeActionButtonUI />
|
|
45
|
+
</DataViewEnumFilterTrigger>
|
|
46
|
+
{actions}
|
|
47
|
+
</div>
|
|
48
|
+
</TooltipContent>
|
|
49
|
+
</Tooltip>
|
|
50
|
+
</TooltipProvider>
|
|
51
|
+
</DataViewEnumFilter>
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const DataGridEnumFilterList = ({ options }: {
|
|
56
|
+
options: Record<string, ReactNode>
|
|
57
|
+
}) => (
|
|
58
|
+
<>
|
|
59
|
+
{Object.entries(options).map(([value, label]) => (
|
|
60
|
+
<DataViewEnumFilterTrigger action={'unset'} value={value} key={value}>
|
|
61
|
+
<DataGridActiveFilterUI>
|
|
62
|
+
{label}
|
|
63
|
+
</DataGridActiveFilterUI>
|
|
64
|
+
</DataViewEnumFilterTrigger>
|
|
65
|
+
))}
|
|
66
|
+
|
|
67
|
+
<DataViewNullFilterTrigger action={'unset'}>
|
|
68
|
+
<DataGridActiveFilterUI>
|
|
69
|
+
<span className={'italic'}>{dict.datagrid.na}</span>
|
|
70
|
+
</DataGridActiveFilterUI>
|
|
71
|
+
</DataViewNullFilterTrigger>
|
|
72
|
+
</>
|
|
73
|
+
)
|
|
74
|
+
const DataGridEnumFilterSelectItem = ({ value, children, filterFactory }: {
|
|
75
|
+
value: string
|
|
76
|
+
children: ReactNode
|
|
77
|
+
filterFactory: (value: string) => UseDataViewEnumFilter
|
|
78
|
+
}) => {
|
|
79
|
+
|
|
80
|
+
const [current, setFilter] = filterFactory(value)
|
|
81
|
+
const include = useCallback(() => setFilter('toggleInclude'), [setFilter])
|
|
82
|
+
const exclude = useCallback(() => setFilter('toggleExclude'), [setFilter])
|
|
83
|
+
const isIncluded = current === 'include'
|
|
84
|
+
|
|
85
|
+
const isExcluded = current == 'exclude'
|
|
86
|
+
return (
|
|
87
|
+
<DataGridFilterSelectItemUI onExclude={exclude} onInclude={include} isExcluded={isExcluded} isIncluded={isIncluded}>
|
|
88
|
+
{children}
|
|
89
|
+
</DataGridFilterSelectItemUI>
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
const DataGridEnumFilterSelect = ({ options, label }: {
|
|
94
|
+
options: Record<string, ReactNode>
|
|
95
|
+
label?: ReactNode
|
|
96
|
+
}) => {
|
|
97
|
+
const filterFactory = useDataViewEnumFilterFactory(useDataViewFilterName())
|
|
98
|
+
return (
|
|
99
|
+
<Popover>
|
|
100
|
+
<PopoverTrigger asChild>
|
|
101
|
+
<DataGridFilterSelectTriggerUI>{label}</DataGridFilterSelectTriggerUI>
|
|
102
|
+
</PopoverTrigger>
|
|
103
|
+
<PopoverContent className="p-2">
|
|
104
|
+
<div className={'relative flex flex-col gap-2'}>
|
|
105
|
+
{Object.entries(options).map(([value, label]) => (
|
|
106
|
+
<DataGridEnumFilterSelectItem value={value} key={value} filterFactory={filterFactory}>
|
|
107
|
+
{label}
|
|
108
|
+
</DataGridEnumFilterSelectItem>
|
|
109
|
+
))}
|
|
110
|
+
<DataGridNullFilter />
|
|
111
|
+
</div>
|
|
112
|
+
</PopoverContent>
|
|
113
|
+
</Popover>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useDataViewFilteringState, useDataViewFilterName } from '@contember/react-dataview'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { createContext, ReactNode, useContext } from 'react'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export const DataGridShowFiltersContext = createContext(true)
|
|
7
|
+
|
|
8
|
+
export const DataGridFilterMobileHiding = ({ name, children }: { name?: string, children: ReactNode }) => {
|
|
9
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
10
|
+
name ??= useDataViewFilterName()
|
|
11
|
+
const activeFilter = useDataViewFilteringState().artifact
|
|
12
|
+
const isActive = !!activeFilter[name]
|
|
13
|
+
const alwaysShow = useContext(DataGridShowFiltersContext)
|
|
14
|
+
return (
|
|
15
|
+
<div key={name} className={alwaysShow || isActive ? 'contents' : 'hidden sm:contents'}>
|
|
16
|
+
{children}
|
|
17
|
+
</div>
|
|
18
|
+
)
|
|
19
|
+
}
|