From 9f2a1b52482dab803961eeb13656bc3f380ca7e3 Mon Sep 17 00:00:00 2001
From: Rongrong Chai <rchai@sagebase.org>
Date: Tue, 2 Apr 2024 23:30:43 +0000
Subject: [PATCH] add descriptive name to avoid conflicts

---
 .../src/lib/challenge-search-filters.ts       | 60 +++---------
 .../challenge-overview.component.html         |  6 +-
 .../challenge-overview.component.ts           | 10 +-
 .../challenge-card.component.html             |  2 +-
 .../challenge-card.component.ts               |  9 +-
 libs/openchallenges/util/src/index.ts         |  2 +-
 .../lib/pipe/challenge-property-label.pipe.ts | 63 +++++++++---
 ...abels.ts => challenge-property-options.ts} | 95 +++++++++++++------
 8 files changed, 148 insertions(+), 99 deletions(-)
 rename libs/openchallenges/util/src/lib/pipe/{challenge-property-labels.ts => challenge-property-options.ts} (59%)

diff --git a/libs/openchallenges/challenge-search/src/lib/challenge-search-filters.ts b/libs/openchallenges/challenge-search/src/lib/challenge-search-filters.ts
index e1800ef5f7..f5284094c1 100644
--- a/libs/openchallenges/challenge-search/src/lib/challenge-search-filters.ts
+++ b/libs/openchallenges/challenge-search/src/lib/challenge-search-filters.ts
@@ -1,12 +1,10 @@
-import {
-  ChallengeSort,
-  ChallengeStatus,
-} from '@sagebionetworks/openchallenges/api-client-angular';
 import { Filter } from '@sagebionetworks/openchallenges/ui';
 import {
-  challengeCategoriesLabels,
-  challengeIncentivesLabels,
-  challengeSubmissionTypesLabels,
+  ChallengeCategoriesOptions,
+  ChallengeIncentivesOptions,
+  ChallengeStatusOptions,
+  ChallengeSubmissionTypesOptions,
+  ChallengeSortOptions,
 } from '@sagebionetworks/openchallenges/util';
 
 const thisYear = new Date().getFullYear();
@@ -57,47 +55,13 @@ export const challengeStartYearRangeFilter: Filter[] = [
   },
 ];
 
-export const challengeStatusFilter: Filter[] = [
-  {
-    value: ChallengeStatus.Active,
-    label: 'Active',
-  },
-  {
-    value: ChallengeStatus.Upcoming,
-    label: 'Upcoming',
-  },
-  {
-    value: ChallengeStatus.Completed,
-    label: 'Completed',
-  },
-];
-
-export const challengeSubmissionTypesFilter: Filter[] =
-  challengeSubmissionTypesLabels;
-
-export const challengeIncentivesFilter: Filter[] = challengeIncentivesLabels;
-
-export const challengePlatformsFilter: Filter[] = [];
-
+export const challengeCategoriesFilter: Filter[] = ChallengeCategoriesOptions;
+export const challengeIncentivesFilter: Filter[] = ChallengeIncentivesOptions;
 export const challengeInputDataTypesFilter: Filter[] = [];
-
-export const challengeCategoriesFilter: Filter[] = challengeCategoriesLabels;
-
 export const challengeOrganizationsFilter: Filter[] = [];
-
 export const challengeOrganizersFilter: Filter[] = [];
-
-export const challengeSortFilter: Filter[] = [
-  {
-    value: ChallengeSort.Relevance,
-    label: 'Relevance',
-  },
-  {
-    value: ChallengeSort.StartDate,
-    label: 'Start Date',
-  },
-  {
-    value: ChallengeSort.Starred,
-    label: 'Most Starred',
-  },
-];
+export const challengePlatformsFilter: Filter[] = [];
+export const challengeSortFilter: Filter[] = ChallengeSortOptions;
+export const challengeStatusFilter: Filter[] = ChallengeStatusOptions;
+export const challengeSubmissionTypesFilter: Filter[] =
+  ChallengeSubmissionTypesOptions;
diff --git a/libs/openchallenges/challenge/src/lib/challenge-overview/challenge-overview.component.html b/libs/openchallenges/challenge/src/lib/challenge-overview/challenge-overview.component.html
index a3ac7e669c..a0bbd06385 100644
--- a/libs/openchallenges/challenge/src/lib/challenge-overview/challenge-overview.component.html
+++ b/libs/openchallenges/challenge/src/lib/challenge-overview/challenge-overview.component.html
@@ -26,7 +26,7 @@ <h3 class="section-title">Challenge Details</h3>
         </tr>
         <tr>
           <td class="text-right">Status</td>
-          <td>{{ challenge.status | titlecase }}</td>
+          <td>{{ challenge.status | challengeStatusLabel }}</td>
         </tr>
         <tr>
           <td class="text-right">Platform</td>
@@ -58,7 +58,7 @@ <h3 class="section-title">Challenge Details</h3>
               nowrap
               *ngFor="let submissionType of challenge.submissionTypes; let isLast = last"
             >
-              {{ submissionType | submissionTypeLabel }}{{ isLast ? '' : ', ' }}</span
+              {{ submissionType | challengeSubmissionTypeLabel }}{{ isLast ? '' : ', ' }}</span
             >
           </td>
           <ng-template #na_subs>
@@ -69,7 +69,7 @@ <h3 class="section-title">Challenge Details</h3>
           <td class="text-right">Incentive(s)</td>
           <td *ngIf="challenge.incentives && challenge.incentives.length > 0; else na_prize">
             <span nowrap *ngFor="let incentive of challenge.incentives; let isLast = last">
-              {{ incentive | incentiveLabel }}{{ isLast ? '' : ', ' }}</span
+              {{ incentive | challengeIncentiveLabel }}{{ isLast ? '' : ', ' }}</span
             >
           </td>
           <ng-template #na_prize>
diff --git a/libs/openchallenges/challenge/src/lib/challenge-overview/challenge-overview.component.ts b/libs/openchallenges/challenge/src/lib/challenge-overview/challenge-overview.component.ts
index 8cda34665f..611fc4ce7d 100644
--- a/libs/openchallenges/challenge/src/lib/challenge-overview/challenge-overview.component.ts
+++ b/libs/openchallenges/challenge/src/lib/challenge-overview/challenge-overview.component.ts
@@ -8,17 +8,19 @@ import {
 
 import { MatIconModule } from '@angular/material/icon';
 import {
-  IncentiveLabelPipe,
-  SubmissionTypeLabelPipe,
+  ChallengeIncentiveLabelPipe,
+  ChallengeStatusLabelPipe,
+  ChallengeSubmissionTypeLabelPipe,
 } from '@sagebionetworks/openchallenges/util';
 @Component({
   selector: 'openchallenges-challenge-overview',
   standalone: true,
   imports: [
+    ChallengeIncentiveLabelPipe,
+    ChallengeStatusLabelPipe,
+    ChallengeSubmissionTypeLabelPipe,
     CommonModule,
-    IncentiveLabelPipe,
     MatIconModule,
-    SubmissionTypeLabelPipe,
   ],
   templateUrl: './challenge-overview.component.html',
   styleUrls: ['./challenge-overview.component.scss'],
diff --git a/libs/openchallenges/ui/src/lib/challenge-card/challenge-card.component.html b/libs/openchallenges/ui/src/lib/challenge-card/challenge-card.component.html
index f6612b1a82..b5f8532d3e 100644
--- a/libs/openchallenges/ui/src/lib/challenge-card/challenge-card.component.html
+++ b/libs/openchallenges/ui/src/lib/challenge-card/challenge-card.component.html
@@ -33,7 +33,7 @@
         *ngIf="challenge.incentives.length > 0; else noIncentives"
       >
         <ng-container *ngFor="let incentive of challenge.incentives; let isLast = last">
-          {{ incentive | incentiveLabel }}{{ isLast ? '' : ', ' }}
+          {{ incentive | challengeIncentiveLabel }}{{ isLast ? '' : ', ' }}
         </ng-container>
       </div>
     </div>
diff --git a/libs/openchallenges/ui/src/lib/challenge-card/challenge-card.component.ts b/libs/openchallenges/ui/src/lib/challenge-card/challenge-card.component.ts
index 7e02d68048..6aa29f79f0 100644
--- a/libs/openchallenges/ui/src/lib/challenge-card/challenge-card.component.ts
+++ b/libs/openchallenges/ui/src/lib/challenge-card/challenge-card.component.ts
@@ -7,13 +7,18 @@ import {
   Image,
   ImageService,
 } from '@sagebionetworks/openchallenges/api-client-angular';
-import { IncentiveLabelPipe } from '@sagebionetworks/openchallenges/util';
+import { ChallengeIncentiveLabelPipe } from '@sagebionetworks/openchallenges/util';
 import { Observable } from 'rxjs';
 
 @Component({
   selector: 'openchallenges-challenge-card',
   standalone: true,
-  imports: [CommonModule, IncentiveLabelPipe, MatIconModule, RouterModule],
+  imports: [
+    ChallengeIncentiveLabelPipe,
+    CommonModule,
+    MatIconModule,
+    RouterModule,
+  ],
   templateUrl: './challenge-card.component.html',
   styleUrls: ['./challenge-card.component.scss'],
 })
diff --git a/libs/openchallenges/util/src/index.ts b/libs/openchallenges/util/src/index.ts
index dae8eb421b..b92bfcda35 100644
--- a/libs/openchallenges/util/src/index.ts
+++ b/libs/openchallenges/util/src/index.ts
@@ -5,4 +5,4 @@ export * from './lib/http-status-redirect';
 export * from './lib/is-api-client-error';
 export * from './lib/page-title.service';
 export * from './lib/pipe/challenge-property-label.pipe';
-export * from './lib/pipe/challenge-property-labels';
+export * from './lib/pipe/challenge-property-options';
diff --git a/libs/openchallenges/util/src/lib/pipe/challenge-property-label.pipe.ts b/libs/openchallenges/util/src/lib/pipe/challenge-property-label.pipe.ts
index a4620bde86..1861f8e2e4 100644
--- a/libs/openchallenges/util/src/lib/pipe/challenge-property-label.pipe.ts
+++ b/libs/openchallenges/util/src/lib/pipe/challenge-property-label.pipe.ts
@@ -1,35 +1,76 @@
 import { Pipe, PipeTransform } from '@angular/core';
 import {
+  ChallengeCategory,
   ChallengeIncentive,
+  ChallengeSort,
+  ChallengeStatus,
   ChallengeSubmissionType,
 } from '@sagebionetworks/openchallenges/api-client-angular';
 import {
-  challengeIncentivesLabels,
-  challengeSubmissionTypesLabels,
-} from './challenge-property-labels';
+  ChallengeCategoriesOptions,
+  ChallengeIncentivesOptions,
+  ChallengeSortOptions,
+  ChallengeStatusOptions,
+  ChallengeSubmissionTypesOptions,
+} from './challenge-property-options';
 
 @Pipe({
-  name: 'incentiveLabel',
+  name: 'challengeCategoryLabel',
   standalone: true,
 })
-export class IncentiveLabelPipe implements PipeTransform {
+export class ChallengeCategoryLabelPipe implements PipeTransform {
+  transform(category: ChallengeCategory): string | undefined {
+    const option = ChallengeCategoriesOptions.find(
+      (item) => item.value === category
+    );
+    return option ? option.label : undefined;
+  }
+}
+
+@Pipe({
+  name: 'challengeIncentiveLabel',
+  standalone: true,
+})
+export class ChallengeIncentiveLabelPipe implements PipeTransform {
   transform(incentive: ChallengeIncentive): string | undefined {
-    const filterItem = challengeIncentivesLabels.find(
+    const option = ChallengeIncentivesOptions.find(
       (item) => item.value === incentive
     );
-    return filterItem ? filterItem.label : undefined;
+    return option ? option.label : undefined;
+  }
+}
+
+@Pipe({
+  name: 'challengeSortLabel',
+  standalone: true,
+})
+export class ChallengeSortLabelPipe implements PipeTransform {
+  transform(sort: ChallengeSort): string | undefined {
+    const option = ChallengeSortOptions.find((item) => item.value === sort);
+    return option ? option.label : undefined;
+  }
+}
+
+@Pipe({
+  name: 'challengeStatusLabel',
+  standalone: true,
+})
+export class ChallengeStatusLabelPipe implements PipeTransform {
+  transform(status: ChallengeStatus): string | undefined {
+    const option = ChallengeStatusOptions.find((item) => item.value === status);
+    return option ? option.label : undefined;
   }
 }
 
 @Pipe({
-  name: 'submissionTypeLabel',
+  name: 'challengeSubmissionTypeLabel',
   standalone: true,
 })
-export class SubmissionTypeLabelPipe implements PipeTransform {
+export class ChallengeSubmissionTypeLabelPipe implements PipeTransform {
   transform(submissionType: ChallengeSubmissionType): string | undefined {
-    const filterItem = challengeSubmissionTypesLabels.find(
+    const option = ChallengeSubmissionTypesOptions.find(
       (item) => item.value === submissionType
     );
-    return filterItem ? filterItem.label : undefined;
+    return option ? option.label : undefined;
   }
 }
diff --git a/libs/openchallenges/util/src/lib/pipe/challenge-property-labels.ts b/libs/openchallenges/util/src/lib/pipe/challenge-property-options.ts
similarity index 59%
rename from libs/openchallenges/util/src/lib/pipe/challenge-property-labels.ts
rename to libs/openchallenges/util/src/lib/pipe/challenge-property-options.ts
index 8266c5ebb9..e70e51963e 100644
--- a/libs/openchallenges/util/src/lib/pipe/challenge-property-labels.ts
+++ b/libs/openchallenges/util/src/lib/pipe/challenge-property-options.ts
@@ -1,38 +1,53 @@
 import {
   ChallengeCategory,
   ChallengeIncentive,
+  ChallengeSort,
+  ChallengeStatus,
   ChallengeSubmissionType,
 } from '@sagebionetworks/openchallenges/api-client-angular';
 
-type ChallengeLabels = {
-  value: ChallengeSubmissionType | ChallengeIncentive | ChallengeCategory;
+type ChallengePropertyOption = {
+  value:
+    | ChallengeCategory
+    | ChallengeIncentive
+    | ChallengeSort
+    | ChallengeStatus
+    | ChallengeSubmissionType;
   label: string;
 };
 
-export const challengeSubmissionTypesLabels: ChallengeLabels[] = [
+export const ChallengeCategoriesOptions: ChallengePropertyOption[] = [
   {
-    value: ChallengeSubmissionType.ContainerImage,
-    label: 'Container Image',
+    value: ChallengeCategory.Featured,
+    label: 'Featured',
   },
   {
-    value: ChallengeSubmissionType.Mlcube,
-    label: 'MLCube',
+    value: ChallengeCategory.Benchmark,
+    label: 'Benchmark',
   },
   {
-    value: ChallengeSubmissionType.Notebook,
-    label: 'Notebook',
+    value: ChallengeCategory.Hackathon,
+    label: 'Hackathon',
   },
   {
-    value: ChallengeSubmissionType.PredictionFile,
-    label: 'Prediction File',
+    value: ChallengeCategory.StartingSoon,
+    label: 'Starting Soon',
   },
   {
-    value: ChallengeSubmissionType.Other,
-    label: 'Other',
+    value: ChallengeCategory.EndingSoon,
+    label: 'Closing Soon',
+  },
+  {
+    value: ChallengeCategory.RecentlyStarted,
+    label: 'Recently Launched',
+  },
+  {
+    value: ChallengeCategory.RecentlyEnded,
+    label: 'Recently Completed',
   },
 ];
 
-export const challengeIncentivesLabels: ChallengeLabels[] = [
+export const ChallengeIncentivesOptions: ChallengePropertyOption[] = [
   {
     value: ChallengeIncentive.Monetary,
     label: 'Monetary',
@@ -51,33 +66,55 @@ export const challengeIncentivesLabels: ChallengeLabels[] = [
   },
 ];
 
-export const challengeCategoriesLabels: ChallengeLabels[] = [
+export const ChallengeSortOptions: ChallengePropertyOption[] = [
   {
-    value: ChallengeCategory.Featured,
-    label: 'Featured',
+    value: ChallengeSort.Relevance,
+    label: 'Relevance',
   },
   {
-    value: ChallengeCategory.Benchmark,
-    label: 'Benchmark',
+    value: ChallengeSort.StartDate,
+    label: 'Start Date',
   },
   {
-    value: ChallengeCategory.Hackathon,
-    label: 'Hackathon',
+    value: ChallengeSort.Starred,
+    label: 'Most Starred',
   },
+];
+
+export const ChallengeStatusOptions: ChallengePropertyOption[] = [
   {
-    value: ChallengeCategory.StartingSoon,
-    label: 'Starting Soon',
+    value: ChallengeStatus.Active,
+    label: 'Active',
   },
   {
-    value: ChallengeCategory.EndingSoon,
-    label: 'Closing Soon',
+    value: ChallengeStatus.Upcoming,
+    label: 'Upcoming',
   },
   {
-    value: ChallengeCategory.RecentlyStarted,
-    label: 'Recently Launched',
+    value: ChallengeStatus.Completed,
+    label: 'Completed',
   },
+];
+
+export const ChallengeSubmissionTypesOptions: ChallengePropertyOption[] = [
   {
-    value: ChallengeCategory.RecentlyEnded,
-    label: 'Recently Completed',
+    value: ChallengeSubmissionType.ContainerImage,
+    label: 'Container Image',
+  },
+  {
+    value: ChallengeSubmissionType.Mlcube,
+    label: 'MLCube',
+  },
+  {
+    value: ChallengeSubmissionType.Notebook,
+    label: 'Notebook',
+  },
+  {
+    value: ChallengeSubmissionType.PredictionFile,
+    label: 'Prediction File',
+  },
+  {
+    value: ChallengeSubmissionType.Other,
+    label: 'Other',
   },
 ];