@snteam/amplify-angular-core 1.0.46 → 1.0.48

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