@topconsultnpm/sdkui-react-beta 6.15.12 → 6.15.13

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.
@@ -22,61 +22,78 @@ const TMDataGridExportForm = (props) => {
22
22
  const [exportSelectedOnly, setExportSelectedOnly] = useState(selectedRowKeys.length > 0 ? true : false);
23
23
  // Boolean state to indicate whether to export the "description" fields in data lists
24
24
  const [exportDescriptionsForDataLists, setExportDescriptionsForDataLists] = useState(true);
25
- // Boolean state to indicate whether to hide the selection during export
26
- const [hideSelection, setHideSelection] = useState(false);
25
+ // Boolean state to indicate whether to hide the selection and format during export
26
+ const [exportSelectedFormatColumns, setExportSelectedFormatColumns] = useState(true);
27
27
  const onStatusValueChange = (e) => {
28
28
  if (!e?.target?.value)
29
29
  return;
30
30
  setFormatSelected(e.target.value);
31
31
  };
32
+ // Function to trigger download of a file represented by a Blob with the given file extension
32
33
  const downloadFile = (blob, extension) => {
34
+ // Helper function to ensure numbers (e.g., 4 -> '04') are two digits
33
35
  const formatNumber = (n) => n.toString().padStart(2, '0');
36
+ // Helper function to generate a timestamp string in the format 'YYYY-MM-DD_HH-MM-SS'
34
37
  const getTimestamp = () => {
35
38
  const now = new Date();
36
39
  const date = `${now.getFullYear()}-${formatNumber(now.getMonth() + 1)}-${formatNumber(now.getDate())}`;
37
40
  const time = `${formatNumber(now.getHours())}-${formatNumber(now.getMinutes())}-${formatNumber(now.getSeconds())}`;
38
41
  return `${date}_${time}`;
39
42
  };
43
+ // Create a temporary URL representing the file Blob
40
44
  const url = URL.createObjectURL(blob);
45
+ // Create an anchor element to trigger the download
41
46
  const a = document.createElement('a');
42
47
  a.href = url;
48
+ // Set the filename using a localized prefix and the generated timestamp
43
49
  a.download = `${SDKUI_Localizator.SearchResult}_${getTimestamp()}.${extension}`;
50
+ // Append the anchor to the document, click it to start download, then remove it
44
51
  document.body.appendChild(a);
45
52
  a.click();
46
53
  document.body.removeChild(a);
54
+ // Revoke the created URL to release memory
47
55
  URL.revokeObjectURL(url);
48
56
  };
49
57
  const handleExport = async () => {
58
+ // Exit early if dataSource or dataColumns are not defined to avoid errors
50
59
  if (!dataSource || !dataColumns)
51
60
  return;
52
61
  let result = [];
53
62
  try {
54
63
  TMSpinner.show({ description: SDKUI_Localizator.Loading });
55
- // Exit early if dataSource or dataColumns are not defined to avoid errors
64
+ // Retrieve columns from the search result, or use an empty array if not available
56
65
  const columns = searchResult?.dtdResult?.columns ?? [];
66
+ // If exportDescriptionsForDataLists is true, build a map of values to labels for the columns; otherwise use an empty Map
57
67
  const valueToNameMap = exportDescriptionsForDataLists ? await buildValueToLabelMapFromDataColumns(columns) : new Map();
68
+ // Create a Set from selectedRowKeys for efficient lookup
58
69
  const selectedSet = new Set(selectedRowKeys);
70
+ // If exporting only selected rows, filter the dataSource accordingly; otherwise use the full dataSource
59
71
  const rowsToExport = exportSelectedOnly ? dataSource.filter((_, idx) => selectedSet.has(idx)) : dataSource;
60
- const visibleColumns = dataColumns.filter(col => hideSelection ? col.visible !== false && col.dataType !== 'object' : col.visible !== false);
72
+ // Filter columns to only those that are visible; optionally hide 'object' data types based on the `hideSelection` flag
73
+ const visibleColumns = dataColumns.filter(col => exportSelectedFormatColumns ? col.visible !== false && col.dataType !== 'object' : col.visible !== false);
74
+ // Function to get the value for a column and its value in a row
61
75
  const getValue = (col, value) => {
76
+ // Replace raw value with corresponding label from the map if applicable
62
77
  let result = exportDescriptionsForDataLists ? valueToNameMap.get(value) ?? value : value;
78
+ // If the column is a datetime type, attempt to format it as a locale date string
63
79
  if (col.dataType === 'datetime' && result) {
64
80
  const parsedDate = new Date(result);
65
81
  if (!isNaN(parsedDate.getTime())) {
66
82
  result = parsedDate.toLocaleDateString();
67
83
  }
68
84
  }
85
+ // Return the cleaned string value, stripping double quotes to avoid CSV formatting issues
69
86
  return (result ?? '').toString().replace(/"/g, '');
70
87
  };
71
88
  switch (formatSelected) {
72
89
  case 'csv': {
73
- const headers = hideSelection ? visibleColumns.map(col => col.caption !== undefined ? col.caption : col.dataField) : [SDKUI_Localizator.SelectedSingular, ...visibleColumns.map(col => col.caption !== undefined ? col.caption : col.dataField)];
90
+ const headers = exportSelectedFormatColumns ? visibleColumns.map(col => col.caption !== undefined ? col.caption : col.dataField) : [SDKUI_Localizator.SelectedSingular, ...visibleColumns.map(col => col.caption !== undefined ? col.caption : col.dataField)];
74
91
  const csvRows = [];
75
92
  csvRows.push(headers.join(';'));
76
93
  rowsToExport.forEach((item, idx) => {
77
94
  const originalIndex = exportSelectedOnly ? selectedRowKeys[idx] : dataSource.indexOf(item);
78
95
  const rowValues = [];
79
- if (!hideSelection) {
96
+ if (!exportSelectedFormatColumns) {
80
97
  const status = selectedSet.has(originalIndex) ? SDKUI_Localizator.SelectedSingular : SDKUI_Localizator.Deselected;
81
98
  rowValues.push(status || '');
82
99
  }
@@ -99,7 +116,7 @@ const TMDataGridExportForm = (props) => {
99
116
  // Map visible columns to worksheet column definitions
100
117
  const baseColumns = visibleColumns.map(col => ({ header: col.caption !== undefined ? col.caption : col.dataField, key: col.dataField, width: 10, style: { numFmt: '@' } }));
101
118
  // Add a selection status column at the beginning if hideSelection is false
102
- worksheet.columns = hideSelection ? baseColumns : [{ header: SDKUI_Localizator.SelectedSingular, key: '_selected', width: 10, style: { numFmt: '@' } }, ...baseColumns];
119
+ worksheet.columns = exportSelectedFormatColumns ? baseColumns : [{ header: SDKUI_Localizator.SelectedSingular, key: '_selected', width: 10, style: { numFmt: '@' } }, ...baseColumns];
103
120
  // Style the header row cells: font, fill color, and border
104
121
  worksheet.getRow(1).eachCell({ includeEmpty: true }, cell => {
105
122
  cell.font = { name: 'Segoe UI', size: 9 };
@@ -112,7 +129,7 @@ const TMDataGridExportForm = (props) => {
112
129
  const originalIndex = exportSelectedOnly ? selectedRowKeys[idx] : dataSource.indexOf(item);
113
130
  const rowObj = {};
114
131
  // Add selection status if hideSelection is false
115
- if (!hideSelection) {
132
+ if (!exportSelectedFormatColumns) {
116
133
  rowObj._selected = selectedSet.has(originalIndex) ? SDKUI_Localizator.SelectedSingular : SDKUI_Localizator.Deselected;
117
134
  }
118
135
  // Add data for each visible column
@@ -170,7 +187,7 @@ const TMDataGridExportForm = (props) => {
170
187
  return _jsx(TMModal, { title: `${SDKUI_Localizator.Export}`, width: '400px', height: '230px', onClose: onCloseExportForm, children: _jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '16px', padding: '6px 12px', height: '100%', width: '100%' }, children: [_jsx("div", { style: { display: 'flex', alignItems: 'center', gap: '12px' }, children: _jsx(TMDropDown, { label: SDKUI_Localizator.Format, value: formatSelected, dataSource: formatDataSource, onValueChanged: onStatusValueChange }) }), _jsx("div", { style: { display: 'flex', alignItems: 'center', gap: '12px' }, children: _jsx(TMCheckBox, { elementStyle: {
171
188
  opacity: selectedRowKeys.length === 0 ? 0.5 : 1,
172
189
  cursor: selectedRowKeys.length === 0 ? 'not-allowed' : 'pointer'
173
- }, label: `${SDKUI_Localizator.ExportOnlySelectedDocuments} (${selectedRowKeys.length})`, value: exportSelectedOnly, disabled: selectedRowKeys.length === 0, onValueChanged: () => { setExportSelectedOnly(prev => !prev); } }) }), _jsx("div", { style: { display: 'flex', alignItems: 'center', gap: '12px' }, children: _jsx(TMCheckBox, { label: SDKUI_Localizator.ExportDataListsDescriptionField, value: exportDescriptionsForDataLists, onValueChanged: () => { setExportDescriptionsForDataLists(prev => !prev); } }) }), _jsx("div", { style: { display: 'flex', alignItems: 'center', gap: '12px' }, children: _jsx(TMCheckBox, { label: SDKUI_Localizator.HideSelectionColumnsAndIcons, value: hideSelection, onValueChanged: () => { setHideSelection(prev => !prev); } }) }), _jsx("div", { style: {
190
+ }, label: `${SDKUI_Localizator.ExportOnlySelectedDocuments} (${selectedRowKeys.length})`, value: exportSelectedOnly, disabled: selectedRowKeys.length === 0, onValueChanged: () => { setExportSelectedOnly(prev => !prev); } }) }), _jsx("div", { style: { display: 'flex', alignItems: 'center', gap: '12px' }, children: _jsx(TMCheckBox, { label: SDKUI_Localizator.ExportDataListsDescriptionField, value: exportDescriptionsForDataLists, onValueChanged: () => { setExportDescriptionsForDataLists(prev => !prev); } }) }), _jsx("div", { style: { display: 'flex', alignItems: 'center', gap: '12px' }, children: _jsx(TMCheckBox, { label: SDKUI_Localizator.ExportSelectedColumnsAndFormatLabel, value: exportSelectedFormatColumns, onValueChanged: () => { setExportSelectedFormatColumns(prev => !prev); } }) }), _jsx("div", { style: {
174
191
  display: 'flex',
175
192
  justifyContent: 'center',
176
193
  gap: '10px',
@@ -153,6 +153,7 @@ export declare class SDKUI_Localizator {
153
153
  static get ErrorParsingFileContent(): "Fehler beim Parsen des Dateiinhalts. Stellen Sie sicher, dass die Datei im richtigen Format vorliegt." | "Error parsing the file content. Ensure the file is in the correct format." | "Error al analizar el contenido del archivo. Asegúrese de que el archivo esté en el formato correcto." | "Erreur lors de l'analyse du contenu du fichier. Assurez-vous que le fichier est dans le bon format." | "Erro ao analisar o conteúdo do arquivo. Certifique-se de que o arquivo está no formato correto." | "Errore durante l'analisi del contenuto del file. Assicurati che il file sia nel formato corretto.";
154
154
  static get ExportDataListsDescriptionField(): "Exportiere die \"Beschreibung\"-Felder der Datenlisten" | "Export the \"description\" fields of data lists" | "Exportar los campos \"descripción\" de las listas de datos" | "Exporter les champs \"description\" des listes de données" | "Exportar os campos \"descrição\" das listas de dados" | "Esporta la \"Descrizione\" delle liste dati";
155
155
  static get ExportOnlySelectedDocuments(): "Nur ausgewählte Dokumente exportieren" | "Export only selected documents" | "Exportar solo los documentos seleccionados" | "Exporter uniquement les documents sélectionnés" | "Exportar apenas os documentos selecionados" | "Esporta solo i documenti selezionati";
156
+ static get ExportSelectedColumnsAndFormatLabel(): string;
156
157
  static get ExtractedBy(): "Ausgezogen von" | "Extracted by" | "Extraído por" | "Extrait par" | "Estratto da";
157
158
  static get ExtractedFromOtherUser(): string;
158
159
  static get ExtractedOn(): "Ausgezogen am" | "Extracted on" | "Extraído el" | "Extrait le" | "Extraído em" | "Estratto il";
@@ -215,7 +216,6 @@ export declare class SDKUI_Localizator {
215
216
  static get HideFormattingOptions(): "Formatierungsoptionen ausblenden" | "Hide formatting options" | "Ocultar opciones de formato" | "Masquer les options de formatage" | "Ocultar opções de formatação" | "Nascondi opzioni di formattazione";
216
217
  static get HideMetadata(): string;
217
218
  static get HideSearch(): "Suche ausblenden" | "Hide search" | "Ocultar búsqueda" | "Masquer la recherche" | "Ocultar pesquisa" | "Nascondi ricerca";
218
- static get HideSelectionColumnsAndIcons(): "Auswahlspalten und Symbole ausblenden" | "Hide selection columns and icons" | "Ocultar columnas de selección e iconos" | "Masquer les colonnes de sélection et les icônes" | "Ocultar colunas de seleção e ícones" | "Non esportare le colonne di selezione e formato";
219
219
  static get HistoryActionLabel(): string;
220
220
  static get HistoryLabel(): string;
221
221
  static get ID_Hide(): "Ausblenden ID" | "Hide ID" | "Ocultar ID" | "Masquer ID" | "Nascondi ID";
@@ -1497,6 +1497,16 @@ export class SDKUI_Localizator {
1497
1497
  default: return "Esporta solo i documenti selezionati";
1498
1498
  }
1499
1499
  }
1500
+ static get ExportSelectedColumnsAndFormatLabel() {
1501
+ switch (this._cultureID) {
1502
+ case CultureIDs.De_DE: return "Ausgewählte Spalten und Format exportieren";
1503
+ case CultureIDs.En_US: return "Export selected columns and format";
1504
+ case CultureIDs.Es_ES: return "Exportar columnas seleccionadas y formato";
1505
+ case CultureIDs.Fr_FR: return "Exporter les colonnes sélectionnées et le format";
1506
+ case CultureIDs.Pt_PT: return "Exportar colunas selecionadas e formato";
1507
+ default: return "Esporta le colonne selezione e formato";
1508
+ }
1509
+ }
1500
1510
  static get ExtractedBy() {
1501
1511
  switch (this._cultureID) {
1502
1512
  case CultureIDs.De_DE: return "Ausgezogen von";
@@ -2116,16 +2126,6 @@ export class SDKUI_Localizator {
2116
2126
  default: return "Nascondi ricerca";
2117
2127
  }
2118
2128
  }
2119
- static get HideSelectionColumnsAndIcons() {
2120
- switch (this._cultureID) {
2121
- case CultureIDs.De_DE: return "Auswahlspalten und Symbole ausblenden";
2122
- case CultureIDs.En_US: return "Hide selection columns and icons";
2123
- case CultureIDs.Es_ES: return "Ocultar columnas de selección e iconos";
2124
- case CultureIDs.Fr_FR: return "Masquer les colonnes de sélection et les icônes";
2125
- case CultureIDs.Pt_PT: return "Ocultar colunas de seleção e ícones";
2126
- default: return "Non esportare le colonne di selezione e formato";
2127
- }
2128
- }
2129
2129
  static get HistoryActionLabel() {
2130
2130
  switch (this._cultureID) {
2131
2131
  case CultureIDs.De_DE: return "Archivieren";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topconsultnpm/sdkui-react-beta",
3
- "version": "6.15.12",
3
+ "version": "6.15.13",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",