Unable to Download Example CSV

Details

Type: SpringBot
Bot Version: [v2.4.0.0]
Browser / OS: [Chrome/Windows 10]

Description

On the CRUD List, I want to do an import, however, I can’t download the example CSV template. This problem is replicated in a new app generated from the latest version of Springbot.

Attempted Resolutions

Captured the console error then reported it as a bug.

Hi @Afriana_Putra_I_B,

Thanks for getting in touch.

The download template functionality has the following steps.

  1. Click event is emitted in the collection.component.ts.

    emitDownloadCsvExample() {
    	this.collectionActionEventEmitter.emit({
    		actionName: 'Import',
    	});
    }
    
  2. This is then parsed up to the parent component where this event can be utilised. The method handling the collectionActionClick event below.

    <cb-collection #childCollection
    	[models]="admins | async"
    	[modelCount]="adminsCount"
    	[pageIndex]="pageIndex"
    	[isLastPage]="isLastPage"
    	[headerOptions]="headerOptions"
    	[expandOptions]="expandOptions"
    	[enableExpands]="enableExpands"
    	[filterQuestions]="filterQuestions"
    	[itemActions]="itemActions"
    	[collectionActions]="collectionActions"
    	[multipleItemsActions]="multipleItemsActions"
    	[loadingType]="loadingType"
    	[hideSearchBar]="!searchFields.length"
    	(itemActionClick)="onItemActionClicked($event)"
    	(collectionActionClick)="onCollectionActionClicked($event)"
    	(multipleItemsActionClick)="onMultipleItemsActionClicked($event)"
    	(sort)="onCollectionSort($event)"
    	(filter)="onCollectionFilter($event)"
    	(search)="onCollectionSearch($event)"
    	(first)="onFirstPageRequested()"
    	(prev)="onPrevPageRequested()"
    	(next)="onNextPageRequested()"
    	(last)="onLastPageRequested()">
    </cb-collection>
    
  3. In the case of the CRUD list component, the event is handled based on its action name.

    onCollectionActionClicked(event: { actionName: string, payload?: any }) {
    	// % protected region % [Add any additional onCollectionActionClicked logic before the main body here] off begin
    	// % protected region % [Add any additional onCollectionActionClicked logic before the main body here] end
    
    	// Overwriting any of the default logic for an action can be done by adding a check in the protected region at the start of this method
    	// and implementing different logic there.
    
    	if (event.actionName === CollectionActionEnum.Create) {
    		this.onCreateClicked();
    		return;
    	}
    
    	if (event.actionName === CollectionActionEnum.Export) {
    		// passing these fields to the export function will cause it to use the export all excluding action,
    		// and exclude no entities, as models is empty
    		this.onExportClicked(false, []);
    		return;
    	}
    
    	if (event.actionName === CollectionActionEnum.Import) {
    		this.onImportClicked(event.payload.file);
    		return;
    	}
    
    	// % protected region % [Add any additional onCollectionActionClicked logic after the main body here] off begin
    	// % protected region % [Add any additional onCollectionActionClicked logic after the main body here] end
    }
    

    For CSV import, this falls into the onImportClicked method. If the download template button is clicked, there is no payload.file

  4. In this onImportClicked method, if there is no payload. The example CSV is downloaded instead.

    onImportClicked(file?: any) {
    		// % protected region % [Customise onImportClicked logic here] off begin
    		if (file) {
    			this.store.dispatch(new modelAction.AdminAction(
    				modelAction.AdminModelActionTypes.IMPORT_ADMINS,
    				{
    					file: file,
    				},
    				[new modelAction.AdminAction(
    					modelAction.AdminModelActionTypes.FETCH_ADMIN_WITH_QUERY,
    					{
    						queryParams: this.queryParams,
    						collectionId: this.collectionId
    					},
    					[
    						new modelAction.AdminAction(
    							modelAction.AdminModelActionTypes.COUNT_ADMINS,
    							null
    						)
    					]
    				)]
    			));
    		} else {
    			// This is the API Route for the import example CSV, so opening it in a new tab will trigger a download
    			window.open(environment.API_URL + '/api/admin/example-import');
    		}
    		// % protected region % [Customise onImportClicked logic here] end
    	}
    	```
    
    

The import thing here is that the event name matches in both content and case to enable this chain of actions to be successful.

Hi @Afriana_Putra_I_B,

The bot issue has now been fixed in SpringBot Release 2.4.0.1.

Once you upgrade you will be able to download the example CSV again.

Thank you for your patience.