Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,17 @@ const CollectionHeaderActions: React.FunctionComponent<
!hasSchemaAnalysisData &&
schemaAnalysisStatus !== SCHEMA_ANALYSIS_STATE_ANALYZING;

const hasSchemaAnalysisUnsupportedStateError = Boolean(
schemaAnalysisError && schemaAnalysisError.errorType === 'unsupportedState'
);

const isView = isReadonly && sourceName && !editViewName;

const showViewEdit = isView && !preferencesReadWrite;
const shouldDisableMockDataButton =
!hasSchemaAnalysisData || exceedsMaxNestingDepth;
!hasSchemaAnalysisData ||
exceedsMaxNestingDepth ||
hasSchemaAnalysisUnsupportedStateError;

const onMockDataGeneratorCtaButtonClicked = useCallback(() => {
track('Mock Data Generator Opened', {
Expand Down Expand Up @@ -184,7 +190,11 @@ const CollectionHeaderActions: React.FunctionComponent<
)}
{shouldShowMockDataButton && (
<Tooltip
enabled={exceedsMaxNestingDepth || isCollectionEmpty}
enabled={
exceedsMaxNestingDepth ||
isCollectionEmpty ||
hasSchemaAnalysisUnsupportedStateError
}
trigger={
<div>
<Button
Expand All @@ -199,29 +209,22 @@ const CollectionHeaderActions: React.FunctionComponent<
</div>
}
>
{/* TODO(CLOUDP-333853): update disabled open-modal button
tooltip to communicate if schema analysis is incomplete */}
<>
{exceedsMaxNestingDepth && (
{hasSchemaAnalysisUnsupportedStateError ? (
<span className={tooltipMessageStyles}>
{schemaAnalysisError?.errorMessage}
</span>
) : exceedsMaxNestingDepth ? (
<span className={tooltipMessageStyles}>
At this time we are unable to generate mock data for collections
that have deeply nested documents.
</span>
)}
{isCollectionEmpty && (
) : isCollectionEmpty ? (
<span className={tooltipMessageStyles}>
Please add data to your collection to generate similar mock
documents.
</span>
)}
{schemaAnalysisError &&
schemaAnalysisError.errorType === 'unsupportedState' && (
<span className={tooltipMessageStyles}>
This collection has a field with a name that contains a
&quot.&quot, which mock data generation does not support at
this time.
</span>
)}
) : null}
</>
</Tooltip>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,120 @@ describe('processSchema', function () {
};

expect(() => processSchema(schema)).to.throw(
"invalid fieldPath '[]': field parts must have characters other than '[]'"
ProcessSchemaUnsupportedStateError,
"Feature is unsupported for field names that end with '[]'; field name: '[]'"
);
});

it('throws error for field names ending with []', function () {
const schema: Schema = {
fields: [
{
name: 'users[]',
path: ['users[]'],
count: 1,
type: ['String'],
probability: 1.0,
hasDuplicates: false,
types: [
{
name: 'String',
bsonType: 'String',
path: ['users[]'],
count: 1,
probability: 1.0,
values: ['test'],
},
],
},
],
count: 1,
};

expect(() => processSchema(schema)).to.throw(
ProcessSchemaUnsupportedStateError,
"Feature is unsupported for field names that end with '[]'; field name: 'users[]'"
);
});

it('throws error for nested field names ending with []', function () {
const schema: Schema = {
fields: [
{
name: 'parent',
path: ['parent'],
count: 1,
type: ['Document'],
probability: 1.0,
hasDuplicates: false,
types: [
{
name: 'Document',
bsonType: 'Document',
path: ['parent'],
count: 1,
probability: 1.0,
fields: [
{
name: 'child[]',
path: ['parent', 'child[]'],
count: 1,
type: ['String'],
probability: 1.0,
hasDuplicates: false,
types: [
{
name: 'String',
bsonType: 'String',
path: ['parent', 'child[]'],
count: 1,
probability: 1.0,
values: ['test'],
},
],
},
],
},
],
},
],
count: 1,
};

expect(() => processSchema(schema)).to.throw(
ProcessSchemaUnsupportedStateError,
"Feature is unsupported for field names that end with '[]'; field name: 'child[]'"
);
});

it('throws error for field names containing dots', function () {
const schema: Schema = {
fields: [
{
name: 'user.name',
path: ['user.name'],
count: 1,
type: ['String'],
probability: 1.0,
hasDuplicates: false,
types: [
{
name: 'String',
bsonType: 'String',
path: ['user.name'],
count: 1,
probability: 1.0,
values: ['test'],
},
],
},
],
count: 1,
};

expect(() => processSchema(schema)).to.throw(
ProcessSchemaUnsupportedStateError,
"Feature is unsupported for field names that contain a '.'; field name: 'user.name'"
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@ function processNamedField(

if (field.name.includes(FIELD_NAME_SEPARATOR)) {
throw new ProcessSchemaUnsupportedStateError(
`no support for field names that contain a '${FIELD_NAME_SEPARATOR}' ; field name: '${field.name}'`
`Feature is unsupported for field names that contain a '${FIELD_NAME_SEPARATOR}'; field name: '${field.name}'`
);
}

if (field.name.endsWith('[]')) {
throw new ProcessSchemaUnsupportedStateError(
`Feature is unsupported for field names that end with '[]'; field name: '${field.name}'`
);
}

Expand Down
Loading