1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: metrics apps should be selected from the longest time span (#5923)

This commit is contained in:
Mateusz Kwasniewski 2024-01-17 09:51:59 +01:00 committed by GitHub
parent f61750a755
commit 6a55964ce8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 4 deletions

View File

@ -3,6 +3,7 @@ import { PageContent } from 'component/common/PageContent/PageContent';
import { useEffect, useMemo, useState } from 'react';
import {
FEATURE_METRIC_HOURS_BACK_DEFAULT,
FEATURE_METRIC_HOURS_BACK_MAX,
FeatureMetricsHours,
} from './FeatureMetricsHours/FeatureMetricsHours';
import { IFeatureMetricsRaw } from 'interfaces/featureToggle';
@ -21,6 +22,7 @@ import {
withDefault,
} from 'use-query-params';
import { aggregateFeatureMetrics } from './aggregateFeatureMetrics';
import { useExtendedFeatureMetrics } from './useExtendedFeatureMetrics';
export const FeatureMetrics = () => {
const projectId = useRequiredPathParam('projectId');
@ -163,9 +165,12 @@ const useFeatureMetricsEnvironments = (
// Get all application names for a feature. Fetch apps for the max time range
// so that the list of apps doesn't change when selecting a shorter range.
const useFeatureMetricsApplications = (featureId: string): Set<string> => {
const extendedOptions = useExtendedFeatureMetrics();
const { featureMetrics = [] } = useFeatureMetricsRaw(
featureId,
FEATURE_METRIC_HOURS_BACK_DEFAULT,
extendedOptions
? FEATURE_METRIC_HOURS_BACK_MAX
: FEATURE_METRIC_HOURS_BACK_DEFAULT,
);
const applications = featureMetrics.map((metric) => {

View File

@ -6,6 +6,7 @@ import { subWeeks, subMonths, differenceInHours } from 'date-fns';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { useUiFlag } from 'hooks/useUiFlag';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
import { useExtendedFeatureMetrics } from '../useExtendedFeatureMetrics';
const StyledTitle = styled('h2')(({ theme }) => ({
margin: 0,
@ -36,9 +37,7 @@ export const FeatureMetricsHours = ({
},
});
};
const { isEnterprise } = useUiConfig();
const extendedUsageMetrics = useUiFlag('extendedUsageMetricsUI');
const extendedOptions = isEnterprise() && extendedUsageMetrics;
const extendedOptions = useExtendedFeatureMetrics();
const options = extendedOptions
? [...hourOptions, ...daysOptions]
: hourOptions;
@ -89,3 +88,8 @@ const daysOptions: { key: `${number}`; label: string }[] = [
label: 'Last 3 months',
},
];
export const FEATURE_METRIC_HOURS_BACK_MAX = differenceInHours(
now,
subMonths(now, 3),
);

View File

@ -0,0 +1,10 @@
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { useUiFlag } from 'hooks/useUiFlag';
export const useExtendedFeatureMetrics = () => {
const { isEnterprise } = useUiConfig();
const extendedUsageMetrics = useUiFlag('extendedUsageMetricsUI');
const extendedOptions = isEnterprise() && extendedUsageMetrics;
return extendedOptions;
};