From 889a059ca41a4d1227e080174e4ffa7417826a9b Mon Sep 17 00:00:00 2001 From: Camille Moussu Date: Fri, 17 May 2024 16:43:48 +0400 Subject: [PATCH] [#8]fully functionning auth param --- .../authParamOptions/OptionRenderer.tsx | 105 +++++-- .../managerComponents/URLLoader.tsx | 1 - src/dashboards/AuthParams.tsx | 260 +++++++++--------- src/dashboards/Manager.tsx | 1 - src/features/config/configSlice.ts | 43 +++ 5 files changed, 256 insertions(+), 154 deletions(-) diff --git a/src/components/authParamOptions/OptionRenderer.tsx b/src/components/authParamOptions/OptionRenderer.tsx index 03271ee..d907914 100644 --- a/src/components/authParamOptions/OptionRenderer.tsx +++ b/src/components/authParamOptions/OptionRenderer.tsx @@ -26,14 +26,17 @@ import { delChoiceParam, delCombOverParam, delCombParam, + delModuleOpt, newChoiceOverParam, newChoiceParam, newCombOverParam, newCombParam, + newModuleOpt, updateChoiceOverParam, updateChoiceParam, updateCombOverParam, updateCombParam, + updateModuleOpt, updateModuleParams, } from "../../features/config/configSlice"; function updateComb( @@ -161,6 +164,7 @@ function cmbModuleContainer( , dispatch: Function) { @@ -398,6 +403,7 @@ function authChoiceContainer(data: Record, dispatch: Function) { @@ -413,6 +419,7 @@ function authChoiceContainer(data: Record, dispatch: Function) { @@ -503,7 +510,9 @@ function RecursRender( case "int": return (
    + {t(el)} dispatch( @@ -521,7 +530,9 @@ function RecursRender( case "text": return (
      + {t(el)} dispatch( @@ -539,7 +550,9 @@ function RecursRender( case "PerlModule": return (
        + {t(el)} dispatch( @@ -557,7 +570,9 @@ function RecursRender( case "password": return (
          + {t(el)} dispatch( @@ -575,7 +590,9 @@ function RecursRender( case "intOrNull": return (
            + {t(el)} dispatch( @@ -591,14 +608,27 @@ function RecursRender(
          ); case "authChoiceContainer": - return authChoiceContainer( - config[el as keyof llngConfig] as Record, - dispatch + return ( + <> + {t(el)} + {authChoiceContainer( + config[el as keyof llngConfig] as Record, + dispatch + )} + ); case "cmbModuleContainer": - return cmbModuleContainer( - config[el as keyof llngConfig] as Record>, - dispatch + return ( + <> + {t(el)}{" "} + {cmbModuleContainer( + config[el as keyof llngConfig] as Record< + string, + Record + >, + dispatch + )} + ); case "select": return ( @@ -665,35 +695,53 @@ function RecursRender( ); case "keyTextContainer": return ( - - - - - - - - - {TableVars( - el, - config[el as keyof llngConfig] as Record, - el + "Table", - console.log, - console.log, - console.log - )} -
          {t("keys")}{t("values")} - -
          + <> + {t(el)} + + + + + + + + + {TableVars( + el, + config[el as keyof llngConfig] as Record, + el + "Table", + dispatch, + delModuleOpt, + updateModuleOpt + )} +
          {t("keys")}{t("values")} + +
          + ); case "url": return (
            + {t(el)} + dispatch( + updateModuleParams({ + param: el as keyof llngConfig, + value: String(e.target.value), + }) + ) + } />
          ); @@ -726,6 +774,7 @@ function RecursRender( @@ -761,7 +810,7 @@ export function OptionRenderer({ selected }: { selected: string }) { return (
          {t(l)} -
          +
          {nodeSelected ? RecursRender(nodeSelected, config, 0, dispatch) : ""}
          diff --git a/src/components/managerComponents/URLLoader.tsx b/src/components/managerComponents/URLLoader.tsx index 809ebdd..5ff6ba1 100644 --- a/src/components/managerComponents/URLLoader.tsx +++ b/src/components/managerComponents/URLLoader.tsx @@ -33,7 +33,6 @@ export function URLLoader({ setLoading(true); setError(false); const data = await getFromURL(url); - console.log(data); dispatch( loadFunction({ name: appName ? appName : "", diff --git a/src/dashboards/AuthParams.tsx b/src/dashboards/AuthParams.tsx index 7d71ea5..cae5997 100644 --- a/src/dashboards/AuthParams.tsx +++ b/src/dashboards/AuthParams.tsx @@ -5,12 +5,17 @@ import { useAppDispatch, useAppSelector } from "../app/hooks"; import "./AuthParams.css"; import { useState } from "react"; import { OptionRenderer } from "../components/authParamOptions/OptionRenderer"; -import { updateAuthParams } from "../features/config/configSlice"; +import { + removeError, + setError, + updateAuthParams, +} from "../features/config/configSlice"; export function AuthParams() { const dispatch = useAppDispatch(); const authChoiceModules = useAppSelector( (state) => state.config.data.config.authChoiceModules ); + const config = useAppSelector((state) => state.config); const authModule = useAppSelector( (state) => state.config.data.config.authentication ); @@ -51,132 +56,139 @@ export function AuthParams() { ]; const [optionSelected, setOptionSelected] = useState(authModule); - - return ( -
          + try { + return (
          - {t("authParams")} -
          -
          - - - {t("authentication")} - - - - - {t("userDB")} - + dispatch( + updateAuthParams({ + param: "authentication", + value: String(e.target.value), + }) + ) + } + > + {attributes.authentication.select.map((el) => { + return ( + + {t(el.v)} + + ); + })} + + + + {t("userDB")} + + + + {t("passwordDB")} + + + + {t("registerDB")} + - - - {t("passwordDB")} - - - - {t("registerDB")} - - -
          -
          - {allOptChoices.map((el) => - selectedOptions.includes(el.k) && el.k !== "Same" ? ( - setOptionSelected(el.k)}> - {el.v} - - ) : ( - <> - ) - )} + ))} + + +
          +
          + {allOptChoices.map((el) => + selectedOptions.includes(el.k) && el.k !== "Same" ? ( + setOptionSelected(el.k)}> + {el.v} + + ) : ( + <> + ) + )} +
          +
          + +
          -
          - -
          -
          - ); + ); + } catch (e) { + if (e instanceof Error) { + dispatch(setError(`${e.name} : ${e.message}`)); + dispatch(removeError()); + } + return
          {config.error.errorContent}
          ; + } } diff --git a/src/dashboards/Manager.tsx b/src/dashboards/Manager.tsx index 9d9f744..4c9f1ab 100644 --- a/src/dashboards/Manager.tsx +++ b/src/dashboards/Manager.tsx @@ -37,7 +37,6 @@ export default function Manager() { ); useEffect(() => { - console.log(configNum, config.data.metadata.cfgNum); if (!configPresent) { setConfigPresent(true); dispatch( diff --git a/src/features/config/configSlice.ts b/src/features/config/configSlice.ts index 4ea373e..a2aff03 100644 --- a/src/features/config/configSlice.ts +++ b/src/features/config/configSlice.ts @@ -876,6 +876,46 @@ const configSlice = createSlice({ } } }, + newModuleOpt( + state: { + data: { config: llngConfig; metadata: MetaData }; + }, + action: PayloadAction + ) { + if (!state.data.config[action.payload]) { + state.data.config[action.payload] = {} as llngConfig[K]; + } + if (typeof state.data.config[action.payload] === "object") { + (state.data.config[action.payload] as Record)["new"] = + ""; + } + }, + updateModuleOpt( + state: { + data: { config: llngConfig; metadata: MetaData }; + }, + action: PayloadAction<{ name: K; data: Record }> + ) { + if (!state.data.config[action.payload.name]) { + state.data.config[action.payload.name] = {} as llngConfig[K]; + } + state.data.config[action.payload.name] = action.payload + .data as llngConfig[K]; + }, + delModuleOpt( + state: { + data: { config: llngConfig; metadata: MetaData }; + }, + action: PayloadAction<{ name: K; key: string }> + ) { + if (state.data.config[action.payload.name]) { + if (typeof state.data.config[action.payload.name] === "object") { + delete ( + state.data.config[action.payload.name] as Record + )[action.payload.key]; + } + } + }, }, extraReducers: (builder) => { builder @@ -979,5 +1019,8 @@ export const { newChoiceOverParam, delChoiceOverParam, updateChoiceOverParam, + newModuleOpt, + delModuleOpt, + updateModuleOpt, } = configSlice.actions; export default configSlice.reducer;