Skip to content

Commit

Permalink
Added logic to getFilterHeaderText (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
kslazykv authored Jan 29, 2025
1 parent bce37b1 commit 0d63807
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/filter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/workspace-filter",
"version": "4.0.8",
"version": "4.0.9",
"type": "module",
"sideEffects": false,
"license": "MIT",
Expand Down
27 changes: 19 additions & 8 deletions packages/filter/src/lib/utils/getFilterHeaderText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ export function getFilterHeaderText(
name: string,
checkedValues: string[]
): string | JSX.Element {
if (isAllChecked || checkedValues.length === 0) return <StyledNormalText>{name}</StyledNormalText>;
const selectedCount = checkedValues.length;

return (
<div style={{ color: tokens.colors.interactive.primary__resting.hex }}>
{checkedValues.length - 1 > 0
? `${checkedValues[0] ?? '(Blank)'}(+${checkedValues.length - 1})`
: `${checkedValues[0]}`}{' '}
</div>
);
const hasBlank = checkedValues.includes('(Blank)');
const nonBlankCount = hasBlank ? selectedCount - 1 : selectedCount;

if (hasBlank && nonBlankCount > 0) {
return <StyledNormalText>{`${name} (Blank) (+${nonBlankCount})`}</StyledNormalText>;
}

if (selectedCount === 1 && hasBlank) {
return <StyledNormalText>{`${name} (Blank)`}</StyledNormalText>;
}

const displayText = selectedCount > 0 ? `${name} (+${selectedCount})` : name;

if (isAllChecked || selectedCount === 0) {
return <StyledNormalText>{displayText}</StyledNormalText>;
}

return <div style={{ color: tokens.colors.interactive.primary__resting.hex }}>{displayText}</div>;
}
2 changes: 1 addition & 1 deletion packages/workspace-fusion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/workspace-fusion",
"version": "9.0.22",
"version": "9.0.23",
"type": "module",
"sideEffects": false,
"license": "MIT",
Expand Down

0 comments on commit 0d63807

Please sign in to comment.