Skip to content

Commit 459e2bf

Browse files
bexsoftBenjamin Perez
andauthored
Added file name visualization in file select (#289)
* Added missing validations in add tenant modal * Added file name visualization in file selector Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 858d363 commit 459e2bf

File tree

6 files changed

+524
-43
lines changed

6 files changed

+524
-43
lines changed

portal-ui/src/screens/Console/Common/CredentialsPrompt/CredentialsPrompt.tsx

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

1717
import React from "react";
18+
import get from "lodash/get";
1819
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
1920
import { NewServiceAccount } from "./types";
2021
import { Button } from "@material-ui/core";
@@ -67,6 +68,8 @@ const CredentialsPrompt = ({
6768
return null;
6869
}
6970

71+
const consoleCreds = get(newServiceAccount, "console", null);
72+
7073
return (
7174
<ModalWrapper
7275
modalOpen={open}
@@ -87,6 +90,21 @@ const CredentialsPrompt = ({
8790
<b>Secret Key:</b> {newServiceAccount.secretKey}
8891
</li>
8992
</ul>
93+
{consoleCreds && (
94+
<React.Fragment>
95+
<Grid item xs={12}>
96+
<strong>Console Credentials</strong>
97+
<ul>
98+
<li>
99+
<b>Access Key:</b> {consoleCreds.accessKey}
100+
</li>
101+
<li>
102+
<b>Secret Key:</b> {consoleCreds.secretKey}
103+
</li>
104+
</ul>
105+
</Grid>
106+
</React.Fragment>
107+
)}
90108
<Typography
91109
component="p"
92110
variant="body1"
@@ -99,11 +117,23 @@ const CredentialsPrompt = ({
99117
<Grid item xs={12} className={classes.buttonContainer}>
100118
<Button
101119
onClick={() => {
120+
let consoleExtras = {};
121+
122+
if (consoleCreds) {
123+
consoleExtras = {
124+
console: {
125+
access_key: consoleCreds.accessKey,
126+
secret_key: consoleCreds.secretKey,
127+
},
128+
};
129+
}
130+
102131
download(
103132
"credentials.json",
104133
JSON.stringify({
105134
access_key: newServiceAccount.accessKey,
106135
secret_key: newServiceAccount.secretKey,
136+
...consoleExtras,
107137
})
108138
);
109139
}}

portal-ui/src/screens/Console/Common/CredentialsPrompt/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@
1717
export interface NewServiceAccount {
1818
accessKey: string;
1919
secretKey: string;
20+
console?: ConsoleSA;
21+
}
22+
23+
export interface ConsoleSA {
24+
accessKey: string;
25+
secretKey: string;
2026
}

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

Lines changed: 88 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
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 from "react";
17+
import React, { useState } from "react";
18+
import get from "lodash/get";
1819
import { Grid, InputLabel, Tooltip } from "@material-ui/core";
20+
import IconButton from "@material-ui/core/IconButton";
21+
import AttachFileIcon from "@material-ui/icons/AttachFile";
22+
import CancelIcon from "@material-ui/icons/Cancel";
1923
import HelpIcon from "@material-ui/icons/Help";
2024
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
2125
import { fieldBasic, tooltipHelper } from "../common/styleLibrary";
@@ -24,14 +28,15 @@ import { fileProcess } from "./utils";
2428
interface InputBoxProps {
2529
label: string;
2630
classes: any;
27-
onChange: (e: string) => void;
31+
onChange: (e: string, i: string) => void;
2832
id: string;
2933
name: string;
3034
disabled?: boolean;
3135
tooltip?: string;
3236
required?: boolean;
3337
error?: string;
3438
accept?: string;
39+
value?: string;
3540
}
3641

3742
const styles = (theme: Theme) =>
@@ -41,6 +46,7 @@ const styles = (theme: Theme) =>
4146
textBoxContainer: {
4247
flexGrow: 1,
4348
position: "relative",
49+
flexDirection: "column",
4450
},
4551
errorState: {
4652
color: "#b53b4b",
@@ -49,6 +55,27 @@ const styles = (theme: Theme) =>
4955
top: 7,
5056
right: 7,
5157
},
58+
errorText: {
59+
margin: "0",
60+
fontSize: "0.75rem",
61+
marginTop: 3,
62+
textAlign: "left",
63+
fontFamily: "Lato,sans-serif",
64+
fontWeight: 400,
65+
lineHeight: "1.66",
66+
color: "#dc1f2e",
67+
},
68+
valueString: {
69+
maxWidth: 350,
70+
whiteSpace: "nowrap",
71+
overflow: "hidden",
72+
textOverflow: "ellipsis",
73+
marginTop: 2,
74+
},
75+
fileReselect: {
76+
display: "flex",
77+
alignItems: "center",
78+
},
5279
});
5380

5481
const FileSelector = ({
@@ -62,7 +89,10 @@ const FileSelector = ({
6289
required,
6390
error = "",
6491
accept = "",
92+
value = "",
6593
}: InputBoxProps) => {
94+
const [showFileSelector, setShowSelector] = useState(false);
95+
6696
return (
6797
<React.Fragment>
6898
<Grid
@@ -92,19 +122,62 @@ const FileSelector = ({
92122
)}
93123
</InputLabel>
94124
)}
95-
<div className={classes.textBoxContainer}>
96-
<input
97-
type="file"
98-
name={name}
99-
onChange={(e) => {
100-
fileProcess(e, (data: any) => {
101-
onChange(data);
102-
});
103-
}}
104-
accept={accept}
105-
required
106-
/>
107-
</div>
125+
126+
{showFileSelector || value === "" ? (
127+
<div className={classes.textBoxContainer}>
128+
<input
129+
type="file"
130+
name={name}
131+
onChange={(e) => {
132+
const fileName = get(e, "target.files[0].name", "");
133+
fileProcess(e, (data: any) => {
134+
onChange(data, fileName);
135+
});
136+
}}
137+
accept={accept}
138+
required={required}
139+
disabled={disabled}
140+
/>
141+
142+
{value !== "" && (
143+
<IconButton
144+
color="primary"
145+
aria-label="upload picture"
146+
component="span"
147+
onClick={() => {
148+
setShowSelector(false);
149+
}}
150+
disableRipple={false}
151+
disableFocusRipple={false}
152+
>
153+
<CancelIcon />
154+
</IconButton>
155+
)}
156+
157+
{error !== "" && (
158+
<React.Fragment>
159+
<br />
160+
<span className={classes.errorText}>{error}</span>
161+
</React.Fragment>
162+
)}
163+
</div>
164+
) : (
165+
<div className={classes.fileReselect}>
166+
<div className={classes.valueString}>{value}</div>
167+
<IconButton
168+
color="primary"
169+
aria-label="upload picture"
170+
component="span"
171+
onClick={() => {
172+
setShowSelector(true);
173+
}}
174+
disableRipple={false}
175+
disableFocusRipple={false}
176+
>
177+
<AttachFileIcon />
178+
</IconButton>
179+
</div>
180+
)}
108181
</Grid>
109182
</React.Fragment>
110183
);

0 commit comments

Comments
 (0)