Skip to content

Commit c5d2411

Browse files
fix: improve date validation for string type metadata (#1797)
## Description Fixes issues found in the dataset metadata while testing in develop server with more relevant data. ## Motivation There were bugs found in develop while testing and also some improvements needed. ## Fixes: Please provide a list of the fixes implemented in this PR * Fixes an issue where invalid dates were being considered valid * Full screen mode didn't show the menu if you click on the three dots. ## Changes: Please provide a list of the changes implemented by this PR * changes are only in the metadata view and the dynamic material table module ## 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 Bug Fixes: - Fixes an issue where invalid dates were being considered valid. ## Summary by Sourcery Improve date validation and metadata display in scientific metadata view New Features: - Added a method to generate human-readable names for metadata entries Bug Fixes: - Fixed invalid date validation to correctly identify and handle date strings - Resolved an issue with full-screen mode menu display Enhancements: - Refactored metadata name display logic to use a more consistent human-readable name generation - Improved date validation checks to be more robust
1 parent 9d0b06f commit c5d2411

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/app/shared/modules/dynamic-material-table/table/dynamic-mat-table.module.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ import { MatMenuModule } from "@angular/material/menu";
2727
import { MatTooltipModule } from "@angular/material/tooltip";
2828
import { MatRippleModule } from "@angular/material/core";
2929
import { TooltipComponent } from "../tooltip/tooltip.component";
30-
import { OverlayModule } from "@angular/cdk/overlay";
30+
import {
31+
FullscreenOverlayContainer,
32+
OverlayContainer,
33+
OverlayModule,
34+
} from "@angular/cdk/overlay";
3135
import { TooltipDirective } from "../tooltip/tooltip.directive";
3236
import { TemplateOrStringDirective } from "../tooltip/template-or-string.directive";
3337
import { FormsModule } from "@angular/forms";
@@ -71,6 +75,12 @@ const ExtensionsModule = [HeaderFilterModule, RowMenuModule];
7175
TooltipDirective,
7276
TemplateOrStringDirective,
7377
],
78+
providers: [
79+
{
80+
provide: OverlayContainer,
81+
useClass: FullscreenOverlayContainer,
82+
},
83+
],
7484
})
7585
export class DynamicMatTableModule {
7686
static forRoot(

src/app/shared/modules/scientific-metadata/metadata-view/metadata-view.component.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
OnChanges,
66
SimpleChange,
77
} from "@angular/core";
8-
import { DateTime } from "luxon";
98
import {
109
ScientificMetadataTableData,
1110
ScientificMetadata,
@@ -22,6 +21,7 @@ import { ReplaceUnderscorePipe } from "shared/pipes/replace-underscore.pipe";
2221
import { DatePipe, TitleCasePipe } from "@angular/common";
2322
import { LinkyPipe } from "ngx-linky";
2423
import { PrettyUnitPipe } from "shared/pipes/pretty-unit.pipe";
24+
import { DateTime } from "luxon";
2525
import { MetadataTypes } from "../metadata-edit/metadata-edit.component";
2626

2727
@Component({
@@ -83,14 +83,6 @@ export class MetadataViewComponent implements OnInit, OnChanges {
8383
header: "Name",
8484
name: "human_name",
8585
width: 250,
86-
customRender: (column, row) => {
87-
return (
88-
row[column.name] ||
89-
this.titleCase.transform(
90-
this.replaceUnderscore.transform(row.name),
91-
)
92-
);
93-
},
9486
},
9587
{
9688
name: "name",
@@ -161,12 +153,19 @@ export class MetadataViewComponent implements OnInit, OnChanges {
161153
public prettyUnit: PrettyUnitPipe,
162154
) {}
163155

156+
getHumanReadableName(name: string): string {
157+
return this.titleCase.transform(this.replaceUnderscore.transform(name));
158+
}
159+
164160
createMetadataArray(
165161
metadata: Record<string, any>,
166162
): ScientificMetadataTableData[] {
167163
const metadataArray: ScientificMetadataTableData[] = [];
168164
Object.keys(metadata).forEach((key) => {
169165
let metadataObject: ScientificMetadataTableData;
166+
const humanReadableName =
167+
metadata[key]["human_name"] || this.getHumanReadableName(key);
168+
170169
if (
171170
typeof metadata[key] === "object" &&
172171
"value" in (metadata[key] as ScientificMetadata)
@@ -175,7 +174,7 @@ export class MetadataViewComponent implements OnInit, OnChanges {
175174
name: key,
176175
value: metadata[key]["value"],
177176
unit: metadata[key]["unit"],
178-
human_name: metadata[key]["human_name"],
177+
human_name: humanReadableName,
179178
type: metadata[key]["type"],
180179
ontology_reference: metadata[key]["ontology_reference"],
181180
};
@@ -196,7 +195,7 @@ export class MetadataViewComponent implements OnInit, OnChanges {
196195
name: key,
197196
value: metadataValue,
198197
unit: "",
199-
human_name: metadata[key]["human_name"],
198+
human_name: humanReadableName,
200199
type: metadata[key]["type"],
201200
ontology_reference: metadata[key]["ontology_reference"],
202201
};
@@ -212,10 +211,12 @@ export class MetadataViewComponent implements OnInit, OnChanges {
212211
return true;
213212
}
214213

215-
if (
214+
const isValidDate =
216215
typeof scientificMetadata.value !== "number" &&
217-
DateTime.fromISO(scientificMetadata.value).isValid
218-
) {
216+
new Date(scientificMetadata.value).toString() !== "Invalid Date" &&
217+
DateTime.fromISO(scientificMetadata.value).isValid;
218+
219+
if (isValidDate) {
219220
return true;
220221
}
221222

0 commit comments

Comments
 (0)