cloud-ide-element 1.1.85 → 1.1.87

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.
@@ -9634,7 +9634,9 @@ class CideEleDataGridComponent {
9634
9634
  */
9635
9635
  getItemId(item) {
9636
9636
  if (item && typeof item === 'object') {
9637
- const id = item['_id'];
9637
+ // Use trackBy from config, fallback to '_id' if not specified
9638
+ const trackBy = this.mergedConfig().trackBy || '_id';
9639
+ const id = this.getNestedValue(item, trackBy);
9638
9640
  return id ? String(id) : null;
9639
9641
  }
9640
9642
  return null;
@@ -9768,26 +9770,13 @@ class CideEleDataGridComponent {
9768
9770
  valueA = '';
9769
9771
  if (valueB === null || valueB === undefined)
9770
9772
  valueB = '';
9771
- // Handle objects - extract display text for comparison
9773
+ // Handle objects - convert to string for comparison
9774
+ // The consuming component should normalize data before passing to grid
9772
9775
  if (typeof valueA === 'object' && valueA !== null && !Array.isArray(valueA) && !(valueA instanceof Date)) {
9773
- const objA = valueA;
9774
- const displayProps = ['name', 'title', 'label', 'text', 'display_text', 'user_fullname', 'sygms_title'];
9775
- for (const prop of displayProps) {
9776
- if (objA[prop] !== undefined && objA[prop] !== null) {
9777
- valueA = objA[prop];
9778
- break;
9779
- }
9780
- }
9776
+ valueA = String(valueA);
9781
9777
  }
9782
9778
  if (typeof valueB === 'object' && valueB !== null && !Array.isArray(valueB) && !(valueB instanceof Date)) {
9783
- const objB = valueB;
9784
- const displayProps = ['name', 'title', 'label', 'text', 'display_text', 'user_fullname', 'sygms_title'];
9785
- for (const prop of displayProps) {
9786
- if (objB[prop] !== undefined && objB[prop] !== null) {
9787
- valueB = objB[prop];
9788
- break;
9789
- }
9790
- }
9779
+ valueB = String(valueB);
9791
9780
  }
9792
9781
  // Convert to strings for comparison
9793
9782
  const strA = String(valueA || '').toLowerCase();
@@ -9897,7 +9886,8 @@ class CideEleDataGridComponent {
9897
9886
  itemsToProcess.forEach(item => {
9898
9887
  const itemId = String(this.getNestedValue(item, primaryKey) || '');
9899
9888
  const parentIdValue = this.getNestedValue(item, foreignKey);
9900
- const parentId = parentIdValue !== null && parentIdValue !== undefined ? String(parentIdValue) : '';
9889
+ // Extract parent ID generically - handle both string IDs and nested objects
9890
+ const parentId = this.extractIdFromForeignKey(parentIdValue, primaryKey);
9901
9891
  const treeItem = itemMap.get(itemId);
9902
9892
  // Skip if already processed
9903
9893
  if (processedItems.has(itemId)) {
@@ -9906,7 +9896,8 @@ class CideEleDataGridComponent {
9906
9896
  if (treeItem && parentId && itemMap.has(parentId)) {
9907
9897
  // This is a child item - check if parent is processed or is a root
9908
9898
  const parent = itemMap.get(parentId);
9909
- const parentParentId = this.getNestedValue(parent, foreignKey);
9899
+ const parentParentIdValue = this.getNestedValue(parent, foreignKey);
9900
+ const parentParentId = this.extractIdFromForeignKey(parentParentIdValue, primaryKey);
9910
9901
  const isParentRoot = !parentParentId || parentParentId === null || parentParentId === undefined;
9911
9902
  if (isParentRoot || processedItems.has(parentId)) {
9912
9903
  // Parent is processed or is root, we can process this child
@@ -9915,13 +9906,12 @@ class CideEleDataGridComponent {
9915
9906
  const childExists = parentChildren.some(child => String(this.getNestedValue(child, primaryKey) || '') === itemId);
9916
9907
  if (!childExists) {
9917
9908
  // Calculate level based on parent - automatically set level key
9918
- const parentLevel = this.getNestedValue(parent, 'level') || 0;
9909
+ const parentLevel = this.getNestedValue(parent, levelKey) || 0;
9919
9910
  const childLevel = parentLevel + 1;
9920
9911
  // Update child item with correct level
9921
9912
  const updatedTreeItem = {
9922
9913
  ...treeItem,
9923
- [levelKey]: childLevel,
9924
- level: childLevel // Always add 'level' property for consistent access
9914
+ [levelKey]: childLevel
9925
9915
  };
9926
9916
  itemMap.set(itemId, updatedTreeItem);
9927
9917
  // Add updated child to parent's children array
@@ -9945,8 +9935,7 @@ class CideEleDataGridComponent {
9945
9935
  // This is a root item - automatically set level to 0
9946
9936
  const updatedRootItem = {
9947
9937
  ...treeItem,
9948
- [levelKey]: 0,
9949
- level: 0 // Always add 'level' property for consistent access
9938
+ [levelKey]: 0
9950
9939
  };
9951
9940
  itemMap.set(itemId, updatedRootItem);
9952
9941
  if (!rootItems.some(rootItem => String(this.getNestedValue(rootItem, primaryKey) || '') === itemId)) {
@@ -10013,7 +10002,8 @@ class CideEleDataGridComponent {
10013
10002
  // Get parent information
10014
10003
  const itemId = String(this.getNestedValue(item, primaryKey) || '');
10015
10004
  const parentIdValue = this.getNestedValue(item, foreignKey);
10016
- const parentId = parentIdValue !== null && parentIdValue !== undefined ? String(parentIdValue) : '';
10005
+ // Extract parent ID generically - handle both string IDs and nested objects
10006
+ const parentId = this.extractIdFromForeignKey(parentIdValue, primaryKey);
10017
10007
  // If no parent, this is a root item (level 0)
10018
10008
  if (!parentId || !itemMap.has(parentId)) {
10019
10009
  return 0;
@@ -10122,7 +10112,8 @@ class CideEleDataGridComponent {
10122
10112
  return;
10123
10113
  }
10124
10114
  const parentIdValue = this.getNestedValue(item, foreignKey);
10125
- const parentId = parentIdValue !== null && parentIdValue !== undefined ? String(parentIdValue) : '';
10115
+ // Extract parent ID generically - handle both string IDs and nested objects
10116
+ const parentId = this.extractIdFromForeignKey(parentIdValue, primaryKey);
10126
10117
  if (parentId) {
10127
10118
  // Item has a parent - try to find parent
10128
10119
  const parent = findParentInResult(parentId);
@@ -10180,13 +10171,15 @@ class CideEleDataGridComponent {
10180
10171
  return updatedItem;
10181
10172
  }
10182
10173
  // Check children recursively
10183
- const children = this.getNestedValue(treeItem, 'children') || [];
10174
+ const { childrenKey = 'children' } = treeConfig;
10175
+ const children = this.getNestedValue(treeItem, childrenKey) || [];
10184
10176
  if (children.length > 0) {
10185
10177
  const updatedChildren = updateItemInTree(children);
10186
- return {
10187
- ...treeItem,
10188
- children: updatedChildren
10178
+ const updatedItem = {
10179
+ ...treeItem
10189
10180
  };
10181
+ this.setNestedValue(updatedItem, childrenKey, updatedChildren);
10182
+ return updatedItem;
10190
10183
  }
10191
10184
  return treeItem;
10192
10185
  });
@@ -10410,20 +10403,14 @@ class CideEleDataGridComponent {
10410
10403
  * Get item level in tree
10411
10404
  */
10412
10405
  getItemLevel(item) {
10413
- // Always try to get level from standard 'level' property first (set by transformToTree)
10414
- let level = this.getNestedValue(item, 'level');
10415
- // If not found, try tree config level key
10416
- if (level === undefined || level === null) {
10417
- const treeConfig = this.getTreeConfig();
10418
- if (treeConfig) {
10419
- const { levelKey = 'level' } = treeConfig;
10420
- level = this.getNestedValue(item, levelKey) || 0;
10421
- }
10422
- else {
10423
- level = 0;
10424
- }
10406
+ // Get level from tree config level key
10407
+ const treeConfig = this.getTreeConfig();
10408
+ if (treeConfig) {
10409
+ const { levelKey = 'level' } = treeConfig;
10410
+ const itemLevel = this.getNestedValue(item, levelKey);
10411
+ return itemLevel !== undefined && itemLevel !== null ? itemLevel : 0;
10425
10412
  }
10426
- return level;
10413
+ return 0;
10427
10414
  }
10428
10415
  /**
10429
10416
  * Check if item is expanded
@@ -10626,10 +10613,11 @@ class CideEleDataGridComponent {
10626
10613
  return actualOrder;
10627
10614
  }
10628
10615
  // Final fallback to index-based calculation
10616
+ const trackBy = this.mergedConfig().trackBy || '_id';
10629
10617
  const currentIndex = this.displayedData.findIndex(currentItem => {
10630
10618
  if (item && currentItem && typeof item === 'object' && typeof currentItem === 'object') {
10631
- const itemId = item['_id'];
10632
- const currentItemId = currentItem['_id'];
10619
+ const itemId = this.getNestedValue(item, trackBy);
10620
+ const currentItemId = this.getNestedValue(currentItem, trackBy);
10633
10621
  return itemId && currentItemId && itemId === currentItemId;
10634
10622
  }
10635
10623
  return item === currentItem;
@@ -11200,30 +11188,15 @@ class CideEleDataGridComponent {
11200
11188
  * Tries common field patterns based on column key
11201
11189
  */
11202
11190
  extractValueFromRowForTemplateColumn(row, column) {
11203
- // Try common patterns based on column key
11204
11191
  const rowData = row;
11205
- // If column key is 'details', try common detail/display fields
11206
- if (column.key === 'details' || column.key.includes('detail')) {
11207
- // Try display_text, name, title fields
11208
- if (rowData['fdlds_display_text'])
11209
- return rowData['fdlds_display_text'];
11210
- if (rowData['display_text'])
11211
- return rowData['display_text'];
11212
- if (rowData['name'])
11213
- return rowData['name'];
11214
- if (rowData['title'])
11215
- return rowData['title'];
11216
- }
11217
11192
  // Try to find a field that matches the column key pattern
11218
- // For example, if key is 'details', try 'detail', 'detail_text', etc.
11193
+ // Try variations like: key, key_text, key_name, key_title, key_display
11219
11194
  const keyVariations = [
11220
11195
  column.key,
11221
11196
  `${column.key}_text`,
11222
11197
  `${column.key}_name`,
11223
11198
  `${column.key}_title`,
11224
- `${column.key}_display`,
11225
- `fdlds_${column.key}`,
11226
- `${column.key.replace('details', 'display_text')}`
11199
+ `${column.key}_display`
11227
11200
  ];
11228
11201
  for (const variation of keyVariations) {
11229
11202
  if (rowData[variation] !== undefined && rowData[variation] !== null) {
@@ -11231,12 +11204,14 @@ class CideEleDataGridComponent {
11231
11204
  }
11232
11205
  }
11233
11206
  // Try to find any string field in the row that might be a display value
11207
+ // Skip ID fields using trackBy from config
11208
+ const trackBy = this.mergedConfig().trackBy || '_id';
11234
11209
  for (const key in rowData) {
11235
11210
  if (rowData.hasOwnProperty(key)) {
11236
11211
  const value = rowData[key];
11237
11212
  if (value !== null && value !== undefined && typeof value === 'string' && value.trim() !== '') {
11238
- // Skip common ID fields
11239
- if (!key.includes('_id') && !key.includes('id_')) {
11213
+ // Skip ID fields - use trackBy from config
11214
+ if (key !== trackBy && !key.toLowerCase().includes('id')) {
11240
11215
  return value;
11241
11216
  }
11242
11217
  }
@@ -11246,16 +11221,19 @@ class CideEleDataGridComponent {
11246
11221
  }
11247
11222
  /**
11248
11223
  * Get a stable key for filter value comparison
11249
- * Handles objects by using _id or JSON stringification
11224
+ * Handles objects by using trackBy/primaryKey or JSON stringification
11250
11225
  */
11251
11226
  getFilterValueKey(value) {
11252
11227
  if (value === null || value === undefined)
11253
11228
  return 'null';
11254
11229
  if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
11255
11230
  const obj = value;
11256
- // Use _id if available for object comparison
11257
- if ('_id' in obj && obj['_id'] !== undefined) {
11258
- return `obj_${String(obj['_id'])}`;
11231
+ // Use trackBy or primaryKey from config for object comparison
11232
+ const trackBy = this.mergedConfig().trackBy;
11233
+ const treeConfig = this.mergedConfig().tree;
11234
+ const primaryKey = treeConfig?.primaryKey || trackBy;
11235
+ if (primaryKey && primaryKey in obj && obj[primaryKey] !== undefined) {
11236
+ return `obj_${String(obj[primaryKey])}`;
11259
11237
  }
11260
11238
  // Otherwise use JSON string for comparison
11261
11239
  try {
@@ -11274,34 +11252,21 @@ class CideEleDataGridComponent {
11274
11252
  return value ? 'Yes' : 'No';
11275
11253
  if (value instanceof Date)
11276
11254
  return value.toLocaleDateString();
11277
- // Handle objects - try to extract display text
11255
+ // Handle objects - convert to string generically
11256
+ // The consuming component should normalize data before passing to grid
11278
11257
  if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
11258
+ // Try to get first string property (excluding ID fields)
11279
11259
  const obj = value;
11280
- // Try common display property names in order of preference
11281
- const displayProperties = [
11282
- 'name', 'title', 'label', 'text', 'display_text',
11283
- 'user_fullname', 'fullname', 'full_name',
11284
- 'sygms_title', 'sygmt_title',
11285
- 'user_name', 'username',
11286
- 'email', 'description'
11287
- ];
11288
- for (const prop of displayProperties) {
11289
- if (obj[prop] !== undefined && obj[prop] !== null && typeof obj[prop] !== 'object') {
11290
- return String(obj[prop]);
11291
- }
11292
- }
11293
- // If no display property found, try to get first string property
11294
11260
  for (const key in obj) {
11295
11261
  if (obj.hasOwnProperty(key) && typeof obj[key] === 'string' && obj[key] !== '') {
11296
- return String(obj[key]);
11262
+ // Skip ID fields
11263
+ if (!key.toLowerCase().includes('id') && !key.toLowerCase().includes('_id')) {
11264
+ return String(obj[key]);
11265
+ }
11297
11266
  }
11298
11267
  }
11299
- // Last resort: use _id if available
11300
- if ('_id' in obj && obj['_id'] !== undefined) {
11301
- return String(obj['_id']);
11302
- }
11303
- // If still no value, return a generic label
11304
- return '(Object)';
11268
+ // If no suitable string property found, convert to string
11269
+ return String(value);
11305
11270
  }
11306
11271
  // Handle arrays
11307
11272
  if (Array.isArray(value)) {
@@ -11448,6 +11413,35 @@ class CideEleDataGridComponent {
11448
11413
  return current && typeof current === 'object' ? current[key] : undefined;
11449
11414
  }, obj);
11450
11415
  }
11416
+ /**
11417
+ * Extract ID from foreign key value generically
11418
+ * Handles both string IDs and nested objects (e.g., { _id: "...", name: "..." })
11419
+ * @param foreignKeyValue - The foreign key value (can be string, object, or null/undefined)
11420
+ * @param primaryKey - The primary key field name (from tree config or defaults to trackBy or '_id')
11421
+ * @returns The extracted ID as a string, or empty string if not found
11422
+ */
11423
+ extractIdFromForeignKey(foreignKeyValue, primaryKey) {
11424
+ // Get primary key from tree config or trackBy, fallback to '_id'
11425
+ if (!primaryKey) {
11426
+ const treeConfig = this.mergedConfig().tree;
11427
+ primaryKey = treeConfig?.primaryKey || this.mergedConfig().trackBy || '_id';
11428
+ }
11429
+ if (foreignKeyValue === null || foreignKeyValue === undefined) {
11430
+ return '';
11431
+ }
11432
+ // If it's already a string, return it
11433
+ if (typeof foreignKeyValue === 'string') {
11434
+ return foreignKeyValue.trim();
11435
+ }
11436
+ // If it's an object, extract the ID using the primary key
11437
+ if (typeof foreignKeyValue === 'object' && foreignKeyValue !== null) {
11438
+ const id = foreignKeyValue[primaryKey];
11439
+ if (id !== null && id !== undefined) {
11440
+ return String(id);
11441
+ }
11442
+ }
11443
+ return '';
11444
+ }
11451
11445
  /**
11452
11446
  * Set a nested value in an object using dot notation
11453
11447
  * @param obj The object to modify
@@ -11746,6 +11740,7 @@ class CideEleDataGridComponent {
11746
11740
  displayValue = this.formatValue(displayValue, column);
11747
11741
  }
11748
11742
  // If display value is still an object, convert to string
11743
+ // The consuming component should normalize data before passing to grid
11749
11744
  if (typeof displayValue === 'object' && displayValue !== null && !Array.isArray(displayValue) && !(displayValue instanceof Date)) {
11750
11745
  displayValue = String(displayValue);
11751
11746
  }
@@ -12033,32 +12028,18 @@ class CideEleDataGridComponent {
12033
12028
  // Handle objects - extract display text
12034
12029
  if (typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date)) {
12035
12030
  const obj = value;
12036
- // Try common display properties
12037
- const displayProperties = [
12038
- 'name', 'title', 'label', 'text', 'display_text',
12039
- 'user_fullname', 'fullname', 'full_name',
12040
- 'sygms_title', 'sygmt_title',
12041
- 'user_name', 'username',
12042
- 'email', 'description'
12043
- ];
12044
- for (const prop of displayProperties) {
12045
- if (obj[prop] !== undefined && obj[prop] !== null && typeof obj[prop] !== 'object') {
12046
- return String(obj[prop]);
12047
- }
12048
- }
12049
- // Try first string property
12031
+ // Try to get first string property (excluding ID fields)
12032
+ // The consuming component should normalize data before passing to grid
12050
12033
  for (const key in obj) {
12051
12034
  if (obj.hasOwnProperty(key) && typeof obj[key] === 'string' && obj[key] !== '') {
12052
- if (!key.includes('_id') && !key.includes('id_')) {
12035
+ // Skip ID fields
12036
+ if (!key.toLowerCase().includes('id') && !key.toLowerCase().includes('_id')) {
12053
12037
  return String(obj[key]);
12054
12038
  }
12055
12039
  }
12056
12040
  }
12057
- // Use _id as fallback
12058
- if ('_id' in obj && obj['_id'] !== undefined) {
12059
- return String(obj['_id']);
12060
- }
12061
- return '';
12041
+ // If no suitable string property found, convert to string
12042
+ return String(value);
12062
12043
  }
12063
12044
  // Handle arrays
12064
12045
  if (Array.isArray(value)) {