[bugfix] Ensure the delete function is callable and correctly handled in config setters.
This commit is contained in:
@@ -226,7 +226,7 @@ export const SETTINGS_ARRAY = [
|
|||||||
Base_Name: "DeepLAuthKey",
|
Base_Name: "DeepLAuthKey",
|
||||||
default_value: "",
|
default_value: "",
|
||||||
ui_template_id: "input",
|
ui_template_id: "input",
|
||||||
logics_template_id: "get_set",
|
logics_template_id: "get_set_delete",
|
||||||
base_endpoint_name: "deepl_auth_key",
|
base_endpoint_name: "deepl_auth_key",
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -558,24 +558,19 @@ for (const setting_data of SETTINGS_ARRAY) {
|
|||||||
const buildCategoryApiFromSettings = (settings, settingsArray, Category, extraFunctions = {}) => {
|
const buildCategoryApiFromSettings = (settings, settingsArray, Category, extraFunctions = {}) => {
|
||||||
const api = {};
|
const api = {};
|
||||||
const filtered = settingsArray.filter((s) => s.Category === Category);
|
const filtered = settingsArray.filter((s) => s.Category === Category);
|
||||||
|
const COMMON_PROPS = [ "current", "update", "get", "set", "toggle", "setSuccess", "delete", "deleteSuccess", "updateFromBackend" ];
|
||||||
|
|
||||||
for (const s of filtered) {
|
for (const s of filtered) {
|
||||||
const base = s.Base_Name;
|
const base = s.Base_Name;
|
||||||
const currentKey = `current${base}`;
|
|
||||||
const updateKey = `update${base}`;
|
|
||||||
const getKey = `get${base}`;
|
|
||||||
const setKey = `set${base}`;
|
|
||||||
const toggleKey = `toggle${base}`;
|
|
||||||
const setSuccessKey = `setSuccess${base}`;
|
|
||||||
const updateFromBackendKey = `updateFromBackend${base}`;
|
|
||||||
|
|
||||||
if (settings[currentKey] !== undefined) api[currentKey] = settings[currentKey];
|
COMMON_PROPS.forEach(prop => {
|
||||||
if (settings[updateKey] !== undefined) api[updateKey] = settings[updateKey];
|
const key = `${prop}${base}`;
|
||||||
if (typeof settings[getKey] === "function") api[getKey] = settings[getKey];
|
const settingValue = settings[key];
|
||||||
if (typeof settings[setKey] === "function") api[setKey] = settings[setKey];
|
|
||||||
if (typeof settings[toggleKey] === "function") api[toggleKey] = settings[toggleKey];
|
if (settingValue !== undefined) {
|
||||||
if (typeof settings[setSuccessKey] === "function") api[setSuccessKey] = settings[setSuccessKey];
|
api[key] = settingValue;
|
||||||
if (typeof settings[updateFromBackendKey] === "function") api[updateFromBackendKey] = settings[updateFromBackendKey];
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (s.logics_template_id === "weight_download_status") {
|
if (s.logics_template_id === "weight_download_status") {
|
||||||
const updateDownloadProgressKey = `updateDownloadProgress${base}`;
|
const updateDownloadProgressKey = `updateDownloadProgress${base}`;
|
||||||
@@ -589,6 +584,8 @@ const buildCategoryApiFromSettings = (settings, settingsArray, Category, extraFu
|
|||||||
if (typeof settings[pendingKey] === "function") api[pendingKey] = settings[pendingKey];
|
if (typeof settings[pendingKey] === "function") api[pendingKey] = settings[pendingKey];
|
||||||
if (typeof settings[downloadedKey] === "function") api[downloadedKey] = settings[downloadedKey];
|
if (typeof settings[downloadedKey] === "function") api[downloadedKey] = settings[downloadedKey];
|
||||||
if (typeof settings[downloadKey] === "function") api[downloadKey] = settings[downloadKey];
|
if (typeof settings[downloadKey] === "function") api[downloadKey] = settings[downloadKey];
|
||||||
|
|
||||||
|
const updateFromBackendKey = `updateFromBackend${base}`;
|
||||||
if (typeof settings[updateFromBackendKey] === "function") api[updateFromBackendKey] = settings[updateFromBackendKey];
|
if (typeof settings[updateFromBackendKey] === "function") api[updateFromBackendKey] = settings[updateFromBackendKey];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,8 +55,10 @@ export const useSettingsLogics = (settingsArray, Category) => {
|
|||||||
const updateFromBackendExportName = `updateFromBackend${base}`;
|
const updateFromBackendExportName = `updateFromBackend${base}`;
|
||||||
const getExportName = `get${base}`;
|
const getExportName = `get${base}`;
|
||||||
const setExportName = `set${base}`;
|
const setExportName = `set${base}`;
|
||||||
|
const deleteExportName = `delete${base}`;
|
||||||
const toggleExportName = `toggle${base}`;
|
const toggleExportName = `toggle${base}`;
|
||||||
const setSuccessExportName = `setSuccess${base}`;
|
const setSuccessExportName = `setSuccess${base}`;
|
||||||
|
const deleteSuccessExportName = `deleteSuccess${base}`;
|
||||||
|
|
||||||
const runExportName = `runSuccess${base}`;
|
const runExportName = `runSuccess${base}`;
|
||||||
|
|
||||||
@@ -75,6 +77,13 @@ export const useSettingsLogics = (settingsArray, Category) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildDelete = () => {
|
||||||
|
return (value) => {
|
||||||
|
if (pending) pending();
|
||||||
|
asyncStdoutToPython(`/delete/data/${s.base_endpoint_name}`, value);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const buildRun = () => {
|
const buildRun = () => {
|
||||||
return () => {
|
return () => {
|
||||||
asyncStdoutToPython(`/run/${s.base_endpoint_name}`);
|
asyncStdoutToPython(`/run/${s.base_endpoint_name}`);
|
||||||
@@ -91,6 +100,14 @@ export const useSettingsLogics = (settingsArray, Category) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildDeleteSuccess = (transformName) => {
|
||||||
|
return (payload) => {
|
||||||
|
const transformed = transformResponse(transformName, payload);
|
||||||
|
if (update) update(transformed);
|
||||||
|
showNotification_SaveSuccess();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const buildUpdateFromBackend = (transformName) => {
|
const buildUpdateFromBackend = (transformName) => {
|
||||||
return (payload) => {
|
return (payload) => {
|
||||||
const transformed = transformResponse(transformName, payload);
|
const transformed = transformResponse(transformName, payload);
|
||||||
@@ -120,6 +137,15 @@ export const useSettingsLogics = (settingsArray, Category) => {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s.logics_template_id === "get_set_delete") {
|
||||||
|
result[getExportName] = buildGet();
|
||||||
|
result[setExportName] = buildSet();
|
||||||
|
result[setSuccessExportName] = buildSetSuccess(s.response_transform ?? null);
|
||||||
|
result[deleteExportName] = buildDelete();
|
||||||
|
result[deleteSuccessExportName] = buildDeleteSuccess(s.response_transform ?? null);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (s.logics_template_id === "toggle_enable_disable") {
|
if (s.logics_template_id === "toggle_enable_disable") {
|
||||||
result[getExportName] = buildGet();
|
result[getExportName] = buildGet();
|
||||||
result[toggleExportName] = () => {
|
result[toggleExportName] = () => {
|
||||||
|
|||||||
@@ -210,6 +210,7 @@ const buildRouteMetaList = () => {
|
|||||||
const ep = s.base_endpoint_name;
|
const ep = s.base_endpoint_name;
|
||||||
const hookName = `use${category}`;
|
const hookName = `use${category}`;
|
||||||
const setSuccessMethodName = `setSuccess${base}`;
|
const setSuccessMethodName = `setSuccess${base}`;
|
||||||
|
const deleteSuccessMethodName = `deleteSuccess${base}`;
|
||||||
const updateFromBackendMethodName = `updateFromBackend${base}`;
|
const updateFromBackendMethodName = `updateFromBackend${base}`;
|
||||||
|
|
||||||
|
|
||||||
@@ -231,6 +232,15 @@ const buildRouteMetaList = () => {
|
|||||||
method_name: updateFromBackendMethodName,
|
method_name: updateFromBackendMethodName,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (s.logics_template_id === "get_set_delete") {
|
||||||
|
generated.push({
|
||||||
|
endpoint: `/delete/data/${ep}`,
|
||||||
|
ns: namespace_module,
|
||||||
|
hook_name: hookName,
|
||||||
|
method_name: deleteSuccessMethodName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (s.logics_template_id !== "get_list") {
|
if (s.logics_template_id !== "get_list") {
|
||||||
generated.push({
|
generated.push({
|
||||||
endpoint: `/set/data/${ep}`,
|
endpoint: `/set/data/${ep}`,
|
||||||
|
|||||||
@@ -215,7 +215,9 @@ const DeeplAuthKey_Box = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const saveFunction = () => {
|
const saveFunction = () => {
|
||||||
if (input_value === "") return deleteDeepLAuthKey();
|
if (input_value === "" || input_value === null) {
|
||||||
|
return deleteDeepLAuthKey();
|
||||||
|
};
|
||||||
setDeepLAuthKey(input_value);
|
setDeepLAuthKey(input_value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user