Skip to content

Commit

Permalink
[Gitar] Updating TypeScript files
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitar committed Sep 16, 2024
1 parent 0749b76 commit 87adbfb
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ import useSWRInfinite, {
type SWRInfiniteConfiguration,
type SWRInfiniteKeyLoader,
} from 'swr/infinite';
import { formatApiPath } from 'utils/formatPath';
import handleErrorResponses from '../httpErrorResponseHandler';
import useUiConfig from '../useUiConfig/useUiConfig';
import type { ISignalEndpointSignal } from 'interfaces/signal';
import { useUiFlag } from 'hooks/useUiFlag';

const ENDPOINT = 'api/admin/signal-endpoints';

type SignalsResponse = {
signalEndpointSignals: ISignalEndpointSignal[];
Expand All @@ -25,25 +20,12 @@ export const useSignalEndpointSignals = (
limit = 50,
options: SWRInfiniteConfiguration = {},
) => {
const { isEnterprise } = useUiConfig();
const signalsEnabled = useUiFlag('signals');

const getKey: SWRInfiniteKeyLoader = (
pageIndex: number,
previousPageData: SignalsResponse,
) => {
// Does not meet conditions
if (!signalEndpointId || !isEnterprise || !signalsEnabled) return null;

// Reached the end
if (previousPageData && !previousPageData.signalEndpointSignals.length)
return null;

return formatApiPath(
`${ENDPOINT}/${signalEndpointId}/signals?limit=${limit}&offset=${
pageIndex * limit
}`,
);
return null;
};

const { data, error, size, setSize, mutate } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { useMemo } from 'react';
import { formatApiPath } from 'utils/formatPath';
import handleErrorResponses from '../httpErrorResponseHandler';
import { useConditionalSWR } from '../useConditionalSWR/useConditionalSWR';
import useUiConfig from '../useUiConfig/useUiConfig';
import type { ISignalEndpointToken } from 'interfaces/signal';
import { useUiFlag } from 'hooks/useUiFlag';

const ENDPOINT = 'api/admin/signal-endpoints';

Expand All @@ -13,13 +11,10 @@ const DEFAULT_DATA = {
};

export const useSignalEndpointTokens = (signalEndpointId: number) => {
const { isEnterprise } = useUiConfig();
const signalsEnabled = useUiFlag('signals');

const { data, error, mutate } = useConditionalSWR<{
signalEndpointTokens: ISignalEndpointToken[];
}>(
isEnterprise() && signalsEnabled,
false,
DEFAULT_DATA,
formatApiPath(`${ENDPOINT}/${signalEndpointId}/tokens`),
fetcher,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { useContext, useMemo } from 'react';
import { formatApiPath } from 'utils/formatPath';
import handleErrorResponses from '../httpErrorResponseHandler';
import { useConditionalSWR } from '../useConditionalSWR/useConditionalSWR';
import useUiConfig from '../useUiConfig/useUiConfig';
import type { ISignalEndpoint } from 'interfaces/signal';
import { useUiFlag } from 'hooks/useUiFlag';
import AccessContext from 'contexts/AccessContext';

const ENDPOINT = 'api/admin/signal-endpoints';

Expand All @@ -14,18 +11,9 @@ const DEFAULT_DATA = {
};

export const useSignalEndpoints = () => {
const { isAdmin } = useContext(AccessContext);
const { isEnterprise } = useUiConfig();
const signalsEnabled = useUiFlag('signals');

const { data, error, mutate } = useConditionalSWR<{
signalEndpoints: ISignalEndpoint[];
}>(
isEnterprise() && isAdmin && signalsEnabled,
DEFAULT_DATA,
formatApiPath(ENDPOINT),
fetcher,
);
}>(false, DEFAULT_DATA, formatApiPath(ENDPOINT), fetcher);

return useMemo(
() => ({
Expand Down
1 change: 0 additions & 1 deletion frontend/src/interfaces/uiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export type UiFlags = {
doraMetrics?: boolean;
dependentFeatures?: boolean;
newStrategyConfiguration?: boolean;
signals?: boolean;
automatedActions?: boolean;
celebrateUnleash?: boolean;
featureSearchFeedback?: Variant;
Expand Down
5 changes: 0 additions & 5 deletions src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export type IFlagKey =
| 'filterInvalidClientMetrics'
| 'disableMetrics'
| 'stripHeadersOnAPI'
| 'signals'
| 'automatedActions'
| 'celebrateUnleash'
| 'featureSearchFeedback'
Expand Down Expand Up @@ -137,10 +136,6 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_DISABLE_METRICS,
false,
),
signals: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_SIGNALS,
false,
),
automatedActions: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_AUTOMATED_ACTIONS,
false,
Expand Down

0 comments on commit 87adbfb

Please sign in to comment.