mirror of
https://github.com/Unleash/unleash.git
synced 2025-03-18 00:19:49 +01:00
fix: update PR based on feedback
This commit is contained in:
parent
c10525108e
commit
4d0d39891a
@ -4,8 +4,9 @@ import { formatApiPath } from '../../../../utils/format-path';
|
|||||||
import handleErrorResponses from '../httpErrorResponseHandler';
|
import handleErrorResponses from '../httpErrorResponseHandler';
|
||||||
|
|
||||||
const useApplication = (name: string, options: SWRConfiguration = {}) => {
|
const useApplication = (name: string, options: SWRConfiguration = {}) => {
|
||||||
const fetcher = async () => {
|
|
||||||
const path = formatApiPath(`api/admin/metrics/applications/${name}`);
|
const path = formatApiPath(`api/admin/metrics/applications/${name}`);
|
||||||
|
|
||||||
|
const fetcher = async () => {
|
||||||
return fetch(path, {
|
return fetch(path, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
})
|
})
|
||||||
@ -13,16 +14,16 @@ const useApplication = (name: string, options: SWRConfiguration = {}) => {
|
|||||||
.then(res => res.json());
|
.then(res => res.json());
|
||||||
};
|
};
|
||||||
|
|
||||||
const FEATURE_CACHE_KEY = `api/admin/metrics/applications/${name}`;
|
const APPLICATION_CACHE_KEY = `api/admin/metrics/applications/${name}`;
|
||||||
|
|
||||||
const { data, error } = useSWR(FEATURE_CACHE_KEY, fetcher, {
|
const { data, error } = useSWR(APPLICATION_CACHE_KEY, fetcher, {
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [loading, setLoading] = useState(!error && !data);
|
const [loading, setLoading] = useState(!error && !data);
|
||||||
|
|
||||||
const refetchApplication = () => {
|
const refetchApplication = () => {
|
||||||
mutate(FEATURE_CACHE_KEY);
|
mutate(APPLICATION_CACHE_KEY);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -43,7 +44,7 @@ const useApplication = (name: string, options: SWRConfiguration = {}) => {
|
|||||||
error,
|
error,
|
||||||
loading,
|
loading,
|
||||||
refetchApplication,
|
refetchApplication,
|
||||||
FEATURE_CACHE_KEY,
|
APPLICATION_CACHE_KEY,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,26 +3,27 @@ import { useState, useEffect } from 'react';
|
|||||||
import { formatApiPath } from '../../../../utils/format-path';
|
import { formatApiPath } from '../../../../utils/format-path';
|
||||||
import handleErrorResponses from '../httpErrorResponseHandler';
|
import handleErrorResponses from '../httpErrorResponseHandler';
|
||||||
|
|
||||||
|
const path = formatApiPath('api/admin/metrics/applications');
|
||||||
|
|
||||||
const useApplications = (options: SWRConfiguration = {}) => {
|
const useApplications = (options: SWRConfiguration = {}) => {
|
||||||
const fetcher = async () => {
|
const fetcher = async () => {
|
||||||
const path = formatApiPath('api/admin/metrics/applications');
|
|
||||||
return fetch(path, {
|
return fetch(path, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
})
|
})
|
||||||
.then(handleErrorResponses('Context data'))
|
.then(handleErrorResponses('Applications data'))
|
||||||
.then(res => res.json());
|
.then(res => res.json());
|
||||||
};
|
};
|
||||||
|
|
||||||
const FEATURE_CACHE_KEY = 'api/admin/metrics/applications';
|
const APPLICATIONS_CACHE_KEY = 'api/admin/metrics/applications';
|
||||||
|
|
||||||
const { data, error } = useSWR(FEATURE_CACHE_KEY, fetcher, {
|
const { data, error } = useSWR(APPLICATIONS_CACHE_KEY, fetcher, {
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [loading, setLoading] = useState(!error && !data);
|
const [loading, setLoading] = useState(!error && !data);
|
||||||
|
|
||||||
const refetchApplications = () => {
|
const refetchApplications = () => {
|
||||||
mutate(FEATURE_CACHE_KEY);
|
mutate(APPLICATIONS_CACHE_KEY);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -34,7 +35,7 @@ const useApplications = (options: SWRConfiguration = {}) => {
|
|||||||
error,
|
error,
|
||||||
loading,
|
loading,
|
||||||
refetchApplications,
|
refetchApplications,
|
||||||
FEATURE_CACHE_KEY,
|
APPLICATIONS_CACHE_KEY,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user