Skip to content

Commit 238da29

Browse files
authored
fix(compass-crud): add outdated warning to feature flagged crud toolbar (#3448)
1 parent 0aad51a commit 238da29

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

packages/compass-crud/src/components/crud-toolbar.spec.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const mockQueryBarStore = {
3939
},
4040
};
4141

42+
const testOutdatedMessageId = 'crud-outdated-message-id';
43+
4244
function renderCrudToolbar(
4345
props?: Partial<React.ComponentProps<typeof CrudToolbar>>
4446
) {
@@ -61,6 +63,7 @@ function renderCrudToolbar(
6163
onApplyClicked={noop}
6264
onResetClicked={noop}
6365
openExportFileDialog={noop}
66+
outdated={false}
6467
page={0}
6568
readonly={false}
6669
refreshDocuments={noop}
@@ -241,6 +244,12 @@ describe('CrudToolbar Component', function () {
241244
expect(exportSpy.calledOnce).to.be.true;
242245
});
243246

247+
it('should not render the outdated message', function () {
248+
renderCrudToolbar();
249+
250+
expect(screen.queryByTestId(testOutdatedMessageId)).to.not.exist;
251+
});
252+
244253
describe('when the instance is in a writable state (`isWritable` is true)', function () {
245254
beforeEach(function () {
246255
renderCrudToolbar({
@@ -268,4 +277,16 @@ describe('CrudToolbar Component', function () {
268277
).to.exist;
269278
});
270279
});
280+
281+
describe('when the documents are outdated', function () {
282+
beforeEach(function () {
283+
renderCrudToolbar({
284+
outdated: true,
285+
});
286+
});
287+
288+
it('should render the outdated message', function () {
289+
expect(screen.getByTestId(testOutdatedMessageId)).to.be.visible;
290+
});
291+
});
271292
});

packages/compass-crud/src/components/crud-toolbar.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
css,
1414
spacing,
1515
useId,
16+
WarningSummary,
1617
} from '@mongodb-js/compass-components';
1718

1819
import { AddDataMenu } from './add-data-menu';
@@ -55,10 +56,15 @@ const exportCollectionButtonStyles = css({
5556
whiteSpace: 'nowrap',
5657
});
5758

59+
const OUTDATED_WARNING = `The content is outdated and no longer in sync
60+
with the current query. Press "Find" again to see the results for
61+
the current query.`;
62+
5863
type CrudToolbarProps = {
5964
activeDocumentView: string;
6065
count?: number;
6166
end: number;
67+
error?: Error;
6268
getPage: (page: number) => void;
6369
insertDataHandler: (openInsertKey: 'insert-document' | 'import-file') => void;
6470
instanceDescription: string;
@@ -69,6 +75,7 @@ type CrudToolbarProps = {
6975
onApplyClicked: () => void;
7076
onResetClicked: () => void;
7177
openExportFileDialog: () => void;
78+
outdated: boolean;
7279
page: number;
7380
readonly: boolean;
7481
refreshDocuments: () => void;
@@ -81,6 +88,7 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
8188
activeDocumentView,
8289
count,
8390
end,
91+
error,
8492
getPage,
8593
insertDataHandler,
8694
instanceDescription,
@@ -91,6 +99,7 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
9199
onApplyClicked,
92100
onResetClicked,
93101
openExportFileDialog,
102+
outdated,
94103
page,
95104
readonly,
96105
refreshDocuments,
@@ -236,6 +245,12 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
236245
</SegmentedControl>
237246
</div>
238247
</div>
248+
{outdated && !error && (
249+
<WarningSummary
250+
data-testid="crud-outdated-message-id"
251+
warnings={[OUTDATED_WARNING]}
252+
/>
253+
)}
239254
</Toolbar>
240255
);
241256
};

packages/compass-crud/src/components/document-list.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ class DocumentList extends React.Component {
269269
{useNewToolbars ? (
270270
<CrudToolbar
271271
activeDocumentView={this.props.view}
272+
error={this.props.error}
272273
count={this.props.count}
273274
loadingCount={this.props.loadingCount}
274275
start={this.props.start}
@@ -281,6 +282,7 @@ class DocumentList extends React.Component {
281282
onApplyClicked={this.onApplyClicked.bind(this)}
282283
onResetClicked={this.onResetClicked.bind(this)}
283284
openExportFileDialog={this.props.openExportFileDialog}
285+
outdated={this.props.outdated}
284286
readonly={!this.props.isEditable}
285287
viewSwitchHandler={this.props.viewChanged}
286288
isWritable={this.props.isWritable}

0 commit comments

Comments
 (0)