mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
AAE-40136 Migrate locale settings to signals (#11361)
This commit is contained in:
+4
-1
@@ -22,12 +22,14 @@ import { DateCloudFilterType } from '../../models/date-cloud-filter.model';
|
||||
import { DateRangeFilterService } from './date-range-filter.service';
|
||||
import { mockFilterProperty } from '../mock/date-range-filter.mock';
|
||||
import { add, endOfDay } from 'date-fns';
|
||||
import { enUS } from 'date-fns/locale';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatSelectHarness } from '@angular/material/select/testing';
|
||||
import { MatFormFieldHarness } from '@angular/material/form-field/testing';
|
||||
import { MatDateRangeInputHarness } from '@angular/material/datepicker/testing';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
import { MAT_DATE_LOCALE } from '@angular/material/core';
|
||||
|
||||
describe('DateRangeFilterComponent', () => {
|
||||
let component: DateRangeFilterComponent;
|
||||
@@ -37,7 +39,8 @@ describe('DateRangeFilterComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [NoopTranslateModule, DateRangeFilterComponent]
|
||||
imports: [NoopTranslateModule, DateRangeFilterComponent],
|
||||
providers: [{ provide: MAT_DATE_LOCALE, useValue: enUS }]
|
||||
});
|
||||
fixture = TestBed.createComponent(DateRangeFilterComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
+11
-10
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, DestroyRef, EventEmitter, inject, Input, OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation } from '@angular/core';
|
||||
import { Component, DestroyRef, effect, EventEmitter, inject, Input, OnChanges, Output, SimpleChanges, ViewEncapsulation } from '@angular/core';
|
||||
import { AbstractControl, FormBuilder, FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
||||
import { DateAdapter } from '@angular/material/core';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
@@ -29,7 +29,7 @@ import {
|
||||
ProcessFilterProperties,
|
||||
ProcessSortFilterProperty
|
||||
} from '../../models/process-filter-cloud.model';
|
||||
import { DateFnsUtils, IconComponent, TranslationService, UserPreferencesService, UserPreferenceValues } from '@alfresco/adf-core';
|
||||
import { DateFnsUtils, IconComponent, TranslationService, UserPreferencesService } from '@alfresco/adf-core';
|
||||
import { ProcessFilterCloudService } from '../../services/process-filter-cloud.service';
|
||||
import { ProcessFilterDialogCloudComponent } from '../process-filter-dialog/process-filter-dialog-cloud.component';
|
||||
import { ProcessCloudService } from '../../../services/process-cloud.service';
|
||||
@@ -101,7 +101,7 @@ interface ProcessFilterFormProps {
|
||||
styleUrls: ['./edit-process-filter-cloud.component.scss'],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class EditProcessFilterCloudComponent implements OnInit, OnChanges {
|
||||
export class EditProcessFilterCloudComponent implements OnChanges {
|
||||
/** The name of the application. */
|
||||
@Input()
|
||||
appName: string = '';
|
||||
@@ -228,13 +228,14 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges {
|
||||
private processFilterCloudService: ProcessFilterCloudService,
|
||||
private appsProcessCloudService: AppsProcessCloudService,
|
||||
private processCloudService: ProcessCloudService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.userPreferencesService
|
||||
.select(UserPreferenceValues.Locale)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((locale) => this.dateAdapter.setLocale(locale));
|
||||
) {
|
||||
// Use effect to react to locale signal changes (must be in injection context)
|
||||
effect(() => {
|
||||
const locale = this.userPreferencesService.localeSignal();
|
||||
if (locale) {
|
||||
this.dateAdapter.setLocale(DateFnsUtils.getLocaleFromString(locale));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
|
||||
+11
-8
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DestroyRef, Directive, EventEmitter, inject, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
|
||||
import { DestroyRef, Directive, effect, EventEmitter, inject, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
|
||||
import { AssignmentType, FilterOptions, TaskFilterAction, TaskFilterProperties, TaskStatusFilter } from '../../models/filter-cloud.model';
|
||||
import { TaskCloudService } from './../../../services/task-cloud.service';
|
||||
import { AppsProcessCloudService } from './../../../../app/services/apps-process-cloud.service';
|
||||
@@ -24,7 +24,7 @@ import { AbstractControl, UntypedFormBuilder, UntypedFormGroup } from '@angular/
|
||||
import { debounceTime, filter, finalize, switchMap } from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs';
|
||||
import { DateAdapter } from '@angular/material/core';
|
||||
import { DateFnsUtils, TranslationService, UserPreferencesService, UserPreferenceValues } from '@alfresco/adf-core';
|
||||
import { DateFnsUtils, TranslationService, UserPreferencesService } from '@alfresco/adf-core';
|
||||
import { TaskFilterDialogCloudComponent } from '../task-filter-dialog/task-filter-dialog-cloud.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { IdentityUserModel } from '../../../../people/models/identity-user.model';
|
||||
@@ -55,7 +55,7 @@ const ORDER_PROPERTY = 'order';
|
||||
|
||||
@Directive()
|
||||
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
||||
export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnChanges {
|
||||
export abstract class BaseEditTaskFilterCloudComponent<T> implements OnChanges {
|
||||
public static ACTIONS_DISABLED_BY_DEFAULT = [ACTION_SAVE, ACTION_DELETE];
|
||||
|
||||
/** (required) Name of the app. */
|
||||
@@ -145,11 +145,14 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
|
||||
protected formBuilder = inject(UntypedFormBuilder);
|
||||
protected dateAdapter = inject<DateAdapter<Date>>(DateAdapter);
|
||||
|
||||
ngOnInit() {
|
||||
this.userPreferencesService
|
||||
.select(UserPreferenceValues.Locale)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((locale) => this.dateAdapter.setLocale(locale));
|
||||
constructor() {
|
||||
// Use effect to react to locale signal changes (must be in injection context)
|
||||
effect(() => {
|
||||
const locale = this.userPreferencesService.localeSignal();
|
||||
if (locale) {
|
||||
this.dateAdapter.setLocale(DateFnsUtils.getLocaleFromString(locale));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
|
||||
Reference in New Issue
Block a user