mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
fix: remove stickiness error (#3338)
<!-- Thanks for creating a PR! To make it easier for reviewers and everyone else to understand what your changes relate to, please add some relevant content to the headings below. Feel free to ignore or delete sections that you don't think are relevant. Thank you! ❤️ --> ## About the changes Code was failing on create project because project id is empty <img width="1123" alt="Screenshot 2023-03-16 at 16 43 55" src="https://user-images.githubusercontent.com/1394682/225688715-98a2bd19-cb1a-43ce-a405-f1911645c638.png"> ### Important files <!-- PRs can contain a lot of changes, but not all changes are equally important. Where should a reviewer start looking to get an overview of the changes? Are any files particularly important? --> ## Discussion points <!-- Anything about the PR you'd like to discuss before it gets merged? Got any questions or doubts? -->
This commit is contained in:
parent
c5af024537
commit
f907dfad15
@ -51,7 +51,11 @@ export const StickinessSelect = ({
|
||||
disabled={!editable}
|
||||
data-testid={dataTestId}
|
||||
onChange={onChange}
|
||||
style={{ width: 'inherit', minWidth: '100%' }}
|
||||
style={{
|
||||
width: 'inherit',
|
||||
minWidth: '100%',
|
||||
marginBottom: '16px',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
@ -1,15 +1,12 @@
|
||||
import useUiConfig from './api/getters/useUiConfig/useUiConfig';
|
||||
import useSWR, { SWRConfiguration } from 'swr';
|
||||
import { SWRConfiguration } from 'swr';
|
||||
import { useCallback } from 'react';
|
||||
import handleErrorResponses from './api/getters/httpErrorResponseHandler';
|
||||
import { useConditionalSWR } from './api/getters/useConditionalSWR/useConditionalSWR';
|
||||
|
||||
export interface IStickinessResponse {
|
||||
status: number;
|
||||
|
||||
body?: {
|
||||
defaultStickiness: string;
|
||||
mode?: string;
|
||||
};
|
||||
defaultStickiness?: string;
|
||||
mode?: string;
|
||||
}
|
||||
const DEFAULT_STICKINESS = 'default';
|
||||
export const useDefaultProjectSettings = (
|
||||
@ -21,16 +18,15 @@ export const useDefaultProjectSettings = (
|
||||
const PATH = `/api/admin/projects/${projectId}/settings`;
|
||||
const { projectScopedStickiness } = uiConfig.flags;
|
||||
|
||||
const { data, error, mutate } = useSWR<IStickinessResponse>(
|
||||
const { data, error, mutate } = useConditionalSWR<IStickinessResponse>(
|
||||
Boolean(projectId) && Boolean(projectScopedStickiness),
|
||||
{},
|
||||
['useDefaultProjectSettings', PATH],
|
||||
() => fetcher(PATH),
|
||||
options
|
||||
);
|
||||
|
||||
const defaultStickiness =
|
||||
Boolean(projectScopedStickiness) && data?.body != null && projectId
|
||||
? data.body.defaultStickiness
|
||||
: DEFAULT_STICKINESS;
|
||||
const defaultStickiness = data?.defaultStickiness ?? DEFAULT_STICKINESS;
|
||||
|
||||
const refetch = useCallback(() => {
|
||||
mutate().catch(console.warn);
|
||||
@ -39,24 +35,12 @@ export const useDefaultProjectSettings = (
|
||||
defaultStickiness,
|
||||
refetch,
|
||||
loading: !error && !data,
|
||||
status: data?.status,
|
||||
error,
|
||||
};
|
||||
};
|
||||
|
||||
export const fetcher = async (path: string): Promise<IStickinessResponse> => {
|
||||
const res = await fetch(path);
|
||||
|
||||
if (res.status === 404) {
|
||||
return { status: 404 };
|
||||
}
|
||||
|
||||
if (!res.ok) {
|
||||
await handleErrorResponses('Project stickiness data')(res);
|
||||
}
|
||||
|
||||
return {
|
||||
status: res.status,
|
||||
body: await res.json(),
|
||||
};
|
||||
const fetcher = (path: string) => {
|
||||
return fetch(path)
|
||||
.then(handleErrorResponses('Project stickiness data'))
|
||||
.then(res => res.json());
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user