UI: Fixed widget bundle and widget editor after review

This commit is contained in:
Vladyslav_Prykhodko 2023-10-23 16:43:57 +03:00
parent e69c986d53
commit d23c6c1047
4 changed files with 14 additions and 12 deletions

View File

@ -52,11 +52,11 @@ import {
SaveWidgetTypeAsDialogComponent,
SaveWidgetTypeAsDialogResult
} from '@home/pages/widget/save-widget-type-as-dialog.component';
import { forkJoin, mergeMap, of, Subscription, throwError } from 'rxjs';
import { forkJoin, mergeMap, of, Subscription } from 'rxjs';
import { ResizeObserver } from '@juggle/resize-observer';
import { widgetEditorCompleter } from '@home/pages/widget/widget-editor.models';
import { Observable } from 'rxjs/internal/Observable';
import { catchError, map, tap } from 'rxjs/operators';
import { map, tap } from 'rxjs/operators';
import { beautifyCss, beautifyHtml, beautifyJs } from '@shared/models/beautify.models';
import Timeout = NodeJS.Timeout;
@ -566,12 +566,9 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
this.widgetService.saveWidgetTypeDetails(this.widget, id, createdTime).pipe(
mergeMap((widgetTypeDetails) => {
const widgetsBundleId = this.route.snapshot.params.widgetsBundleId as string;
if (widgetsBundleId) {
if (widgetsBundleId && !id) {
return this.widgetService.addWidgetFqnToWidgetBundle(widgetsBundleId, widgetTypeDetails.fqn).pipe(
map(() => widgetTypeDetails),
catchError((error) => this.widgetService.deleteWidgetType(widgetTypeDetails.id.id).pipe(
mergeMap(() => throwError(() => error))
))
map(() => widgetTypeDetails)
);
}
return of(widgetTypeDetails);

View File

@ -28,7 +28,7 @@
<span class="mat-headline-5">{{ widgetsBundle.title }}: {{ 'widget.widgets' | translate }}</span>
<span fxFlex></span>
<button mat-icon-button [disabled]="isLoading$ | async"
*ngIf="editMode"
*ngIf="!isReadOnly"
matTooltip="{{ 'widget.add-new-widget' | translate }}"
matTooltipPosition="above"
[matMenuTriggerFor]="addWidgetMenu">

View File

@ -202,13 +202,18 @@ export class WidgetsBundleWidgetsComponent extends PageComponent implements OnIn
this.importExport.importWidgetType().subscribe(
(widgetType) => {
if (widgetType) {
if (this.widgets.some(widget => widget.id.id === widgetType.id.id)) {
const isExistWidget = this.widgets.some(widget => widget.id.id === widgetType.id.id);
if (isExistWidget) {
this.widgets = this.widgets.map(widget => widget.id.id !== widgetType.id.id ? widget : widgetType);
} else {
this.widgets.push(widgetType);
}
if (this.editMode) {
this.isDirty = true;
this.cd.markForCheck();
} else if (!isExistWidget) {
this.widgetsService.addWidgetFqnToWidgetBundle(this.widgetsBundle.id.id, widgetType.fqn).subscribe(() => {});
}
}
}
);

View File

@ -4759,7 +4759,7 @@
"no-widgets-text": "No widgets found",
"management": "Widget management",
"editor": "Widget Editor",
"confirm-to-exit-editor-html": "You have unsaved default widget settings.<br>Are you sure you want to leave this page?",
"confirm-to-exit-editor-html": "You have unsaved widget settings.<br>Are you sure you want to leave this page?",
"widget-type-not-found": "Problem loading widget configuration.<br>Probably associated\n widget type was removed.",
"widget-type-load-error": "Widget wasn't loaded due to the following errors:",
"remove": "Remove widget",