@snteam/amplify-angular-core 1.0.46 → 1.0.47

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.
@@ -5868,103 +5868,89 @@ return fields;
5868
5868
  // Get all available models from the schema
5869
5869
  const models = this.outputs.data.model_introspection.models;
5870
5870
  const modelNames = Object.keys(models);
5871
- // Get existing TableConfigs to link ListViews to
5872
- const tableConfigObservable = this.ams.listItemsForModel('TableConfig');
5873
- if (!tableConfigObservable) {
5874
- this.snackBar.open('Failed to get TableConfig records', 'Dismiss', { duration: 3000 });
5871
+ // Get existing TableConfigs and existing ListViews
5872
+ const [tableConfigs, existingListViews] = await Promise.all([
5873
+ this.getItemsFromModel('TableConfig'),
5874
+ this.getItemsFromModel('ListView')
5875
+ ]);
5876
+ if (tableConfigs.length === 0) {
5877
+ this.snackBar.open('No TableConfig records found. Please create TableConfigs first.', 'Dismiss', { duration: 3000 });
5875
5878
  return;
5876
5879
  }
5877
- tableConfigObservable.subscribe({
5878
- next: async ({ items: tableConfigs }) => {
5879
- if (tableConfigs.length === 0) {
5880
- this.snackBar.open('No TableConfig records found. Please create TableConfigs first.', 'Dismiss', { duration: 3000 });
5881
- return;
5882
- }
5883
- let totalCreated = 0;
5884
- let createdListViews = [];
5885
- let createdListViewFields = [];
5886
- // Create ListView records for each TableConfig
5887
- console.log('ConfigurationsComponent: Creating ListView records for', tableConfigs.length, 'TableConfigs');
5888
- for (const tableConfig of tableConfigs) {
5889
- const modelName = tableConfig.name;
5890
- const modelData = models[modelName];
5891
- if (!modelData) {
5892
- console.warn('ConfigurationsComponent: Model data not found for', modelName);
5893
- continue;
5894
- }
5895
- // Check if ListView already exists for this TableConfig
5896
- const existingListViewObservable = this.ams.listItemsForModel('ListView');
5897
- if (existingListViewObservable) {
5898
- const existingListViews = await new Promise((resolve) => {
5899
- existingListViewObservable.subscribe({
5900
- next: ({ items }) => resolve(items.filter((lv) => lv.tableConfigId === tableConfig.id)),
5901
- error: () => resolve([])
5902
- });
5903
- });
5904
- if (existingListViews.length > 0) {
5905
- console.log('ConfigurationsComponent: ListView already exists for', modelName);
5880
+ let totalCreated = 0;
5881
+ let createdListViews = [];
5882
+ let createdListViewFields = [];
5883
+ // Create ListView records for each TableConfig
5884
+ console.log('ConfigurationsComponent: Creating ListView records for', tableConfigs.length, 'TableConfigs');
5885
+ for (const tableConfig of tableConfigs) {
5886
+ const modelName = tableConfig.name;
5887
+ const modelData = models[modelName];
5888
+ if (!modelData) {
5889
+ console.warn('ConfigurationsComponent: Model data not found for', modelName);
5890
+ continue;
5891
+ }
5892
+ // Check if ListView already exists for this TableConfig
5893
+ const existingListView = existingListViews.find((lv) => lv.tableConfigId === tableConfig.id);
5894
+ if (existingListView) {
5895
+ console.log('ConfigurationsComponent: ListView already exists for', modelName, 'with ID:', existingListView.id);
5896
+ continue;
5897
+ }
5898
+ const listView = {
5899
+ label: `Default ${this.formatModelLabel(modelName)} List`,
5900
+ tableConfigId: tableConfig.id
5901
+ };
5902
+ const listViewResult = await this.ams.createItemPromise('ListView', listView);
5903
+ if (listViewResult && listViewResult.data) {
5904
+ createdListViews.push(listViewResult.data);
5905
+ totalCreated++;
5906
+ console.log('ConfigurationsComponent: Created ListView for', modelName);
5907
+ // Create ListViewField records for each field in the model
5908
+ if (modelData.fields) {
5909
+ const fields = Object.values(modelData.fields);
5910
+ const skipFields = ['id', 'createdAt', 'updatedAt']; // Skip system fields
5911
+ let fieldOrder = 0;
5912
+ for (const field of fields) {
5913
+ const fieldData = field;
5914
+ // Skip system fields and relationship fields for list view
5915
+ if (skipFields.includes(fieldData.name) ||
5916
+ (fieldData.association && fieldData.association.connectionType)) {
5906
5917
  continue;
5907
5918
  }
5908
- }
5909
- const listView = {
5910
- label: `Default ${this.formatModelLabel(modelName)} List`,
5911
- tableConfigId: tableConfig.id
5912
- };
5913
- const listViewResult = await this.ams.createItemPromise('ListView', listView);
5914
- if (listViewResult && listViewResult.data) {
5915
- createdListViews.push(listViewResult.data);
5916
- totalCreated++;
5917
- console.log('ConfigurationsComponent: Created ListView for', modelName);
5918
- // Create ListViewField records for each field in the model
5919
- if (modelData.fields) {
5920
- const fields = Object.values(modelData.fields);
5921
- const skipFields = ['id', 'createdAt', 'updatedAt']; // Skip system fields
5922
- let fieldOrder = 0;
5923
- for (const field of fields) {
5924
- const fieldData = field;
5925
- // Skip system fields and relationship fields for list view
5926
- if (skipFields.includes(fieldData.name) ||
5927
- (fieldData.association && fieldData.association.connectionType)) {
5928
- continue;
5929
- }
5930
- const listViewField = {
5931
- field_name: fieldData.name,
5932
- display_label: this.formatFieldLabel(fieldData.name),
5933
- field_type: this.mapFieldType(fieldData.type),
5934
- order: fieldOrder++,
5935
- listViewId: listViewResult.data.id
5936
- };
5937
- const listViewFieldResult = await this.ams.createItemPromise('ListViewField', listViewField);
5938
- if (listViewFieldResult && listViewFieldResult.data) {
5939
- createdListViewFields.push(listViewFieldResult.data);
5940
- totalCreated++;
5941
- }
5942
- }
5943
- console.log('ConfigurationsComponent: Created ListViewFields for', modelName, 'with', fieldOrder, 'fields');
5944
- }
5945
- // Update TableConfig to set this as the default ListView if none exists
5946
- if (!tableConfig.defaultListViewId) {
5947
- const updatedTableConfig = {
5948
- id: tableConfig.id,
5949
- defaultListViewId: listViewResult.data.id
5950
- };
5951
- await this.ams.updateItemForModel('TableConfig', updatedTableConfig);
5952
- console.log('ConfigurationsComponent: Updated TableConfig with default ListView for', modelName);
5919
+ const listViewField = {
5920
+ field_name: fieldData.name,
5921
+ display_label: this.formatFieldLabel(fieldData.name),
5922
+ field_type: this.mapFieldType(fieldData.type),
5923
+ order: fieldOrder++,
5924
+ listViewId: listViewResult.data.id
5925
+ };
5926
+ const listViewFieldResult = await this.ams.createItemPromise('ListViewField', listViewField);
5927
+ if (listViewFieldResult && listViewFieldResult.data) {
5928
+ createdListViewFields.push(listViewFieldResult.data);
5929
+ totalCreated++;
5953
5930
  }
5954
5931
  }
5932
+ console.log('ConfigurationsComponent: Created ListViewFields for', modelName, 'with', fieldOrder, 'fields');
5933
+ }
5934
+ // Update TableConfig to set this as the default ListView if none exists
5935
+ if (!tableConfig.defaultListViewId) {
5936
+ const updatedTableConfig = {
5937
+ id: tableConfig.id,
5938
+ defaultListViewId: listViewResult.data.id
5939
+ };
5940
+ await this.ams.updateItemForModel('TableConfig', updatedTableConfig);
5941
+ console.log('ConfigurationsComponent: Updated TableConfig with default ListView for', modelName);
5955
5942
  }
5956
- console.log('ConfigurationsComponent: Successfully created', totalCreated, 'total records');
5957
- console.log('ConfigurationsComponent: Created', createdListViews.length, 'ListViews');
5958
- console.log('ConfigurationsComponent: Created', createdListViewFields.length, 'ListViewFields');
5959
- this.snackBar.open(`Created ${totalCreated} ListView records: ${createdListViews.length} ListViews, ${createdListViewFields.length} ListViewFields`, 'Dismiss', { duration: 5000 });
5960
- },
5961
- error: (error) => {
5962
- console.error('ConfigurationsComponent: Error getting TableConfig records:', error);
5963
- this.snackBar.open('Error getting TableConfig records: ' + error, 'Dismiss', {
5964
- duration: 5000
5965
- });
5966
5943
  }
5967
- });
5944
+ }
5945
+ console.log('ConfigurationsComponent: Successfully created', totalCreated, 'total records');
5946
+ console.log('ConfigurationsComponent: Created', createdListViews.length, 'ListViews');
5947
+ console.log('ConfigurationsComponent: Created', createdListViewFields.length, 'ListViewFields');
5948
+ if (totalCreated > 0) {
5949
+ this.snackBar.open(`Created ${totalCreated} ListView records: ${createdListViews.length} ListViews, ${createdListViewFields.length} ListViewFields`, 'Dismiss', { duration: 5000 });
5950
+ }
5951
+ else {
5952
+ this.snackBar.open('All ListViews already exist for existing TableConfigs', 'Dismiss', { duration: 3000 });
5953
+ }
5968
5954
  }
5969
5955
  catch (error) {
5970
5956
  console.error('ConfigurationsComponent: Error in createDefaultListViews:', error);
@@ -5973,6 +5959,22 @@ return fields;
5973
5959
  });
5974
5960
  }
5975
5961
  }
5962
+ async getItemsFromModel(modelName) {
5963
+ return new Promise((resolve, reject) => {
5964
+ const observable = this.ams.listItemsForModel(modelName);
5965
+ if (!observable) {
5966
+ resolve([]);
5967
+ return;
5968
+ }
5969
+ observable.subscribe({
5970
+ next: ({ items }) => resolve(items),
5971
+ error: (error) => {
5972
+ console.error(`ConfigurationsComponent: Error getting ${modelName} items:`, error);
5973
+ resolve([]);
5974
+ }
5975
+ });
5976
+ });
5977
+ }
5976
5978
  async clearAllRelationshipConfigs() {
5977
5979
  if (!this.hasRelationshipConfig) {
5978
5980
  this.snackBar.open('RelationshipConfig model not available in schema', 'Dismiss', { duration: 3000 });