mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
actionScript
This commit is contained in:
@@ -12,6 +12,7 @@ import { cloudFunction } from "firebase/callables";
|
||||
import { formatPath } from "utils/fns";
|
||||
import { useConfirmation } from "components/ConfirmationDialog";
|
||||
import { useActionParams } from "./FormDialog/Context";
|
||||
import { RunRoutes } from "@src/constants/runRoutes";
|
||||
|
||||
const replacer = (data: any) => (m: string, key: string) => {
|
||||
const objKey = key.split(":")[0];
|
||||
@@ -49,7 +50,7 @@ export default function ActionFab({
|
||||
const { requestConfirmation } = useConfirmation();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
const { requestParams } = useActionParams();
|
||||
const { tableState } = useProjectContext();
|
||||
const { tableState, rowyRun } = useProjectContext();
|
||||
const { ref } = row;
|
||||
const { config } = column as any;
|
||||
|
||||
@@ -64,7 +65,8 @@ export default function ActionFab({
|
||||
|
||||
const callableName: string =
|
||||
(column as any).callableName ?? config.callableName ?? "actionScript";
|
||||
const handleRun = (actionParams = null) => {
|
||||
const handleRun = async (actionParams = null) => {
|
||||
if (!rowyRun) return;
|
||||
setIsRunning(true);
|
||||
|
||||
const data = {
|
||||
@@ -74,27 +76,34 @@ export default function ActionFab({
|
||||
schemaDocPath: formatPath(tableState?.tablePath ?? ""),
|
||||
actionParams,
|
||||
};
|
||||
cloudFunction(
|
||||
callableName,
|
||||
data,
|
||||
async (response) => {
|
||||
const { message, cellValue, success } = response.data;
|
||||
setIsRunning(false);
|
||||
enqueueSnackbar(JSON.stringify(message), {
|
||||
variant: success ? "success" : "error",
|
||||
});
|
||||
if (cellValue && cellValue.status) {
|
||||
await ref.update({
|
||||
[column.key]: cellValue,
|
||||
});
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
console.error("ERROR", callableName, error);
|
||||
setIsRunning(false);
|
||||
enqueueSnackbar(JSON.stringify(error), { variant: "error" });
|
||||
}
|
||||
);
|
||||
|
||||
const resp = await rowyRun({
|
||||
route: RunRoutes.actionScript,
|
||||
body: data,
|
||||
params: [],
|
||||
});
|
||||
const { message, success } = resp;
|
||||
setIsRunning(false);
|
||||
enqueueSnackbar(JSON.stringify(message), {
|
||||
variant: success ? "success" : "error",
|
||||
});
|
||||
|
||||
// cloudFunction(
|
||||
// callableName,
|
||||
// data,
|
||||
// async (response) => {
|
||||
// const { message, cellValue, success } = response.data;
|
||||
// setIsRunning(false);
|
||||
// enqueueSnackbar(JSON.stringify(message), {
|
||||
// variant: success ? "success" : "error",
|
||||
// });
|
||||
// },
|
||||
// (error) => {
|
||||
// console.error("ERROR", callableName, error);
|
||||
// setIsRunning(false);
|
||||
// enqueueSnackbar(JSON.stringify(error), { variant: "error" });
|
||||
// }
|
||||
// );
|
||||
};
|
||||
const hasRan = value && value.status;
|
||||
|
||||
|
||||
@@ -6,4 +6,5 @@ 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" },
|
||||
};
|
||||
|
||||
@@ -194,9 +194,8 @@ export const ProjectContextProvider: React.FC = ({ children }) => {
|
||||
const { method, path } = route;
|
||||
let url =
|
||||
//'http://localhost:8080'
|
||||
settings.doc.rowyRunUrl + route.path;
|
||||
settings.doc.rowyRunUrl + path;
|
||||
if (params && params.length > 0) url = url + "/" + params.join("/");
|
||||
console.log(url, settings);
|
||||
const response = await fetch(url, {
|
||||
method: method, // *GET, POST, PUT, DELETE, etc.
|
||||
mode: "cors", // no-cors, *cors, same-origin
|
||||
@@ -211,6 +210,7 @@ export const ProjectContextProvider: React.FC = ({ children }) => {
|
||||
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
|
||||
});
|
||||
console.log(response);
|
||||
return response.json(); // parses JSON response into native JavaScript objects
|
||||
};
|
||||
// A ref to the data grid. Contains data grid functions
|
||||
|
||||
Reference in New Issue
Block a user