@adaptabletools/adaptable 16.1.0 → 16.1.1-canary.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptabletools/adaptable",
3
- "version": "16.1.0",
3
+ "version": "16.1.1-canary.1",
4
4
  "description": "Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements",
5
5
  "keywords": [
6
6
  "web-components",
@@ -1,2 +1,2 @@
1
- declare const _default: 1698160309123;
1
+ declare const _default: 1698258143889;
2
2
  export default _default;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = 1698160309123;
3
+ exports.default = 1698258143889;
@@ -262,7 +262,7 @@ export interface AdaptableOptions<TData = any> {
262
262
  /**
263
263
  *
264
264
  */
265
- dataImportOptions?: DataImportOptions<TData>;
265
+ dataImportOptions?: DataImportOptions;
266
266
  /**
267
267
  * Used for managing the AdapTable Plugins
268
268
  */
@@ -14,7 +14,7 @@ export interface DataImportOptions<T = Record<string, unknown>> {
14
14
  /**
15
15
  * Function to validate the imported Data
16
16
  */
17
- validate?: (context: DataImportValidateContext) => DataImportValidationError[] | null;
17
+ validate?: (context: DataImportValidateContext<T>) => DataImportValidationError[] | undefined;
18
18
  /**
19
19
  * Function to apply the Import (instead of AdapTable)
20
20
  */
@@ -23,6 +23,10 @@ export interface DataImportOptions<T = Record<string, unknown>> {
23
23
  * Function to preprocess the data before it is imported
24
24
  */
25
25
  preprocessData?: (context: PreprocessDataContext<T>) => Record<string, unknown>[];
26
+ /**
27
+ * Function to get the Primary Key value for a row of data. It defaults to the value of the `AdaptableOptions.primaryKey` column
28
+ */
29
+ getPrimaryKeyValue?: (context: GetPrimaryKeyValueContext<T>) => string | number;
26
30
  }
27
31
  export interface PreprocessDataContext<T = Record<string, unknown>> extends BaseContext {
28
32
  /**
@@ -65,3 +69,12 @@ export interface DataImportValidateContext<T = Record<string, unknown>> extends
65
69
  */
66
70
  rowData: T;
67
71
  }
72
+ /**
73
+ * Context that manages Data Validation
74
+ */
75
+ export interface GetPrimaryKeyValueContext<T = Record<string, unknown>> extends BaseContext {
76
+ /**
77
+ * Data being imported
78
+ */
79
+ rowData: T;
80
+ }
@@ -4,13 +4,6 @@ import { AdaptableColumn, AdaptableIcon, AdaptableModule, BaseContext } from '..
4
4
  * Options for managing menus in AdapTable
5
5
  */
6
6
  export interface MenuOptions<TData = any> {
7
- /**
8
- * Adds 'Ungroup' Column Menu item to a row grouped column menu
9
- *
10
- * @defaultValue true
11
- * @gridInfoItem
12
- */
13
- showUngroupColumnMenuItem?: boolean;
14
7
  /**
15
8
  * Customised Context Menu. Default context menu items are available in the provided context.
16
9
  */
@@ -35,6 +28,14 @@ export interface MenuOptions<TData = any> {
35
28
  * @gridInfoItem
36
29
  */
37
30
  showAdaptableColumnMenu?: boolean | ((menuItem: AdaptableMenuItem, menuContext: ColumnMenuContext<TData>) => boolean);
31
+ /**
32
+ * Adds 'Ungroup' Column Menu item to a row grouped column menu
33
+ *
34
+ * @deprecated Now provided by AG Grid and property is ignored
35
+ * @defaultValue true
36
+ * @gridInfoItem
37
+ */
38
+ showUngroupColumnMenuItem?: boolean;
38
39
  /**
39
40
  * Order in which AG Grid, AdapTable and User Menu sections will appear in Column Menu (list or function)
40
41
  *
@@ -73,12 +74,12 @@ export interface CustomContextMenuContext<TData = any> extends ContextMenuContex
73
74
  */
74
75
  defaultAgGridMenuItems: AgGridMenuItem<AgGridContextMenuItemType>[];
75
76
  /**
76
- * Default Adaptable Menu Items
77
+ * Default AdapTable Menu Items
77
78
  */
78
79
  defaultAdaptableMenuItems: AdaptableSystemMenuItem[];
79
80
  }
80
81
  /**
81
- * Context info provided when building Custom Context Menus
82
+ * Context info provided when building Custom Column Menus
82
83
  */
83
84
  export interface CustomColumnMenuContext<TData = any> extends ColumnMenuContext<TData> {
84
85
  /**
@@ -86,7 +87,7 @@ export interface CustomColumnMenuContext<TData = any> extends ColumnMenuContext<
86
87
  */
87
88
  defaultAgGridMenuItems: AgGridMenuItem<AgGridColumnMenuItemType>[];
88
89
  /**
89
- * Default Adaptable Menu Items
90
+ * Default AdapTable Menu Items
90
91
  */
91
92
  defaultAdaptableMenuItems: AdaptableSystemMenuItem[];
92
93
  }
@@ -43,5 +43,5 @@ export declare class OptionsApiImpl extends ApiBase implements OptionsApi {
43
43
  getFlashingCellOptions(): FlashingCellOptions;
44
44
  getSettingsPanelOptions(): SettingsPanelOptions;
45
45
  getFdc3Options(): Fdc3Options;
46
- getDataImportOptions(): import("../../types").DataImportOptions<any>;
46
+ getDataImportOptions(): import("../../types").DataImportOptions<Record<string, unknown>>;
47
47
  }
@@ -42,7 +42,7 @@ class AdaptablePopover extends React.Component {
42
42
  overflow: 'visible',
43
43
  }, defaultZIndex: 100000, alignPosition: this.props.alignPosition }, useButton ? (React.createElement(ButtonInfo_1.ButtonInfo, { style: iconStyle, variant: "text", onClick: () => null, icon: showIcon && icon, tooltip: this.props.tooltipText }, this.props.children)) : (React.createElement("div", { title: this.props.tooltipText, tabIndex: 0, style: { cursor: 'pointer', display: 'inline-block' } },
44
44
  this.props.children,
45
- showIcon && React.createElement(icons_1.Icon, { name: icon }))))));
45
+ showIcon && React.createElement(icons_1.Icon, { name: icon, style: iconStyle }))))));
46
46
  }
47
47
  }
48
48
  exports.AdaptablePopover = AdaptablePopover;
@@ -14,13 +14,19 @@ const ValidationSection_1 = require("./sections/ValidationSection");
14
14
  const DataImportWizard = (props) => {
15
15
  var _a;
16
16
  const adaptable = (0, AdaptableContext_1.useAdaptable)();
17
- const primaryKey = adaptable.api.optionsApi.getPrimaryKey();
18
17
  const dataImportOptions = adaptable.api.optionsApi.getDataImportOptions();
19
18
  const module = adaptable.ModuleService.getModuleById('DataImport');
20
19
  const [rowData, setRowData] = React.useState(null);
21
20
  const [file, setFile] = React.useState(null);
22
21
  const [text, setText] = React.useState('');
23
22
  const [importType, setImportType] = React.useState('file');
23
+ const primaryKey = adaptable.api.optionsApi.getPrimaryKey();
24
+ const getPrimaryKeyValue = (rowData) => {
25
+ if (typeof dataImportOptions.getPrimaryKeyValue === 'function') {
26
+ return dataImportOptions.getPrimaryKeyValue(Object.assign(Object.assign({}, (0, ObjectFactory_1.createBaseContext)(adaptable.api)), { rowData }));
27
+ }
28
+ return rowData[primaryKey];
29
+ };
24
30
  const handleRowDataChange = React.useCallback((data) => {
25
31
  if (Array.isArray(data)) {
26
32
  setRowData(data);
@@ -120,8 +126,9 @@ const DataImportWizard = (props) => {
120
126
  }
121
127
  return (_a = rowData === null || rowData === void 0 ? void 0 : rowData.reduce) === null || _a === void 0 ? void 0 : _a.call(rowData, (acc, rowData) => {
122
128
  const error = dataImportOptions.validate(Object.assign({ rowData }, (0, ObjectFactory_1.createBaseContext)(adaptable.api)));
123
- if (error && rowData[primaryKey] && error.length) {
124
- acc[rowData[primaryKey]] = error;
129
+ const primaryKeyValue = getPrimaryKeyValue(rowData);
130
+ if (error && primaryKeyValue && error.length) {
131
+ acc[primaryKeyValue] = error;
125
132
  }
126
133
  return acc;
127
134
  }, {});
@@ -132,7 +139,7 @@ const DataImportWizard = (props) => {
132
139
  };
133
140
  const handleFinish = () => {
134
141
  const validData = rowData.filter((row) => {
135
- const rowErrors = errors[row[primaryKey]];
142
+ const rowErrors = errors[getPrimaryKeyValue(row)];
136
143
  return !rowErrors || rowErrors.length === 0;
137
144
  });
138
145
  adaptable.api.dataImportApi.internalApi.importData(validData);
@@ -11,6 +11,7 @@ const Tag_1 = require("../../../../components/Tag");
11
11
  const AdaptableContext_1 = require("../../../AdaptableContext");
12
12
  const AdaptablePopover_1 = require("../../../AdaptablePopover");
13
13
  const UIHelper_1 = tslib_1.__importDefault(require("../../../UIHelper"));
14
+ const ObjectFactory_1 = require("../../../../Utilities/ObjectFactory");
14
15
  const tableDOMProps = {
15
16
  style: {
16
17
  height: '100%',
@@ -34,6 +35,7 @@ const getCellError = (errors, primaryKeyValue, columnId) => {
34
35
  };
35
36
  const DataPreview = (props) => {
36
37
  const adaptable = (0, AdaptableContext_1.useAdaptable)();
38
+ const dataImportOptions = adaptable.api.optionsApi.getDataImportOptions();
37
39
  if (!props.data) {
38
40
  return (React.createElement(HelpBlock_1.default, { color: 'var(--ab-color-error)' },
39
41
  "No Data has been Imported. Go to ",
@@ -61,6 +63,12 @@ const DataPreview = (props) => {
61
63
  }
62
64
  return dataType;
63
65
  };
66
+ const getPrimaryKeyValue = (rowData) => {
67
+ if (typeof dataImportOptions.getPrimaryKeyValue === 'function') {
68
+ return dataImportOptions.getPrimaryKeyValue(Object.assign(Object.assign({}, (0, ObjectFactory_1.createBaseContext)(adaptable.api)), { rowData }));
69
+ }
70
+ return rowData[primaryKey];
71
+ };
64
72
  const infiniteColumns = adaptableColumnsInData.reduce((acc, column) => {
65
73
  const isPrimaryKey = column.columnId === primaryKey;
66
74
  let editable = !isPrimaryKey;
@@ -89,7 +97,7 @@ const DataPreview = (props) => {
89
97
  minWidth: 90,
90
98
  align: 'center',
91
99
  renderValue: (params) => {
92
- const cellErrors = getRowErrors(props.errors, params.data[primaryKey]);
100
+ const cellErrors = getRowErrors(props.errors, getPrimaryKeyValue(params.data));
93
101
  const successColor = UIHelper_1.default.getColorByMessageType('Success');
94
102
  if (!cellErrors || cellErrors.length === 0) {
95
103
  return React.createElement(icons_1.Icon, { name: "check", style: { color: successColor, fill: 'currentColor' } });
@@ -104,7 +112,7 @@ const DataPreview = (props) => {
104
112
  minWidth: 90,
105
113
  renderValue: (params) => {
106
114
  try {
107
- const isExistingRow = adaptable.api.gridApi.getRowNodeForPrimaryKey(params.data[primaryKey]);
115
+ const isExistingRow = adaptable.api.gridApi.getRowNodeForPrimaryKey(getPrimaryKeyValue(params.data));
108
116
  return isExistingRow ? 'Update' : 'New';
109
117
  }
110
118
  catch (error) {
@@ -19,7 +19,7 @@ const parseCSV = (content) => {
19
19
  const item = {};
20
20
  for (let j = 0; j < headers.length; j++) {
21
21
  const value = values[j];
22
- item[headers[j]] = isNaN(Number(value)) ? value : Number(value);
22
+ item[headers[j]] = value === '' || isNaN(Number(value)) ? value : Number(value);
23
23
  }
24
24
  data.push(item);
25
25
  }
@@ -3238,6 +3238,16 @@ export declare const ADAPTABLE_METAMODEL: {
3238
3238
  desc: string;
3239
3239
  }[];
3240
3240
  };
3241
+ GetPrimaryKeyValueContext: {
3242
+ name: string;
3243
+ kind: string;
3244
+ desc: string;
3245
+ props: {
3246
+ name: string;
3247
+ kind: string;
3248
+ desc: string;
3249
+ }[];
3250
+ };
3241
3251
  GlobalExpressionFunctionsContext: {
3242
3252
  name: string;
3243
3253
  kind: string;