forked from thanos-io/thanos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStores.tsx
More file actions
38 lines (32 loc) · 1.15 KB
/
Stores.tsx
File metadata and controls
38 lines (32 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React, { FC } from 'react';
import { RouteComponentProps } from '@reach/router';
import { withStatusIndicator } from '../../../components/withStatusIndicator';
import { useFetch } from '../../../hooks/useFetch';
import { Store } from './store';
import { StorePoolPanel } from './StorePoolPanel';
interface StoreListProps {
[storeType: string]: Store[];
}
export const StoreContent: FC<{ data: StoreListProps }> = ({ data }) => {
return (
<>
{Object.keys(data).map<JSX.Element>(storeGroup => (
<StorePoolPanel key={storeGroup} title={storeGroup} storePool={data[storeGroup]} />
))}
</>
);
};
const StoresWithStatusIndicator = withStatusIndicator(StoreContent);
export const Stores: FC<RouteComponentProps> = () => {
const { response, error, isLoading } = useFetch<StoreListProps>(`/api/v1/stores`);
const { status: responseStatus } = response;
const badResponse = responseStatus !== 'success' && responseStatus !== 'start fetching';
return (
<StoresWithStatusIndicator
data={response.data}
error={badResponse ? new Error(responseStatus) : error}
isLoading={isLoading}
/>
);
};
export default Stores;