Skip to content

Commit

Permalink
feat: delete namespace functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rita committed Dec 19, 2024
1 parent b7f0b51 commit 9556893
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/components/sections/NamespaceDataSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import i18n from '../../locales'
import ErrorNotice from '../error/ErrorNotice'
import CenteredLoader from '../loader/Loader'
import CreateModal from '../modals/CreateModal'
import DeleteModal from '../modals/DeleteModal'
import { KeysField, NamespaceField } from '../modals/Fields'
import ItemsTable from '../table/ItemsTable'
import CreateButton from './CreateButton'
Expand All @@ -21,6 +22,8 @@ const NamespaceDataSection = ({ query }) => {
const navigate = useNavigate()
const { store } = useParams()
const [openModal, setOpenModal] = useState(false)
const [openDeleteModal, setOpenDeleteModal] = useState(false)
const [selectedNamespace, setSelectedNamespace] = useState(null)

const { error, loading, data, refetch } = useDataQuery<QueryResults>(query)

Expand All @@ -34,6 +37,22 @@ const NamespaceDataSection = ({ query }) => {
navigate(`edit/${values?.namespace}`)
}

const handleDelete = async () => {
await engine.mutate(
{
type: 'delete' as const,
resource: `${store}`,
id: selectedNamespace,
},
{
onComplete: () => {
setOpenDeleteModal(false)
refetch()
},
}
)
}

if (error) {
return <ErrorNotice />
}
Expand All @@ -53,7 +72,14 @@ const NamespaceDataSection = ({ query }) => {
/>
</div>
<div>
{data && <ItemsTable data={data} label={i18n.t('Namespace')} />}
{data && (
<ItemsTable
data={data}
label={i18n.t('Namespace')}
setOpenDeleteModal={setOpenDeleteModal}
setSelectedItem={setSelectedNamespace}
/>
)}
</div>
{openModal && (
<CreateModal
Expand All @@ -65,6 +91,24 @@ const NamespaceDataSection = ({ query }) => {
<KeysField />
</CreateModal>
)}
{openDeleteModal && (
<DeleteModal
closeModal={() => setOpenDeleteModal(false)}
handleDelete={handleDelete}
title={i18n.t('Delete Namespace')}
>
<p>
{i18n.t(
`Are you sure you want to delete '${selectedNamespace}'?`
)}
</p>
<p>
{i18n.t(
`This will delete all the keys in this namespace`
)}
</p>
</DeleteModal>
)}
</>
)
}
Expand Down

0 comments on commit 9556893

Please sign in to comment.