-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathCache.tsx
More file actions
114 lines (103 loc) · 2.99 KB
/
Cache.tsx
File metadata and controls
114 lines (103 loc) · 2.99 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { Fragment, useState } from "react";
import { css } from "@emotion/react";
import { gql, useQuery, useReactiveVar } from "@apollo/client";
import { rem } from "polished";
import { colors } from "@apollo/space-kit/colors";
import { SidebarLayout } from "../Layouts/SidebarLayout";
import { Search } from "./sidebar/Search";
import { EntityList } from "./sidebar/EntityList";
import { EntityView } from "./main/EntityView";
import { Loading } from "./common/Loading";
import { currentClient } from "../..";
const { Header, Sidebar, Main, Content } = SidebarLayout;
const h1Styles = css`
font-family: monospace;
font-weight: normal;
font-size: ${rem(20)};
`;
const headerLabelStyles = css`
margin: ${rem(3)} 0 0 ${rem(8)};
font-family: "Source Sans Pro", sans-serif;
color: ${colors.grey.light};
text-transform: uppercase;
font-size: ${rem(11)};
`;
const noDataStyles = css`
margin-left: ${rem(12)};
text-transform: uppercase;
font-size: ${rem(13)};
font-weight: normal;
letter-spacing: ${rem(1)};
color: var(--whiteTransparent);
padding-top: ${rem(16)};
`;
const GET_CACHE = gql`
query GetCache($clientId: ID!) {
client(id: $clientId) @client {
cache
}
}
`;
export function Cache({ navigationProps }: {
navigationProps: {
queriesCount: number,
mutationsCount: number,
}
}): JSX.Element {
const [searchResults, setSearchResults] = useState({});
const [cacheId, setCacheId] = useState<string>("ROOT_QUERY");
const selectedClient = useReactiveVar(currentClient);
const { loading, data } = useQuery(GET_CACHE, {
variables: {
clientId: selectedClient
}
});
let parsedData: Record<string, any> = {};
if (!loading && data && data?.client?.cache) {
parsedData = JSON.parse(data.client.cache);
}
const dataExists = parsedData && Object.keys(parsedData).length > 0;
return (
<SidebarLayout navigationProps={navigationProps}>
<Sidebar navigationProps={navigationProps}>
{loading ? (
<Loading />
) : dataExists ? (
<Fragment>
<Search data={parsedData} setSearchResults={setSearchResults} />
<EntityList
data={parsedData}
cacheId={cacheId}
setCacheId={setCacheId}
searchResults={searchResults}
/>
</Fragment>
) : (
<h3 css={noDataStyles}>No cache data</h3>
)}
</Sidebar>
<Content>
<Header>
{dataExists ? (
<Fragment>
<h1 css={h1Styles}>{cacheId || undefined}</h1>
<span css={headerLabelStyles}>CACHE ID</span>
</Fragment>
) : null}
</Header>
<Main>
{loading ? (
<Loading />
) : (
<EntityView
cacheId={cacheId}
data={parsedData[cacheId]}
searchResults={searchResults}
setCacheId={setCacheId}
/>
)}
</Main>
</Content>
</SidebarLayout>
);
}