Skip to content

Commit a3c4dc7

Browse files
authored
feat(compass-collection): Disable Mock Data Generator button if fields end in "[]" - CLOUDP-347300 (#7497)
* Error for trailing [] * Remove space * WIP
1 parent 231c0b0 commit a3c4dc7

File tree

3 files changed

+140
-18
lines changed

3 files changed

+140
-18
lines changed

packages/compass-collection/src/components/collection-header-actions/collection-header-actions.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,17 @@ const CollectionHeaderActions: React.FunctionComponent<
125125
!hasSchemaAnalysisData &&
126126
schemaAnalysisStatus !== SCHEMA_ANALYSIS_STATE_ANALYZING;
127127

128+
const hasSchemaAnalysisUnsupportedStateError = Boolean(
129+
schemaAnalysisError && schemaAnalysisError.errorType === 'unsupportedState'
130+
);
131+
128132
const isView = isReadonly && sourceName && !editViewName;
129133

130134
const showViewEdit = isView && !preferencesReadWrite;
131135
const shouldDisableMockDataButton =
132-
!hasSchemaAnalysisData || exceedsMaxNestingDepth;
136+
!hasSchemaAnalysisData ||
137+
exceedsMaxNestingDepth ||
138+
hasSchemaAnalysisUnsupportedStateError;
133139

134140
const onMockDataGeneratorCtaButtonClicked = useCallback(() => {
135141
track('Mock Data Generator Opened', {
@@ -184,7 +190,11 @@ const CollectionHeaderActions: React.FunctionComponent<
184190
)}
185191
{shouldShowMockDataButton && (
186192
<Tooltip
187-
enabled={exceedsMaxNestingDepth || isCollectionEmpty}
193+
enabled={
194+
exceedsMaxNestingDepth ||
195+
isCollectionEmpty ||
196+
hasSchemaAnalysisUnsupportedStateError
197+
}
188198
trigger={
189199
<div>
190200
<Button
@@ -199,29 +209,22 @@ const CollectionHeaderActions: React.FunctionComponent<
199209
</div>
200210
}
201211
>
202-
{/* TODO(CLOUDP-333853): update disabled open-modal button
203-
tooltip to communicate if schema analysis is incomplete */}
204212
<>
205-
{exceedsMaxNestingDepth && (
213+
{hasSchemaAnalysisUnsupportedStateError ? (
214+
<span className={tooltipMessageStyles}>
215+
{schemaAnalysisError?.errorMessage}
216+
</span>
217+
) : exceedsMaxNestingDepth ? (
206218
<span className={tooltipMessageStyles}>
207219
At this time we are unable to generate mock data for collections
208220
that have deeply nested documents.
209221
</span>
210-
)}
211-
{isCollectionEmpty && (
222+
) : isCollectionEmpty ? (
212223
<span className={tooltipMessageStyles}>
213224
Please add data to your collection to generate similar mock
214225
documents.
215226
</span>
216-
)}
217-
{schemaAnalysisError &&
218-
schemaAnalysisError.errorType === 'unsupportedState' && (
219-
<span className={tooltipMessageStyles}>
220-
This collection has a field with a name that contains a
221-
&quot.&quot, which mock data generation does not support at
222-
this time.
223-
</span>
224-
)}
227+
) : null}
225228
</>
226229
</Tooltip>
227230
)}

packages/compass-collection/src/transform-schema-to-field-info.spec.ts

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,120 @@ describe('processSchema', function () {
13441344
};
13451345

13461346
expect(() => processSchema(schema)).to.throw(
1347-
"invalid fieldPath '[]': field parts must have characters other than '[]'"
1347+
ProcessSchemaUnsupportedStateError,
1348+
"Feature is unsupported for field names that end with '[]'; field name: '[]'"
1349+
);
1350+
});
1351+
1352+
it('throws error for field names ending with []', function () {
1353+
const schema: Schema = {
1354+
fields: [
1355+
{
1356+
name: 'users[]',
1357+
path: ['users[]'],
1358+
count: 1,
1359+
type: ['String'],
1360+
probability: 1.0,
1361+
hasDuplicates: false,
1362+
types: [
1363+
{
1364+
name: 'String',
1365+
bsonType: 'String',
1366+
path: ['users[]'],
1367+
count: 1,
1368+
probability: 1.0,
1369+
values: ['test'],
1370+
},
1371+
],
1372+
},
1373+
],
1374+
count: 1,
1375+
};
1376+
1377+
expect(() => processSchema(schema)).to.throw(
1378+
ProcessSchemaUnsupportedStateError,
1379+
"Feature is unsupported for field names that end with '[]'; field name: 'users[]'"
1380+
);
1381+
});
1382+
1383+
it('throws error for nested field names ending with []', function () {
1384+
const schema: Schema = {
1385+
fields: [
1386+
{
1387+
name: 'parent',
1388+
path: ['parent'],
1389+
count: 1,
1390+
type: ['Document'],
1391+
probability: 1.0,
1392+
hasDuplicates: false,
1393+
types: [
1394+
{
1395+
name: 'Document',
1396+
bsonType: 'Document',
1397+
path: ['parent'],
1398+
count: 1,
1399+
probability: 1.0,
1400+
fields: [
1401+
{
1402+
name: 'child[]',
1403+
path: ['parent', 'child[]'],
1404+
count: 1,
1405+
type: ['String'],
1406+
probability: 1.0,
1407+
hasDuplicates: false,
1408+
types: [
1409+
{
1410+
name: 'String',
1411+
bsonType: 'String',
1412+
path: ['parent', 'child[]'],
1413+
count: 1,
1414+
probability: 1.0,
1415+
values: ['test'],
1416+
},
1417+
],
1418+
},
1419+
],
1420+
},
1421+
],
1422+
},
1423+
],
1424+
count: 1,
1425+
};
1426+
1427+
expect(() => processSchema(schema)).to.throw(
1428+
ProcessSchemaUnsupportedStateError,
1429+
"Feature is unsupported for field names that end with '[]'; field name: 'child[]'"
1430+
);
1431+
});
1432+
1433+
it('throws error for field names containing dots', function () {
1434+
const schema: Schema = {
1435+
fields: [
1436+
{
1437+
name: 'user.name',
1438+
path: ['user.name'],
1439+
count: 1,
1440+
type: ['String'],
1441+
probability: 1.0,
1442+
hasDuplicates: false,
1443+
types: [
1444+
{
1445+
name: 'String',
1446+
bsonType: 'String',
1447+
path: ['user.name'],
1448+
count: 1,
1449+
probability: 1.0,
1450+
values: ['test'],
1451+
},
1452+
],
1453+
},
1454+
],
1455+
count: 1,
1456+
};
1457+
1458+
expect(() => processSchema(schema)).to.throw(
1459+
ProcessSchemaUnsupportedStateError,
1460+
"Feature is unsupported for field names that contain a '.'; field name: 'user.name'"
13481461
);
13491462
});
13501463
});

packages/compass-collection/src/transform-schema-to-field-info.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,13 @@ function processNamedField(
244244

245245
if (field.name.includes(FIELD_NAME_SEPARATOR)) {
246246
throw new ProcessSchemaUnsupportedStateError(
247-
`no support for field names that contain a '${FIELD_NAME_SEPARATOR}' ; field name: '${field.name}'`
247+
`Feature is unsupported for field names that contain a '${FIELD_NAME_SEPARATOR}'; field name: '${field.name}'`
248+
);
249+
}
250+
251+
if (field.name.endsWith('[]')) {
252+
throw new ProcessSchemaUnsupportedStateError(
253+
`Feature is unsupported for field names that end with '[]'; field name: '${field.name}'`
248254
);
249255
}
250256

0 commit comments

Comments
 (0)