Skip to content

Commit 715cf12

Browse files
committed
Delegate to WorkPackageResource#formattedId in display field
The wpFormattedId getter duplicated the semantic/classic detection logic from WorkPackageResource#formattedId and tripped eslint's no-unsafe-* rules because this.value resolves to any. Cast this.value to WorkPackageResource so the loaded-resource path can delegate to the existing formattedId getter. The unloaded fallback (numeric ID from self-link href) stays as-is, with a cast on this.wpId to clear the last unsafe-assignment warning without touching the pre-existing (untyped) wpId getter.
1 parent 5631b53 commit 715cf12

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

frontend/src/app/shared/components/fields/display/field-types/work-package-display-field.module.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
//++
2828

2929
import { DisplayField } from 'core-app/shared/components/fields/display/display-field.module';
30+
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
3031

3132
export class WorkPackageDisplayField extends DisplayField {
3233
public text = {
@@ -61,18 +62,17 @@ export class WorkPackageDisplayField extends DisplayField {
6162
* Returns the work package ID formatted for display.
6263
* Classic mode: `#123` (hash-prefixed), Semantic mode: `PROJ-42` (no prefix).
6364
*
64-
* This mirrors the logic in `WorkPackageBaseResource.formattedId`
65-
* but cannot delegate to it because the linked resource (`this.value`)
66-
* may not be loaded — in that case `wpId` falls back to extracting the
67-
* numeric ID from the self-link href, which won't have a `displayId`.
65+
* Delegates to `WorkPackageResource#formattedId` when the linked resource
66+
* is loaded. When unloaded, falls back to the numeric ID extracted from
67+
* the self-link href (which has no `displayId` available).
6868
*/
6969
public get wpFormattedId():string {
70-
if (this.value?.$loaded && this.value.displayId) {
71-
const displayId = this.value.displayId.toString();
72-
return /[A-Za-z]/.test(displayId) ? displayId : `#${displayId}`;
70+
const linkedWp = this.value as WorkPackageResource | undefined;
71+
if (linkedWp?.$loaded) {
72+
return linkedWp.formattedId;
7373
}
7474

75-
const id = this.wpId;
75+
const id = this.wpId as string | number | null;
7676
if (!id) return '';
7777

7878
return `#${id}`;

0 commit comments

Comments
 (0)