d2coreui 23.0.59 → 23.0.61
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/CHANGELOG.md +35 -0
- package/README.md +1 -1
- package/components/date/dateTimeInput.d.ts +4 -9
- package/components/date/dateTimeInput.js +19 -34
- package/components/date/dateTimeInput.js.map +1 -1
- package/components/date/durationInput.js +6 -6
- package/components/date/durationInput.js.map +1 -1
- package/components/grid/dataGrid.d.ts +34 -1
- package/components/grid/dataGrid.js +93 -59
- package/components/grid/dataGrid.js.map +1 -1
- package/components/grid/export/contextMenu.d.ts +13 -3
- package/components/grid/export/contextMenu.js +69 -31
- package/components/grid/export/contextMenu.js.map +1 -1
- package/components/grid/export/worker/csvExport.js +3 -1
- package/components/grid/export/worker/csvExport.js.map +1 -1
- package/components/grid/extendedDataGrid.d.ts +21 -4
- package/components/grid/extendedDataGrid.js +21 -3
- package/components/grid/extendedDataGrid.js.map +1 -1
- package/package.json +1 -1
|
@@ -27,9 +27,8 @@ export interface ContextMenuProps {
|
|
|
27
27
|
/** Called when the user toggles the PDF orientation switch; the caller is expected to pass the new `pageOrientation` back. */
|
|
28
28
|
onPageOrientationChange: (pageOrientation: PageOrientation) => void;
|
|
29
29
|
/**
|
|
30
|
-
* Called with `true` when
|
|
31
|
-
*
|
|
32
|
-
* export fails.
|
|
30
|
+
* Called with `true` when an export starts and with `false` when it has finished - for the PDF export once the file
|
|
31
|
+
* is saved - or failed. Clicks on custom items added by `renderer` do not call it.
|
|
33
32
|
*/
|
|
34
33
|
onExport: (start: boolean) => void;
|
|
35
34
|
/** Receives the built-in menu items and returns the items to show, e.g. with custom items added. */
|
|
@@ -41,6 +40,17 @@ export interface ContextMenuProps {
|
|
|
41
40
|
}
|
|
42
41
|
/** Page orientation of the PDF export. */
|
|
43
42
|
export type PageOrientation = "PORTRAIT" | "LANDSCAPE";
|
|
43
|
+
/** Target of a grid export: a TXT, CSV or PDF file or the clipboard. */
|
|
44
|
+
export type ExportType = "txt" | "csv" | "pdf" | "clipboard";
|
|
45
|
+
/**
|
|
46
|
+
* Runs one export the same way as the menu of {@link getContextMenu}, for an export started from outside the menu
|
|
47
|
+
* (e.g. a custom button). `props.onExport` is called with `true` before and with `false` after the export (also a
|
|
48
|
+
* failed one), and `props.onExported` after a successful one; `renderer` and `onClick` are not used.
|
|
49
|
+
*
|
|
50
|
+
* The returned promise is resolved once the content is saved or copied (a failed clipboard copy shows an error
|
|
51
|
+
* notification). It is rejected when the export fails, after the progress notification is replaced by an error one.
|
|
52
|
+
*/
|
|
53
|
+
export declare function runExport(exportType: ExportType, props: ContextMenuProps): Promise<void>;
|
|
44
54
|
/**
|
|
45
55
|
* Builds the export menu of a grid as antd `MenuProps` (for a `Dropdown`): export to TXT, CSV and PDF files and copy to
|
|
46
56
|
* the clipboard. Content comes from `getExportContent` and is converted in a web worker; progress is shown by a
|
|
@@ -7,24 +7,34 @@ import dayjs from "dayjs";
|
|
|
7
7
|
import ProgressPopup from "./progressPopup";
|
|
8
8
|
import { ClipboardUtils } from "d2coreui/components/clipboard/clipboardUtils";
|
|
9
9
|
import PlatformSpecific from "d2coreui/components/platformSpecific";
|
|
10
|
+
/** Export types of the built-in export menu items, by the item key. */
|
|
11
|
+
const EXPORT_TYPES_BY_MENU_KEY = {
|
|
12
|
+
txtExport: "txt",
|
|
13
|
+
csvExport: "csv",
|
|
14
|
+
pdfExport: "pdf",
|
|
15
|
+
clipboardCopy: "clipboard",
|
|
16
|
+
};
|
|
10
17
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
18
|
+
* Runs one export the same way as the menu of {@link getContextMenu}, for an export started from outside the menu
|
|
19
|
+
* (e.g. a custom button). `props.onExport` is called with `true` before and with `false` after the export (also a
|
|
20
|
+
* failed one), and `props.onExported` after a successful one; `renderer` and `onClick` are not used.
|
|
14
21
|
*
|
|
15
|
-
* The
|
|
16
|
-
*
|
|
22
|
+
* The returned promise is resolved once the content is saved or copied (a failed clipboard copy shows an error
|
|
23
|
+
* notification). It is rejected when the export fails, after the progress notification is replaced by an error one.
|
|
17
24
|
*/
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
export async function runExport(exportType, props) {
|
|
26
|
+
var _a, _b, _c, _d;
|
|
27
|
+
const { hideNotificationOnClipboardCopy, getExportContent } = props;
|
|
28
|
+
// progress notification and worker of the running export, for the error handling
|
|
29
|
+
let progressPopup = null;
|
|
30
|
+
let worker = null;
|
|
31
|
+
props.onExport(true);
|
|
32
|
+
try {
|
|
33
|
+
switch (exportType) {
|
|
34
|
+
case "txt": {
|
|
35
|
+
progressPopup = new ProgressPopup(i18n("Export List to") + " TXT");
|
|
26
36
|
const tableContent = await getExportContent(progressPopup, props);
|
|
27
|
-
const txtExport = await spawn(new Worker(new URL('./worker/txtExport.js', import.meta.url), { type: 'module' }));
|
|
37
|
+
const txtExport = worker = await spawn(new Worker(new URL('./worker/txtExport.js', import.meta.url), { type: 'module' }));
|
|
28
38
|
const textContent = await txtExport(tableContent);
|
|
29
39
|
const fileName = `export_${dayjs().format("YYYYMMDD_HHmm")}.txt`;
|
|
30
40
|
await Thread.terminate(txtExport);
|
|
@@ -33,10 +43,10 @@ export default function getContextMenu(props) {
|
|
|
33
43
|
(_a = props.onExported) === null || _a === void 0 ? void 0 : _a.call(props, tableContent.length - 1, fileName);
|
|
34
44
|
break;
|
|
35
45
|
}
|
|
36
|
-
case "
|
|
37
|
-
|
|
46
|
+
case "csv": {
|
|
47
|
+
progressPopup = new ProgressPopup(i18n("Export List to") + " CSV");
|
|
38
48
|
const tableContent = await getExportContent(progressPopup, props);
|
|
39
|
-
const csvExport = await spawn(new Worker(new URL('./worker/csvExport.js', import.meta.url), { type: 'module' }));
|
|
49
|
+
const csvExport = worker = await spawn(new Worker(new URL('./worker/csvExport.js', import.meta.url), { type: 'module' }));
|
|
40
50
|
const csvContent = await csvExport(tableContent);
|
|
41
51
|
const fileName = `export_${dayjs().format("YYYYMMDD_HHmm")}.csv`;
|
|
42
52
|
await Thread.terminate(csvExport);
|
|
@@ -45,10 +55,10 @@ export default function getContextMenu(props) {
|
|
|
45
55
|
(_b = props.onExported) === null || _b === void 0 ? void 0 : _b.call(props, tableContent.length - 1, fileName);
|
|
46
56
|
break;
|
|
47
57
|
}
|
|
48
|
-
case "
|
|
49
|
-
|
|
58
|
+
case "clipboard": {
|
|
59
|
+
progressPopup = !hideNotificationOnClipboardCopy ? new ProgressPopup(i18n("Export List to") + " " + i18n("Clipboard")) : null;
|
|
50
60
|
const tableContent = await getExportContent(progressPopup, props);
|
|
51
|
-
const clipboardExport = await spawn(new Worker(new URL('./worker/clipboardExport.js', import.meta.url), { type: 'module' }));
|
|
61
|
+
const clipboardExport = worker = await spawn(new Worker(new URL('./worker/clipboardExport.js', import.meta.url), { type: 'module' }));
|
|
52
62
|
const clipboardContent = await clipboardExport(tableContent);
|
|
53
63
|
const success = ClipboardUtils.copyToClipboard(clipboardContent);
|
|
54
64
|
if (success) {
|
|
@@ -61,23 +71,51 @@ export default function getContextMenu(props) {
|
|
|
61
71
|
}
|
|
62
72
|
break;
|
|
63
73
|
}
|
|
64
|
-
case "
|
|
65
|
-
|
|
74
|
+
case "pdf": {
|
|
75
|
+
progressPopup = new ProgressPopup(i18n("Export List to") + " PDF");
|
|
66
76
|
const tableContent = await getExportContent(progressPopup, props);
|
|
67
|
-
const pdfExport = await spawn(new Worker(new URL('./worker/pdfExport.js', import.meta.url), { type: 'module' }));
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
await progressPopup.update(100);
|
|
73
|
-
PlatformSpecific.INSTANCE.saveContent(fileName, data, false);
|
|
74
|
-
(_a = props.onExported) === null || _a === void 0 ? void 0 : _a.call(props, tableContent.length - 1, fileName);
|
|
77
|
+
const pdfExport = worker = await spawn(new Worker(new URL('./worker/pdfExport.js', import.meta.url), { type: 'module' }));
|
|
78
|
+
// the PDF is generated asynchronously, its content comes through `handler()`
|
|
79
|
+
const data = await new Promise((resolve, reject) => {
|
|
80
|
+
pdfExport.handler().subscribe(resolve, reject);
|
|
81
|
+
pdfExport.export(tableContent, { pageOrientation: props.pageOrientation }).catch(reject);
|
|
75
82
|
});
|
|
76
|
-
|
|
83
|
+
const fileName = `export_${dayjs().format("YYYYMMDD_HHmm")}.pdf`;
|
|
84
|
+
Thread.terminate(pdfExport);
|
|
85
|
+
await progressPopup.update(100);
|
|
86
|
+
PlatformSpecific.INSTANCE.saveContent(fileName, data, false);
|
|
87
|
+
(_d = props.onExported) === null || _d === void 0 ? void 0 : _d.call(props, tableContent.length - 1, fileName);
|
|
77
88
|
break;
|
|
78
89
|
}
|
|
79
90
|
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
progressPopup === null || progressPopup === void 0 ? void 0 : progressPopup.error();
|
|
94
|
+
if (worker) {
|
|
95
|
+
Thread.terminate(worker).catch(() => undefined);
|
|
96
|
+
}
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
80
100
|
props.onExport(false);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Builds the export menu of a grid as antd `MenuProps` (for a `Dropdown`): export to TXT, CSV and PDF files and copy to
|
|
105
|
+
* the clipboard. Content comes from `getExportContent` and is converted in a web worker; progress is shown by a
|
|
106
|
+
* {@link ProgressPopup}, and files named `export_YYYYMMDD_HHmm.<ext>` are saved through {@link PlatformSpecific}.
|
|
107
|
+
*
|
|
108
|
+
* The workers are started with `new Worker(new URL(..., import.meta.url))`, so the consuming bundler must emit them as
|
|
109
|
+
* separate chunks; a webpack application emitting its chunks into a subdirectory needs `output.publicPath: "auto"`.
|
|
110
|
+
*/
|
|
111
|
+
export default function getContextMenu(props) {
|
|
112
|
+
const { renderer, onClick } = props;
|
|
113
|
+
const onExportMenuClick = (menuKey) => {
|
|
114
|
+
const exportType = EXPORT_TYPES_BY_MENU_KEY[menuKey];
|
|
115
|
+
if (exportType) {
|
|
116
|
+
// the error is already shown by the error notification of the export
|
|
117
|
+
runExport(exportType, props).catch(error => console.error("Grid export failed", error));
|
|
118
|
+
}
|
|
81
119
|
};
|
|
82
120
|
let menuItems = [
|
|
83
121
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextMenu.js","sourceRoot":"","sources":["../../../../../components/grid/export/contextMenu.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAY,MAAM,EAAE,UAAU,EAAC,MAAM,MAAM,CAAC;AACnD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,kBAAkB,CAAC;AAEpC,OAAO,EAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAC,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,8CAA8C,CAAC;AAC5E,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AAgDpE;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,KAAuB;IAC1D,MAAM,EAAC,+BAA+B,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,EAAC,GAAG,KAAK,CAAC;IAErF,MAAM,iBAAiB,GAAG,KAAK,EAAE,OAAe,EAAE,EAAE;;QAChD,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACrB,QAAQ,OAAO,EAAE,CAAC;YAClB,KAAK,WAAW,CAAC,CAAC,CAAC;gBACX,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC,CAAC;g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AAI,IAAC,IAAI,QAAC,KAAK,EAAE,EAAC,KAAK,EAAE,OAAO,EAAC,aAA0B,CACxE;SACN;KACJ,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACX,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;QACH,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACd,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,OAAO,EAAE,CAAC;gBACV,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YACjC,CAAC;QACL,CAAC;KACJ,CAAA;AACL,CAAC","sourcesContent":["import {CopyOutlined, FileOutlined, FilePdfOutlined, FileTextOutlined} from \"@ant-design/icons\";\r\nimport {MenuProps, Switch, Typography} from \"antd\";\r\nimport React from \"react\";\r\nimport i18n from \"d2core/i18n/i18n\";\r\nimport {ResolvedUtcOffsetMode} from \"d2core/i18n/localeHolder\";\r\nimport {spawn, Thread, Worker} from \"threads\"\r\nimport dayjs from \"dayjs\";\r\nimport ProgressPopup from \"./progressPopup\";\r\nimport {MenuElement} from \"../dataGrid\";\r\nimport {ClipboardUtils} from \"d2coreui/components/clipboard/clipboardUtils\";\r\nimport PlatformSpecific from \"d2coreui/components/platformSpecific\";\r\n\r\n\r\n/** Properties of {@link getContextMenu}. The whole object is also passed to `getExportContent`. */\r\nexport interface ContextMenuProps {\r\n /** Hint for `getExportContent` to export only the selected rows. */\r\n onlySelectedNodes?: boolean\r\n /** Hint for `getExportContent` to format date-time values with milliseconds. */\r\n showMilliseconds: boolean\r\n /** Hint for `getExportContent` to format dates with the year. */\r\n showYear: boolean\r\n /** Hint for `getExportContent` how to format date-time values of the hour repeated at the end of the daylight saving time. */\r\n showUtcOffset: ResolvedUtcOffsetMode\r\n /** Copy to the clipboard without the progress (and error) notification. */\r\n hideNotificationOnClipboardCopy?: boolean\r\n /** Page orientation of the PDF export, shown by the switch in the PDF menu item. */\r\n pageOrientation: PageOrientation\r\n /** Disables the export items, e.g. while an export is running. */\r\n exporting: boolean\r\n\r\n /**\r\n * Produces the exported table: an array of rows of cell texts, the first row being the column headers.\r\n * It may report progress through `progressPopup`, which is `null` for a clipboard copy with\r\n * `hideNotificationOnClipboardCopy`.\r\n */\r\n getExportContent: (progressPopup: ProgressPopup | null, props: ContextMenuProps) => Promise<string[][]>\r\n /** Called when the user toggles the PDF orientation switch; the caller is expected to pass the new `pageOrientation` back. */\r\n onPageOrientationChange:(pageOrientation: PageOrientation)=>void\r\n /**\r\n * Called with `true` when any menu item is clicked and with `false` when the item has been processed. For the PDF\r\n * export, `false` comes before the PDF is produced (it is generated asynchronously), and it is not called at all when the\r\n * export fails.\r\n */\r\n onExport:(start: boolean)=>void\r\n\r\n /** Receives the built-in menu items and returns the items to show, e.g. with custom items added. */\r\n renderer?(menuElements: MenuElement[]): MenuElement[]\r\n\r\n /** Called with the key of every clicked item, built-in ones (`txtExport`, `csvExport`, `pdfExport`, `clipboardCopy`) included. */\r\n onClick?(key: string): void\r\n\r\n /** Called after a successful export with the number of exported data rows and the file name, or `\"[CLIPBOARD]\"` for a clipboard copy. */\r\n onExported?: (rowCount: number, destination: string) => void\r\n}\r\n\r\n/** Page orientation of the PDF export. */\r\nexport type PageOrientation = \"PORTRAIT\" | \"LANDSCAPE\";\r\n\r\n/**\r\n * Builds the export menu of a grid as antd `MenuProps` (for a `Dropdown`): export to TXT, CSV and PDF files and copy to\r\n * the clipboard. Content comes from `getExportContent` and is converted in a web worker; progress is shown by a\r\n * {@link ProgressPopup}, and files named `export_YYYYMMDD_HHmm.<ext>` are saved through {@link PlatformSpecific}.\r\n *\r\n * The workers are started with `new Worker(new URL(..., import.meta.url))`, so the consuming bundler must emit them as\r\n * separate chunks; a webpack application emitting its chunks into a subdirectory needs `output.publicPath: \"auto\"`.\r\n */\r\nexport default function getContextMenu(props: ContextMenuProps): MenuProps {\r\n const {hideNotificationOnClipboardCopy, getExportContent, renderer, onClick} = props;\r\n\r\n const onExportMenuClick = async (menuKey: string) => {\r\n props.onExport(true);\r\n switch (menuKey) {\r\n case \"txtExport\": {\r\n const progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" TXT\");\r\n const tableContent = await getExportContent(progressPopup, props);\r\n const txtExport = await spawn(new Worker(new URL('./worker/txtExport.js', import.meta.url) as any, {type: 'module'}));\r\n const textContent = await txtExport(tableContent);\r\n const fileName = `export_${dayjs().format(\"YYYYMMDD_HHmm\")}.txt`;\r\n await Thread.terminate(txtExport);\r\n await progressPopup.update(100);\r\n PlatformSpecific.INSTANCE.saveContent(fileName, textContent, true);\r\n props.onExported?.(tableContent.length - 1, fileName);\r\n break;\r\n }\r\n case \"csvExport\": {\r\n const progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" CSV\");\r\n const tableContent = await getExportContent(progressPopup, props);\r\n const csvExport = await spawn(new Worker(new URL('./worker/csvExport.js', import.meta.url) as any, {type: 'module'}));\r\n const csvContent = await csvExport(tableContent);\r\n const fileName = `export_${dayjs().format(\"YYYYMMDD_HHmm\")}.csv`;\r\n await Thread.terminate(csvExport);\r\n await progressPopup.update(100);\r\n PlatformSpecific.INSTANCE.saveContent(fileName, csvContent, true);\r\n props.onExported?.(tableContent.length - 1, fileName);\r\n break;\r\n }\r\n case \"clipboardCopy\": {\r\n const progressPopup = !hideNotificationOnClipboardCopy ? new ProgressPopup(i18n(\"Export List to\") + \" \" + i18n(\"Clipboard\")) : null;\r\n const tableContent = await getExportContent(progressPopup, props);\r\n const clipboardExport = await spawn(new Worker(new URL('./worker/clipboardExport.js', import.meta.url) as any, {type: 'module'}));\r\n const clipboardContent = await clipboardExport(tableContent);\r\n const success = ClipboardUtils.copyToClipboard(clipboardContent);\r\n if (success) {\r\n await Thread.terminate(clipboardExport);\r\n await progressPopup?.update(100);\r\n props.onExported?.(tableContent.length - 1, \"[CLIPBOARD]\");\r\n } else {\r\n progressPopup?.error();\r\n }\r\n break;\r\n }\r\n case \"pdfExport\": {\r\n const progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" PDF\");\r\n const tableContent = await getExportContent(progressPopup, props);\r\n const pdfExport = await spawn(new Worker(new URL('./worker/pdfExport.js', import.meta.url) as any, {type: 'module'}));\r\n pdfExport.handler().subscribe(async (data: string) => {\r\n const fileName = `export_${dayjs().format(\"YYYYMMDD_HHmm\")}.pdf`;\r\n Thread.terminate(pdfExport);\r\n await progressPopup.update(100);\r\n PlatformSpecific.INSTANCE.saveContent(fileName, data, false);\r\n props.onExported?.(tableContent.length - 1, fileName);\r\n });\r\n pdfExport.export(tableContent, {pageOrientation: props.pageOrientation});\r\n break;\r\n }\r\n }\r\n props.onExport(false);\r\n }\r\n\r\n let menuItems: MenuElement[] = [\r\n {\r\n key: \"txtExport\",\r\n icon: <FileOutlined/>,\r\n disabled: props.exporting,\r\n label: i18n(\"Export List to\") + \" TXT\",\r\n },\r\n {\r\n key: \"csvExport\",\r\n icon: <FileTextOutlined/>,\r\n disabled: props.exporting,\r\n label: i18n(\"Export List to\") + \" CSV\",\r\n },\r\n {\r\n key: \"pdfExport\",\r\n icon: <FilePdfOutlined/>,\r\n disabled: props.exporting,\r\n label: <>\r\n {i18n(\"Export List to\") + \" PDF\"}\r\n <Switch\r\n style={{marginLeft: 8}}\r\n checkedChildren={i18n(\"Landscape\") + \" \"}\r\n unCheckedChildren={\"\" + i18n(\"Portrait\")}\r\n checked={props.pageOrientation !== \"PORTRAIT\"}\r\n onChange={(checked, e) => {\r\n e.stopPropagation();\r\n (e as any).nativeEvent.stopImmediatePropagation();\r\n props.onPageOrientationChange(checked ? \"LANDSCAPE\" : \"PORTRAIT\")\r\n }}\r\n />\r\n </>\r\n },\r\n {\r\n key: \"divider1\",\r\n type: \"divider\",\r\n },\r\n {\r\n key: \"clipboardCopy\",\r\n icon: <CopyOutlined/>,\r\n disabled: props.exporting,\r\n label: <>\r\n {i18n(\"Copy to Clipboard\")}\r\n <Typography.Text code style={{float: \"right\"}}>CTRL+C</Typography.Text>\r\n </>,\r\n }\r\n ];\r\n\r\n if (renderer) {\r\n menuItems = renderer(menuItems);\r\n }\r\n\r\n return {\r\n items: menuItems,\r\n onClick: (item) => {\r\n onExportMenuClick(item.key);\r\n if (onClick) {\r\n onClick(item.key.toString());\r\n }\r\n },\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"contextMenu.js","sourceRoot":"","sources":["../../../../../components/grid/export/contextMenu.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAY,MAAM,EAAE,UAAU,EAAC,MAAM,MAAM,CAAC;AACnD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,kBAAkB,CAAC;AAEpC,OAAO,EAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAC,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,8CAA8C,CAAC;AAC5E,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AAkDpE,uEAAuE;AACvE,MAAM,wBAAwB,GAA2C;IACrE,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,aAAa,EAAE,WAAW;CAC7B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,UAAsB,EAAE,KAAuB;;IAC3E,MAAM,EAAC,+BAA+B,EAAE,gBAAgB,EAAC,GAAG,KAAK,CAAC;IAClE,iFAAiF;IACjF,IAAI,aAAa,GAAyB,IAAI,CAAC;IAC/C,IAAI,MAAM,GAAQ,IAAI,CAAC;IACvB,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAA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,QAAQ,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;QACH,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACd,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,OAAO,EAAE,CAAC;gBACV,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YACjC,CAAC;QACL,CAAC;KACJ,CAAA;AACL,CAAC","sourcesContent":["import {CopyOutlined, FileOutlined, FilePdfOutlined, FileTextOutlined} from \"@ant-design/icons\";\r\nimport {MenuProps, Switch, Typography} from \"antd\";\r\nimport React from \"react\";\r\nimport i18n from \"d2core/i18n/i18n\";\r\nimport {ResolvedUtcOffsetMode} from \"d2core/i18n/localeHolder\";\r\nimport {spawn, Thread, Worker} from \"threads\"\r\nimport dayjs from \"dayjs\";\r\nimport ProgressPopup from \"./progressPopup\";\r\nimport {MenuElement} from \"../dataGrid\";\r\nimport {ClipboardUtils} from \"d2coreui/components/clipboard/clipboardUtils\";\r\nimport PlatformSpecific from \"d2coreui/components/platformSpecific\";\r\n\r\n\r\n/** Properties of {@link getContextMenu}. The whole object is also passed to `getExportContent`. */\r\nexport interface ContextMenuProps {\r\n /** Hint for `getExportContent` to export only the selected rows. */\r\n onlySelectedNodes?: boolean\r\n /** Hint for `getExportContent` to format date-time values with milliseconds. */\r\n showMilliseconds: boolean\r\n /** Hint for `getExportContent` to format dates with the year. */\r\n showYear: boolean\r\n /** Hint for `getExportContent` how to format date-time values of the hour repeated at the end of the daylight saving time. */\r\n showUtcOffset: ResolvedUtcOffsetMode\r\n /** Copy to the clipboard without the progress (and error) notification. */\r\n hideNotificationOnClipboardCopy?: boolean\r\n /** Page orientation of the PDF export, shown by the switch in the PDF menu item. */\r\n pageOrientation: PageOrientation\r\n /** Disables the export items, e.g. while an export is running. */\r\n exporting: boolean\r\n\r\n /**\r\n * Produces the exported table: an array of rows of cell texts, the first row being the column headers.\r\n * It may report progress through `progressPopup`, which is `null` for a clipboard copy with\r\n * `hideNotificationOnClipboardCopy`.\r\n */\r\n getExportContent: (progressPopup: ProgressPopup | null, props: ContextMenuProps) => Promise<string[][]>\r\n /** Called when the user toggles the PDF orientation switch; the caller is expected to pass the new `pageOrientation` back. */\r\n onPageOrientationChange:(pageOrientation: PageOrientation)=>void\r\n /**\r\n * Called with `true` when an export starts and with `false` when it has finished - for the PDF export once the file\r\n * is saved - or failed. Clicks on custom items added by `renderer` do not call it.\r\n */\r\n onExport:(start: boolean)=>void\r\n\r\n /** Receives the built-in menu items and returns the items to show, e.g. with custom items added. */\r\n renderer?(menuElements: MenuElement[]): MenuElement[]\r\n\r\n /** Called with the key of every clicked item, built-in ones (`txtExport`, `csvExport`, `pdfExport`, `clipboardCopy`) included. */\r\n onClick?(key: string): void\r\n\r\n /** Called after a successful export with the number of exported data rows and the file name, or `\"[CLIPBOARD]\"` for a clipboard copy. */\r\n onExported?: (rowCount: number, destination: string) => void\r\n}\r\n\r\n/** Page orientation of the PDF export. */\r\nexport type PageOrientation = \"PORTRAIT\" | \"LANDSCAPE\";\r\n\r\n/** Target of a grid export: a TXT, CSV or PDF file or the clipboard. */\r\nexport type ExportType = \"txt\" | \"csv\" | \"pdf\" | \"clipboard\";\r\n\r\n/** Export types of the built-in export menu items, by the item key. */\r\nconst EXPORT_TYPES_BY_MENU_KEY: Record<string, ExportType | undefined> = {\r\n txtExport: \"txt\",\r\n csvExport: \"csv\",\r\n pdfExport: \"pdf\",\r\n clipboardCopy: \"clipboard\",\r\n};\r\n\r\n/**\r\n * Runs one export the same way as the menu of {@link getContextMenu}, for an export started from outside the menu\r\n * (e.g. a custom button). `props.onExport` is called with `true` before and with `false` after the export (also a\r\n * failed one), and `props.onExported` after a successful one; `renderer` and `onClick` are not used.\r\n *\r\n * The returned promise is resolved once the content is saved or copied (a failed clipboard copy shows an error\r\n * notification). It is rejected when the export fails, after the progress notification is replaced by an error one.\r\n */\r\nexport async function runExport(exportType: ExportType, props: ContextMenuProps): Promise<void> {\r\n const {hideNotificationOnClipboardCopy, getExportContent} = props;\r\n // progress notification and worker of the running export, for the error handling\r\n let progressPopup: ProgressPopup | null = null;\r\n let worker: any = null;\r\n props.onExport(true);\r\n try {\r\n switch (exportType) {\r\n case \"txt\": {\r\n progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" TXT\");\r\n const tableContent = await getExportContent(progressPopup, props);\r\n const txtExport = worker = await spawn(new Worker(new URL('./worker/txtExport.js', import.meta.url) as any, {type: 'module'}));\r\n const textContent = await txtExport(tableContent);\r\n const fileName = `export_${dayjs().format(\"YYYYMMDD_HHmm\")}.txt`;\r\n await Thread.terminate(txtExport);\r\n await progressPopup.update(100);\r\n PlatformSpecific.INSTANCE.saveContent(fileName, textContent, true);\r\n props.onExported?.(tableContent.length - 1, fileName);\r\n break;\r\n }\r\n case \"csv\": {\r\n progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" CSV\");\r\n const tableContent = await getExportContent(progressPopup, props);\r\n const csvExport = worker = await spawn(new Worker(new URL('./worker/csvExport.js', import.meta.url) as any, {type: 'module'}));\r\n const csvContent = await csvExport(tableContent);\r\n const fileName = `export_${dayjs().format(\"YYYYMMDD_HHmm\")}.csv`;\r\n await Thread.terminate(csvExport);\r\n await progressPopup.update(100);\r\n PlatformSpecific.INSTANCE.saveContent(fileName, csvContent, true);\r\n props.onExported?.(tableContent.length - 1, fileName);\r\n break;\r\n }\r\n case \"clipboard\": {\r\n progressPopup = !hideNotificationOnClipboardCopy ? new ProgressPopup(i18n(\"Export List to\") + \" \" + i18n(\"Clipboard\")) : null;\r\n const tableContent = await getExportContent(progressPopup, props);\r\n const clipboardExport = worker = await spawn(new Worker(new URL('./worker/clipboardExport.js', import.meta.url) as any, {type: 'module'}));\r\n const clipboardContent = await clipboardExport(tableContent);\r\n const success = ClipboardUtils.copyToClipboard(clipboardContent);\r\n if (success) {\r\n await Thread.terminate(clipboardExport);\r\n await progressPopup?.update(100);\r\n props.onExported?.(tableContent.length - 1, \"[CLIPBOARD]\");\r\n } else {\r\n progressPopup?.error();\r\n }\r\n break;\r\n }\r\n case \"pdf\": {\r\n progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" PDF\");\r\n const tableContent = await getExportContent(progressPopup, props);\r\n const pdfExport = worker = await spawn(new Worker(new URL('./worker/pdfExport.js', import.meta.url) as any, {type: 'module'}));\r\n // the PDF is generated asynchronously, its content comes through `handler()`\r\n const data = await new Promise<string>((resolve, reject) => {\r\n pdfExport.handler().subscribe(resolve, reject);\r\n pdfExport.export(tableContent, {pageOrientation: props.pageOrientation}).catch(reject);\r\n });\r\n const fileName = `export_${dayjs().format(\"YYYYMMDD_HHmm\")}.pdf`;\r\n Thread.terminate(pdfExport);\r\n await progressPopup.update(100);\r\n PlatformSpecific.INSTANCE.saveContent(fileName, data, false);\r\n props.onExported?.(tableContent.length - 1, fileName);\r\n break;\r\n }\r\n }\r\n } catch (error) {\r\n progressPopup?.error();\r\n if (worker) {\r\n Thread.terminate(worker).catch(() => undefined);\r\n }\r\n throw error;\r\n } finally {\r\n props.onExport(false);\r\n }\r\n}\r\n\r\n/**\r\n * Builds the export menu of a grid as antd `MenuProps` (for a `Dropdown`): export to TXT, CSV and PDF files and copy to\r\n * the clipboard. Content comes from `getExportContent` and is converted in a web worker; progress is shown by a\r\n * {@link ProgressPopup}, and files named `export_YYYYMMDD_HHmm.<ext>` are saved through {@link PlatformSpecific}.\r\n *\r\n * The workers are started with `new Worker(new URL(..., import.meta.url))`, so the consuming bundler must emit them as\r\n * separate chunks; a webpack application emitting its chunks into a subdirectory needs `output.publicPath: \"auto\"`.\r\n */\r\nexport default function getContextMenu(props: ContextMenuProps): MenuProps {\r\n const {renderer, onClick} = props;\r\n\r\n const onExportMenuClick = (menuKey: string) => {\r\n const exportType = EXPORT_TYPES_BY_MENU_KEY[menuKey];\r\n if (exportType) {\r\n // the error is already shown by the error notification of the export\r\n runExport(exportType, props).catch(error => console.error(\"Grid export failed\", error));\r\n }\r\n }\r\n\r\n let menuItems: MenuElement[] = [\r\n {\r\n key: \"txtExport\",\r\n icon: <FileOutlined/>,\r\n disabled: props.exporting,\r\n label: i18n(\"Export List to\") + \" TXT\",\r\n },\r\n {\r\n key: \"csvExport\",\r\n icon: <FileTextOutlined/>,\r\n disabled: props.exporting,\r\n label: i18n(\"Export List to\") + \" CSV\",\r\n },\r\n {\r\n key: \"pdfExport\",\r\n icon: <FilePdfOutlined/>,\r\n disabled: props.exporting,\r\n label: <>\r\n {i18n(\"Export List to\") + \" PDF\"}\r\n <Switch\r\n style={{marginLeft: 8}}\r\n checkedChildren={i18n(\"Landscape\") + \" \"}\r\n unCheckedChildren={\"\" + i18n(\"Portrait\")}\r\n checked={props.pageOrientation !== \"PORTRAIT\"}\r\n onChange={(checked, e) => {\r\n e.stopPropagation();\r\n (e as any).nativeEvent.stopImmediatePropagation();\r\n props.onPageOrientationChange(checked ? \"LANDSCAPE\" : \"PORTRAIT\")\r\n }}\r\n />\r\n </>\r\n },\r\n {\r\n key: \"divider1\",\r\n type: \"divider\",\r\n },\r\n {\r\n key: \"clipboardCopy\",\r\n icon: <CopyOutlined/>,\r\n disabled: props.exporting,\r\n label: <>\r\n {i18n(\"Copy to Clipboard\")}\r\n <Typography.Text code style={{float: \"right\"}}>CTRL+C</Typography.Text>\r\n </>,\r\n }\r\n ];\r\n\r\n if (renderer) {\r\n menuItems = renderer(menuItems);\r\n }\r\n\r\n return {\r\n items: menuItems,\r\n onClick: (item) => {\r\n onExportMenuClick(item.key);\r\n if (onClick) {\r\n onClick(item.key.toString());\r\n }\r\n },\r\n }\r\n}\r\n"]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { expose } from "threads/worker";
|
|
2
|
+
/** UTF-8 byte order mark - without it Excel opens the CSV in the ANSI code page and breaks non-ASCII characters. */
|
|
3
|
+
const UTF8_BOM = String.fromCharCode(0xFEFF);
|
|
2
4
|
function csvExport(tableData) {
|
|
3
5
|
const textContent = tableData.map((row) => {
|
|
4
6
|
return row.join(";");
|
|
5
7
|
}).join("\r\n");
|
|
6
|
-
return textContent;
|
|
8
|
+
return UTF8_BOM + textContent;
|
|
7
9
|
}
|
|
8
10
|
expose(csvExport);
|
|
9
11
|
//# sourceMappingURL=csvExport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csvExport.js","sourceRoot":"","sources":["../../../../../../components/grid/export/worker/csvExport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAA;AAErC,SAAS,SAAS,CAAC,SAAoB;IACnC,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACtC,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChB,OAAO,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"csvExport.js","sourceRoot":"","sources":["../../../../../../components/grid/export/worker/csvExport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAA;AAErC,oHAAoH;AACpH,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;AAE7C,SAAS,SAAS,CAAC,SAAoB;IACnC,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACtC,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChB,OAAO,QAAQ,GAAG,WAAW,CAAC;AAClC,CAAC;AAED,MAAM,CAAC,SAAS,CAAC,CAAC","sourcesContent":["import {expose} from \"threads/worker\"\n\n/** UTF-8 byte order mark - without it Excel opens the CSV in the ANSI code page and breaks non-ASCII characters. */\nconst UTF8_BOM = String.fromCharCode(0xFEFF);\n\nfunction csvExport(tableData:string[][]) {\n const textContent = tableData.map((row) => {\n return row.join(\";\");\n }).join(\"\\r\\n\");\n return UTF8_BOM + textContent;\n}\n\nexpose(csvExport);\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { ReactElement } from "react";
|
|
2
2
|
import DataGrid, { DataGridFilterProps, DataGridProps, DataGridSearchProps, SortItem } from "./dataGrid";
|
|
3
|
+
import { ExportType, PageOrientation } from "d2coreui/components/grid/export/contextMenu";
|
|
3
4
|
import { RowStyleRule } from "d2coreui/components/grid/cell/tableDefaultRowStyleRules";
|
|
4
5
|
import { ColumnState, RowDataUpdatedEvent } from "ag-grid-community";
|
|
5
6
|
import { DataChangeStateEnum } from "d2core/types/dataChangeStateEnum";
|
|
@@ -69,13 +70,13 @@ export interface GridConfiguration {
|
|
|
69
70
|
/**
|
|
70
71
|
* How date-time columns tell apart the two readings of a DST fold - see `UtcOffsetMode` of
|
|
71
72
|
* `d2core/i18n/localeHolder`: `true` / `"offset"` the UTC offset at every time, `"offsetInFold"` the UTC offset only
|
|
72
|
-
* in the repeated hour, `"hourLetter"` the hour as `A2` / `B2`, `false` / `"none"` not at all.
|
|
73
|
-
*
|
|
73
|
+
* in the repeated hour, `"hourLetter"` the hour as `A2` / `B2`, `false` / `"none"` not at all. When not set, the
|
|
74
|
+
* global mode of `LocaleHolder.setUtcOffsetMode` applies.
|
|
74
75
|
*/
|
|
75
76
|
showUtcOffset?: UtcOffsetMode;
|
|
76
77
|
/**
|
|
77
|
-
* Value of {@link GridConfiguration.showUtcOffset} restored when the user reverts the table settings.
|
|
78
|
-
*
|
|
78
|
+
* Value of {@link GridConfiguration.showUtcOffset} restored when the user reverts the table settings. When not set,
|
|
79
|
+
* the global mode of `LocaleHolder.setUtcOffsetMode` applies.
|
|
79
80
|
*/
|
|
80
81
|
defaultShowUtcOffset?: UtcOffsetMode;
|
|
81
82
|
/**
|
|
@@ -102,6 +103,14 @@ interface ExtendedDataGridFilterProps extends DataGridFilterProps {
|
|
|
102
103
|
*/
|
|
103
104
|
quickFilterEnabled?: boolean;
|
|
104
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* dayjs format of a date-time value as the date-time columns of a grid with the given configuration show it - the year,
|
|
108
|
+
* the milliseconds and the UTC offset follow {@link GridConfiguration.hideYear}, {@link GridConfiguration.showMilliseconds}
|
|
109
|
+
* and {@link GridConfiguration.showUtcOffset}. Use it for a column that formats date-time values itself.
|
|
110
|
+
* @param configuration from {@link ExtendedDataGrid.getConfiguration}; without it the year is shown, the milliseconds are
|
|
111
|
+
* not and the global mode of `LocaleHolder.setUtcOffsetMode` applies
|
|
112
|
+
*/
|
|
113
|
+
export declare function getGridDateTimeFormat(configuration?: GridConfiguration): string;
|
|
105
114
|
/** Parameters passed to the filter panel renderer ({@link ExtendedDataGridProps.filterPanel}). */
|
|
106
115
|
export interface FilterPanelRendererParams {
|
|
107
116
|
/** Deep copy of `filterPanel.defaultFilter`, taken when the grid was constructed. */
|
|
@@ -279,6 +288,14 @@ export default class ExtendedDataGrid<T extends {
|
|
|
279
288
|
isActive(): boolean;
|
|
280
289
|
/** Focuses a cell of the last selected row (or the first row) of the inner grid. */
|
|
281
290
|
focus(): void;
|
|
291
|
+
/**
|
|
292
|
+
* Exports the inner grid the same way as the toolbar export menu, for an export started from a custom button - see
|
|
293
|
+
* `DataGrid.exportData`.
|
|
294
|
+
*/
|
|
295
|
+
exportData(exportType: ExportType, options?: {
|
|
296
|
+
onlySelectedRows?: boolean;
|
|
297
|
+
pageOrientation?: PageOrientation;
|
|
298
|
+
}): Promise<void>;
|
|
282
299
|
private _changeConfiguration;
|
|
283
300
|
private _onGridReady;
|
|
284
301
|
private _onNewColumnsLoaded;
|
|
@@ -20,6 +20,7 @@ import isEqualWith from "lodash/isEqualWith";
|
|
|
20
20
|
import cloneDeep from "lodash/cloneDeep";
|
|
21
21
|
import tableDefaultRowStyleRules from "d2coreui/components/grid/cell/tableDefaultRowStyleRules";
|
|
22
22
|
import { ColumnUtils } from "./columnUtils";
|
|
23
|
+
import { LocaleHolder } from "d2core/i18n/localeHolder";
|
|
23
24
|
import WithCss from "../style/withCss";
|
|
24
25
|
import { createStyles } from "antd-style";
|
|
25
26
|
const useStyles = createStyles(({ css }) => {
|
|
@@ -36,6 +37,16 @@ const useStyles = createStyles(({ css }) => {
|
|
|
36
37
|
};
|
|
37
38
|
});
|
|
38
39
|
const CONFIGURATION_VERSION = 2;
|
|
40
|
+
/**
|
|
41
|
+
* dayjs format of a date-time value as the date-time columns of a grid with the given configuration show it - the year,
|
|
42
|
+
* the milliseconds and the UTC offset follow {@link GridConfiguration.hideYear}, {@link GridConfiguration.showMilliseconds}
|
|
43
|
+
* and {@link GridConfiguration.showUtcOffset}. Use it for a column that formats date-time values itself.
|
|
44
|
+
* @param configuration from {@link ExtendedDataGrid.getConfiguration}; without it the year is shown, the milliseconds are
|
|
45
|
+
* not and the global mode of `LocaleHolder.setUtcOffsetMode` applies
|
|
46
|
+
*/
|
|
47
|
+
export function getGridDateTimeFormat(configuration) {
|
|
48
|
+
return LocaleHolder.getDateTimeFormat(!(configuration === null || configuration === void 0 ? void 0 : configuration.hideYear), true, !!(configuration === null || configuration === void 0 ? void 0 : configuration.showMilliseconds), configuration === null || configuration === void 0 ? void 0 : configuration.showUtcOffset);
|
|
49
|
+
}
|
|
39
50
|
/**
|
|
40
51
|
* {@link DataGrid} with a persistable {@link GridConfiguration}, optional side panels and batched live updates.
|
|
41
52
|
*
|
|
@@ -86,9 +97,8 @@ class ExtendedDataGrid extends React.Component {
|
|
|
86
97
|
gridConfiguration.defaultShowMilliseconds = gridConfigurationOk && props.defaultGridConfiguration.defaultShowMilliseconds ? props.defaultGridConfiguration.defaultShowMilliseconds : false;
|
|
87
98
|
gridConfiguration.hideYear = gridConfigurationOk && props.defaultGridConfiguration.hideYear ? props.defaultGridConfiguration.hideYear : false;
|
|
88
99
|
gridConfiguration.defaultHideYear = gridConfigurationOk && props.defaultGridConfiguration.defaultHideYear ? props.defaultGridConfiguration.defaultHideYear : false;
|
|
89
|
-
|
|
90
|
-
gridConfiguration.
|
|
91
|
-
gridConfiguration.defaultShowUtcOffset = gridConfigurationOk && props.defaultGridConfiguration.defaultShowUtcOffset !== undefined ? props.defaultGridConfiguration.defaultShowUtcOffset : true;
|
|
100
|
+
gridConfiguration.showUtcOffset = gridConfigurationOk ? props.defaultGridConfiguration.showUtcOffset : undefined;
|
|
101
|
+
gridConfiguration.defaultShowUtcOffset = gridConfigurationOk ? props.defaultGridConfiguration.defaultShowUtcOffset : undefined;
|
|
92
102
|
gridConfiguration.filterPanelWidth = gridConfigurationOk && props.defaultGridConfiguration.filterPanelWidth
|
|
93
103
|
? props.defaultGridConfiguration.filterPanelWidth
|
|
94
104
|
: (props.filterPanel ? (props.filterPanel.defaultWidth ? props.filterPanel.defaultWidth : 220) : 0);
|
|
@@ -194,6 +204,14 @@ class ExtendedDataGrid extends React.Component {
|
|
|
194
204
|
var _a;
|
|
195
205
|
(_a = this.dataGrid) === null || _a === void 0 ? void 0 : _a.focus();
|
|
196
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Exports the inner grid the same way as the toolbar export menu, for an export started from a custom button - see
|
|
209
|
+
* `DataGrid.exportData`.
|
|
210
|
+
*/
|
|
211
|
+
exportData(exportType, options) {
|
|
212
|
+
var _a, _b;
|
|
213
|
+
return (_b = (_a = this.dataGrid) === null || _a === void 0 ? void 0 : _a.exportData(exportType, options)) !== null && _b !== void 0 ? _b : Promise.resolve();
|
|
214
|
+
}
|
|
197
215
|
_changeConfiguration(configuration, callback) {
|
|
198
216
|
if (this.props.disableConfigurationChange) {
|
|
199
217
|
return;
|