Skip to content

Commit

Permalink
chore(compass-crud): remove less and unused styles from compass-crud (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Anemy authored Oct 25, 2023
1 parent 209ee55 commit 866405a
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const DocumentIcon: React.FunctionComponent = () => {

return (
<svg
className="document-list-zero-state-graphic"
width="72"
height="72"
viewBox="0 0 72 72"
Expand Down
9 changes: 0 additions & 9 deletions packages/compass-crud/src/components/compass-container.less

This file was deleted.

27 changes: 0 additions & 27 deletions packages/compass-crud/src/components/document-json-view.less

This file was deleted.

31 changes: 16 additions & 15 deletions packages/compass-crud/src/components/document-json-view.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import React from 'react';
import { css, cx, KeylineCard } from '@mongodb-js/compass-components';
import { css, cx, KeylineCard, spacing } from '@mongodb-js/compass-components';

import type { JSONEditorProps } from './json-editor';
import JSONEditor from './json-editor';
import type Document from 'hadron-document';

/**
* The full document list container class.
*/
const LIST_CLASS = 'document-json';
const listStyles = css({
listStyle: 'none',
position: 'relative',
width: '100%',
});

/**
* The list item class.
*/
const LIST_ITEM_CLASS = `${LIST_CLASS}-item`;
const listItemStyles = css({
position: 'relative',
marginBottom: spacing[2],

/**
* The list item test id.
*/
const LIST_ITEM_TEST_ID = LIST_ITEM_CLASS;
'&:last-child': {
marginBottom: 0,
borderBottom: '0px solid transparent',
},
});

export type DocumentJsonViewProps = {
docs: Document[];
Expand Down Expand Up @@ -54,7 +55,7 @@ class DocumentJsonView extends React.Component<DocumentJsonViewProps> {
renderDocuments() {
return this.props.docs.map((doc, i) => {
return (
<li className={LIST_ITEM_CLASS} data-testid={LIST_ITEM_TEST_ID} key={i}>
<li className={listItemStyles} data-testid="document-json-item" key={i}>
<KeylineCard className={keylineCardCSS}>
<JSONEditor
key={doc.uuid}
Expand Down Expand Up @@ -82,7 +83,7 @@ class DocumentJsonView extends React.Component<DocumentJsonViewProps> {
*/
render() {
return (
<ol className={cx(LIST_CLASS, this.props.className)}>
<ol className={cx(listStyles, this.props.className)}>
{this.renderDocuments()}
</ol>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('<DocumentListView />', function () {
);

it('renders all the documents', function () {
const wrapper = component.find('.document');
const wrapper = component.find('[data-testid="readonly-document"]');
expect(wrapper).to.have.length(2);
});
});
Expand Down
36 changes: 20 additions & 16 deletions packages/compass-crud/src/components/document-list-view.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import React from 'react';
import PropTypes from 'prop-types';
import { KeylineCard, cx } from '@mongodb-js/compass-components';
import { KeylineCard, css, cx, spacing } from '@mongodb-js/compass-components';

import type { DocumentProps } from './document';
import Document from './document';
import type HadronDocument from 'hadron-document';
import type { BSONObject } from '../stores/crud-store';

/**
* The full document list container class.
*/
const LIST_CLASS = 'document-list';
const listStyles = css({
listStyle: 'none',
position: 'relative',
width: '100%',
});

/**
* The list item class.
*/
const LIST_ITEM_CLASS = `${LIST_CLASS}-item`;
const listItemStyles = css({
position: 'relative',
marginBottom: spacing[1],

/**
* The list item test id.
*/
const LIST_ITEM_TEST_ID = LIST_ITEM_CLASS;
'&:last-child': {
marginBottom: 0,
borderBottom: '0 solid transparent',
},
});

export type DocumentListViewProps = {
docs: (HadronDocument | BSONObject)[];
Expand Down Expand Up @@ -52,8 +53,8 @@ class DocumentListView extends React.Component<DocumentListViewProps> {
return this.props.docs.map((doc, index) => {
return (
<li
className={LIST_ITEM_CLASS}
data-testid={LIST_ITEM_TEST_ID}
className={listItemStyles}
data-testid="document-list-item"
key={index}
>
<KeylineCard>
Expand Down Expand Up @@ -81,7 +82,10 @@ class DocumentListView extends React.Component<DocumentListViewProps> {
*/
render() {
return (
<ol className={cx(LIST_CLASS, this.props.className)}>
<ol
className={cx(listStyles, this.props.className)}
data-testid="document-list"
>
{this.renderDocuments()}
</ol>
);
Expand Down
23 changes: 0 additions & 23 deletions packages/compass-crud/src/components/document-list.less

This file was deleted.

25 changes: 20 additions & 5 deletions packages/compass-crud/src/components/document-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
DOCUMENTS_STATUSES_ALL,
} from '../constants/documents-statuses';

import './index.less';
import type {
CrudStore,
BSONObject,
Expand All @@ -54,6 +53,22 @@ const tableStyles = css({
paddingLeft: spacing[3],
});

const documentsContainerStyles = css({
display: 'flex',
flexDirection: 'column',
alignItems: 'stretch',
width: '100%',
height: '100%',
flexGrow: 1,
position: 'relative',
});

const loaderContainerStyles = css({
height: '100%',
display: 'flex',
justifyContent: 'center',
});

export type DocumentListProps = {
store: CrudStore;
openInsertDocumentDialog?: (doc: BSONObject, cloned: boolean) => void;
Expand Down Expand Up @@ -179,7 +194,7 @@ class DocumentList extends React.Component<DocumentListProps> {
*/
renderFetching() {
return (
<div className="loader">
<div className={loaderContainerStyles}>
<CancelLoader
data-testid="fetching-documents"
progressText="Fetching Documents"
Expand Down Expand Up @@ -288,7 +303,7 @@ class DocumentList extends React.Component<DocumentListProps> {
this.props.status === DOCUMENTS_STATUS_FETCHED_CUSTOM
) {
return (
<div className="document-list-zero-state">
<div data-testid="document-list-zero-state">
<EmptyContent
icon={DocumentIcon}
title="No results"
Expand All @@ -299,7 +314,7 @@ class DocumentList extends React.Component<DocumentListProps> {
}

return (
<div className="document-list-zero-state">
<div data-testid="document-list-zero-state">
<EmptyContent
icon={DocumentIcon}
title="This collection has no data"
Expand Down Expand Up @@ -329,7 +344,7 @@ class DocumentList extends React.Component<DocumentListProps> {
*/
render() {
return (
<div className="compass-documents">
<div className={documentsContainerStyles}>
<WorkspaceContainer
toolbar={
<CrudToolbar
Expand Down
27 changes: 0 additions & 27 deletions packages/compass-crud/src/components/document.less

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ describe('<EditableDocument />', function () {
});

it('renders the list div', function () {
const component = wrapper.find('.document');
const component = wrapper.find('[data-testid="editable-document"]');
(expect(component) as any).to.be.present();
});

it('renders the base element list', function () {
const component = wrapper.find('.document-elements');
const component = wrapper.find(
'[data-testid="editable-document-elements"]'
);
(expect(component) as any).to.be.present();
});

Expand Down
55 changes: 15 additions & 40 deletions packages/compass-crud/src/components/editable-document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,22 @@ import React from 'react';
import PropTypes from 'prop-types';
import type { Document } from 'hadron-document';
import HadronDocument from 'hadron-document';
import { DocumentList } from '@mongodb-js/compass-components';
import type { CrudActions } from '../stores/crud-store';
import { DocumentList, css } from '@mongodb-js/compass-components';
import { withPreferences } from 'compass-preferences-model';
import { getInsightsForDocument } from '../utils';

/**
* The base class.
*/
const BASE = 'document';

/**
* The contents class.
*/
const CONTENTS = `${BASE}-contents`;
import { documentStyles, documentContentStyles } from './readonly-document';
import { getInsightsForDocument } from '../utils';
import type { CrudActions } from '../stores/crud-store';

/**
* The contents class.
*/
const ELEMENTS = `${BASE}-elements`;
const documentElementsContainerStyles = css({
position: 'relative',
});

/**
* The initial field limit.
*/
const INITIAL_FIELD_LIMIT = 25;

/**
* The test id.
*/
const TEST_ID = 'editable-document';

export type EditableDocumentProps = {
doc: Document;
expandAll?: boolean;
Expand Down Expand Up @@ -192,22 +178,6 @@ class EditableDocument extends React.Component<
this.setState({ expandAll: !this.state.expandAll });
}

/**
* Get the current style of the document div.
*
* @returns {String} The document class name.
*/
style() {
let style = BASE;
if (this.state.editing) {
style = style.concat(' document-is-editing');
}
if (this.state.deleting) {
style = style.concat(' document-is-deleting');
}
return style;
}

/**
* Render the actions component.
*
Expand Down Expand Up @@ -286,9 +256,14 @@ class EditableDocument extends React.Component<
*/
render() {
return (
<div className={this.style()} data-testid={TEST_ID}>
<div className={CONTENTS}>
<div className={ELEMENTS}>{this.renderElements()}</div>
<div className={documentStyles} data-testid="editable-document">
<div className={documentContentStyles}>
<div
className={documentElementsContainerStyles}
data-testid="editable-document-elements"
>
{this.renderElements()}
</div>
{this.renderActions()}
</div>
{this.renderFooter()}
Expand Down
Loading

0 comments on commit 866405a

Please sign in to comment.