Skip to content

Commit

Permalink
chore: bump connection-form for global css reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Anemy committed Dec 7, 2023
1 parent 708520c commit 1023dce
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 132 deletions.
66 changes: 33 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@
"@iconify-icons/codicon": "^1.2.25",
"@iconify/react": "^1.1.4",
"@mongodb-js/compass-components": "^1.20.0",
"@mongodb-js/connection-form": "^1.20.3",
"@mongodb-js/connection-form": "^1.20.4",
"@mongodb-js/mongodb-constants": "^0.7.1",
"@mongosh/browser-runtime-electron": "^2.0.2",
"@mongosh/i18n": "^2.0.2",
Expand Down
5 changes: 5 additions & 0 deletions src/test/suite/views/webview-app/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
const Enzyme = require('enzyme');
const Adapter = require('@wojtekmaj/enzyme-adapter-react-17');
const chai = require('chai');
const { TextEncoder, TextDecoder } = require('util');

chai.use(require('sinon-chai'));
Enzyme.configure({ adapter: new Adapter() });

// eslint-disable-next-line no-undef
jest.mock('@iconify-icons/codicon/book', () => {});

// Note applied with js dom so we do manually. (Required by node_modules/mongodb-connection-string-url/node_modules/whatwg-url/lib/encoding.js)
Object.assign(global, { TextDecoder, TextEncoder });

global.vscodeFake = {
postMessage: (message) => {},
};
Expand Down
19 changes: 19 additions & 0 deletions src/test/suite/views/webview-app/overview-page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from 'react';
import { expect } from 'chai';
import { cleanup, render, screen } from '@testing-library/react';
import sinon from 'sinon';

import OverviewPage from '../../../../views/webview-app/overview-page';
import * as featureFlags from '../../../../featureFlags';

describe('OverviewPage test suite', function () {
afterEach(cleanup);
Expand All @@ -26,4 +29,20 @@ describe('OverviewPage test suite', function () {
screen.getByLabelText('Close').click();
expect(screen.queryByText('Product overview')).to.be.null;
});

describe('with the new connection form feature flag useNewConnectionForm enabled', function () {
beforeEach(function () {
sinon.stub(featureFlags, 'getFeatureFlag').returns(true);

render(<OverviewPage />);
});

test('it renders the new connection form when opened', function () {
const connectionFormTestId = 'connection-form-modal';
expect(screen.queryByTestId(connectionFormTestId)).to.not.exist;

screen.getByText('Open form').click();
expect(screen.getByTestId(connectionFormTestId)).to.exist;
});
});
});
2 changes: 1 addition & 1 deletion src/views/webview-app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useDetectVsCodeDarkMode } from './use-detect-vscode-dark-mode';
const App: React.FC = () => {
const darkMode = useDetectVsCodeDarkMode();

return true || getFeatureFlag('useNewConnectionForm') ? (
return getFeatureFlag('useNewConnectionForm') ? (
<LeafyGreenProvider darkMode={darkMode}>
<OverviewPage />
</LeafyGreenProvider>
Expand Down
45 changes: 23 additions & 22 deletions src/views/webview-app/connection-form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import CompassConnectionForm from '@mongodb-js/connection-form';
import { Modal, ModalBody, css, spacing } from '@mongodb-js/compass-components';
import { Modal, css, spacing } from '@mongodb-js/compass-components';
import { v4 as uuidv4 } from 'uuid';

const modalContentStyles = css({
Expand All @@ -9,7 +9,10 @@ const modalContentStyles = css({
});

const formContainerStyles = css({
padding: spacing[1],
padding: spacing[3],
position: 'relative',
display: 'flex',
flexDirection: 'column',
});

function createNewConnectionInfo() {
Expand Down Expand Up @@ -39,26 +42,24 @@ const ConnectionForm: React.FunctionComponent<{
data-testid="connection-form-modal"
size="large"
>
<ModalBody>
<div className={formContainerStyles}>
<CompassConnectionForm
onConnectClicked={onConnectClicked}
initialConnectionInfo={initialConnectionInfo}
preferences={{
protectConnectionStrings: false,
forceConnectionOptions: [],
showKerberosPasswordField: false,
showOIDCDeviceAuthFlow: false,
enableOidc: false,
enableDebugUseCsfleSchemaMap: false,
protectConnectionStringsForNewConnections: false,
showOIDCAuth: false,
showKerberosAuth: false,
showCSFLE: false,
}}
/>
</div>
</ModalBody>
<div className={formContainerStyles}>
<CompassConnectionForm
onConnectClicked={onConnectClicked}
initialConnectionInfo={initialConnectionInfo}
preferences={{
protectConnectionStrings: false,
forceConnectionOptions: [],
showKerberosPasswordField: false,
showOIDCDeviceAuthFlow: false,
enableOidc: false,
enableDebugUseCsfleSchemaMap: false,
protectConnectionStringsForNewConnections: false,
showOIDCAuth: false,
showKerberosAuth: false,
showCSFLE: false,
}}
/>
</div>
</Modal>
</>
);
Expand Down
4 changes: 0 additions & 4 deletions src/views/webview-app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';

import App from './app';
// import './reset.less';

import { resetGlobalCSS } from './reset-css';

resetGlobalCSS();
ReactDOM.render(<App />, document.getElementById('root'));
17 changes: 15 additions & 2 deletions src/views/webview-app/overview-page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { useCallback, useState } from 'react';
import { HorizontalRule, css, spacing } from '@mongodb-js/compass-components';
import React, { useCallback, useLayoutEffect, useState } from 'react';
import {
HorizontalRule,
css,
resetGlobalCSS,
spacing,
} from '@mongodb-js/compass-components';

import OverviewHeader from './overview-header';
import ConnectionStatus from './connection-status';
import ConnectHelper from './connect-helper';
Expand Down Expand Up @@ -31,6 +37,13 @@ const OverviewPage: React.FC = () => {
() => setShowResourcesPanel(true),
[]
);

useLayoutEffect(() => {
// TODO(VSCODE-490): Move this reset css call to the top level entry point
// of the app and out of the react lifecycle.
resetGlobalCSS();
}, []);

return (
<div className={pageStyles}>
{showResourcesPanel && (
Expand Down
69 changes: 0 additions & 69 deletions src/views/webview-app/reset-css.ts

This file was deleted.

0 comments on commit 1023dce

Please sign in to comment.