Skip to content

Commit 9660650

Browse files
bexsoftBenjamin Perez
andauthored
Settings forms connection (#95)
Connected the forms to backend to send & receive the information stored in MinIO settings Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 9ac754d commit 9660650

File tree

8 files changed

+260
-198
lines changed

8 files changed

+260
-198
lines changed

portal-ui/bindata_assetfs.go

Lines changed: 116 additions & 116 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

portal-ui/src/screens/Console/Common/FormComponents/CSVMultiSelector/CSVMultiSelector.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
//
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
import React, {
17-
useState,
18-
useEffect,
19-
createRef,
20-
ChangeEvent,
21-
useCallback
22-
} from "react";
16+
import React, { useState, useEffect, createRef, ChangeEvent } from "react";
2317
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
2418
import Grid from "@material-ui/core/Grid";
2519
import get from "lodash/get";
@@ -69,15 +63,19 @@ const CSVMultiSelector = ({
6963
const bottomList = createRef<HTMLDivElement>();
7064

7165
// Use effect to get the initial values from props
72-
useCallback(() => {
73-
if (currentElements.length === 1 && currentElements[0] === "") {
74-
const elementsSplitted = elements.split(",");
75-
if (elementsSplitted[elementsSplitted.length - 1].trim() !== "") {
76-
elementsSplitted.push("");
77-
}
78-
setCurrentElements(elementsSplitted);
66+
useEffect(() => {
67+
if (
68+
currentElements.length === 1 &&
69+
currentElements[0] === "" &&
70+
elements &&
71+
elements !== ""
72+
) {
73+
const elementsSplit = elements.split(",");
74+
elementsSplit.push("");
75+
76+
setCurrentElements(elementsSplit);
7977
}
80-
}, [elements, setCurrentElements, currentElements]);
78+
}, [elements, currentElements]);
8179

8280
// Use effect to send new values to onChange
8381
useEffect(() => {

portal-ui/src/screens/Console/Configurations/ConfTargetGeneric.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,55 @@ import CSVMultiSelector from "../Common/FormComponents/CSVMultiSelector/CSVMulti
2525
interface IConfGenericProps {
2626
onChange: (newValue: IElementValue[]) => void;
2727
fields: KVField[];
28+
defaultVals?: IElementValue[];
2829
classes: any;
2930
}
3031

3132
const styles = (theme: Theme) => createStyles({});
3233

34+
// Function to get defined values,
35+
//we make this because the backed sometimes don't return all the keys when there is an initial configuration
36+
export const valueDef = (
37+
key: string,
38+
type: string,
39+
defaults: IElementValue[]
40+
) => {
41+
let defValue = type === "on|off" ? "false" : "";
42+
43+
if (defaults.length > 0) {
44+
const storedConfig = defaults.find(element => element.key === key);
45+
46+
if (storedConfig) {
47+
defValue = storedConfig.value;
48+
}
49+
}
50+
51+
return defValue;
52+
};
53+
3354
const ConfTargetGeneric = ({
3455
onChange,
3556
fields,
57+
defaultVals,
3658
classes
3759
}: IConfGenericProps) => {
3860
const [valueHolder, setValueHolder] = useState<IElementValue[]>([]);
3961
const fieldsElements = !fields ? [] : fields;
62+
const defValList = !defaultVals ? [] : defaultVals;
4063

4164
// Effect to create all the values to hold
4265
useEffect(() => {
4366
const values: IElementValue[] = [];
4467
fields.forEach(field => {
4568
const stateInsert: IElementValue = {
4669
key: field.name,
47-
value: field.type === "on|off" ? "false" : ""
70+
value: valueDef(field.name, field.type, defValList)
4871
};
4972
values.push(stateInsert);
5073
});
5174

5275
setValueHolder(values);
53-
}, [fields]);
76+
}, [fields, defaultVals]);
5477

5578
useEffect(() => {
5679
onChange(valueHolder);

portal-ui/src/screens/Console/Configurations/ConfigurationPanels/ConfigurationsList.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const ConfigurationsList = ({ classes }: IListConfiguration) => {
6666
configuration_id: "",
6767
configuration_label: ""
6868
});
69-
const [isLoading, setIsLoading] = useState(false);
7069
const [error, setError] = useState("");
7170
const [filter, setFilter] = useState("");
7271

@@ -99,7 +98,6 @@ const ConfigurationsList = ({ classes }: IListConfiguration) => {
9998
<EditConfiguration
10099
open={editScreenOpen}
101100
closeModalAndRefresh={() => {
102-
setIsLoading(true);
103101
setEditScreenOpen(false);
104102
}}
105103
selectedConfiguration={selectedConfiguration}
@@ -141,7 +139,7 @@ const ConfigurationsList = ({ classes }: IListConfiguration) => {
141139
columns={[
142140
{ label: "Configuration", elementKey: "configuration_id" }
143141
]}
144-
isLoading={isLoading}
142+
isLoading={false}
145143
records={filteredRecords}
146144
entityName="Configurations"
147145
idField="configuration_id"

portal-ui/src/screens/Console/Configurations/CustomForms/EditConfiguration.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import React, { useCallback, useEffect, useState } from "react";
18+
import get from "lodash/get";
1819
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
19-
import { Button } from "@material-ui/core";
20+
import { Button, LinearProgress } from "@material-ui/core";
2021
import Grid from "@material-ui/core/Grid";
2122
import Typography from "@material-ui/core/Typography";
2223
import ModalWrapper from "../../Common/ModalWrapper/ModalWrapper";
@@ -64,9 +65,27 @@ const EditConfiguration = ({
6465
//Local States
6566
const [valuesObj, setValueObj] = useState<IElementValue[]>([]);
6667
const [saving, setSaving] = useState<boolean>(false);
67-
const [addError, setError] = useState<string>("");
68-
68+
const [loadingConfig, setLoadingConfig] = useState<boolean>(true);
69+
const [errorConfig, setErrorConfig] = useState<string>("");
70+
const [configValues, setConfigValues] = useState<IElementValue[]>([]);
6971
//Effects
72+
useEffect(() => {
73+
const configId = get(selectedConfiguration, "configuration_id", false);
74+
75+
if (configId) {
76+
api
77+
.invoke("GET", `/api/v1/configs/${configId}`)
78+
.then(res => {
79+
const keyVals = get(res, "key_values", []);
80+
setConfigValues(keyVals);
81+
})
82+
.catch(err => {
83+
setLoadingConfig(false);
84+
setErrorConfig(err);
85+
});
86+
}
87+
setLoadingConfig(false);
88+
}, [selectedConfiguration]);
7089

7190
useEffect(() => {
7291
if (saving) {
@@ -81,14 +100,14 @@ const EditConfiguration = ({
81100
)
82101
.then(res => {
83102
setSaving(false);
84-
setError("");
103+
setErrorConfig("");
85104
serverNeedsRestart(true);
86105

87106
closeModalAndRefresh();
88107
})
89108
.catch(err => {
90109
setSaving(false);
91-
setError(err);
110+
setErrorConfig(err);
92111
});
93112
}
94113
}, [
@@ -119,14 +138,14 @@ const EditConfiguration = ({
119138
title={selectedConfiguration.configuration_label}
120139
>
121140
<React.Fragment>
122-
{addError !== "" && (
141+
{errorConfig !== "" && (
123142
<Grid item xs={12}>
124143
<Typography
125144
component="p"
126145
variant="body1"
127146
className={classes.errorBlock}
128147
>
129-
{addError}
148+
{errorConfig}
130149
</Typography>
131150
</Grid>
132151
)}
@@ -136,6 +155,7 @@ const EditConfiguration = ({
136155
fieldsConfigurations[selectedConfiguration.configuration_id]
137156
}
138157
onChange={onValueChange}
158+
defaultVals={configValues}
139159
/>
140160
<Grid item xs={3} className={classes.buttonContainer}>
141161
<Button
@@ -148,6 +168,11 @@ const EditConfiguration = ({
148168
Save
149169
</Button>
150170
</Grid>
171+
{loadingConfig && (
172+
<Grid item xs={12}>
173+
<LinearProgress />
174+
</Grid>
175+
)}
151176
<Grid item xs={9} />
152177
</form>
153178
</React.Fragment>

portal-ui/src/screens/Console/Configurations/utils.ts

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ export const configurationElements: IConfigurationElement[] = [
5353
{ configuration_id: "kms_kes", configuration_label: "KMS KES Configuration" },
5454
{
5555
configuration_id: "logger_webhook",
56-
configuration_label: "Logger Webhook Configuration",
57-
url: "/webhook/logger"
56+
configuration_label: "Logger Webhook Configuration"
5857
},
5958
{
6059
configuration_id: "audit_webhook",
61-
configuration_label: "Audit Webhook Configuration",
62-
url: "/webhook/audit"
60+
configuration_label: "Audit Webhook Configuration"
6361
}
6462
];
6563

@@ -119,6 +117,20 @@ export const fieldsConfigurations: any = {
119117
tooltip: "Minimum number of access before caching an object",
120118
type: "number"
121119
},
120+
{
121+
name: "watermark_low",
122+
required: false,
123+
label: "Watermark Low",
124+
tooltip: "Watermark Low",
125+
type: "number"
126+
},
127+
{
128+
name: "watermark_high",
129+
required: false,
130+
label: "Watermark High",
131+
tooltip: "Watermark High",
132+
type: "number"
133+
},
122134
{
123135
name: "comment",
124136
required: false,
@@ -129,12 +141,6 @@ export const fieldsConfigurations: any = {
129141
}
130142
],
131143
compression: [
132-
{
133-
name: "minio_compress",
134-
required: true,
135-
label: "MinIO Compress",
136-
type: "on|off"
137-
},
138144
{
139145
name: "extensions",
140146
required: false,
@@ -199,17 +205,31 @@ export const fieldsConfigurations: any = {
199205
}
200206
],
201207
identity_openid: [
208+
{
209+
name: "config_url",
210+
required: false,
211+
label: "Config URL",
212+
tooltip: "Config URL for Client ID configuration",
213+
type: "string"
214+
},
202215
{
203216
name: "client_id",
204217
required: false,
205218
label: "Client ID",
206219
type: "string"
207220
},
208221
{
209-
name: "config_url",
222+
name: "claim_name",
210223
required: false,
211-
label: "Config URL",
212-
tooltip: "Config URL for Client ID configuration",
224+
label: "Claim Name",
225+
tooltip: "Claim Name",
226+
type: "string"
227+
},
228+
{
229+
name: "claim_prefix",
230+
required: false,
231+
label: "Claim Prefix",
232+
tooltip: "Claim Prefix",
213233
type: "string"
214234
}
215235
],
@@ -294,21 +314,10 @@ export const fieldsConfigurations: any = {
294314
],
295315
policy_opa: [
296316
{
297-
name: "opa_url",
317+
name: "url",
298318
required: true,
299319
label: "OPA URL",
300320
type: "string"
301-
}
302-
],
303-
kms_vault: [],
304-
kms_kes: [],
305-
logger_webhook: [
306-
{
307-
name: "name",
308-
required: true,
309-
label: "Name",
310-
tooltip: "Name of the webhook",
311-
type: "string"
312321
},
313322
{
314323
name: "auth_token",
@@ -317,31 +326,40 @@ export const fieldsConfigurations: any = {
317326
type: "string"
318327
},
319328
{
320-
name: "endpoint",
329+
name: "policy_opa",
321330
required: true,
322-
label: "Endpoint",
331+
label: "Policy OPA",
323332
type: "string"
324333
}
325334
],
326-
audit_webhook: [
335+
kms_vault: [],
336+
kms_kes: [],
337+
logger_webhook: [
327338
{
328-
name: "name",
339+
name: "endpoint",
329340
required: true,
330-
label: "Name",
331-
tooltip: "Name of the webhook",
341+
label: "Endpoint",
332342
type: "string"
333343
},
334344
{
335345
name: "auth_token",
336346
required: true,
337347
label: "Auth Token",
338348
type: "string"
339-
},
349+
}
350+
],
351+
audit_webhook: [
340352
{
341353
name: "endpoint",
342354
required: true,
343355
label: "Endpoint",
344356
type: "string"
357+
},
358+
{
359+
name: "auth_token",
360+
required: true,
361+
label: "Auth Token",
362+
type: "string"
345363
}
346364
]
347365
};

portal-ui/src/screens/LoginPage/LoginCallback.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
import React, {FC, useEffect} from "react";
18-
import {RouteComponentProps} from "react-router";
17+
import React, { FC, useEffect } from "react";
18+
import { RouteComponentProps } from "react-router";
1919
import storage from "local-storage-fallback";
2020
import api from "../../common/api";
2121

22-
const LoginCallback: FC<RouteComponentProps> = ({location}) => {
22+
const LoginCallback: FC<RouteComponentProps> = ({ location }) => {
2323
useEffect(() => {
2424
const code = (location.search.match(/code=([^&]+)/) || [])[1];
2525
const state = (location.search.match(/state=([^&]+)/) || [])[1];
2626
api
27-
.invoke("POST", "/api/v1/login/oauth2/auth", {code, state})
27+
.invoke("POST", "/api/v1/login/oauth2/auth", { code, state })
2828
.then((res: any) => {
2929
if (res && res.sessionId) {
3030
// store the jwt token

0 commit comments

Comments
 (0)