Skip to content

Commit

Permalink
chore(databases-collections): refactor drop collection / drop databse…
Browse files Browse the repository at this point in the history
… to drop namespace plugin
  • Loading branch information
gribnoysup committed Nov 10, 2023
1 parent 60997d1 commit d945d04
Show file tree
Hide file tree
Showing 27 changed files with 263 additions and 814 deletions.
20 changes: 12 additions & 8 deletions packages/compass-components/src/hooks/use-confirmation.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import React, { useContext, useEffect, useRef, useState } from 'react';

import {
default as ConfirmationModal,
Variant as ConfirmationModalVariant,
} from '@leafygreen-ui/confirmation-modal';

export { ConfirmationModalVariant };

type ConfirmationProperties = {
title: string;
description: React.ReactNode;
buttonText?: string;
variant?: ConfirmationModalVariant;
requiredInputText?: string;
type ConfirmationModalProps = React.ComponentProps<typeof ConfirmationModal>;

type ConfirmationProperties = Partial<
Pick<
ConfirmationModalProps,
'title' | 'buttonText' | 'variant' | 'requiredInputText'
>
> & {
description?: React.ReactNode;
'data-testid'?: string;
};

type ConfirmationCallback = (value: boolean) => void;

interface ConfirmationModalContextData {
Expand Down Expand Up @@ -130,7 +134,7 @@ export const ConfirmationModalArea: React.FC = ({ children }) => {
<ConfirmationModalContext.Provider value={contextValue}>
{children}
<ConfirmationModal
data-testid={'confirmation-modal'}
data-testid={confirmationProps['data-testid'] ?? 'confirmation-modal'}
open={confirmationProps.open}
title={confirmationProps.title ?? 'Are you sure?'}
variant={confirmationProps.variant ?? ConfirmationModalVariant.Default}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function dropCollectionFromSidebar(
await browser.clickVisible(Selectors.CollectionShowActionsButton);
await browser.clickVisible(Selectors.DropCollectionButton);

await browser.dropCollection(collectionName);
await browser.dropNamespace(collectionName);

// wait for it to be gone
await collectionElement.waitForExist({ reverse: true });
Expand Down
19 changes: 0 additions & 19 deletions packages/compass-e2e-tests/helpers/commands/drop-collection.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function dropDatabaseFromSidebar(

await browser.clickVisible(Selectors.DropDatabaseButton);

await browser.dropDatabase(dbName);
await browser.dropNamespace(dbName);

// wait for it to be gone
await browser
Expand Down
19 changes: 0 additions & 19 deletions packages/compass-e2e-tests/helpers/commands/drop-database.ts

This file was deleted.

23 changes: 23 additions & 0 deletions packages/compass-e2e-tests/helpers/commands/drop-namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';

export async function dropNamespace(
browser: CompassBrowser,
collectionName: string
): Promise<void> {
const dropModalElement = await browser.$(Selectors.DropNamespaceModal);
await dropModalElement.waitForDisplayed();
const confirmInput = await browser.$(Selectors.DropNamespaceConfirmNameInput);
await confirmInput.setValue(collectionName);
const confirmButton = await browser.$(Selectors.DropNamespaceDropButton);
await confirmButton.waitForEnabled();

await browser.screenshot('drop-namespace-modal.png');

await confirmButton.click();

const successToast = browser.$(Selectors.DropNamespaceSuccessToast);
await successToast.waitForDisplayed();
await browser.clickVisible(Selectors.DropNamespaceSuccessToastCloseButton);
await successToast.waitForDisplayed({ reverse: true });
}
3 changes: 1 addition & 2 deletions packages/compass-e2e-tests/helpers/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export * from './do-connect';
export * from './hover';
export * from './add-database';
export * from './add-collection';
export * from './drop-database';
export * from './drop-collection';
export * from './drop-namespace';
export * from './get-query-id';
export * from './run-find';
export * from './export-to-language';
Expand Down
23 changes: 10 additions & 13 deletions packages/compass-e2e-tests/helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,6 @@ export const CreateDatabaseCreateButton =
export const CreateDatabaseCancelButton =
'[data-testid="create-database-modal"] [data-testid="cancel-button"]';

// Drop database modal
export const DropDatabaseModal = '[data-testid="drop-database-modal"]';
export const DropDatabaseConfirmName =
'[data-testid="confirm-drop-database-name"]';
export const DropDatabaseDropButton =
'[data-testid="drop-database-modal"] [data-testid="submit-button"]';

// Create collection modal
export const CreateCollectionModal = '[data-testid="create-collection-modal"]';
export const CreateCollectionCollectionName = '[data-testid="collection-name"]';
Expand Down Expand Up @@ -361,12 +354,16 @@ export const createCollectionCustomCollationFieldMenu = (
return `[data-testid="use-custom-collation-fields"] #collation-field-${fieldName}-menu`;
};

// Drop collection modal
export const DropCollectionModal = '[data-testid="drop-collection-modal"]';
export const DropCollectionConfirmName =
'[data-testid="confirm-drop-collection-name"]';
export const DropCollectionDropButton =
'[data-testid="drop-collection-modal"] [data-testid="submit-button"]';
// Drop namespace modal
export const DropNamespaceModal =
'[data-testid="drop-namespace-confirmation-modal"]';
export const DropNamespaceConfirmNameInput = `${DropNamespaceModal} input`;
export const DropNamespaceDropButton = `${DropNamespaceModal} button:first-of-type`;
export const DropNamespaceCancelButton = `${DropNamespaceModal} button:last-of-type`;
export const DropNamespaceSuccessToast =
'[data-testid="toast-drop-namespace-success"]';
export const DropNamespaceSuccessToastCloseButton =
'[data-testid="toast-drop-namespace-success"] [data-testid="lg-toast-dismiss-button"]';

// Shell
export const ShellSection = '[data-testid="shell-section"]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('Database collections tab', function () {

await browser.clickVisible(Selectors.CollectionCardDrop);

await browser.dropCollection(collectionName);
await browser.dropNamespace(collectionName);

// wait for it to be gone
await collectionCard.waitForExist({ reverse: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('Instance databases tab', function () {

await browser.clickVisible(Selectors.DatabaseCardDrop);

await browser.dropDatabase(dbName);
await browser.dropNamespace(dbName);

// wait for it to be gone (which it will be anyway because the app should
// redirect back to the databases tab)
Expand Down
6 changes: 2 additions & 4 deletions packages/compass-home/src/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ import { CreateViewPlugin } from '@mongodb-js/compass-aggregations';
import { CompassFindInPagePlugin } from '@mongodb-js/compass-find-in-page';
import {
CreateDatabasePlugin,
DropDatabasePlugin,
CreateCollectionPlugin,
DropCollectionPlugin,
DropNamespacePlugin,
} from '@mongodb-js/compass-databases-collections';
import { ImportPlugin, ExportPlugin } from '@mongodb-js/compass-import-export';
import { DataServiceProvider } from 'mongodb-data-service/provider';
Expand Down Expand Up @@ -358,6 +357,7 @@ function Home({
<ImportPlugin></ImportPlugin>
<ExportPlugin></ExportPlugin>
<CreateViewPlugin></CreateViewPlugin>
<DropNamespacePlugin></DropNamespacePlugin>
<Workspace namespace={namespace} />
</DataServiceProvider>
</AppRegistryProvider>
Expand All @@ -384,9 +384,7 @@ function Home({
<CompassSettingsPlugin></CompassSettingsPlugin>
<CompassFindInPagePlugin></CompassFindInPagePlugin>
<CreateDatabasePlugin></CreateDatabasePlugin>
<DropDatabasePlugin></DropDatabasePlugin>
<CreateCollectionPlugin></CreateCollectionPlugin>
<DropCollectionPlugin></DropCollectionPlugin>
<AtlasSignIn></AtlasSignIn>
</SignalHooksProvider>
);
Expand Down
5 changes: 3 additions & 2 deletions packages/databases-collections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@mongodb-js/databases-collections-list": "^1.19.1",
"compass-preferences-model": "^2.15.6",
"hadron-app-registry": "^9.0.14",
"mongodb-data-service": "^22.15.1",
"react": "^17.0.2"
},
"devDependencies": {
Expand All @@ -73,7 +74,6 @@
"mocha": "^10.2.0",
"mongodb": "^6.0.0",
"mongodb-collection-model": "^5.15.1",
"mongodb-data-service": "^22.15.1",
"mongodb-instance-model": "^12.15.1",
"mongodb-ns": "^2.4.0",
"mongodb-query-parser": "^3.1.3",
Expand All @@ -92,6 +92,7 @@
"@mongodb-js/compass-logging": "^1.2.6",
"@mongodb-js/databases-collections-list": "^1.19.1",
"compass-preferences-model": "^2.15.6",
"hadron-app-registry": "^9.0.14"
"hadron-app-registry": "^9.0.14",
"mongodb-data-service": "^22.15.1"
}
}

This file was deleted.

Loading

0 comments on commit d945d04

Please sign in to comment.