[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",
|
||||
default_value: "",
|
||||
ui_template_id: "input",
|
||||
logics_template_id: "get_set",
|
||||
logics_template_id: "get_set_delete",
|
||||
base_endpoint_name: "deepl_auth_key",
|
||||
},
|
||||
|
||||
@@ -558,24 +558,19 @@ for (const setting_data of SETTINGS_ARRAY) {
|
||||
const buildCategoryApiFromSettings = (settings, settingsArray, Category, extraFunctions = {}) => {
|
||||
const api = {};
|
||||
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) {
|
||||
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];
|
||||
if (settings[updateKey] !== undefined) api[updateKey] = settings[updateKey];
|
||||
if (typeof settings[getKey] === "function") api[getKey] = settings[getKey];
|
||||
if (typeof settings[setKey] === "function") api[setKey] = settings[setKey];
|
||||
if (typeof settings[toggleKey] === "function") api[toggleKey] = settings[toggleKey];
|
||||
if (typeof settings[setSuccessKey] === "function") api[setSuccessKey] = settings[setSuccessKey];
|
||||
if (typeof settings[updateFromBackendKey] === "function") api[updateFromBackendKey] = settings[updateFromBackendKey];
|
||||
COMMON_PROPS.forEach(prop => {
|
||||
const key = `${prop}${base}`;
|
||||
const settingValue = settings[key];
|
||||
|
||||
if (settingValue !== undefined) {
|
||||
api[key] = settingValue;
|
||||
}
|
||||
});
|
||||
|
||||
if (s.logics_template_id === "weight_download_status") {
|
||||
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[downloadedKey] === "function") api[downloadedKey] = settings[downloadedKey];
|
||||
if (typeof settings[downloadKey] === "function") api[downloadKey] = settings[downloadKey];
|
||||
|
||||
const updateFromBackendKey = `updateFromBackend${base}`;
|
||||
if (typeof settings[updateFromBackendKey] === "function") api[updateFromBackendKey] = settings[updateFromBackendKey];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,8 +55,10 @@ export const useSettingsLogics = (settingsArray, Category) => {
|
||||
const updateFromBackendExportName = `updateFromBackend${base}`;
|
||||
const getExportName = `get${base}`;
|
||||
const setExportName = `set${base}`;
|
||||
const deleteExportName = `delete${base}`;
|
||||
const toggleExportName = `toggle${base}`;
|
||||
const setSuccessExportName = `setSuccess${base}`;
|
||||
const deleteSuccessExportName = `deleteSuccess${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 = () => {
|
||||
return () => {
|
||||
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) => {
|
||||
return (payload) => {
|
||||
const transformed = transformResponse(transformName, payload);
|
||||
@@ -120,6 +137,15 @@ export const useSettingsLogics = (settingsArray, Category) => {
|
||||
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") {
|
||||
result[getExportName] = buildGet();
|
||||
result[toggleExportName] = () => {
|
||||
|
||||
@@ -210,6 +210,7 @@ const buildRouteMetaList = () => {
|
||||
const ep = s.base_endpoint_name;
|
||||
const hookName = `use${category}`;
|
||||
const setSuccessMethodName = `setSuccess${base}`;
|
||||
const deleteSuccessMethodName = `deleteSuccess${base}`;
|
||||
const updateFromBackendMethodName = `updateFromBackend${base}`;
|
||||
|
||||
|
||||
@@ -231,6 +232,15 @@ const buildRouteMetaList = () => {
|
||||
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") {
|
||||
generated.push({
|
||||
endpoint: `/set/data/${ep}`,
|
||||
|
||||
@@ -215,7 +215,9 @@ const DeeplAuthKey_Box = () => {
|
||||
};
|
||||
|
||||
const saveFunction = () => {
|
||||
if (input_value === "") return deleteDeepLAuthKey();
|
||||
if (input_value === "" || input_value === null) {
|
||||
return deleteDeepLAuthKey();
|
||||
};
|
||||
setDeepLAuthKey(input_value);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user