-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(compas-indexes): store real indexes and in-progress indexes as separate lists #6300
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c3883b0
store real indexes and in-progress indexes as separate lists
lerouxb a3bdbef
fixes after reading through it
lerouxb c1d52f5
more comments
lerouxb 3af56b5
fix helper
lerouxb 66b979f
move drop failed index to its own action creator
lerouxb 774c96e
split index actions into two specialised components
lerouxb ef1ffed
nit
lerouxb 133fb30
unnecessary assertions
lerouxb f5382f7
function that asserts
lerouxb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
58 changes: 58 additions & 0 deletions
58
...s/compass-indexes/src/components/regular-indexes-table/in-progress-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,58 @@ | ||
import React from 'react'; | ||
import { | ||
cleanup, | ||
render, | ||
screen, | ||
userEvent, | ||
} from '@mongodb-js/testing-library-compass'; | ||
import { expect } from 'chai'; | ||
import { spy } from 'sinon'; | ||
import type { SinonSpy } from 'sinon'; | ||
|
||
import InProgressIndexActions from './in-progress-index-actions'; | ||
|
||
describe('IndexActions Component', function () { | ||
let onDeleteSpy: SinonSpy; | ||
|
||
before(cleanup); | ||
afterEach(cleanup); | ||
beforeEach(function () { | ||
onDeleteSpy = spy(); | ||
}); | ||
|
||
it('does not render the delete button for an in progress index that is still in progress', function () { | ||
render( | ||
<InProgressIndexActions | ||
index={{ | ||
name: 'artist_id_index', | ||
status: 'inprogress', | ||
}} | ||
onDeleteFailedIndexClick={onDeleteSpy} | ||
/> | ||
); | ||
|
||
const button = screen.queryByTestId('index-actions-delete-action'); | ||
expect(button).to.not.exist; | ||
}); | ||
|
||
it('renders delete button for an in progress index that has failed', function () { | ||
render( | ||
<InProgressIndexActions | ||
index={{ | ||
name: 'artist_id_index', | ||
status: 'failed', | ||
}} | ||
onDeleteFailedIndexClick={onDeleteSpy} | ||
/> | ||
); | ||
|
||
const button = screen.getByTestId('index-actions-delete-action'); | ||
expect(button).to.exist; | ||
expect(button.getAttribute('aria-label')).to.equal( | ||
'Drop Index artist_id_index' | ||
); | ||
expect(onDeleteSpy.callCount).to.equal(0); | ||
userEvent.click(button); | ||
expect(onDeleteSpy.callCount).to.equal(1); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
packages/compass-indexes/src/components/regular-indexes-table/in-progress-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,55 @@ | ||
import React, { useCallback, useMemo } from 'react'; | ||
import type { GroupedItemAction } from '@mongodb-js/compass-components'; | ||
import { ItemActionGroup } from '@mongodb-js/compass-components'; | ||
import type { InProgressIndex } from '../../modules/regular-indexes'; | ||
|
||
type Index = { | ||
name: string; | ||
status: InProgressIndex['status']; | ||
}; | ||
|
||
type IndexActionsProps = { | ||
index: Index; | ||
onDeleteFailedIndexClick: (name: string) => void; | ||
}; | ||
|
||
type IndexAction = 'delete'; | ||
|
||
const IndexActions: React.FunctionComponent<IndexActionsProps> = ({ | ||
index, | ||
onDeleteFailedIndexClick, | ||
}) => { | ||
const indexActions: GroupedItemAction<IndexAction>[] = useMemo(() => { | ||
const actions: GroupedItemAction<IndexAction>[] = []; | ||
|
||
// you can only drop regular indexes or failed inprogress indexes | ||
if (index.status === 'failed') { | ||
actions.push({ | ||
action: 'delete', | ||
label: `Drop Index ${index.name}`, | ||
icon: 'Trash', | ||
}); | ||
} | ||
|
||
return actions; | ||
}, [index]); | ||
|
||
const onAction = useCallback( | ||
(action: IndexAction) => { | ||
if (action === 'delete') { | ||
onDeleteFailedIndexClick(index.name); | ||
} | ||
}, | ||
[onDeleteFailedIndexClick, index] | ||
); | ||
|
||
return ( | ||
<ItemActionGroup<IndexAction> | ||
data-testid="index-actions" | ||
actions={indexActions} | ||
onAction={onAction} | ||
></ItemActionGroup> | ||
); | ||
}; | ||
|
||
export default IndexActions; |
94 changes: 0 additions & 94 deletions
94
packages/compass-indexes/src/components/regular-indexes-table/index-actions.spec.tsx
This file was deleted.
Oops, something went wrong.
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by: I spotted the TODO when I audited the new TODOs I'm adding in this PR.