function builder

This commit is contained in:
shamsmosowi
2021-09-09 23:21:34 +10:00
parent 65f5198c94
commit 8b322ca819
3 changed files with 40 additions and 41 deletions

View File

@@ -23,6 +23,7 @@ import Button from "@material-ui/core/Button";
import routes from "constants/routes";
import { SETTINGS } from "config/dbPaths";
import { name as appName } from "@root/package.json";
import { RunRoutes } from "@src/constants/runRoutes";
export default function FieldSettings(props: IMenuModalProps) {
const { name, fieldName, type, open, config, handleClose, handleSave } =
@@ -35,7 +36,7 @@ export default function FieldSettings(props: IMenuModalProps) {
const { requestConfirmation } = useConfirmation();
const { enqueueSnackbar } = useSnackbar();
const { tableState } = useProjectContext();
const { tableState, rowyRun } = useProjectContext();
const snackLog = useSnackLogContext();
const appContext = useAppContext();
@@ -123,44 +124,14 @@ export default function FieldSettings(props: IMenuModalProps) {
confirm: "Deploy",
cancel: "Later",
handleConfirm: async () => {
const settingsDoc = await db.doc(SETTINGS).get();
const buildUrl = settingsDoc.get("buildUrl");
if (!buildUrl) {
enqueueSnackbar(`${appName} Run is not set up`, {
variant: "error",
action: (
<Button
variant="contained"
color="secondary"
component={"a"}
target="_blank"
href={routes.projectSettings}
rel="noopener noreferrer"
>
Go to Settings
</Button>
),
});
}
const userTokenInfo =
await appContext?.currentUser?.getIdTokenResult();
const userToken = userTokenInfo?.token;
try {
snackLog.requestSnackLog();
const response = await fetch(buildUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
configPath: tableState?.config.tableConfig.path,
token: userToken,
}),
});
const data = await response.json();
} catch (e) {
console.error(e);
}
if (!rowyRun) return;
rowyRun({
route: RunRoutes.buildFunction,
body: {
configPath: tableState?.config.tableConfig.path,
},
params: [],
});
},
});
}

View File

@@ -2,9 +2,37 @@ export type RunRoute = {
path: string;
method: "POST" | "GET";
};
type impersonateUserRequest = {
path: "/impersonateUser";
method: "GET";
params: string[];
};
type ActionData = {
ref: {
id: string;
path: string;
parentId: string;
tablePath: string;
};
schemaDocPath?: string;
column: any;
action: "run" | "redo" | "undo";
actionParams: any;
};
type actionScriptRequest = {
path: "/actionScript";
method: "POST";
body: ActionData;
};
type RunRoutes = actionScriptRequest | impersonateUserRequest;
export const RunRoutes: { [key: string]: RunRoute } = {
impersonateUser: { path: "/impersonateUser", method: "GET" },
version: { path: "/version", method: "GET" },
listCollections: { path: "/listCollections", method: "GET" },
actionScript: { path: "/actionScript", method: "POST" },
buildFunction: { path: "/buildFunction", method: "POST" },
};

View File

@@ -193,7 +193,7 @@ export const ProjectContextProvider: React.FC = ({ children }) => {
}) => {
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, {
@@ -208,7 +208,7 @@ export const ProjectContextProvider: React.FC = ({ children }) => {
},
redirect: "follow", // manual, *follow, error
referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: method !== "GET" ? JSON.stringify(body) : null, // body data type must match "Content-Type" header
body: body && method !== "GET" ? JSON.stringify(body) : null, // body data type must match "Content-Type" header
});
console.log(response);
return response.json(); // parses JSON response into native JavaScript objects