@zambon-dev/ui 1.2.1 → 1.3.0

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.
package/CHANGELOG.md CHANGED
@@ -23,6 +23,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
23
 
24
24
  ### ⚠ Breaking Changes / Migration
25
25
 
26
+ ## [1.3.0] - 2026-10-31
27
+
28
+ ### Added
29
+
30
+ - **A details view can depend on the record.** A view's route `data` takes `visibleWhen`, which
31
+ lists the view only for the records it accepts, and `enabledWhen`, which lists it for all of them
32
+ but lets it be chosen only for those. Both receive the record, its ID and the details route, may
33
+ call `inject()`, and may answer with an `Observable`. They run again on every record the data
34
+ provider emits, so a status change updates the Views menu at once. When the view on screen
35
+ becomes hidden or disabled, the tab goes back to its first view. `IDetailsViewRouteData` types a
36
+ view's route `data`, and [the details views guide](../../docs/guides/details-views.md) lists
37
+ every key.
38
+
39
+ ## [1.2.2] - 2026-10-30
40
+
41
+ ### Fixed
42
+
43
+ - **A field shows the server's validation message as soon as the answer arrives.**
44
+ `lib-form-input-group` read its control's errors and touched state straight from the control,
45
+ which is not a signal. Under `OnPush` nothing told it when they changed from outside the field.
46
+ So when a save came back with a 400, the input turned red, but the message stayed hidden until
47
+ the user typed in the field again. The group now follows the control's events. This also covers
48
+ `lib-catalog-select`, which draws its field inside the group.
49
+ - **A save that marks every field as touched shows the required messages.** Same cause, same fix.
50
+
26
51
  ## [1.2.1] - 2026-10-27
27
52
 
28
53
  ### Added
@@ -1,9 +1,9 @@
1
1
  import * as i0 from "@angular/core";
2
- import { ApplicationRef, Component, EventEmitter, Inject, Injectable, InjectionToken, Input, NgModule, Output, ViewChild, afterEveryRender, computed, effect, forwardRef, inject, input, model, output, signal, viewChild } from "@angular/core";
2
+ import { ApplicationRef, Component, EventEmitter, Inject, Injectable, InjectionToken, Injector, Input, NgModule, Output, ViewChild, afterEveryRender, computed, effect, forwardRef, inject, input, model, output, runInInjectionContext, signal, viewChild } from "@angular/core";
3
3
  import { toObservable, toSignal } from "@angular/core/rxjs-interop";
4
4
  import * as i2 from "@zambon-dev/ui/library";
5
5
  import { ButtonComponent as ButtonComponent$1, DataGridConfigsProvider, DataGridDataset, DataProviderService, DateValidators, DisplayControls, FormService, GroupContainerComponent, ModalComponent, MultiEditorComponent, MultiEditorDataset, MultiSelectComponent, MultiSelectResultDataset, RibbonButtonComponent, RibbonComponent, RibbonGroupChild, RibbonGroupComponent, RouterFormatter } from "@zambon-dev/ui/library";
6
- import { ReplaySubject, Subject, filter, map, of, skip, startWith, switchMap, take, takeUntil, tap, throwError } from "rxjs";
6
+ import { ReplaySubject, Subject, catchError, combineLatest, filter, isObservable, map, of, skip, startWith, switchMap, take, takeUntil, tap, throwError } from "rxjs";
7
7
  import { __decorate } from "tslib";
8
8
  import * as i1$1 from "@angular/common";
9
9
  import { NgClass, NgTemplateOutlet } from "@angular/common";
@@ -2976,11 +2976,14 @@ var ButtonViewsComponent = class ButtonViewsComponent extends BaseButton {
2976
2976
  detailsViewRoute = input(null, ...ngDevMode ? [{ debugName: "detailsViewRoute" }] : /* istanbul ignore next */ []);
2977
2977
  baseUrlPath;
2978
2978
  dataProviderService = inject(DataProviderService, { optional: true });
2979
+ hasViewStates = false;
2980
+ injector = inject(Injector);
2979
2981
  isInternalNavigation = false;
2980
2982
  router = inject(Router);
2981
2983
  selectedViewId = signal(void 0, ...ngDevMode ? [{ debugName: "selectedViewId" }] : /* istanbul ignore next */ []);
2982
2984
  tabService = inject(TabService);
2983
2985
  tabViewService = inject(TabViewService);
2986
+ viewStates = /* @__PURE__ */ new Map();
2984
2987
  get hasOptions() {
2985
2988
  return this.options().some((option) => (option.isVisible ?? true) && (option.allowedActions === void 0 || option.allowedActions.length === 0 || option.isAccessAllowed === true || option.isAccessAllowed === void 0 && option.allowedActions?.length > 0));
2986
2989
  }
@@ -3002,23 +3005,38 @@ var ButtonViewsComponent = class ButtonViewsComponent extends BaseButton {
3002
3005
  ngOnInit() {
3003
3006
  const detailsViewRoute = this.detailsViewRoute();
3004
3007
  if (detailsViewRoute) {
3005
- this.options.set(detailsViewRoute.routeConfig?.children?.filter((route) => !!route.data && route.data["ignoreRoute"] !== true)?.map((route) => {
3008
+ const viewRoutes = detailsViewRoute.routeConfig?.children?.filter((route) => !!route.data && route.data["ignoreRoute"] !== true) ?? [];
3009
+ this.options.set(viewRoutes.map((route) => {
3006
3010
  const data = route.data ?? {};
3007
3011
  const option = {
3008
3012
  id: route.path ?? "",
3009
3013
  isDisabled: false,
3010
3014
  isVisible: true,
3011
- label: data["title"] ?? ""
3015
+ label: data.title ?? ""
3012
3016
  };
3013
- const icon = data["icon"];
3017
+ const icon = data.icon;
3014
3018
  if (icon) option.icon = icon;
3015
- const allowedActions = data["allowedActions"];
3019
+ const allowedActions = data.allowedActions;
3016
3020
  if (allowedActions && allowedActions.length > 0) option.allowedActions = allowedActions;
3017
3021
  return option;
3018
- }) ?? []);
3022
+ }));
3023
+ const conditionalViews = viewRoutes.slice(1).map((route) => {
3024
+ const data = route.data ?? {};
3025
+ return {
3026
+ enabledWhen: data.enabledWhen,
3027
+ id: route.path ?? "",
3028
+ visibleWhen: data.visibleWhen
3029
+ };
3030
+ }).filter((view) => !!view.visibleWhen || !!view.enabledWhen);
3031
+ conditionalViews.forEach((view) => this.viewStates.set(view.id, {
3032
+ isEnabled: !view.enabledWhen,
3033
+ isVisible: !view.visibleWhen
3034
+ }));
3035
+ this.applyViewStates();
3019
3036
  const url = RouteHelper.getRouteURL(detailsViewRoute);
3020
3037
  this.baseUrlPath = url;
3021
3038
  if ((detailsViewRoute.children[0]?.url?.map((segment) => segment.path)?.join("/") ?? "") === this.defaultViewId) this.changeSelectedView(this.defaultViewId);
3039
+ if (conditionalViews.length > 0) this.watchViewConditions(detailsViewRoute, conditionalViews);
3022
3040
  }
3023
3041
  this.router.events.pipe(filter((event) => event instanceof NavigationEnd), takeUntil(this.destroy$)).subscribe((event) => {
3024
3042
  if (this.detailsViewRoute()) {
@@ -3030,6 +3048,7 @@ var ButtonViewsComponent = class ButtonViewsComponent extends BaseButton {
3030
3048
  if (!this.isInternalNavigation) {
3031
3049
  if (this.selectedViewId() !== activeViewId) this.changeSelectedView(activeViewId);
3032
3050
  } else this.isInternalNavigation = false;
3051
+ this.leaveUnavailableView();
3033
3052
  }
3034
3053
  }
3035
3054
  });
@@ -3046,19 +3065,65 @@ var ButtonViewsComponent = class ButtonViewsComponent extends BaseButton {
3046
3065
  this.tabService.replaceCurrentTabSubView(this.baseUrlPath, tab);
3047
3066
  }
3048
3067
  }
3068
+ applyViewStates() {
3069
+ const selectedViewId = this.selectedViewId();
3070
+ this.options.update((options) => options.map((option) => {
3071
+ const state = this.viewStates.get(option.id);
3072
+ const isVisible = state?.isVisible ?? true;
3073
+ const isDisabled = option.id === selectedViewId || !(state?.isEnabled ?? true);
3074
+ return option.isVisible === isVisible && option.isDisabled === isDisabled ? option : {
3075
+ ...option,
3076
+ isDisabled,
3077
+ isVisible
3078
+ };
3079
+ }));
3080
+ }
3049
3081
  changeSelectedView(viewId) {
3050
3082
  this.selectedViewId.set(viewId);
3051
3083
  this.tabViewService.setActiveView(viewId ?? "");
3052
- this.options.update((options) => options.map((option) => option.isDisabled === (option.id === viewId) ? option : {
3053
- ...option,
3054
- isDisabled: option.id === viewId
3055
- }));
3084
+ this.applyViewStates();
3085
+ }
3086
+ evaluateCondition(condition, detailsViewRoute, entity) {
3087
+ if (!condition) return of(true);
3088
+ try {
3089
+ const result = runInInjectionContext(this.injector, () => condition({
3090
+ entity,
3091
+ entityID: this.dataProviderService?.entityID,
3092
+ route: detailsViewRoute
3093
+ }));
3094
+ return (isObservable(result) ? result : of(result)).pipe(map((answer) => answer === true), catchError(() => of(false)));
3095
+ } catch {
3096
+ return of(false);
3097
+ }
3056
3098
  }
3057
3099
  getActiveOption(url) {
3058
3100
  const option = url.replace(this.baseUrlPath ?? "", "").substring(1);
3059
3101
  if (this.options().some((o) => o.id === option)) return option;
3060
3102
  return this.defaultViewId;
3061
3103
  }
3104
+ leaveUnavailableView() {
3105
+ const selectedViewId = this.selectedViewId();
3106
+ if (!this.hasViewStates || selectedViewId === void 0 || selectedViewId === this.defaultViewId) return;
3107
+ const state = this.viewStates.get(selectedViewId);
3108
+ if (!state || state.isVisible && state.isEnabled) return;
3109
+ const currentRoute = RouteHelper.getRouteByData(this.router.routerState.root.snapshot, FRAMEWORK_VIEW_TYPE, FrameworkViewType.Details);
3110
+ if (!currentRoute || currentRoute.routeConfig !== this.detailsViewRoute()?.routeConfig || RouteHelper.getRouteURL(currentRoute) !== this.baseUrlPath) return;
3111
+ this.onViewClicked(this.defaultViewId);
3112
+ }
3113
+ watchViewConditions(detailsViewRoute, conditionalViews) {
3114
+ (this.dataProviderService?.getModel$() ?? of(null)).pipe(switchMap((entity) => combineLatest(conditionalViews.map((view) => combineLatest([this.evaluateCondition(view.visibleWhen, detailsViewRoute, entity), this.evaluateCondition(view.enabledWhen, detailsViewRoute, entity)]).pipe(map(([isVisible, isEnabled]) => ({
3115
+ id: view.id,
3116
+ state: {
3117
+ isEnabled,
3118
+ isVisible
3119
+ }
3120
+ })))))), takeUntil(this.destroy$)).subscribe((answers) => {
3121
+ answers.forEach((answer) => this.viewStates.set(answer.id, answer.state));
3122
+ this.hasViewStates = true;
3123
+ this.applyViewStates();
3124
+ this.leaveUnavailableView();
3125
+ });
3126
+ }
3062
3127
  static ɵfac = i0.ɵɵngDeclareFactory({
3063
3128
  minVersion: "12.0.0",
3064
3129
  version: "22.2.0",