Skip to content

Commit ed6c7d5

Browse files
Junjiequannitrosx
andauthored
fix: update shared filter module to use Luxon date adapter and adjust date formats (#2036)
## Description - Fixed Angular Native Date module overriding Luxon DateAdapter (caused by JsonFormsAngularMaterial library) - Centered the dash in the date input box - Added missing column fields to user external settings ## Motivation Background on use case, changes needed ## Fixes: Please provide a list of the fixes implemented in this PR * Items added ## Changes: Please provide a list of the changes implemented by this PR * changes made ## Tests included - [ ] Included for each change/fix? - [ ] Passing? (Merge will not be approved unless this is checked) ## Documentation - [ ] swagger documentation updated \[required\] - [ ] official documentation updated \[nice-to-have\] ### official documentation info If you have updated the official documentation, please provide PR # and URL of the pages where the updates are included ## Backend version - [ ] Does it require a specific version of the backend - which version of the backend is required: ## Summary by Sourcery Enforce the Luxon date adapter with dynamic date formats in SharedFilterModule, refine the date range input styling, and include missing column type and format settings in table components. Bug Fixes: - Prevent Angular Native Date module from overriding the Luxon adapter by moving the date adapter and MAT_DATE_FORMATS provider into SharedFilterModule and removing the redundant provider from AppModule. Enhancements: - Center and color the date range input separator in SharedFilterComponent to match the primary theme. - Include 'type' and 'format' properties when saving column settings in ProposalTableComponent and DatasetTableComponent. Chores: - Refactor shared module imports to ensure SharedFilterModule is imported exactly once. --------- Co-authored-by: Max Novelli <[email protected]>
1 parent 3f71ca2 commit ed6c7d5

File tree

7 files changed

+43
-26
lines changed

7 files changed

+43
-26
lines changed

cypress/e2e/datasets/datasets-metadata.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ describe("Datasets", () => {
400400
});
401401
});
402402

403-
describe("Different metadata types", () => {
403+
describe.only("Different metadata types", () => {
404404
it("should be able to add a metadata entry with type 'date'", () => {
405405
const newMetadataName = "Cypress dataset date metadata";
406-
const metaDataInvalidValue = "20";
406+
const metaDataInvalidValue = "20ab";
407407
const metadata = {
408408
value: "2025-03-05 10:48",
409409
name: "date_metadata",

src/app/app.module.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import { StoreModule } from "@ngrx/store";
1616
import { ApiModule, Configuration } from "@scicatproject/scicat-sdk-ts-angular";
1717
import { routerReducer } from "@ngrx/router-store";
1818
import { extModules } from "./build-specifics";
19-
import { MAT_DATE_FORMATS } from "@angular/material/core";
20-
2119
import { MatProgressSpinnerModule } from "@angular/material/progress-spinner";
2220
import {
2321
MAT_FORM_FIELD_DEFAULT_OPTIONS,
@@ -130,23 +128,6 @@ const apiConfigurationFn = (
130128
},
131129
deps: [AppConfigService],
132130
},
133-
{
134-
provide: MAT_DATE_FORMATS,
135-
useFactory: (appConfigService: AppConfigService) => {
136-
const base =
137-
appConfigService.getConfig().dateFormat || "yyyy-MM-dd HH:mm";
138-
return {
139-
parse: { dateInput: base },
140-
display: {
141-
dateInput: base,
142-
monthYearLabel: "MMM yyyy",
143-
dateA11yLabel: "LL",
144-
monthYearA11yLabel: "MMMM yyyy",
145-
},
146-
};
147-
},
148-
deps: [AppConfigService],
149-
},
150131
AuthService,
151132
AppThemeService,
152133
Title,

src/app/datasets/dataset-table/dataset-table.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,15 @@ export class DatasetTableComponent implements OnInit, OnDestroy {
214214
saveTableSettings(setting: ITableSetting) {
215215
this.pending = true;
216216
const columnsSetting = setting.columnSetting.map((column, index) => {
217-
const { name, display, width, type } = column;
217+
const { name, display, width, type, format } = column;
218218

219219
return {
220220
name,
221221
enabled: !!(display === "visible"),
222222
order: index,
223223
width,
224224
type,
225+
format,
225226
};
226227
});
227228
this.store.dispatch(

src/app/proposals/proposal-table/proposal-table.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,15 @@ export class ProposalTableComponent implements OnInit, OnDestroy {
243243
saveTableSettings(setting: ITableSetting) {
244244
this.pending = true;
245245
const columnsSetting = setting.columnSetting.map((column) => {
246-
const { name, display, index, width } = column;
246+
const { name, display, index, width, type, format } = column;
247247

248248
return {
249249
name,
250250
enabled: !!(display === "visible"),
251251
order: index,
252252
width,
253+
type,
254+
format,
253255
};
254256
});
255257

src/app/shared/modules/shared-filter/shared-filter.component.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
@include mat.form-field-density(-5);
77
}
88

9+
::ng-deep .mat-date-range-input-wrapper {
10+
min-width: 100px;
11+
}
12+
13+
::ng-deep .mat-date-range-input-separator {
14+
color: var(--theme-primary-default) !important;
15+
}
16+
917
.mat-mdc-form-field {
1018
width: 100%;
1119
}

src/app/shared/modules/shared-filter/shared-filter.module.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ import { SharedFilterComponent } from "./shared-filter.component";
99
import { ReactiveFormsModule } from "@angular/forms";
1010
import { MatFormFieldModule } from "@angular/material/form-field";
1111
import { MultiSelectFilterComponent } from "../filters/multiselect-filter.component";
12-
import { MatOptionModule } from "@angular/material/core";
12+
import { MAT_DATE_FORMATS, MatOptionModule } from "@angular/material/core";
1313
import { MatChipsModule } from "@angular/material/chips";
1414
import { NgxNumericRangeFormFieldModule } from "../numeric-range/ngx-numeric-range-form-field.module";
1515
import { MatAutocompleteModule } from "@angular/material/autocomplete";
1616
import { MatDividerModule } from "@angular/material/divider";
1717
import { MatCheckboxModule } from "@angular/material/checkbox";
1818
import { MatButtonModule } from "@angular/material/button";
1919
import { PipesModule } from "shared/pipes/pipes.module";
20+
import { provideLuxonDateAdapter } from "@angular/material-luxon-adapter";
21+
import { AppConfigService } from "app-config.service";
2022

2123
@NgModule({
2224
declarations: [SharedFilterComponent, MultiSelectFilterComponent],
@@ -38,6 +40,29 @@ import { PipesModule } from "shared/pipes/pipes.module";
3840
MatChipsModule,
3941
NgxNumericRangeFormFieldModule,
4042
],
43+
// Force shared-filter to use the Luxon adapter.
44+
// Needed because JsonFormsAngularMaterialModule brings in MatNativeDateModule,
45+
// which otherwise switches the DateAdapter to the native one.
46+
providers: [
47+
provideLuxonDateAdapter(),
48+
{
49+
provide: MAT_DATE_FORMATS,
50+
useFactory: (appConfigService: AppConfigService) => {
51+
const base =
52+
appConfigService.getConfig().dateFormat || "yyyy-MM-dd HH:mm";
53+
return {
54+
parse: { dateInput: base },
55+
display: {
56+
dateInput: base,
57+
monthYearLabel: "MMM yyyy",
58+
dateA11yLabel: "LL",
59+
monthYearA11yLabel: "MMMM yyyy",
60+
},
61+
};
62+
},
63+
deps: [AppConfigService],
64+
},
65+
],
4166
exports: [SharedFilterComponent, MultiSelectFilterComponent],
4267
})
4368
export class SharedFilterModule {}

src/app/shared/shared.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import { JsonformsAccordionRendererService } from "./services/jsonforms-accordio
4242
SearchParametersDialogModule,
4343
CommonModule,
4444
FormsModule,
45-
SharedFilterModule,
4645
SharedTableModule,
4746
ScientificMetadataTreeModule,
4847
DynamicMatTableModule.forRoot({}),
@@ -51,6 +50,7 @@ import { JsonformsAccordionRendererService } from "./services/jsonforms-accordio
5150
JsonFormsModule,
5251
JsonFormsAngularMaterialModule,
5352
JsonFormsCustomRenderersModule,
53+
SharedFilterModule,
5454
],
5555
providers: [
5656
ConfigService,
@@ -72,7 +72,6 @@ import { JsonformsAccordionRendererService } from "./services/jsonforms-accordio
7272
TableModule,
7373
CommonModule,
7474
FormsModule,
75-
SharedFilterModule,
7675
SharedTableModule,
7776
ScientificMetadataTreeModule,
7877
DynamicMatTableModule,
@@ -81,6 +80,7 @@ import { JsonformsAccordionRendererService } from "./services/jsonforms-accordio
8180
JsonFormsModule,
8281
JsonFormsAngularMaterialModule,
8382
JsonFormsCustomRenderersModule,
83+
SharedFilterModule,
8484
],
8585
})
8686
export class SharedScicatFrontendModule {}

0 commit comments

Comments
 (0)