diff --git a/ui-ngx/src/app/core/http/widget.service.ts b/ui-ngx/src/app/core/http/widget.service.ts index 9dcda4ef8a..6b53e4d0cb 100644 --- a/ui-ngx/src/app/core/http/widget.service.ts +++ b/ui-ngx/src/app/core/http/widget.service.ts @@ -236,6 +236,15 @@ export class WidgetService { return this.http.get>(url, defaultHttpOptionsFromConfig(config)); } + public addWidgetFqnToWidgetBundle(widgetsBundleId: string, fqn: string, config?: RequestConfig) { + return this.getBundleWidgetTypeFqns(widgetsBundleId, config).pipe( + mergeMap(widgetsBundleFqn => { + widgetsBundleFqn.push(fqn); + return this.updateWidgetsBundleWidgetFqns(widgetsBundleId, widgetsBundleFqn, config); + }) + ); + } + public getWidgetTemplate(widgetTypeParam: widgetType, config?: RequestConfig): Observable { const templateWidgetType = widgetTypesData.get(widgetTypeParam); diff --git a/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts b/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts index e91375e75e..e71c4df0d5 100644 --- a/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts +++ b/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts @@ -297,7 +297,7 @@ export class ImportExportService { ); } - public importWidgetType(): Observable { + public importWidgetType(): Observable { return this.openImportDialog('widget-type.import', 'widget-type.widget-type-file').pipe( mergeMap((widgetTypeDetails: WidgetTypeDetails) => { if (!this.validateImportedWidgetTypeDetails(widgetTypeDetails)) { @@ -309,9 +309,7 @@ export class ImportExportService { return this.widgetService.saveImportedWidgetTypeDetails(widgetTypeDetails); } }), - catchError((err) => { - return of(null); - }) + catchError(() => of(null)) ); } diff --git a/ui-ngx/src/app/modules/home/pages/widget/widget-editor.component.ts b/ui-ngx/src/app/modules/home/pages/widget/widget-editor.component.ts index d3ba1d1daa..cc382c420a 100644 --- a/ui-ngx/src/app/modules/home/pages/widget/widget-editor.component.ts +++ b/ui-ngx/src/app/modules/home/pages/widget/widget-editor.component.ts @@ -52,11 +52,11 @@ import { SaveWidgetTypeAsDialogComponent, SaveWidgetTypeAsDialogResult } from '@home/pages/widget/save-widget-type-as-dialog.component'; -import { forkJoin, Subscription } from 'rxjs'; +import { forkJoin, mergeMap, of, Subscription, throwError } from 'rxjs'; import { ResizeObserver } from '@juggle/resize-observer'; import { widgetEditorCompleter } from '@home/pages/widget/widget-editor.models'; import { Observable } from 'rxjs/internal/Observable'; -import { map, tap } from 'rxjs/operators'; +import { catchError, map, tap } from 'rxjs/operators'; import { beautifyCss, beautifyHtml, beautifyJs } from '@shared/models/beautify.models'; import Timeout = NodeJS.Timeout; @@ -543,7 +543,20 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe private commitSaveWidget() { const id = (this.widgetTypeDetails && this.widgetTypeDetails.id) ? this.widgetTypeDetails.id : undefined; const createdTime = (this.widgetTypeDetails && this.widgetTypeDetails.createdTime) ? this.widgetTypeDetails.createdTime : undefined; - this.widgetService.saveWidgetTypeDetails(this.widget, id, createdTime).subscribe({ + this.widgetService.saveWidgetTypeDetails(this.widget, id, createdTime).pipe( + mergeMap((widgetTypeDetails) => { + const widgetsBundleId = this.route.snapshot.params.widgetsBundleId as string; + if (widgetsBundleId) { + return this.widgetService.addWidgetFqnToWidgetBundle(widgetsBundleId, widgetTypeDetails.fqn).pipe( + map(() => widgetTypeDetails), + catchError((error) => this.widgetService.deleteWidgetType(widgetTypeDetails.id.id).pipe( + mergeMap(() => throwError(() => error)) + )) + ); + } + return of(widgetTypeDetails); + }) + ).subscribe({ next: (widgetTypeDetails) => { this.saveWidgetPending = false; if (!this.widgetTypeDetails?.id) { diff --git a/ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-widgets.component.html b/ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-widgets.component.html index 2d95fd1fdb..fcd36d6f00 100644 --- a/ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-widgets.component.html +++ b/ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-widgets.component.html @@ -27,6 +27,23 @@ {{ widgetsBundle.title }}: {{ 'widget.widgets' | translate }} + + + + +