cloud-ide-element 1.0.65 → 1.0.67

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.
@@ -4714,8 +4714,14 @@ class CideEleDataGridComponent {
4714
4714
  let processedData = data;
4715
4715
  // Transform to tree structure if tree config is enabled
4716
4716
  if (this.mergedConfig().tree?.enabled) {
4717
+ // Preserve expansion state from current data before transforming
4718
+ const currentData = this.internalData();
4719
+ const expansionState = this.preserveTreeExpansionState(currentData);
4717
4720
  processedData = this.transformToTree(data);
4718
4721
  console.log('processedData', processedData);
4722
+ // Apply preserved expansion state to new tree data
4723
+ processedData = this.applyTreeExpansionState(processedData, expansionState);
4724
+ console.log('processedData with preserved expansion state', processedData);
4719
4725
  }
4720
4726
  this.internalData.set(processedData);
4721
4727
  console.log('processedData', processedData);
@@ -4747,7 +4753,12 @@ class CideEleDataGridComponent {
4747
4753
  let data = this.config?.data || [];
4748
4754
  // Transform to tree structure if tree config is enabled
4749
4755
  if (this.mergedConfig().tree?.enabled) {
4756
+ // Preserve expansion state from current data before transforming
4757
+ const currentData = this.internalData();
4758
+ const expansionState = this.preserveTreeExpansionState(currentData);
4750
4759
  data = this.transformToTree(data);
4760
+ // Apply preserved expansion state to new tree data
4761
+ data = this.applyTreeExpansionState(data, expansionState);
4751
4762
  }
4752
4763
  this.internalData.set(data);
4753
4764
  // Set pagination values based on mode
@@ -4878,6 +4889,59 @@ class CideEleDataGridComponent {
4878
4889
  }
4879
4890
  this.updatePaginationState();
4880
4891
  }
4892
+ /**
4893
+ * Preserve tree expansion state from current data
4894
+ */
4895
+ preserveTreeExpansionState(currentData) {
4896
+ const expansionState = new Map();
4897
+ const treeConfig = this.mergedConfig().tree;
4898
+ if (!treeConfig)
4899
+ return expansionState;
4900
+ const { expandedKey = 'isExpanded', primaryKey } = treeConfig;
4901
+ const extractExpansionState = (items) => {
4902
+ items.forEach(item => {
4903
+ const itemId = String(this.getNestedValue(item, primaryKey) || '');
4904
+ if (itemId) {
4905
+ const isExpanded = this.getNestedValue(item, expandedKey) || false;
4906
+ expansionState.set(itemId, isExpanded);
4907
+ }
4908
+ // Check for children recursively
4909
+ const children = this.getNestedValue(item, treeConfig.childrenKey || 'children') || [];
4910
+ if (children.length > 0) {
4911
+ extractExpansionState(children);
4912
+ }
4913
+ });
4914
+ };
4915
+ extractExpansionState(currentData);
4916
+ console.log('🔍 DataGrid: Preserved expansion state for', expansionState.size, 'items');
4917
+ return expansionState;
4918
+ }
4919
+ /**
4920
+ * Apply preserved tree expansion state to new data
4921
+ */
4922
+ applyTreeExpansionState(data, expansionState) {
4923
+ const treeConfig = this.mergedConfig().tree;
4924
+ if (!treeConfig)
4925
+ return data;
4926
+ const { expandedKey = 'isExpanded', primaryKey, childrenKey = 'children' } = treeConfig;
4927
+ const applyToItems = (items) => {
4928
+ return items.map(item => {
4929
+ const itemId = String(this.getNestedValue(item, primaryKey) || '');
4930
+ const isExpanded = expansionState.get(itemId) || false;
4931
+ const updatedItem = {
4932
+ ...item,
4933
+ [expandedKey]: isExpanded
4934
+ };
4935
+ // Apply to children recursively
4936
+ const children = this.getNestedValue(item, childrenKey) || [];
4937
+ if (children.length > 0) {
4938
+ this.setNestedValue(updatedItem, childrenKey, applyToItems(children));
4939
+ }
4940
+ return updatedItem;
4941
+ });
4942
+ };
4943
+ return applyToItems(data);
4944
+ }
4881
4945
  /**
4882
4946
  * Transform flat data to tree structure based on foreign key relationships
4883
4947
  */
@@ -5567,10 +5631,17 @@ class CideEleDataGridComponent {
5567
5631
  const baseOrder = Math.min(...this.displayedData.map(item => this.getItemOrder(item)));
5568
5632
  const newOrderValue = baseOrder + index;
5569
5633
  currentEntry.newPosition = newOrderValue;
5634
+ // IMPORTANT: Update the actual sequence value in the item itself
5635
+ this.setNestedValue(item, dragDropConfig.orderField, newOrderValue);
5570
5636
  }
5571
5637
  else {
5572
5638
  // Fallback to index-based position
5573
- currentEntry.newPosition = index + 1;
5639
+ const newOrderValue = index + 1;
5640
+ currentEntry.newPosition = newOrderValue;
5641
+ // Update the actual sequence value in the item itself
5642
+ if (dragDropConfig?.orderField) {
5643
+ this.setNestedValue(item, dragDropConfig.orderField, newOrderValue);
5644
+ }
5574
5645
  }
5575
5646
  this.rowOrderMap.set(itemId, currentEntry);
5576
5647
  }
@@ -5658,6 +5729,23 @@ class CideEleDataGridComponent {
5658
5729
  .sort((a, b) => a.newPosition - b.newPosition)
5659
5730
  .map(orderedItem => orderedItem.item);
5660
5731
  }
5732
+ /**
5733
+ * Get only the items that have actually changed order
5734
+ */
5735
+ getChangedOrders() {
5736
+ const changedItems = [];
5737
+ // Get the full dataset from the config
5738
+ const fullData = this.mergedConfig().data || [];
5739
+ // Check each item to see if its position has changed
5740
+ this.rowOrderMap.forEach((orderInfo, itemId) => {
5741
+ const item = fullData.find(dataItem => this.getItemId(dataItem) === itemId);
5742
+ if (item && orderInfo.oldPosition !== orderInfo.newPosition) {
5743
+ changedItems.push(item);
5744
+ console.log('🔍 Item changed order:', itemId, 'from', orderInfo.oldPosition, 'to', orderInfo.newPosition);
5745
+ }
5746
+ });
5747
+ return changedItems;
5748
+ }
5661
5749
  /**
5662
5750
  * Update local data order for visual reordering (LOCAL ONLY)
5663
5751
  */
@@ -5709,25 +5797,32 @@ class CideEleDataGridComponent {
5709
5797
  console.log('🔍 Reset clicked, row order map reset locally, visual display reverted');
5710
5798
  }
5711
5799
  else if (action.key === 'save-order') {
5712
- this.hasOrderChanged.set(false);
5713
- // Update the row order map to current positions as new baseline
5714
- this.updateRowOrderMapBaseline();
5715
- // Clear local reordered data as it's now the baseline
5716
- this.localReorderedData = [];
5717
- console.log('🔍 Save clicked, row order map updated to new baseline, local data cleared');
5718
- // NOW emit the reorder event to update external components
5719
- const currentOrder = this.getCurrentOrderFromMap();
5720
- if (currentOrder.length > 0) {
5721
- console.log('🔍 Emitting rowReorder event to update external components:', currentOrder);
5800
+ // Check if there are any actual changes before proceeding
5801
+ const hasActualChanges = this.checkIfOrderChanged();
5802
+ if (!hasActualChanges) {
5803
+ console.log('🔍 No actual order changes detected, skipping save');
5804
+ this.hasOrderChanged.set(false);
5805
+ return;
5806
+ }
5807
+ // Get only the changed orders and emit them BEFORE clearing local data
5808
+ const changedOrders = this.getChangedOrders();
5809
+ if (changedOrders.length > 0) {
5810
+ console.log('🔍 Emitting rowReorder event with changed orders only:', changedOrders);
5811
+ console.log('🔍 Number of changed records:', changedOrders.length, 'out of', this.getCurrentOrderFromMap().length, 'total records');
5722
5812
  // Use the expected GridEvent structure for rowReorder
5723
5813
  this.emitEvent('rowReorder', {
5724
- sourceItem: currentOrder[0], // First item as source
5814
+ sourceItem: changedOrders[0], // First changed item as source
5725
5815
  sourceIndex: 0, // First position as source
5726
- targetItem: currentOrder[currentOrder.length - 1], // Last item as target
5727
- targetIndex: currentOrder.length - 1, // Last position as target
5728
- newOrder: currentOrder // The complete new order
5816
+ targetItem: changedOrders[changedOrders.length - 1], // Last changed item as target
5817
+ targetIndex: changedOrders.length - 1, // Last position as target
5818
+ newOrder: changedOrders, // Only the records whose order actually changed
5819
+ allOrders: this.getCurrentOrderFromMap() // Complete order for reference
5729
5820
  });
5730
5821
  }
5822
+ // DON'T clear the local data or reset the order map here
5823
+ // Let the parent component handle the data refresh after API call
5824
+ // The local data will be cleared when new data arrives via ngOnChanges
5825
+ console.log('🔍 Save clicked, rowReorder event emitted, preserving local data until API response');
5731
5826
  }
5732
5827
  if (this.actionHandlers[action.onClick]) {
5733
5828
  this.actionHandlers[action.onClick](item, action);
@@ -5753,6 +5848,60 @@ class CideEleDataGridComponent {
5753
5848
  return current && typeof current === 'object' ? current[key] : undefined;
5754
5849
  }, obj);
5755
5850
  }
5851
+ /**
5852
+ * Set a nested value in an object using dot notation
5853
+ * @param obj The object to modify
5854
+ * @param path The dot notation path (e.g., 'contact.email')
5855
+ * @param value The value to set
5856
+ * @example
5857
+ * const obj = { contact: { email: 'old@example.com' } };
5858
+ * setNestedValue(obj, 'contact.email', 'new@example.com');
5859
+ * // obj.contact.email === 'new@example.com'
5860
+ */
5861
+ setNestedValue(obj, path, value) {
5862
+ const keys = path.split('.');
5863
+ const lastKey = keys.pop();
5864
+ const target = keys.reduce((current, key) => {
5865
+ if (current && typeof current === 'object') {
5866
+ if (!current[key]) {
5867
+ current[key] = {};
5868
+ }
5869
+ return current[key];
5870
+ }
5871
+ return undefined;
5872
+ }, obj);
5873
+ if (target && typeof target === 'object') {
5874
+ target[lastKey] = value;
5875
+ }
5876
+ }
5877
+ /**
5878
+ * Compare two order arrays to check if they are different
5879
+ * This method can be used by parent components to check if order has actually changed
5880
+ * @param currentOrder Current order array
5881
+ * @param originalOrder Original order array
5882
+ * @returns true if orders are different, false if they are the same
5883
+ */
5884
+ compareOrders(currentOrder, originalOrder) {
5885
+ console.log('🔍 DataGrid: Comparing orders - current length:', currentOrder.length, 'original length:', originalOrder.length);
5886
+ // If lengths are different, there are changes
5887
+ if (currentOrder.length !== originalOrder.length) {
5888
+ console.log('🔍 DataGrid: Lengths are different, returning true');
5889
+ return true;
5890
+ }
5891
+ // Compare the order of items by their IDs (not just their sequence values)
5892
+ // This will detect if items have been reordered even if sequence values are the same
5893
+ for (let i = 0; i < currentOrder.length; i++) {
5894
+ const currentItem = currentOrder[i];
5895
+ const originalItem = originalOrder[i];
5896
+ console.log('🔍 DataGrid: Position', i, '- Current ID:', currentItem.id, 'Original ID:', originalItem.id);
5897
+ if (currentItem.id !== originalItem.id) {
5898
+ console.log('🔍 DataGrid: Different item at position', i, 'returning true');
5899
+ return true;
5900
+ }
5901
+ }
5902
+ console.log('🔍 DataGrid: No differences found, returning false');
5903
+ return false;
5904
+ }
5756
5905
  formatValue(value, column) {
5757
5906
  if (column.formatter) {
5758
5907
  if (column.formatter.type === 'custom' && column.formatter.customFunction) {