-
Notifications
You must be signed in to change notification settings - Fork 229
feat(data-modeling): node selection and relationship editing store and actions COMPASS-9476 #7118
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
Merged
+1,145
−110
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0eaeb31
feat(data-modeling): node selection and relationship editing store an…
gribnoysup eb5d54d
chore(data-modeling): add tests
gribnoysup f31e384
Merge remote-tracking branch 'origin/main' into COMPASS-9476
gribnoysup b3b435b
fix(data-modeling): un-only the test and fix types
gribnoysup 4bd103f
chore(data-modeling): remove sidebar state; connect form to the edits…
gribnoysup c6e540e
Merge remote-tracking branch 'origin/main' into COMPASS-9476
gribnoysup cf8a623
chore(data-modeling): fix tests
gribnoysup a2967fd
chore(data-modeling): stricter check for diagram item selection
gribnoysup fad816b
fix(data-modeling): do not use memoize for relationship filter
gribnoysup 7bc8a93
chore(data-modeling): add more tests
gribnoysup 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
88 changes: 88 additions & 0 deletions
88
packages/compass-data-modeling/src/components/collection-drawer-content.tsx
This file contains hidden or 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,88 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import type { Relationship } from '../services/data-model-storage'; | ||
import { Button, H3 } from '@mongodb-js/compass-components'; | ||
import { | ||
createNewRelationship, | ||
deleteRelationship, | ||
getCurrentDiagramFromState, | ||
selectCurrentModel, | ||
selectRelationship, | ||
} from '../store/diagram'; | ||
import type { DataModelingState } from '../store/reducer'; | ||
|
||
type CollectionDrawerContentProps = { | ||
namespace: string; | ||
relationships: Relationship[]; | ||
shouldShowRelationshipEditingForm?: boolean; | ||
onCreateNewRelationshipClick: (namespace: string) => void; | ||
onEditRelationshipClick: (rId: string) => void; | ||
onDeleteRelationshipClick: (rId: string) => void; | ||
}; | ||
|
||
const CollectionDrawerContent: React.FunctionComponent< | ||
CollectionDrawerContentProps | ||
> = ({ | ||
namespace, | ||
relationships, | ||
onCreateNewRelationshipClick, | ||
onEditRelationshipClick, | ||
onDeleteRelationshipClick, | ||
}) => { | ||
return ( | ||
<> | ||
<H3>{namespace}</H3> | ||
<ul> | ||
{relationships.map((r) => { | ||
return ( | ||
<li key={r.id} data-relationship-id={r.id}> | ||
{r.relationship[0].fields?.join('.')} -> | ||
{r.relationship[1].fields?.join('.')} | ||
<Button | ||
onClick={() => { | ||
onEditRelationshipClick(r.id); | ||
}} | ||
> | ||
Edit | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
onDeleteRelationshipClick(r.id); | ||
}} | ||
> | ||
Delete | ||
</Button> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
<Button | ||
onClick={() => { | ||
onCreateNewRelationshipClick(namespace); | ||
}} | ||
> | ||
Add relationship manually | ||
</Button> | ||
</> | ||
); | ||
}; | ||
|
||
export default connect( | ||
(state: DataModelingState, ownProps: { namespace: string }) => { | ||
return { | ||
relationships: selectCurrentModel( | ||
getCurrentDiagramFromState(state).edits | ||
).relationships.filter((r) => { | ||
const [local, foreign] = r.relationship; | ||
return ( | ||
local.ns === ownProps.namespace || foreign.ns === ownProps.namespace | ||
); | ||
}), | ||
}; | ||
}, | ||
{ | ||
onCreateNewRelationshipClick: createNewRelationship, | ||
onEditRelationshipClick: selectRelationship, | ||
onDeleteRelationshipClick: deleteRelationship, | ||
} | ||
)(CollectionDrawerContent); |
This file contains hidden or 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
155 changes: 155 additions & 0 deletions
155
packages/compass-data-modeling/src/components/diagram-editor-side-panel.spec.tsx
This file contains hidden or 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,155 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { | ||
createPluginTestHelpers, | ||
screen, | ||
waitFor, | ||
userEvent, | ||
within, | ||
} from '@mongodb-js/testing-library-compass'; | ||
import { DataModelingWorkspaceTab } from '../index'; | ||
import DiagramEditorSidePanel from './diagram-editor-side-panel'; | ||
import { | ||
getCurrentDiagramFromState, | ||
openDiagram, | ||
selectCollection, | ||
selectCurrentModel, | ||
selectRelationship, | ||
} from '../store/diagram'; | ||
import dataModel from '../../test/fixtures/data-model-with-relationships.json'; | ||
import type { MongoDBDataModelDescription } from '../services/data-model-storage'; | ||
|
||
async function comboboxSelectItem( | ||
label: string, | ||
value: string, | ||
visibleLabel = value | ||
) { | ||
userEvent.click(screen.getByRole('textbox', { name: label })); | ||
await waitFor(() => { | ||
screen.getByRole('option', { name: visibleLabel }); | ||
}); | ||
userEvent.click(screen.getByRole('option', { name: visibleLabel })); | ||
await waitFor(() => { | ||
expect(screen.getByRole('textbox', { name: label })).to.have.attribute( | ||
'value', | ||
value | ||
); | ||
}); | ||
} | ||
|
||
describe('DiagramEditorSidePanel', function () { | ||
function renderDrawer() { | ||
const { renderWithConnections } = createPluginTestHelpers( | ||
DataModelingWorkspaceTab.provider.withMockServices({}) | ||
); | ||
const result = renderWithConnections( | ||
<DiagramEditorSidePanel></DiagramEditorSidePanel> | ||
); | ||
result.plugin.store.dispatch( | ||
openDiagram(dataModel as MongoDBDataModelDescription) | ||
); | ||
return result; | ||
} | ||
|
||
it('should not render if no items are selected', function () { | ||
renderDrawer(); | ||
expect(screen.queryByTestId('data-modeling-drawer')).to.eq(null); | ||
}); | ||
|
||
it('should render a collection context drawer when collection is clicked', function () { | ||
const result = renderDrawer(); | ||
result.plugin.store.dispatch(selectCollection('flights.airlines')); | ||
expect(screen.getByText('flights.airlines')).to.be.visible; | ||
}); | ||
|
||
it('should render a relationship context drawer when relations is clicked', function () { | ||
const result = renderDrawer(); | ||
result.plugin.store.dispatch( | ||
selectRelationship('204b1fc0-601f-4d62-bba3-38fade71e049') | ||
); | ||
expect(screen.getByText('Edit Relationship')).to.be.visible; | ||
expect( | ||
document.querySelector( | ||
'[data-relationship-id="204b1fc0-601f-4d62-bba3-38fade71e049"]' | ||
) | ||
).to.be.visible; | ||
}); | ||
|
||
it('should change the content of the drawer when selecting different items', function () { | ||
const result = renderDrawer(); | ||
|
||
result.plugin.store.dispatch(selectCollection('flights.airlines')); | ||
expect(screen.getByText('flights.airlines')).to.be.visible; | ||
|
||
result.plugin.store.dispatch( | ||
selectCollection('flights.airports_coordinates_for_schema') | ||
); | ||
expect(screen.getByText('flights.airports_coordinates_for_schema')).to.be | ||
.visible; | ||
|
||
result.plugin.store.dispatch( | ||
selectRelationship('204b1fc0-601f-4d62-bba3-38fade71e049') | ||
); | ||
expect( | ||
document.querySelector( | ||
'[data-relationship-id="204b1fc0-601f-4d62-bba3-38fade71e049"]' | ||
) | ||
).to.be.visible; | ||
|
||
result.plugin.store.dispatch( | ||
selectRelationship('6f776467-4c98-476b-9b71-1f8a724e6c2c') | ||
); | ||
expect( | ||
document.querySelector( | ||
'[data-relationship-id="6f776467-4c98-476b-9b71-1f8a724e6c2c"]' | ||
) | ||
).to.be.visible; | ||
|
||
result.plugin.store.dispatch(selectCollection('flights.planes')); | ||
expect(screen.getByText('flights.planes')).to.be.visible; | ||
}); | ||
|
||
it('should open and edit relationship starting from collection', async function () { | ||
const result = renderDrawer(); | ||
result.plugin.store.dispatch(selectCollection('flights.countries')); | ||
|
||
// Open relationshipt editing form | ||
const relationshipCard = document.querySelector<HTMLElement>( | ||
'[data-relationship-id="204b1fc0-601f-4d62-bba3-38fade71e049"]' | ||
); | ||
userEvent.click( | ||
within(relationshipCard!).getByRole('button', { name: 'Edit' }) | ||
); | ||
expect(screen.getByText('Edit Relationship')).to.be.visible; | ||
|
||
// Select new values | ||
await comboboxSelectItem('Local collection', 'planes'); | ||
await comboboxSelectItem('Local field', 'name'); | ||
await comboboxSelectItem('Foreign collection', 'countries'); | ||
await comboboxSelectItem('Foreign field', 'iso_code'); | ||
|
||
// We should be testing through rendered UI but as it's really hard to make | ||
// diagram rendering in tests property, we are just validating the final | ||
// model here | ||
const modifiedRelationship = selectCurrentModel( | ||
getCurrentDiagramFromState(result.plugin.store.getState()).edits | ||
).relationships.find((r) => { | ||
return r.id === '204b1fc0-601f-4d62-bba3-38fade71e049'; | ||
}); | ||
|
||
expect(modifiedRelationship) | ||
.to.have.property('relationship') | ||
.deep.eq([ | ||
{ | ||
ns: 'flights.planes', | ||
fields: ['name'], | ||
cardinality: 1, | ||
}, | ||
{ | ||
ns: 'flights.countries', | ||
fields: ['iso_code'], | ||
cardinality: 1, | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains hidden or 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.
no assertions here?
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.
Totally forgot, added something!