This commit is contained in:
Sidney Alcantara
2021-09-14 11:13:04 +10:00
6 changed files with 111 additions and 5 deletions

View File

@@ -25,6 +25,7 @@ import routes from "constants/routes";
import AuthView from "pages/Auth";
import SignOutView from "pages/Auth/SignOut";
import TestView from "pages/Test";
import RowyRunTestView from "pages/RowyRunTest";
import Favicon from "assets/Favicon";
import "analytics";
@@ -107,6 +108,7 @@ export default function App() {
routes.userSettings,
routes.userManagement,
routes.impersonatorAuth,
routes.rowyRunTest,
]}
render={() => (
<ProjectContextProvider>
@@ -116,6 +118,11 @@ export default function App() {
path={routes.impersonatorAuth}
render={() => <ImpersonatorAuthPage />}
/>
<Route
exact
path={routes.rowyRunTest}
render={() => <RowyRunTestView />}
/>
<PrivateRoute
exact
path={routes.home}

View File

@@ -128,7 +128,8 @@ export default function FieldSettings(props: IMenuModalProps) {
rowyRun({
route: RunRoutes.buildFunction,
body: {
configPath: tableState?.config.tableConfig.path,
triggerPath: "demoAllFieldTypes/{docId}",
// configPath: tableState?.config.tableConfig.path,
},
params: [],
});

View File

@@ -20,6 +20,7 @@ export enum routes {
userSettings = "/settings/user",
projectSettings = "/settings/project",
userManagement = "/settings/userManagement",
rowyRunTest = "/rrTest",
}
export default routes;

View File

@@ -32,6 +32,7 @@ type RunRoutes = actionScriptRequest | impersonateUserRequest;
export const RunRoutes: { [key: string]: RunRoute } = {
impersonateUser: { path: "/impersonateUser", method: "GET" },
version: { path: "/version", method: "GET" },
region: { path: "/region", method: "GET" },
listCollections: { path: "/listCollections", method: "GET" },
actionScript: { path: "/actionScript", method: "POST" },
buildFunction: { path: "/buildFunction", method: "POST" },

View File

@@ -72,7 +72,7 @@ interface ProjectContextProps {
rowyRun: (args: {
route: RunRoute;
body?: any;
params: string[];
params?: string[];
}) => Promise<any>;
}
@@ -181,7 +181,7 @@ export const ProjectContextProvider: React.FC = ({ children }) => {
}
);
};
console.log("tableState", tableState);
// rowyRun access
const rowyRun = async ({
route,
@@ -190,11 +190,11 @@ export const ProjectContextProvider: React.FC = ({ children }) => {
}: {
route: RunRoute;
body?: any;
params: string[];
params?: string[];
}) => {
const { method, path } = route;
let url =
// 'http://localhost:8080'
//'http://localhost:8080'
settings.doc.rowyRunUrl + path;
if (params && params.length > 0) url = url + "/" + params.join("/");
const response = await fetch(url, {

96
src/pages/RowyRunTest.tsx Normal file
View File

@@ -0,0 +1,96 @@
import { useState } from "react";
import { useSnackbar } from "notistack";
import Navigation from "components/Navigation";
import {
useTheme,
Container,
Button,
TextField,
Tabs,
Tab,
LinearProgress,
Select,
InputLabel,
MenuItem,
FormControl,
} from "@mui/material";
import SparkIcon from "@mui/icons-material/OfflineBoltOutlined";
import { useConfirmation } from "components/ConfirmationDialog";
import SnackbarProgress, {
ISnackbarProgressRef,
} from "components/SnackbarProgress";
import { useProjectContext } from "@src/contexts/ProjectContext";
import { RunRoutes } from "@src/constants/runRoutes";
export default function TestView() {
const theme = useTheme();
const { requestConfirmation } = useConfirmation();
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
const [loading, setLoading] = useState(false);
const { rowyRun } = useProjectContext();
const [result, setResult] = useState<any>({});
const [method, setMethod] = useState<"GET" | "POST">("GET");
const [path, setPath] = useState<string>("/");
const handleMethodChange = (_, newMethod) => setMethod(newMethod);
const setDefinedRoute = (newPath) => {
setPath(newPath.target.value);
const _method = Object.values(RunRoutes).find(
(r) => r.path === path
)?.method;
if (_method) {
setMethod(_method);
}
};
const handleRun = async () => {
console.log("run");
if (!rowyRun) return;
setLoading(true);
const resp = await rowyRun({
route: {
method,
path,
},
});
setResult(resp);
setLoading(false);
};
return (
<Navigation title="Rowy Run Sandbox">
{loading && <LinearProgress />}
<Container style={{ margin: "24px 0 200px" }}>
<FormControl style={{ minWidth: 240 }}>
<InputLabel>Defined Route</InputLabel>
<Select
value={
Object.values(RunRoutes).find((r) => r.path === path)?.path ?? ""
}
onChange={setDefinedRoute}
>
{Object.values(RunRoutes).map((route) => (
<MenuItem key={route.path} value={route.path}>
{route.path}
</MenuItem>
))}
</Select>
</FormControl>
<Tabs value={method} onChange={handleMethodChange}>
<Tab label="GET" value="GET" />
<Tab label="POST" value="POST" />
<Tab label="PUT" value="PUT" />
<Tab label="DELETE" value="DELETE" />
</Tabs>
<TextField
value={path}
onChange={(value) => {
setPath(value.target.value);
}}
/>
<Button onClick={handleRun}>Call</Button>
<pre>{JSON.stringify(result, null, 2)}</pre>
</Container>
</Navigation>
);
}