Skip to content

Commit

Permalink
chore: fix namespace UI IT (#3911)
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Phelps <[email protected]>
  • Loading branch information
markphelps authored Feb 11, 2025
1 parent 870a76d commit 1f40d5e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 42 deletions.
6 changes: 1 addition & 5 deletions internal/storage/environments/fs/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ func (s *NamespaceStorage) PutNamespace(ctx context.Context, fs Filesystem, ns *

path := path.Join(ns.Key, FeaturesFilename)
_, err := fs.Stat(path)
if err == nil {
return nil
}

if !errors.Is(err, os.ErrNotExist) {
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}

Expand Down
13 changes: 12 additions & 1 deletion ui/src/app/namespaces/Namespaces.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useRef, useState } from 'react';
import { useSelector } from 'react-redux';

import { selectCurrentEnvironment } from '~/app/environments/environmentsApi';

import { ButtonWithPlus } from '~/components/Button';
import EmptyState from '~/components/EmptyState';
import Modal from '~/components/Modal';
Expand All @@ -11,6 +13,8 @@ import DeletePanel from '~/components/panels/DeletePanel';

import { INamespace } from '~/types/Namespace';

import { getRevision } from '~/utils/helpers';

import { selectNamespaces } from './namespacesApi';
import { useDeleteNamespaceMutation } from './namespacesApi';

Expand All @@ -27,7 +31,10 @@ export default function Namespaces() {
null
);

const environment = useSelector(selectCurrentEnvironment);
const namespaces = useSelector(selectNamespaces);
const revision = useSelector(getRevision);

const [deleteNamespace] = useDeleteNamespaceMutation();
const namespaceFormRef = useRef(null);

Expand Down Expand Up @@ -68,7 +75,11 @@ export default function Namespaces() {
panelType="Namespace"
setOpen={setShowDeleteNamespaceModal}
handleDelete={() =>
deleteNamespace(deletingNamespace?.key ?? '').unwrap()
deleteNamespace({
environmentKey: environment.name,
namespaceKey: deletingNamespace?.key!,
revision: revision
}).unwrap()
}
/>
</Modal>
Expand Down
15 changes: 9 additions & 6 deletions ui/src/app/namespaces/namespacesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const namespaceApi = createApi({
// create the namespace
createNamespace: builder.mutation<
INamespace,
{ environmentKey: string; values: INamespace; revision?: string }
{ environmentKey: string; values: INamespace; revision: string }
>({
query({ environmentKey, values, revision }) {
return {
Expand All @@ -114,11 +114,11 @@ export const namespaceApi = createApi({
// update the namespace
updateNamespace: builder.mutation<
INamespace,
{ environmentKey: string; values: INamespace; revision?: string }
{ environmentKey: string; values: INamespace; revision: string }
>({
query({ environmentKey, values, revision }) {
return {
url: `/${environmentKey}/namespaces/`,
url: `/${environmentKey}/namespaces`,
method: 'PUT',
body: {
...values,
Expand All @@ -133,10 +133,13 @@ export const namespaceApi = createApi({
]
}),
// delete the namespace
deleteNamespace: builder.mutation<void, string>({
query(namespaceKey) {
deleteNamespace: builder.mutation<
void,
{ environmentKey: string; namespaceKey: string; revision: string }
>({
query({ environmentKey, namespaceKey, revision }) {
return {
url: `/namespaces/${namespaceKey}`,
url: `/${environmentKey}/namespaces/${namespaceKey}?revision=${revision}`,
method: 'DELETE'
};
},
Expand Down
30 changes: 0 additions & 30 deletions ui/tests/namespaces.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,4 @@ test.describe('Namespaces', () => {
// assert that the default namespace is still there even after clicking 'delete'
await page.getByRole('cell', { name: 'default' }).first().click();
});

test('cannot delete namespace with flags', async ({ page }) => {
await page.getByRole('button', { name: 'Default' }).click();
await page.getByRole('link', { name: 'Settings' }).click();
await page.getByRole('link', { name: 'Namespaces' }).click();
await page.getByRole('button', { name: 'New Namespace' }).click();
await page.getByLabel('Name', { exact: true }).fill('no delete');
await page.getByLabel('Description').click();
await page.getByRole('button', { name: 'Create' }).click();

await page.getByRole('link', { name: 'Flags' }).click();
await page.getByRole('button', { name: 'Default' }).click();
await page.getByText('no delete').click();

await page.getByRole('button', { name: 'New Flag' }).click();
await page.getByLabel('Name').fill('foo');
await page.getByLabel('Description').click();
await page.getByRole('button', { name: 'Create' }).click();
await page.getByText('Successfully created flag').click();

await page.getByRole('link', { name: 'Settings' }).click();
await page.getByRole('link', { name: 'Namespaces' }).click();
await page.getByRole('link', { name: 'Delete , no delete' }).click();
await page.getByRole('button', { name: 'Delete' }).click();
await expect(
page.getByText(
'namespace "no-delete" cannot be deleted; flags must be deleted first'
)
).toBeVisible();
});
});

0 comments on commit 1f40d5e

Please sign in to comment.