-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search-indexes): drop search index COMPASS-7167 (#4844)
- Loading branch information
Showing
13 changed files
with
224 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../create-search-index-modal/index.spec.tsx → ...modals/create-search-index-modal.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
1 change: 1 addition & 0 deletions
1
packages/compass-indexes/src/components/search-indexes-modals/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as CreateSearchIndexModal } from './create-search-index-modal'; |
36 changes: 36 additions & 0 deletions
36
packages/compass-indexes/src/components/search-indexes-table/search-index-actions.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import { expect } from 'chai'; | ||
import { spy } from 'sinon'; | ||
import type { SinonSpy } from 'sinon'; | ||
import userEvent from '@testing-library/user-event'; | ||
import type { SearchIndex } from 'mongodb-data-service'; | ||
|
||
import SearchIndexActions from './search-index-actions'; | ||
|
||
describe('SearchIndexActions Component', function () { | ||
let onDropSpy: SinonSpy; | ||
|
||
before(cleanup); | ||
afterEach(cleanup); | ||
beforeEach(function () { | ||
onDropSpy = spy(); | ||
render( | ||
<SearchIndexActions | ||
index={{ name: 'artist_id_index' } as SearchIndex} | ||
onDropIndex={onDropSpy} | ||
/> | ||
); | ||
}); | ||
|
||
it('renders drop button', function () { | ||
const button = screen.getByTestId('search-index-actions-drop-action'); | ||
expect(button).to.exist; | ||
expect(button.getAttribute('aria-label')).to.equal( | ||
'Drop Index artist_id_index' | ||
); | ||
expect(onDropSpy.callCount).to.equal(0); | ||
userEvent.click(button); | ||
expect(onDropSpy.callCount).to.equal(1); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
packages/compass-indexes/src/components/search-indexes-table/search-index-actions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, { useCallback, useMemo } from 'react'; | ||
import type { GroupedItemAction } from '@mongodb-js/compass-components'; | ||
import { ItemActionGroup } from '@mongodb-js/compass-components'; | ||
import type { SearchIndex } from 'mongodb-data-service'; | ||
|
||
type IndexActionsProps = { | ||
index: SearchIndex; | ||
onDropIndex: (name: string) => void; | ||
}; | ||
|
||
type SearchIndexAction = 'drop'; | ||
|
||
const IndexActions: React.FunctionComponent<IndexActionsProps> = ({ | ||
index, | ||
onDropIndex, | ||
}) => { | ||
const indexActions: GroupedItemAction<SearchIndexAction>[] = useMemo(() => { | ||
const actions: GroupedItemAction<SearchIndexAction>[] = [ | ||
{ | ||
action: 'drop', | ||
label: `Drop Index ${index.name}`, | ||
icon: 'Trash', | ||
}, | ||
]; | ||
|
||
return actions; | ||
}, [index]); | ||
|
||
const onAction = useCallback( | ||
(action: SearchIndexAction) => { | ||
if (action === 'drop') { | ||
void onDropIndex(index.name); | ||
} | ||
}, | ||
[onDropIndex, index] | ||
); | ||
|
||
return ( | ||
<ItemActionGroup<SearchIndexAction> | ||
data-testid="search-index-actions" | ||
actions={indexActions} | ||
onAction={onAction} | ||
></ItemActionGroup> | ||
); | ||
}; | ||
|
||
export default IndexActions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.