diff --git a/components/dashboard/src/settings/EnvironmentVariables.tsx b/components/dashboard/src/settings/EnvironmentVariables.tsx index 9f8e2efe8e6d37..070b985275d93a 100644 --- a/components/dashboard/src/settings/EnvironmentVariables.tsx +++ b/components/dashboard/src/settings/EnvironmentVariables.tsx @@ -79,6 +79,26 @@ function AddEnvVarModal(p: EnvVarModalProps) { } +function DeleteEnvVarModal(p: { variable: UserEnvVarValue, deleteVariable: () => void, onClose: () => void }) { + return +

Delete Variable?

+
+
+ Name + Scope +
+
+ {p.variable.name} + {p.variable.repositoryPattern} +
+
+
+ + +
+
; +} + function sortEnvVars(a: UserEnvVarValue, b: UserEnvVarValue) { if (a.name === b.name) { return a.repositoryPattern > b.repositoryPattern ? 1 : -1; @@ -90,6 +110,7 @@ export default function EnvVars() { const [envVars, setEnvVars] = useState([] as UserEnvVarValue[]); const [currentEnvVar, setCurrentEnvVar] = useState({ name: '', value: '', repositoryPattern: '' } as UserEnvVarValue); const [isAddEnvVarModalVisible, setAddEnvVarModalVisible] = useState(false); + const [isDeleteEnvVarModalVisible, setDeleteEnvVarModalVisible] = useState(false); const update = async () => { await getGitpodService().server.getAllEnvVars().then(r => setEnvVars(r.sort(sortEnvVars))); } @@ -102,11 +123,19 @@ export default function EnvVars() { const add = () => { setCurrentEnvVar({ name: '', value: '', repositoryPattern: '' }); setAddEnvVarModalVisible(true); + setDeleteEnvVarModalVisible(false); } - const edit = (ev: UserEnvVarValue) => { - setCurrentEnvVar(ev); + const edit = (variable: UserEnvVarValue) => { + setCurrentEnvVar(variable); setAddEnvVarModalVisible(true); + setDeleteEnvVarModalVisible(false); + } + + const confirmDeleteVariable = (variable: UserEnvVarValue) => { + setCurrentEnvVar(variable); + setAddEnvVarModalVisible(false); + setDeleteEnvVarModalVisible(true); } const save = async (variable: UserEnvVarValue) => { @@ -114,7 +143,7 @@ export default function EnvVars() { await update(); }; - const deleteV = async (variable: UserEnvVarValue) => { + const deleteVariable = async (variable: UserEnvVarValue) => { await getGitpodService().server.deleteEnvVar(variable); await update(); }; @@ -145,26 +174,32 @@ export default function EnvVars() { } } } + if (!variable.id && envVars.some(v => v.name === name && v.repositoryPattern === pattern)) { + return 'A variable with this name and scope already exists'; + } return ''; }; - return - {isAddEnvVarModalVisible ? + {isAddEnvVarModalVisible && setAddEnvVarModalVisible(false)} /> : null} + onClose={() => setAddEnvVarModalVisible(false)} />} + {isDeleteEnvVarModalVisible && deleteVariable(currentEnvVar)} + onClose={() => setDeleteEnvVarModalVisible(false)} />}

Environment Variables

Variables are used to store information like passwords.

{envVars.length !== 0 - ? -
- -
- : null} + ?
+ +
+ : null}
{envVars.length === 0 ?
@@ -183,22 +218,22 @@ export default function EnvVars() {
- {envVars.map(ev => { + {envVars.map(variable => { return
-
{ev.name}
-
{ev.repositoryPattern}
+
{variable.name}
+
{variable.repositoryPattern}
edit(ev), + onClick: () => edit(variable), separator: true }, { title: 'Delete', customFontStyle: 'text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300', - onClick: () => deleteV(ev) + onClick: () => confirmDeleteVariable(variable) }, ]}> Actions