Skip to content

Commit

Permalink
fix: use || operator instead of unreachable ?? (#2845)
Browse files Browse the repository at this point in the history
Fix `Right operand of ?? is unreachable because the left operand is never nullish.` error by using `||` operator.

**Checklist:** (if applicable)

- [ ] Mention to the original issue
- [ ] Documentation
- [ ] Minium required manager version
- [ ] Specific setting for review (eg., KB link, endpoint or how to setup)
- [ ] Minimum requirements to check during review
- [ ] Test case(s) to demonstrate the difference of before/after
  • Loading branch information
agatha197 committed Nov 21, 2024
1 parent 4e7230b commit ae54e8a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 8 additions & 7 deletions react/src/components/AgentDetailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ const AgentDetailModal: React.FC<AgentDetailModalProps> = ({
</Typography.Title>
<BAIProgressWithLabel
percent={
((convertBinarySizeUnit(
_.toString(agent?.mem_cur_bytes),
'g',
)?.number ?? 0) /
(convertBinarySizeUnit(parsedAvailableSlots?.mem, 'g')
?.number ?? 0)) *
100 ?? 0
(_.toNumber(
convertBinarySizeUnit(_.toString(agent?.mem_cur_bytes), 'g')
?.number,
) /
_.toNumber(
convertBinarySizeUnit(parsedAvailableSlots?.mem, 'g')?.number,
)) *
100 || 0
}
valueLabel={`${
convertBinarySizeUnit(_.toString(agent?.mem_cur_bytes), 'g')
Expand Down
15 changes: 12 additions & 3 deletions react/src/components/BAIProgressWithLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface BAIProgressWithLabelProps {
const BAIProgressWithLabel: React.FC<BAIProgressWithLabelProps> = ({
title,
valueLabel,
percent = 0,
percent,
width,
strokeColor,
labelStyle,
Expand Down Expand Up @@ -46,7 +46,7 @@ const BAIProgressWithLabel: React.FC<BAIProgressWithLabelProps> = ({
<Flex
style={{
height: '100%',
width: `${percent > 100 ? 100 : percent}%`,
width: `${!percent || _.isNaN(percent) ? 0 : _.min([percent, 100])}%`,
position: 'absolute',
left: 0,
top: 0,
Expand All @@ -60,7 +60,16 @@ const BAIProgressWithLabel: React.FC<BAIProgressWithLabelProps> = ({
<Typography.Text style={{ fontSize, ...labelStyle }}>
{title}
</Typography.Text>
<Typography.Text style={{ fontSize, ...labelStyle }}>
<Typography.Text
style={{
fontSize,
color:
_.isNaN(percent) || _.isUndefined(percent)
? token.colorTextDisabled
: undefined,
...labelStyle,
}}
>
{valueLabel}
</Typography.Text>
</Flex>
Expand Down

0 comments on commit ae54e8a

Please sign in to comment.