Skip to content

Commit

Permalink
Revert "fix: remove www"
Browse files Browse the repository at this point in the history
This reverts commit 6735de8.
  • Loading branch information
Ade Yahya Prasetyo authored and mirza adipradhana committed May 5, 2021
1 parent 70770d3 commit 0dcfc91
Show file tree
Hide file tree
Showing 11 changed files with 439 additions and 27 deletions.
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@warungpintar/warlock",
"version": "1.1.7",
"version": "1.1.15",
"description": "Warung Pintar Mock + Foward Proxy API",
"keywords": [
"mock",
Expand All @@ -26,7 +26,7 @@
"lint": "eslint",
"prebuild": "rimraf dist",
"build": "concurrently yarn:build:*",
"build:esm": "cross-env NODE_ENV=test BUILD_ENV=esm babel src --extensions '.ts,.tsx' -d dist/esm --source-maps",
"build:esm": "cross-env NODE_ENV=production BUILD_ENV=esm babel src --extensions '.ts,.tsx' -d dist/esm --source-maps",
"build:cjs": "cross-env NODE_ENV=test BUILD_ENV=cjs babel src --extensions '.ts,.tsx' -d dist/cjs --source-maps",
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
"test": "concurrently yarn:test:*",
Expand All @@ -37,7 +37,9 @@
"prepublishOnly": "pinst --disable",
"postpublish": "pinst --enable",
"start": "concurrently yarn:start:*",
"start:server": "nodemon src/server.ts --watch .warlock.yaml --watch src"
"start:server": "nodemon src/server.ts --watch .warlock.yaml --watch src",
"start:www": "node scripts/start.js",
"build:www": "node scripts/build.js"
},
"dependencies": {
"@babel/core": "^7.12.17",
Expand All @@ -54,8 +56,8 @@
"@graphql-mesh/utils": "^0.10.0",
"@semantic-release/changelog": "^5.0.1",
"@warungpintar/ninshu": "^0.0.2",
"array-flat-polyfill": "^1.0.1",
"axios": "^0.21.1",
"babel-preset-react-app": "^10.0.0",
"body-parser": "^1.19.0",
"chalk": "^4.1.0",
"commander": "^7.1.0",
Expand All @@ -81,12 +83,12 @@
"node-lmdb": "^0.9.4",
"proxy-from-env": "^1.1.0",
"qs": "^6.9.6",
"react": "^17.0.2",
"sort-keys": "^4.2.0",
"sort-object": "^3.0.3",
"sort-object-keys": "^1.1.3",
"ts-node": "^9.1.1",
"url-pattern": "^1.0.3",
"array-flat-polyfill": "^1.0.1"
"url-pattern": "^1.0.3"
},
"devDependencies": {
"@chakra-ui/react": "^1.4.1",
Expand Down Expand Up @@ -176,7 +178,6 @@
"postcss-preset-env": "6.7.0",
"postcss-safe-parser": "5.0.2",
"prompts": "2.4.0",
"react": "^17.0.2",
"react-app-polyfill": "^2.0.0",
"react-dev-utils": "^11.0.3",
"react-dom": "^17.0.2",
Expand Down Expand Up @@ -225,7 +226,8 @@
[
"react-app",
{
"useBuiltIns": false
"useBuiltIns": "entry",
"absoluteRuntime": false
}
]
]
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'array-flat-polyfill';
import os from 'os';
import path from 'path';
import express from 'express';
import * as E from 'fp-ts/Either';
import * as F from 'fp-ts/function';
Expand Down Expand Up @@ -56,6 +57,7 @@ const init = () => {
// body parser and multer
app.use(parserMiddleware);
app.use('/graphql', graphqlMiddleware(app.get('config')));
app.use('/', express.static(path.join(__dirname, '../www')));
app.use('/api', apiRoutes);

app.use(coreMiddleware(cacheInstance));
Expand All @@ -65,7 +67,7 @@ const init = () => {
typeof res.locals === 'object' &&
Object.keys(res.locals).length === 0
) {
res.status(400);
return res.sendFile(path.join(__dirname, '../www/index.html'));
}

if (typeof res.locals === 'object') {
Expand Down
40 changes: 40 additions & 0 deletions src/www/App.tsx
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;
10 changes: 10 additions & 0 deletions src/www/components/MainPanel.tsx
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;
17 changes: 17 additions & 0 deletions src/www/components/SidePanel.tsx
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;
4 changes: 4 additions & 0 deletions src/www/hooks/config.ts
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);
24 changes: 24 additions & 0 deletions src/www/index.tsx
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();
101 changes: 101 additions & 0 deletions src/www/pages/Home.tsx
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;
15 changes: 15 additions & 0 deletions src/www/reportWebVitals.ts
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;
4 changes: 4 additions & 0 deletions src/www/service/config.ts
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');
Loading

0 comments on commit 0dcfc91

Please sign in to comment.