fix function builder not getting the latest config

This commit is contained in:
shamsmosowi
2021-12-10 10:13:58 +07:00
parent 51a12b647b
commit c62f3a9658
4 changed files with 56 additions and 46 deletions

View File

@@ -74,32 +74,34 @@ export default function Extensions() {
}
};
const handleSaveExtensions = () => {
const handleSaveExtensions = (callback?: Function) => {
tableActions?.table.updateConfig(
"extensionObjects",
localExtensionsObjects
localExtensionsObjects,
callback
);
setOpen(false);
};
const handleSaveDeploy = async () => {
handleSaveExtensions();
try {
if (rowyRun) {
snackLogContext.requestSnackLog();
rowyRun({
route: runRoutes.buildFunction,
body: {
tablePath: tableState?.tablePath,
pathname: window.location.pathname,
tableConfigPath: tableState?.config.tableConfig.path,
},
});
analytics.logEvent("deployed_extensions");
handleSaveExtensions(() => {
try {
if (rowyRun) {
snackLogContext.requestSnackLog();
rowyRun({
route: runRoutes.buildFunction,
body: {
tablePath: tableState?.tablePath,
pathname: window.location.pathname,
tableConfigPath: tableState?.config.tableConfig.path,
},
});
analytics.logEvent("deployed_extensions");
}
} catch (e) {
console.error(e);
}
} catch (e) {
console.error(e);
}
});
};
const handleAddExtension = (extensionObject: IExtension) => {
@@ -233,7 +235,7 @@ export default function Extensions() {
},
secondary: {
children: "Save",
onClick: handleSaveExtensions,
onClick: () => handleSaveExtensions(),
disabled: !edited,
},
}}

View File

@@ -65,35 +65,38 @@ export default function Webhooks() {
}
};
const handleSaveWebhooks = async () => {
tableActions?.table.updateConfig("webhooks", localWebhooksObjects);
const handleSaveWebhooks = async (callback?: Function) => {
tableActions?.table.updateConfig(
"webhooks",
localWebhooksObjects,
callback
);
setOpen(false);
// TODO: convert to async function that awaits for the document write to complete
await new Promise((resolve) => setTimeout(resolve, 500));
};
const handleSaveDeploy = async () => {
await handleSaveWebhooks();
try {
if (rowyRun) {
const resp = await rowyRun({
service: "hooks",
route: runRoutes.publishWebhooks,
body: {
tableConfigPath: tableState?.config.tableConfig.path,
tablePath: tableState?.tablePath,
},
});
enqueueSnackbar(resp.message, {
variant: resp.success ? "success" : "error",
});
analytics.logEvent("published_webhooks");
const handleSaveDeploy = () =>
handleSaveWebhooks(async () => {
try {
if (rowyRun) {
const resp = await rowyRun({
service: "hooks",
route: runRoutes.publishWebhooks,
body: {
tableConfigPath: tableState?.config.tableConfig.path,
tablePath: tableState?.tablePath,
},
});
enqueueSnackbar(resp.message, {
variant: resp.success ? "success" : "error",
});
analytics.logEvent("published_webhooks");
}
} catch (e) {
console.error(e);
}
} catch (e) {
console.error(e);
}
};
});
const handleAddWebhook = (webhookObject: IWebhook) => {
setLocalWebhooksObjects([...localWebhooksObjects, webhookObject]);
@@ -205,12 +208,16 @@ export default function Webhooks() {
actions={{
primary: {
children: "Save & Deploy",
onClick: handleSaveDeploy,
onClick: () => {
handleSaveDeploy();
},
disabled: !edited,
},
secondary: {
children: "Save",
onClick: handleSaveWebhooks,
onClick: () => {
handleSaveWebhooks();
},
disabled: !edited,
},
}}

View File

@@ -28,7 +28,7 @@ const useDoc = (
(prevState.ref ? prevState.ref : db.doc(prevState.path))
.set({ ...newProps.data }, { merge: true })
.then(() => {})
.then(newProps.callback ? newProps.callback : () => {})
.catch((error) => {
console.log(error);
documentDispatch({ error });

View File

@@ -150,10 +150,11 @@ const useTableConfig = (tablePath?: string) => {
* @param key name of parameter eg. rowHeight
* @param value new value eg. 65
*/
const updateConfig = (key: string, value: unknown) => {
const updateConfig = (key: string, value: unknown, callback?: Function) => {
documentDispatch({
action: DocActions.update,
data: { [key]: value },
callback,
});
};
const actions = {