diff --git a/frontend/src/components/namespace/CreateNamespaceButton.tsx b/frontend/src/components/namespace/CreateNamespaceButton.tsx new file mode 100644 index 0000000000..727aa1a8a5 --- /dev/null +++ b/frontend/src/components/namespace/CreateNamespaceButton.tsx @@ -0,0 +1,118 @@ +import { + Box, + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + TextField, +} from '@mui/material'; +import React, { useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { useDispatch } from 'react-redux'; +import { getCluster } from '../../lib/cluster'; +import { post } from '../../lib/k8s/apiProxy'; +import Namespace from '../../lib/k8s/namespace'; +import { clusterAction } from '../../redux/clusterActionSlice'; +import { EventStatus, HeadlampEventType, useEventCallback } from '../../redux/headlampEventSlice'; +import { ActionButton, AuthVisible } from '../common'; + +export function CreateNamespaceButton() { + const { t } = useTranslation(['glossary', 'translation']); + const [namespaceName, setNamespaceName] = useState(''); + const [namespaceDialogOpen, setNamespaceDialogOpen] = useState(false); + const dispatchCreateEvent = useEventCallback(HeadlampEventType.CREATE_RESOURCE); + const dispatch = useDispatch(); + + function createNewNamespace() { + const cluster = getCluster(); + const newNamespaceData = { + apiVersion: 'v1', + kind: 'Namespace', + metadata: { + name: namespaceName, + }, + }; + const newNamespaceName = newNamespaceData.metadata.name; + + async function namespaceRequest() { + try { + const response = await post('/api/v1/namespaces', newNamespaceData, true, { + cluster: `${cluster}`, + }); + return response; + } catch (error) { + console.error('Error creating namespace', error); + throw error; + } + } + + setNamespaceDialogOpen(false); + dispatch( + clusterAction(() => namespaceRequest(), { + startMessage: t('translation|Creating namespace {{ name }}…', { name: newNamespaceName }), + cancelledMessage: t('translation|Cancelled creation of {{ name }}.', { + name: newNamespaceName, + }), + successMessage: t('translation|Created namespace {{ name }}.', { + name: newNamespaceName, + }), + errorMessage: t('translation|Error creating namespace {{ name }}.', { + name: newNamespaceName, + }), + cancelCallback: () => { + setNamespaceDialogOpen(true); + }, + }) + ); + } + + return ( + + { + setNamespaceDialogOpen(true); + }} + /> + + setNamespaceDialogOpen(false)}> + {t('translation|Create Namespace')} + + + setNamespaceName(event.target.value)} + /> + + + + + + + + + ); +} diff --git a/frontend/src/components/namespace/List.tsx b/frontend/src/components/namespace/List.tsx index bdb29c2ff7..9e3cbd8888 100644 --- a/frontend/src/components/namespace/List.tsx +++ b/frontend/src/components/namespace/List.tsx @@ -10,6 +10,7 @@ import { ResourceTableFromResourceClassProps, ResourceTableProps, } from '../common/Resource/ResourceTable'; +import { CreateNamespaceButton } from './CreateNamespaceButton'; export default function NamespacesList() { const { t } = useTranslation(['glossary', 'translation']); @@ -88,12 +89,15 @@ export default function NamespacesList() { }, [allowedNamespaces]); return ( - + <> + ], + noNamespaceFilter: true, + }} + {...resourceTableProps} + /> + ); } diff --git a/frontend/src/i18n/locales/de/translation.json b/frontend/src/i18n/locales/de/translation.json index cab16f9ef4..ece26523dd 100644 --- a/frontend/src/i18n/locales/de/translation.json +++ b/frontend/src/i18n/locales/de/translation.json @@ -315,6 +315,11 @@ "Default Request": "Standardanforderung", "Max": "Max", "Min": "Min", + "Creating namespace {{ name }}…": "", + "Cancelled creation of {{ name }}.": "", + "Created namespace {{ name }}.": "", + "Error creating namespace {{ name }}.": "", + "Create Namespace": "", "To": "An", "used": "benutzt", "Scheduling Disabled": "Planung deaktiviert", diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json index 8f1418aaa7..a37599e28c 100644 --- a/frontend/src/i18n/locales/en/translation.json +++ b/frontend/src/i18n/locales/en/translation.json @@ -315,6 +315,11 @@ "Default Request": "Default Request", "Max": "Max", "Min": "Min", + "Creating namespace {{ name }}…": "Creating namespace {{ name }}…", + "Cancelled creation of {{ name }}.": "Cancelled creation of {{ name }}.", + "Created namespace {{ name }}.": "Created namespace {{ name }}.", + "Error creating namespace {{ name }}.": "Error creating namespace {{ name }}.", + "Create Namespace": "Create Namespace", "To": "To", "used": "used", "Scheduling Disabled": "Scheduling Disabled", diff --git a/frontend/src/i18n/locales/es/translation.json b/frontend/src/i18n/locales/es/translation.json index 6c7f2c28d9..4e7f50ee15 100644 --- a/frontend/src/i18n/locales/es/translation.json +++ b/frontend/src/i18n/locales/es/translation.json @@ -315,6 +315,11 @@ "Default Request": "Solicitud por defecto", "Max": "Máx.", "Min": "Mín.", + "Creating namespace {{ name }}…": "", + "Cancelled creation of {{ name }}.": "", + "Created namespace {{ name }}.": "", + "Error creating namespace {{ name }}.": "", + "Create Namespace": "", "To": "A", "used": "usado", "Scheduling Disabled": "Agendamiento deshabilitado", diff --git a/frontend/src/i18n/locales/fr/translation.json b/frontend/src/i18n/locales/fr/translation.json index c69c097257..bf52ccd1c4 100644 --- a/frontend/src/i18n/locales/fr/translation.json +++ b/frontend/src/i18n/locales/fr/translation.json @@ -315,6 +315,11 @@ "Default Request": "Demande par défaut", "Max": "Max", "Min": "Min", + "Creating namespace {{ name }}…": "", + "Cancelled creation of {{ name }}.": "", + "Created namespace {{ name }}.": "", + "Error creating namespace {{ name }}.": "", + "Create Namespace": "", "To": "À", "used": "utilisé", "Scheduling Disabled": "Planification désactivée", diff --git a/frontend/src/i18n/locales/pt/translation.json b/frontend/src/i18n/locales/pt/translation.json index ce7cdb94a1..94229a6b61 100644 --- a/frontend/src/i18n/locales/pt/translation.json +++ b/frontend/src/i18n/locales/pt/translation.json @@ -315,6 +315,11 @@ "Default Request": "Pedido por defeito", "Max": "Máx.", "Min": "Mín.", + "Creating namespace {{ name }}…": "", + "Cancelled creation of {{ name }}.": "", + "Created namespace {{ name }}.": "", + "Error creating namespace {{ name }}.": "", + "Create Namespace": "", "To": "Para", "used": "usado", "Scheduling Disabled": "Agendamento Desactivado",