Skip to content

Commit

Permalink
Conditional fallback value for some table columns
Browse files Browse the repository at this point in the history
  • Loading branch information
clementprdhomme committed Oct 14, 2024
1 parent f928612 commit 9362e1d
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,17 @@ export const useColumns = (
),
cell: ({ row }) => {
const { mpaa_establishment_stage } = row.original;
const formattedValue = mpaa_establishment_stage.name || t('not-assessed');

const hasSubRowWithValue =
row.subRows.length > 0 &&
row.subRows.some((row) => !!row.original.mpaa_establishment_stage);

let fallbackValue = t('not-assessed');
if (hasSubRowWithValue) {
fallbackValue = '−';
}

const formattedValue = mpaa_establishment_stage.name ?? fallbackValue;
return <>{formattedValue}</>;
},
},
Expand All @@ -448,7 +458,17 @@ export const useColumns = (
),
cell: ({ row }) => {
const { mpaa_protection_level } = row.original;
const formattedValue = mpaa_protection_level.name || t('not-assessed');

const hasSubRowWithValue =
row.subRows.length > 0 &&
row.subRows.some((row) => !!row.original.mpaa_protection_level);

let fallbackValue = t('not-assessed');
if (hasSubRowWithValue) {
fallbackValue = '−';
}

const formattedValue = mpaa_protection_level.name ?? fallbackValue;
return <>{formattedValue}</>;
},
},
Expand Down

0 comments on commit 9362e1d

Please sign in to comment.