Skip to content

Commit 721f272

Browse files
committed
rules generation wip
1 parent 90c1998 commit 721f272

26 files changed

+460
-36
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Is there anything else you’d like to see in Compass? Let us know by submitting
5151
- [**@mongodb-js/compass-maybe-protect-connection-string**](packages/compass-maybe-protect-connection-string): Utility for protecting connection strings if requested
5252
- [**@mongodb-js/compass-settings**](packages/compass-settings): Settings for compass
5353
- [**@mongodb-js/compass-telemetry**](packages/compass-telemetry): Compass telemetry
54+
- [**@mongodb-js/compass-schema-analysis**](packages/compass-schema-analysis): Compass schema analysis
5455
- [**@mongodb-js/compass-test-server**](packages/compass-test-server): Wrapper around mongodb-runner to manage test servers for Compass
5556
- [**@mongodb-js/compass-user-data**](packages/compass-user-data): undefined
5657
- [**@mongodb-js/compass-utils**](packages/compass-utils): Utilities for MongoDB Compass Development

package-lock.json

Lines changed: 223 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-schema-validation/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"@mongodb-js/compass-logging": "^1.6.5",
8080
"@mongodb-js/compass-telemetry": "^1.4.5",
8181
"@mongodb-js/compass-workspaces": "^0.31.5",
82+
"@mongodb-js/compass-schema-analysis": "^1.0.0",
8283
"bson": "^6.10.3",
8384
"compass-preferences-model": "^2.33.5",
8485
"hadron-app-registry": "^9.4.5",

packages/compass-schema-validation/src/components/validation-states.tsx

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
spacing,
1111
} from '@mongodb-js/compass-components';
1212
import { connect } from 'react-redux';
13-
import { usePreference } from 'compass-preferences-model/provider';
13+
import { usePreferences } from 'compass-preferences-model/provider';
1414
import { changeZeroState } from '../modules/zero-state';
1515
import type { RootState } from '../modules';
1616
import ValidationEditor from './validation-editor';
@@ -19,6 +19,10 @@ import { ZeroGraphic } from './zero-graphic';
1919

2020
const validationStatesStyles = css({ padding: spacing[3] });
2121
const contentContainerStyles = css({ height: '100%' });
22+
const zeroStateButtonsStyles = css({
23+
display: 'flex',
24+
gap: spacing[400],
25+
});
2226

2327
/**
2428
* Warnings for the banner.
@@ -110,7 +114,10 @@ export function ValidationStates({
110114
changeZeroState,
111115
editMode,
112116
}: ValidationStatesProps) {
113-
const readOnly = usePreference('readOnly');
117+
const { readOnly, enableExportSchema } = usePreferences([
118+
'readOnly',
119+
'enableExportSchema',
120+
]);
114121

115122
const isEditable =
116123
!editMode.collectionReadOnly &&
@@ -130,18 +137,31 @@ export function ValidationStates({
130137
{isZeroState ? (
131138
<EmptyContent
132139
icon={ZeroGraphic}
133-
title="Add validation rules"
134-
subTitle="Create rules to enforce data structure of documents on updates and inserts."
140+
title="Create validation rules"
141+
subTitle="Generate rules via schema analysis from existing sample data or add them manually to enforce document structure during updates and inserts"
135142
callToAction={
136-
<Button
137-
data-testid="add-rule-button"
138-
disabled={!isEditable}
139-
onClick={() => changeZeroState(false)}
140-
variant={ButtonVariant.Primary}
141-
size="small"
142-
>
143-
Add Rule
144-
</Button>
143+
<div className={zeroStateButtonsStyles}>
144+
{enableExportSchema && (
145+
<Button
146+
data-testid="generate-rules-button"
147+
disabled={!isEditable}
148+
onClick={() => changeZeroState(false)}
149+
variant={ButtonVariant.Primary}
150+
size="small"
151+
>
152+
Generate rules
153+
</Button>
154+
)}
155+
<Button
156+
data-testid="add-rule-button"
157+
disabled={!isEditable}
158+
onClick={() => changeZeroState(false)}
159+
variant={ButtonVariant.PrimaryOutline}
160+
size="small"
161+
>
162+
Add Rule
163+
</Button>
164+
</div>
145165
}
146166
callToActionLink={
147167
<Link href={DOC_SCHEMA_VALIDATION} target="_blank">

packages/compass-schema-validation/src/components/zero-graphic.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import React, { useMemo } from 'react';
2-
import { palette, useDarkMode } from '@mongodb-js/compass-components';
2+
import {
3+
css,
4+
palette,
5+
spacing,
6+
useDarkMode,
7+
} from '@mongodb-js/compass-components';
8+
9+
const svgStyles = css({ marginLeft: spacing[300] });
310

411
const ZeroGraphic: React.FunctionComponent = () => {
512
const darkMode = useDarkMode();
@@ -16,6 +23,7 @@ const ZeroGraphic: React.FunctionComponent = () => {
1623
viewBox="0 0 72 72"
1724
fill="none"
1825
xmlns="http://www.w3.org/2000/svg"
26+
className={svgStyles}
1927
>
2028
<path
2129
d="M41 16V4.00001L55 18H43C41.8954 18 41 17.1046 41 16Z"

packages/compass-schema-validation/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ const CompassSchemaValidationHadronPlugin = registerHadronPlugin(
2424
},
2525
{
2626
dataService: dataServiceLocator as DataServiceLocator<
27-
'aggregate' | 'collectionInfo' | 'updateCollection'
27+
| 'aggregate'
28+
| 'collectionInfo'
29+
| 'updateCollection'
30+
| 'sample'
31+
| 'isCancelError'
2832
>,
2933
connectionInfoRef: connectionInfoRefLocator,
3034
instance: mongoDBInstanceLocator,

0 commit comments

Comments
 (0)