mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-13 11:17:26 +02:00
https://linear.app/unleash/issue/2-3809/implement-the-latest-feedback-from-ux Implements the latest feedback from UX regarding **unknown flags**. Bit unsure about our column headers. E.g. instead of "Last seen" and "Seen in Unleash" we could call them "Reported" and "Last event". <img width="1490" height="838" alt="image" src="https://github.com/user-attachments/assets/30ca2570-1395-429f-8d60-ccc6fe83ba92" />
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { formatApiPath } from 'utils/formatPath';
|
|
import { useUiFlag } from 'hooks/useUiFlag.js';
|
|
import { useConditionalSWR } from 'hooks/api/getters/useConditionalSWR/useConditionalSWR.js';
|
|
import handleErrorResponses from 'hooks/api/getters/httpErrorResponseHandler';
|
|
import type { SWRConfiguration } from 'swr';
|
|
|
|
export type UnknownFlag = {
|
|
name: string;
|
|
appName: string;
|
|
seenAt: Date;
|
|
environment: string;
|
|
lastEventAt: Date;
|
|
};
|
|
|
|
type UnknownFlagsResponse = {
|
|
unknownFlags: UnknownFlag[];
|
|
};
|
|
|
|
const ENDPOINT = 'api/admin/metrics/unknown-flags';
|
|
const DEFAULT_DATA: UnknownFlagsResponse = {
|
|
unknownFlags: [],
|
|
};
|
|
|
|
export const useUnknownFlags = (options?: SWRConfiguration) => {
|
|
const reportUnknownFlagsEnabled = useUiFlag('reportUnknownFlags');
|
|
|
|
const { data, error, mutate } = useConditionalSWR<UnknownFlagsResponse>(
|
|
reportUnknownFlagsEnabled,
|
|
DEFAULT_DATA,
|
|
formatApiPath(ENDPOINT),
|
|
fetcher,
|
|
options,
|
|
);
|
|
|
|
return useMemo(
|
|
() => ({
|
|
unknownFlags: (data || DEFAULT_DATA).unknownFlags,
|
|
loading: !error && !data,
|
|
refetch: () => mutate(),
|
|
error,
|
|
}),
|
|
[data, error, mutate],
|
|
);
|
|
};
|
|
|
|
const fetcher = (path: string) => {
|
|
return fetch(path)
|
|
.then(handleErrorResponses('Unknown Flags'))
|
|
.then((res) => res.json());
|
|
};
|