Skip to content

Commit

Permalink
[fix] metadata are taken form /partial and not /confs
Browse files Browse the repository at this point in the history
  • Loading branch information
Camille Moussu committed Nov 20, 2024
1 parent 6f45a1e commit 9703e46
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 94 deletions.
44 changes: 29 additions & 15 deletions src/dashboards/PartialManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export default function PartialManager() {
useEffect(() => {
if (!configPresent) {
setConfigPresent(true);
dispatch(
getPartialConfigAsync(configNum === "latest" ? undefined : Number(configNum))
);
dispatch(getPartialConfigAsync());
}
const appNum =
(config.data.config.locationRules ? Object.keys(config.data.config.locationRules).length : 0) +
(config.data.config.locationRules
? Object.keys(config.data.config.locationRules).length
: 0) +
(config.data.config.samlSPMetaDataXML
? Object.keys(config.data.config.samlSPMetaDataXML).length
: 0) +
Expand All @@ -56,10 +56,22 @@ export default function PartialManager() {
? Object.keys(config.data.config.casAppMetaDataOptions).length
: 0);
if (appNum === 1) {
const name = config.data.config.locationRules || config.data.config.samlSPMetaDataXML || config.data.config.oidcRPMetaDataOptions || config.data.config.casAppMetaDataOptions
const type = config.data.config.locationRules ? "native" : false || config.data.config.samlSPMetaDataXML ? "SPsaml" : false || config.data.config.oidcRPMetaDataOptions ? "RPoidc" : false || config.data.config.casAppMetaDataOptions ? "AppCas" : false
console.log(Object.keys(name ? name : {})[0])
dispatch(push(`#app/${type}/${Object.keys(name ? name : {})[0]}`))
const name =
config.data.config.locationRules ||
config.data.config.samlSPMetaDataXML ||
config.data.config.oidcRPMetaDataOptions ||
config.data.config.casAppMetaDataOptions;
const type = config.data.config.locationRules
? "native"
: false || config.data.config.samlSPMetaDataXML
? "SPsaml"
: false || config.data.config.oidcRPMetaDataOptions
? "RPoidc"
: false || config.data.config.casAppMetaDataOptions
? "AppCas"
: false;
console.log(Object.keys(name ? name : {})[0]);
dispatch(push(`#app/${type}/${Object.keys(name ? name : {})[0]}`));
}
}, [dispatch, configNum, config.data.metadata, location, configPresent]);
try {
Expand Down Expand Up @@ -200,13 +212,15 @@ export default function PartialManager() {
>
{config.data.metadata.cfgNum}
</Button>
{false && <Button
onClick={() => {
dispatch(push("#catandapp"));
}}
>
<WidgetsOutlinedIcon color="secondary" />
</Button>}
{false && (
<Button
onClick={() => {
dispatch(push("#catandapp"));
}}
>
<WidgetsOutlinedIcon color="secondary" />
</Button>
)}
{false && <Issuers />}
<FilterToggle filters={filters} setFilters={setFilters} />
<Pagination
Expand Down
2 changes: 1 addition & 1 deletion src/features/config/configAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function getConfig(num: number) {
}
}

export function getPartialConfig(num: number) {
export function getPartialConfig() {
try {
const response = window.fetch(`${baseUrl}/partial`);
return response;
Expand Down
143 changes: 86 additions & 57 deletions src/features/config/configSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import attributes from "../../static/attributes.json";
import { treeFormat } from "../../utils/recursTree";
import { changeElementInConf } from "../../utils/searchIntree";
import { MetaData, llngConfig } from "../../utils/types";
import { getConfig, getMetadataConfig, getPartialConfig, saveConfig, savePartialConfig } from "./configAPI";
import {
getConfig,
getMetadataConfig,
getPartialConfig,
saveConfig,
savePartialConfig,
} from "./configAPI";

export interface ConfigState {
loading: boolean;
Expand All @@ -35,20 +41,32 @@ export const getConfigAsync = createAsyncThunk(
return { metadata: configMetadata, config: await response.json() };
} else {
const response = await getConfig(configlatestMetadata.cfgNum);
return { metadata: await configlatestMetadata, config: await response.json() };
return {
metadata: await configlatestMetadata,
config: await response.json(),
};
}
}
);

export const getPartialConfigAsync = createAsyncThunk(
"config/fetchPartialConfig",
async (num?: number): Promise<Object> => {
const metaResponse = await getMetadataConfig(num ? num : undefined);
const configMetadata = await metaResponse.json()
const response = await getPartialConfig(num ? num : (configMetadata).cfgNum);
return { metadata: configMetadata, config: await response.json() }
async (): Promise<Object> => {
const response = await getPartialConfig();
const partialConf = await response.json();
const metadata = {
cfgAuthor: partialConf.cfgAuthor,
cfgAuthorIP: partialConf.cfgAuthorIP,
cfgDate: partialConf.cfgDate,
cfgLog: partialConf.cfgLog,
cfgNum: partialConf.cfgNum,
cfgVersion: partialConf.cfgVersion,
prev: partialConf.prev,
next: partialConf.next,
};
return { metadata, config: partialConf };
}
)
);

export const saveConfigAsync = createAsyncThunk(
"config/saveConfig",
Expand All @@ -61,10 +79,10 @@ export const saveConfigAsync = createAsyncThunk(
export const savePartialConfigAsync = createAsyncThunk(
"config/savePartialConfig",
async (config: llngConfig): Promise<Object> => {
const response = await savePartialConfig(config)
return response.json()
const response = await savePartialConfig(config);
return response.json();
}
)
);

const configSlice = createSlice({
name: "config",
Expand All @@ -91,36 +109,39 @@ const configSlice = createSlice({
},
toggleSAML(state) {
if (!state.data.config.issuerDBSAMLActivation) {
state.data.config.issuerDBSAMLActivation = 0
state.data.config.issuerDBSAMLActivation = 0;
}
state.data.config.issuerDBSAMLActivation =
1 - Number(state.data.config.issuerDBSAMLActivation);
},
toggleOIDC(state) {
if (!state.data.config.issuerDBOpenIDConnectActivation) {
state.data.config.issuerDBOpenIDConnectActivation = 0
state.data.config.issuerDBOpenIDConnectActivation = 0;
}
state.data.config.issuerDBOpenIDConnectActivation =
1 - Number(state.data.config.issuerDBOpenIDConnectActivation);
},
toggleCAS(state) {
if (!state.data.config.issuerDBCASActivation) {
state.data.config.issuerDBCASActivation = 0
state.data.config.issuerDBCASActivation = 0;
}
state.data.config.issuerDBCASActivation =
1 - Number(state.data.config.issuerDBCASActivation);
console.log(state.data.config.issuerDBCASActivation, 1 - Number(state.data.config.issuerDBCASActivation))
console.log(
state.data.config.issuerDBCASActivation,
1 - Number(state.data.config.issuerDBCASActivation)
);
},
toggleOID2(state) {
if (!state.data.config.issuerDBOpenIDActivation) {
state.data.config.issuerDBOpenIDActivation = 0
state.data.config.issuerDBOpenIDActivation = 0;
}
state.data.config.issuerDBOpenIDActivation =
1 - Number(state.data.config.issuerDBOpenIDActivation);
},
toggleGET(state) {
if (!state.data.config.issuerDBGetActivation) {
state.data.config.issuerDBGetActivation = 0
state.data.config.issuerDBGetActivation = 0;
}
state.data.config.issuerDBGetActivation =
1 - Number(state.data.config.issuerDBGetActivation);
Expand Down Expand Up @@ -963,9 +984,10 @@ const configSlice = createSlice({
if (!state.data.config.combModules[action.payload].over) {
state.data.config.combModules[action.payload].over = {};
}
const id: string = `new${Object.keys(state.data.config.combModules[action.payload].over).length +
const id: string = `new${
Object.keys(state.data.config.combModules[action.payload].over).length +
1
}`;
}`;

(
state.data.config.combModules[action.payload].over as unknown as Record<
Expand Down Expand Up @@ -1244,11 +1266,11 @@ const configSlice = createSlice({
.map((key) =>
state.data.config.applicationList
? (
state.data.config.applicationList as Record<
string,
Record<string, number>
>
)[key].order
state.data.config.applicationList as Record<
string,
Record<string, number>
>
)[key].order
: 0
)
.filter((el) => typeof el === "number"),
Expand Down Expand Up @@ -1290,18 +1312,19 @@ const configSlice = createSlice({
.map((key) =>
state.data.config.applicationList
? (
state.data.config.applicationList[action.payload] as Record<
string,
Record<string, number>
>
)[key].order
state.data.config.applicationList[action.payload] as Record<
string,
Record<string, number>
>
)[key].order
: 0
)
.filter((el) => typeof el === "number"),
0
);
state.data.config.applicationList[action.payload][
`new_application${Object.keys(state.data.config.applicationList[action.payload]).length
`new_application${
Object.keys(state.data.config.applicationList[action.payload]).length
}`
] = {
options: { name: "New Application" },
Expand Down Expand Up @@ -1355,11 +1378,11 @@ const configSlice = createSlice({
.filter((key: string) =>
state.data.config.applicationList
? (
state.data.config.applicationList as Record<
string,
Record<string, number>
>
)[key].order
state.data.config.applicationList as Record<
string,
Record<string, number>
>
)[key].order
? true
: false
: false
Expand Down Expand Up @@ -1395,15 +1418,20 @@ const configSlice = createSlice({
console.log(state);
if (appIndex === -1) return;
if (action.payload.direction === "up" && appIndex > 0) {
console.log((state.data.config.applicationList as Record<
string,
Record<string, number>
>
)[categories[appIndex]], (state.data.config.applicationList as Record<
string,
Record<string, number>
>
)[categories[appIndex - 1]]);
console.log(
(
state.data.config.applicationList as Record<
string,
Record<string, number>
>
)[categories[appIndex]],
(
state.data.config.applicationList as Record<
string,
Record<string, number>
>
)[categories[appIndex - 1]]
);
(
state.data.config.applicationList as Record<
string,
Expand Down Expand Up @@ -1459,10 +1487,10 @@ const configSlice = createSlice({
.filter((key: string) =>
state.data.config.applicationList
? (
state.data.config.applicationList[
action.payload.category
] as Record<string, Record<string, number>>
)[key].order
state.data.config.applicationList[
action.payload.category
] as Record<string, Record<string, number>>
)[key].order
? true
: false
: false
Expand All @@ -1472,12 +1500,12 @@ const configSlice = createSlice({
return (
(
state.data.config.applicationList[
action.payload.category
action.payload.category
] as Record<string, Record<string, number>>
)[key1].order -
(
state.data.config.applicationList[
action.payload.category
action.payload.category
] as Record<string, Record<string, number>>
)[key2].order
);
Expand All @@ -1497,16 +1525,16 @@ const configSlice = createSlice({
if (action.payload.direction === "up" && appIndex > 0) {
(
state.data.config.applicationList[
action.payload.category
action.payload.category
] as Record<string, Record<string, number>>
)[action.payload.appName].order = (
state.data.config.applicationList[
action.payload.category
action.payload.category
] as Record<string, Record<string, number>>
)[apps[appIndex - 1]].order;
(
state.data.config.applicationList[
action.payload.category
action.payload.category
] as Record<string, Record<string, number>>
)[apps[appIndex - 1]].order = order;
} else if (
Expand All @@ -1515,16 +1543,16 @@ const configSlice = createSlice({
) {
(
state.data.config.applicationList[
action.payload.category
action.payload.category
] as Record<string, Record<string, number>>
)[action.payload.appName].order = (
state.data.config.applicationList[
action.payload.category
action.payload.category
] as Record<string, Record<string, number>>
)[apps[appIndex + 1]].order;
(
state.data.config.applicationList[
action.payload.category
action.payload.category
] as Record<string, Record<string, number>>
)[apps[appIndex + 1]].order = order;
}
Expand Down Expand Up @@ -1591,7 +1619,8 @@ const configSlice = createSlice({
state.error.errorContent = action.payload.message;
}
}
).addCase(getPartialConfigAsync.pending, (state: ConfigState) => {
)
.addCase(getPartialConfigAsync.pending, (state: ConfigState) => {
state.loading = true;
})
.addCase(
Expand Down
Loading

0 comments on commit 9703e46

Please sign in to comment.