Skip to content

Commit 998ecf2

Browse files
refactor(uikit): replace isDuration with deltaUnit in DeltaDisplay
Signed-off-by: samarthsinh2660 <rajuvala80@gmail.com>
1 parent c66dbbb commit 998ecf2

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

frontend/app/components/modules/widget/config/development/median-time-to-close/median-time-to-close.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SPDX-License-Identifier: MIT
1818
<lfx-delta-display
1919
v-if="selectedTimeRangeKey !== dateOptKeys.alltime"
2020
:summary="summary"
21-
is-duration
21+
:delta-unit="FormatterUnits.SECONDS"
2222
is-reverse
2323
/>
2424
</div>
@@ -50,6 +50,7 @@ SPDX-License-Identifier: MIT
5050
import { useRoute } from 'nuxt/app';
5151
import { ref, computed, watch } from 'vue';
5252
import { storeToRefs } from 'pinia';
53+
import { FormatterUnits } from '~/components/shared/types/formatter.types';
5354
import type { MedianTimeToClose } from '~~/types/development/responses.types';
5455
import type { Summary } from '~~/types/shared/summary.types';
5556
import LfxDeltaDisplay from '~/components/uikit/delta-display/delta-display.vue';

frontend/app/components/modules/widget/config/development/median-time-to-review/median-time-to-review.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SPDX-License-Identifier: MIT
1818
<lfx-delta-display
1919
v-if="selectedTimeRangeKey !== dateOptKeys.alltime"
2020
:summary="summary"
21-
is-duration
21+
:delta-unit="FormatterUnits.SECONDS"
2222
is-reverse
2323
/>
2424
</div>
@@ -50,6 +50,7 @@ SPDX-License-Identifier: MIT
5050
import { useRoute } from 'nuxt/app';
5151
import { ref, computed, watch } from 'vue';
5252
import { storeToRefs } from 'pinia';
53+
import { FormatterUnits } from '~/components/shared/types/formatter.types';
5354
import type { MedianTimeToReview } from '~~/types/development/responses.types';
5455
import type { Summary } from '~~/types/shared/summary.types';
5556
import LfxDeltaDisplay from '~/components/uikit/delta-display/delta-display.vue';

frontend/app/components/uikit/delta-display/delta-display.stories.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2025 The Linux Foundation and each contributor.
22
// SPDX-License-Identifier: MIT
33
import LfxDeltaDisplay from './delta-display.vue';
4+
import { FormatterUnits } from '~/components/shared/types/formatter.types';
45
import type { Summary } from '~~/types/shared/summary.types';
56

67
export default {
@@ -38,10 +39,10 @@ export default {
3839
description: 'Unit to display after the numeric values (e.g., "%", "ms", "K")',
3940
control: 'text',
4041
},
41-
isDuration: {
42-
description: 'Formats values as duration (e.g., "2h 30m")',
43-
defaultValue: false,
44-
control: 'boolean',
42+
deltaUnit: {
43+
description: 'Formats values as duration with a specific unit (e.g., "seconds", "minutes")',
44+
control: 'select',
45+
options: Object.values(FormatterUnits),
4546
},
4647
isShort: {
4748
description: 'Uses short number formatting (e.g., "1.2K" instead of "1,200")',
@@ -108,7 +109,7 @@ export const Reversed = {
108109
export const Duration = {
109110
args: {
110111
summary: createSummary(7200, 3600), // 2 hours vs 1 hour in seconds
111-
isDuration: true,
112+
deltaUnit: FormatterUnits.SECONDS,
112113
isReverse: false,
113114
},
114115
};

frontend/app/components/uikit/delta-display/delta-display.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,19 @@ const deltaDirection = computed<'positive' | 'negative'>(() => {
5757
return value >= 0 ? 'positive' : 'negative';
5858
});
5959
60-
// TODO: remove isDuration and use deltaUnit instead
6160
const delta = computed(() => {
6261
const value = props.summary.changeValue;
63-
const changeDuration = formatSecondsToDuration(Math.abs(value), 'short');
62+
const changeDuration = formatSecondsToDuration(Math.abs(value), 'short', props.deltaUnit);
6463
const changeValue = props.isShort ? formatNumberShort(value) : formatNumber(value, props.decimals || 1);
6564
6665
const sign = value >= 0 ? '+' : '';
67-
return sign + (props.isDuration ? changeDuration : changeValue);
66+
return sign + (props.deltaUnit ? changeDuration : changeValue);
6867
});
6968
7069
const deltaColor = computed(() => (deltaDirection.value === 'negative' ? 'text-negative-600' : 'text-positive-600'));
7170
7271
const deltaDisplay = computed(() => {
73-
const unit = props.isDuration ? '' : props.unit;
72+
const unit = props.deltaUnit ? '' : props.unit;
7473
if (!props.percentageOnly) {
7574
return isHidePercentage.value ? `${delta.value}${unit || ''}` : `(${delta.value}${unit || ''})`;
7675
}
@@ -82,9 +81,9 @@ const deltaIcon = computed(() => (props.summary.changeValue < 0 ? 'circle-arrow-
8281
8382
const previousDisplay = computed(() => {
8483
if (!props.hidePreviousValue) {
85-
const unit = props.isDuration ? '' : props.unit;
86-
const previousValue = props.isDuration
87-
? formatSecondsToDuration(props.summary.previous || 0, 'short')
84+
const unit = props.deltaUnit ? '' : props.unit;
85+
const previousValue = props.deltaUnit
86+
? formatSecondsToDuration(props.summary.previous || 0, 'short', props.deltaUnit)
8887
: formatNumber(props.summary.previous, props.percentageOnly ? 1 : props.decimals);
8988
return `${previousValue}${unit || ''}`;
9089
}

frontend/app/components/uikit/delta-display/types/delta-display.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2025 The Linux Foundation and each contributor.
22
// SPDX-License-Identifier: MIT
3+
import type { FormatterUnits } from '~/components/shared/types/formatter.types';
34
import type { Summary } from '~~/types/shared/summary.types';
45

56
export type DeltaDisplayProps = {
@@ -9,7 +10,7 @@ export type DeltaDisplayProps = {
910
hidePreviousValue?: boolean;
1011
percentageOnly?: boolean;
1112
unit?: string;
12-
isDuration?: boolean;
13+
deltaUnit?: FormatterUnits;
1314
isShort?: boolean;
1415
decimals?: number;
1516
};

0 commit comments

Comments
 (0)