Skip to content

Commit b8c76b1

Browse files
authored
feat: disable create index button if fields aren't filled in for control CLOUDP-323669 (#7013)
* disable create index button if fields are filled in for control * update test and remove unused prop
1 parent d3a0ee7 commit b8c76b1

File tree

5 files changed

+25
-46
lines changed

5 files changed

+25
-46
lines changed

packages/compass-indexes/src/components/create-index-actions/create-index-actions.spec.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { setupStore } from '../../../test/setup-store';
1212
import { Provider } from 'react-redux';
1313

1414
import CreateIndexActions from '.';
15+
import { ActionTypes } from '../../modules/create-index';
1516

1617
describe('CreateIndexActions Component', function () {
1718
let clearErrorSpy: any;
@@ -39,7 +40,6 @@ describe('CreateIndexActions Component', function () {
3940
onErrorBannerCloseClick={clearErrorSpy}
4041
onCreateIndexClick={onCreateIndexClickSpy}
4142
onCancelCreateIndexClick={closeCreateIndexModalSpy}
42-
showIndexesGuidanceVariant={false}
4343
/>
4444
</Provider>
4545
);
@@ -62,9 +62,24 @@ describe('CreateIndexActions Component', function () {
6262
});
6363

6464
context('onConfirm', function () {
65+
it('will not call onCreateIndexClick function if fields are not valid and the button will be disabled', function () {
66+
renderComponent();
67+
const button = screen.getByTestId(
68+
'create-index-actions-create-index-button'
69+
);
70+
userEvent.click(button);
71+
expect(button.ariaDisabled).to.equal('true');
72+
expect(onCreateIndexClickSpy).not.to.have.been.calledOnce;
73+
});
74+
6575
it('calls the onCreateIndexClick function', function () {
6676
renderComponent();
6777

78+
// populate with valid fields first
79+
store.dispatch({
80+
type: ActionTypes.FieldsChanged,
81+
fields: [{ name: 'a', type: '1' }],
82+
});
6883
const button = screen.getByTestId(
6984
'create-index-actions-create-index-button'
7085
);

packages/compass-indexes/src/components/create-index-actions/create-index-actions.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ function CreateIndexActions({
3434
onCancelCreateIndexClick,
3535
fields,
3636
currentTab,
37-
showIndexesGuidanceVariant,
3837
indexSuggestions,
3938
}: {
4039
error: string | null;
@@ -43,25 +42,21 @@ function CreateIndexActions({
4342
onCancelCreateIndexClick: () => void;
4443
fields: Field[];
4544
currentTab: Tab;
46-
showIndexesGuidanceVariant: boolean;
4745
indexSuggestions: Record<string, number> | null;
4846
}) {
4947
const track = useTelemetry();
5048

5149
let isCreateIndexButtonDisabled = false;
52-
53-
if (showIndexesGuidanceVariant) {
54-
// Disable create index button if the user is in Query Flow and has no suggestions
55-
if (currentTab === 'QueryFlow') {
56-
if (indexSuggestions === null) {
57-
isCreateIndexButtonDisabled = true;
58-
}
50+
// Disable create index button if the user is in Query Flow and has no suggestions
51+
if (currentTab === 'QueryFlow') {
52+
if (indexSuggestions === null) {
53+
isCreateIndexButtonDisabled = true;
5954
}
60-
// Or if they are in the Index Flow but have not completed the fields
61-
else {
62-
if (!areAllFieldsFilledIn(fields)) {
63-
isCreateIndexButtonDisabled = true;
64-
}
55+
}
56+
// Or if they are in the Index Flow but have not completed the fields
57+
else {
58+
if (!areAllFieldsFilledIn(fields)) {
59+
isCreateIndexButtonDisabled = true;
6560
}
6661
}
6762

packages/compass-indexes/src/components/create-index-modal/create-index-modal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ function CreateIndexModal({
127127
onErrorBannerCloseClick={onErrorBannerCloseClick}
128128
onCreateIndexClick={onCreateIndexClick}
129129
onCancelCreateIndexClick={onCancelCreateIndexClick}
130-
showIndexesGuidanceVariant={showIndexesGuidanceVariant}
131130
/>
132131
</ModalFooter>
133132
</Modal>

packages/compass-indexes/src/modules/create-index.spec.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,6 @@ describe('create-index module', function () {
2929
store.dispatch(fieldTypeUpdated(0, 'text'));
3030
});
3131

32-
it('validates field name & type', function () {
33-
Object.assign(store.getState(), {
34-
createIndex: {
35-
...store.getState().createIndex,
36-
fields: [
37-
{
38-
name: '',
39-
type: '',
40-
},
41-
],
42-
},
43-
});
44-
store.dispatch(createIndexFormSubmitted());
45-
46-
expect(store.getState().createIndex.error).to.equal(
47-
'You must select a field name and type'
48-
);
49-
});
50-
5132
it('validates collation', function () {
5233
Object.assign(store.getState(), {
5334
createIndex: {

packages/compass-indexes/src/modules/create-index.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,6 @@ export const createIndexFormSubmitted = (): IndexesThunkAction<
507507
: undefined,
508508
});
509509

510-
// Check for field errors.
511-
if (
512-
!isQueryFlow &&
513-
getState().createIndex.fields.some(
514-
(field: Field) => field.name === '' || field.type === ''
515-
)
516-
) {
517-
dispatch(errorEncountered('You must select a field name and type'));
518-
return;
519-
}
520-
521510
const formIndexOptions = getState().createIndex.options;
522511

523512
let spec: Record<string, IndexDirection> = {};

0 commit comments

Comments
 (0)