-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 6735de8.
- Loading branch information
Ade Yahya Prasetyo
authored and
mirza adipradhana
committed
May 5, 2021
1 parent
70770d3
commit 0dcfc91
Showing
11 changed files
with
439 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom'; | ||
import { Stack } from '@chakra-ui/react'; | ||
import { Image, Box } from '@chakra-ui/react'; | ||
|
||
import SidePanel from './components/SidePanel'; | ||
import MainPanel from './components/MainPanel'; | ||
|
||
// pages | ||
import Home from './pages/Home'; | ||
|
||
function App() { | ||
return ( | ||
<Router> | ||
<Stack direction="row"> | ||
<SidePanel w="300px"> | ||
<Box w="200px" position="sticky" top="0" left="0" py="1rem" px="2rem"> | ||
<Image src="/warlock.svg" /> | ||
</Box> | ||
<Stack spacing="0"> | ||
<Link to="/"> | ||
<Box px="2rem" py="1rem" bg="gray.100"> | ||
Home | ||
</Box> | ||
</Link> | ||
</Stack> | ||
</SidePanel> | ||
<MainPanel flex="1"> | ||
<Switch> | ||
<Route path="/"> | ||
<Home /> | ||
</Route> | ||
</Switch> | ||
</MainPanel> | ||
</Stack> | ||
</Router> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import { Box, BoxProps } from '@chakra-ui/react'; | ||
|
||
const MainPanel: React.FC<BoxProps> = (props) => { | ||
return ( | ||
<Box p="3rem" width="100%" height="100vh" overflowY="auto" {...props} /> | ||
); | ||
}; | ||
|
||
export default MainPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { Stack, StackProps } from '@chakra-ui/react'; | ||
|
||
const SidePanel: React.FC<StackProps> = (props) => { | ||
return ( | ||
<Stack | ||
spacing="1rem" | ||
bg="gray.200" | ||
width="100%" | ||
height="100vh" | ||
overflowY="auto" | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default SidePanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { useQuery } from 'react-query'; | ||
import { getConfig } from '../service/config'; | ||
|
||
export const useConfigQuery = () => useQuery('config', getConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
import reportWebVitals from './reportWebVitals'; | ||
import { ChakraProvider } from '@chakra-ui/react'; | ||
import { QueryClient, QueryClientProvider } from 'react-query'; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<QueryClientProvider client={queryClient}> | ||
<ChakraProvider> | ||
<App /> | ||
</ChakraProvider> | ||
</QueryClientProvider> | ||
</React.StrictMode>, | ||
document.getElementById('root'), | ||
); | ||
|
||
// If you want to start measuring performance in your app, pass a function | ||
// to log results (for example: reportWebVitals(console.log)) | ||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals | ||
reportWebVitals(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React from 'react'; | ||
import { Box, Stack, Text, Heading, Badge, Switch } from '@chakra-ui/react'; | ||
import * as F from 'fp-ts/function'; | ||
|
||
import { WarlockConfig } from '../../types'; | ||
import { useConfigQuery } from '../hooks/config'; | ||
|
||
export const flattenPathHandler = (pathHandler: WarlockConfig.Transform) => { | ||
return F.flow((data: WarlockConfig.Transform) => { | ||
return Object.keys(data).map((key) => ({ | ||
key, | ||
...data[key], | ||
})); | ||
})(pathHandler); | ||
}; | ||
|
||
const verbColorsMap = { | ||
get: 'orange', | ||
post: 'pink', | ||
patch: 'teal', | ||
delete: 'blue', | ||
put: 'cyan', | ||
}; | ||
|
||
const Home = () => { | ||
const { data } = useConfigQuery(); | ||
|
||
const sources = data?.data?.rest?.sources ?? []; | ||
|
||
return ( | ||
<Stack spacing="2rem"> | ||
<Heading>Rest Transforms</Heading> | ||
<Stack spacing="2rem"> | ||
{sources.map((source) => ( | ||
<Stack key={source.origin}> | ||
<Stack spacing="1px"> | ||
<Heading size="sm">{source.name}</Heading> | ||
<Text fontSize="sm">{source.origin}</Text> | ||
</Stack> | ||
<Stack px="1rem" bg="gray.100" rounded="md" pb="1rem" spacing="1px"> | ||
{flattenPathHandler(source.transforms as any)?.map((handler) => ( | ||
<Stack key={handler.key} spacing="2px" p="1rem"> | ||
<Stack | ||
direction="row" | ||
align="center" | ||
justify="space-between" | ||
mb="-1rem" | ||
> | ||
<Text fontSize="sm" fontWeight="bold" py="1rem"> | ||
{handler.key} | ||
</Text> | ||
<Switch isChecked /> | ||
</Stack> | ||
<Stack spacing="1rem"> | ||
{Object.keys(handler).map((verb) => ( | ||
<Stack key={verb} spacing="1rem"> | ||
{handler[verb as 'get']?.map?.((fieldHandler) => ( | ||
<Box | ||
key={fieldHandler.field} | ||
bg={`${verbColorsMap[verb]}.100`} | ||
shadow="md" | ||
py="0.5rem" | ||
px="1rem" | ||
rounded="md" | ||
> | ||
<Stack | ||
direction="row" | ||
align="center" | ||
justify="space-between" | ||
> | ||
<Stack flex="1" direction="row" align="center"> | ||
<Badge>{verb}</Badge> | ||
<Text | ||
fontSize="sm" | ||
fontWeight="bold" | ||
color={`${verbColorsMap[verb]}.900`} | ||
> | ||
{fieldHandler.field} | ||
</Text> | ||
</Stack> | ||
<Switch | ||
isChecked | ||
colorScheme={verbColorsMap[verb]} | ||
/> | ||
</Stack> | ||
</Box> | ||
))} | ||
</Stack> | ||
))} | ||
</Stack> | ||
</Stack> | ||
))} | ||
</Stack> | ||
</Stack> | ||
))} | ||
</Stack> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default Home; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ReportHandler } from 'web-vitals'; | ||
|
||
const reportWebVitals = (onPerfEntry?: ReportHandler) => { | ||
if (onPerfEntry && onPerfEntry instanceof Function) { | ||
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { | ||
getCLS(onPerfEntry); | ||
getFID(onPerfEntry); | ||
getFCP(onPerfEntry); | ||
getLCP(onPerfEntry); | ||
getTTFB(onPerfEntry); | ||
}); | ||
} | ||
}; | ||
|
||
export default reportWebVitals; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import axios from 'axios'; | ||
import { Config } from '../../types'; | ||
|
||
export const getConfig = () => axios.get<Config>('/api/config'); |
Oops, something went wrong.