-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add sharded state COMPASS-8279 (#6304)
- Loading branch information
1 parent
2c24180
commit 58fb9f5
Showing
16 changed files
with
1,314 additions
and
231 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
39 changes: 39 additions & 0 deletions
39
packages/compass-global-writes/src/components/shard-zones-table.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,39 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { render, screen, within } from '@mongodb-js/testing-library-compass'; | ||
import { ShardZonesTable } from './shard-zones-table'; | ||
import { type ShardZoneData } from '../store/reducer'; | ||
|
||
describe('Compass GlobalWrites Plugin', function () { | ||
const shardZones: ShardZoneData[] = [ | ||
{ | ||
zoneId: '45893084', | ||
country: 'Germany', | ||
readableName: 'Germany', | ||
isoCode: 'DE', | ||
typeOneIsoCode: 'DE', | ||
zoneName: 'EMEA', | ||
zoneLocations: ['Frankfurt'], | ||
}, | ||
{ | ||
zoneId: '43829408', | ||
country: 'Germany', | ||
readableName: 'Germany - Berlin', | ||
isoCode: 'DE-BE', | ||
typeOneIsoCode: 'DE', | ||
zoneName: 'EMEA', | ||
zoneLocations: ['Frankfurt'], | ||
}, | ||
]; | ||
|
||
it('renders the Location name & Zone for all items', function () { | ||
render(<ShardZonesTable shardZones={shardZones} />); | ||
|
||
const rows = screen.getAllByRole('row'); | ||
expect(rows).to.have.lengthOf(3); // 1 header, 2 items | ||
expect(within(rows[1]).getByText('Germany (DE)')).to.be.visible; | ||
expect(within(rows[1]).getByText('EMEA (Frankfurt)')).to.be.visible; | ||
expect(within(rows[2]).getByText('Germany - Berlin (DE-BE)')).to.be.visible; | ||
expect(within(rows[2]).getByText('EMEA (Frankfurt)')).to.be.visible; | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
packages/compass-global-writes/src/components/shard-zones-table.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,54 @@ | ||
import React from 'react'; | ||
import { | ||
Table, | ||
TableBody, | ||
TableHead, | ||
HeaderRow, | ||
HeaderCell, | ||
Row, | ||
Cell, | ||
css, | ||
} from '@mongodb-js/compass-components'; | ||
import type { ShardZoneData } from '../store/reducer'; | ||
|
||
const containerStyles = css({ | ||
maxWidth: '700px', | ||
height: '400px', | ||
}); | ||
|
||
export function ShardZonesTable({ | ||
shardZones, | ||
}: { | ||
shardZones: ShardZoneData[]; | ||
}) { | ||
return ( | ||
// TODO(COMPASS-8336): | ||
// Add search | ||
// group zones by ShardZoneData.typeOneIsoCode | ||
// and display them in a single row that can be expanded | ||
<Table className={containerStyles} title="Zone Mapping"> | ||
<TableHead isSticky> | ||
<HeaderRow> | ||
<HeaderCell>Location Name</HeaderCell> | ||
<HeaderCell>Zone</HeaderCell> | ||
</HeaderRow> | ||
</TableHead> | ||
<TableBody> | ||
{shardZones.map( | ||
({ readableName, zoneName, zoneLocations, isoCode }, index) => { | ||
return ( | ||
<Row key={index}> | ||
<Cell> | ||
{readableName} ({isoCode}) | ||
</Cell> | ||
<Cell> | ||
{zoneName} ({zoneLocations.join(', ')}) | ||
</Cell> | ||
</Row> | ||
); | ||
} | ||
)} | ||
</TableBody> | ||
</Table> | ||
); | ||
} |
135 changes: 135 additions & 0 deletions
135
packages/compass-global-writes/src/components/states/shard-key-correct.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,135 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { screen, userEvent } from '@mongodb-js/testing-library-compass'; | ||
import { | ||
ShardKeyCorrect, | ||
type ShardKeyCorrectProps, | ||
} from './shard-key-correct'; | ||
import { type ShardZoneData } from '../../store/reducer'; | ||
import Sinon from 'sinon'; | ||
import { renderWithStore } from '../../../tests/create-store'; | ||
import { type ConnectionInfo } from '@mongodb-js/compass-connections/provider'; | ||
|
||
describe('Compass GlobalWrites Plugin', function () { | ||
const shardZones: ShardZoneData[] = [ | ||
{ | ||
zoneId: '45893084', | ||
country: 'Germany', | ||
readableName: 'Germany', | ||
isoCode: 'DE', | ||
typeOneIsoCode: 'DE', | ||
zoneName: 'EMEA', | ||
zoneLocations: ['Frankfurt'], | ||
}, | ||
]; | ||
|
||
const baseProps: ShardKeyCorrectProps = { | ||
shardZones, | ||
namespace: 'db1.coll1', | ||
shardKey: { | ||
fields: [ | ||
{ type: 'HASHED', name: 'location' }, | ||
{ type: 'RANGE', name: 'secondary' }, | ||
], | ||
isUnique: false, | ||
}, | ||
isUnmanagingNamespace: false, | ||
onUnmanageNamespace: () => {}, | ||
}; | ||
|
||
function renderWithProps( | ||
props?: Partial<ShardKeyCorrectProps>, | ||
options?: Parameters<typeof renderWithStore>[1] | ||
) { | ||
return renderWithStore( | ||
<ShardKeyCorrect {...baseProps} {...props} />, | ||
options | ||
); | ||
} | ||
|
||
it('Provides button to unmanage', async function () { | ||
const onUnmanageNamespace = Sinon.spy(); | ||
await renderWithProps({ onUnmanageNamespace }); | ||
|
||
const btn = await screen.findByRole<HTMLButtonElement>('button', { | ||
name: /Unmanage collection/, | ||
}); | ||
expect(btn).to.be.visible; | ||
|
||
userEvent.click(btn); | ||
|
||
expect(onUnmanageNamespace).to.have.been.calledOnce; | ||
}); | ||
|
||
it('Unmanage btn is disabled when the action is in progress', async function () { | ||
const onUnmanageNamespace = Sinon.spy(); | ||
await renderWithProps({ onUnmanageNamespace, isUnmanagingNamespace: true }); | ||
|
||
const btn = await screen.findByTestId<HTMLButtonElement>( | ||
'shard-collection-button' | ||
); | ||
expect(btn).to.be.visible; | ||
expect(btn.getAttribute('aria-disabled')).to.equal('true'); | ||
|
||
userEvent.click(btn); | ||
|
||
expect(onUnmanageNamespace).not.to.have.been.called; | ||
}); | ||
|
||
it('Provides link to Edit Configuration', async function () { | ||
const connectionInfo = { | ||
id: 'testConnection', | ||
connectionOptions: { | ||
connectionString: 'mongodb://test', | ||
}, | ||
atlasMetadata: { | ||
projectId: 'project1', | ||
clusterName: 'myCluster', | ||
} as ConnectionInfo['atlasMetadata'], | ||
}; | ||
await renderWithProps(undefined, { | ||
connectionInfo, | ||
}); | ||
|
||
const link = await screen.findByRole('link', { | ||
name: /Edit Configuration/, | ||
}); | ||
const expectedHref = `/v2/${connectionInfo.atlasMetadata?.projectId}#/clusters/edit/${connectionInfo.atlasMetadata?.clusterName}`; | ||
|
||
expect(link).to.be.visible; | ||
expect(link).to.have.attribute('href', expectedHref); | ||
}); | ||
|
||
it('Describes the shardKey', async function () { | ||
await renderWithProps(); | ||
|
||
const title = await screen.findByTestId('shardkey-description-title'); | ||
expect(title).to.be.visible; | ||
expect(title.textContent).to.equal( | ||
`${baseProps.namespace} is configured with the following shard key:` | ||
); | ||
const list = await screen.findByTestId('shardkey-description-content'); | ||
expect(list).to.be.visible; | ||
expect(list.textContent).to.contain(`"location", "secondary"`); | ||
}); | ||
|
||
it('Contains sample codes', async function () { | ||
await renderWithProps(); | ||
|
||
const findingDocumentsSample = await screen.findByTestId( | ||
'sample-finding-documents' | ||
); | ||
expect(findingDocumentsSample).to.be.visible; | ||
expect(findingDocumentsSample.textContent).to.contain( | ||
`use db1db["coll1"].find({"location": "US-NY", "secondary": "<id_value>"})` | ||
); | ||
|
||
const insertingDocumentsSample = await screen.findByTestId( | ||
'sample-inserting-documents' | ||
); | ||
expect(insertingDocumentsSample).to.be.visible; | ||
expect(insertingDocumentsSample.textContent).to.contain( | ||
`use db1db["coll1"].insertOne({"location": "US-NY", "secondary": "<id_value>",...<other fields>})` | ||
); | ||
}); | ||
}); |
Oops, something went wrong.