-
Notifications
You must be signed in to change notification settings - Fork 229
feat(data-modeling): add add field button to object in diagram COMPASS-9742 #7300
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
Open
Anemy
wants to merge
4
commits into
main
Choose a base branch
from
COMPASS-9742-add-add-field-to-nested-object
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+650
−39
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
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
123 changes: 123 additions & 0 deletions
123
packages/compass-data-modeling/src/components/diagram/object-field-type.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,123 @@ | ||
import React, { useCallback } from 'react'; | ||
import { | ||
css, | ||
cx, | ||
focusRing, | ||
palette, | ||
spacing, | ||
transitionDuration, | ||
transparentize, | ||
useDarkMode, | ||
} from '@mongodb-js/compass-components'; | ||
|
||
import PlusWithSquare from '../icons/plus-with-square'; | ||
|
||
const objectTypeContainerStyles = css({ | ||
display: 'flex', | ||
justifyContent: 'flex-end', | ||
alignItems: 'center', | ||
}); | ||
|
||
const iconButtonHoverStyles = css({ | ||
Anemy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
color: palette.gray.dark1, | ||
|
||
'&::before': { | ||
content: '""', | ||
transition: `${transitionDuration.default}ms all ease-in-out`, | ||
position: 'absolute', | ||
top: 0, | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
borderRadius: '100%', | ||
transform: 'scale(0.8)', | ||
}, | ||
|
||
[`&:active:before, | ||
&:hover:before, | ||
&:focus:before, | ||
&[data-hover='true']:before, | ||
&[data-focus='true']:before`]: { | ||
transform: 'scale(1)', | ||
}, | ||
|
||
[`&:active, | ||
&:hover, | ||
&[data-hover='true'], | ||
&:focus-visible, | ||
&[data-focus='true']`]: { | ||
color: palette.black, | ||
|
||
'&::before': { | ||
backgroundColor: transparentize(0.9, palette.gray.dark2), | ||
}, | ||
}, | ||
}); | ||
|
||
const iconButtonHoverDarkModeStyles = css({ | ||
color: palette.gray.light1, | ||
|
||
[`&:active, | ||
&:hover, | ||
&[data-hover='true'], | ||
&:focus-visible, | ||
&[data-focus='true']`]: { | ||
color: palette.gray.light3, | ||
|
||
'&::before': { | ||
backgroundColor: transparentize(0.9, palette.gray.light2), | ||
}, | ||
}, | ||
}); | ||
|
||
const addNestedFieldStyles = css(iconButtonHoverStyles, focusRing, { | ||
background: 'none', | ||
border: 'none', | ||
padding: spacing[100], | ||
margin: 0, | ||
marginLeft: spacing[100], | ||
cursor: 'pointer', | ||
color: 'inherit', | ||
display: 'flex', | ||
}); | ||
|
||
type ObjectFieldTypeProps = { | ||
onClickAddNestedField: (event: React.MouseEvent<HTMLButtonElement>) => void; | ||
['data-testid']: string; | ||
}; | ||
|
||
const ObjectFieldType: React.FunctionComponent<ObjectFieldTypeProps> = ({ | ||
'data-testid': dataTestId, | ||
onClickAddNestedField: _onClickAddNestedField, | ||
}) => { | ||
const darkMode = useDarkMode(); | ||
|
||
const onClickAddNestedField = useCallback( | ||
(event: React.MouseEvent<HTMLButtonElement>) => { | ||
// Don't click on the field element. | ||
event.stopPropagation(); | ||
_onClickAddNestedField(event); | ||
}, | ||
[_onClickAddNestedField] | ||
); | ||
|
||
return ( | ||
<div className={objectTypeContainerStyles}> | ||
{'{}'} | ||
<button | ||
className={cx( | ||
addNestedFieldStyles, | ||
darkMode && iconButtonHoverDarkModeStyles | ||
)} | ||
data-testid={dataTestId} | ||
onClick={onClickAddNestedField} | ||
aria-label="Add new field" | ||
title="Add Field" | ||
> | ||
<PlusWithSquare /> | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export { ObjectFieldType }; |
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
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
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.
I was testing that the next field name logic is working fine and managed to get into some weird state where if I rename the field and then without unfocusing first I click on the "add new field" button, the new field is created with the name "interact" in the diagram, but the drawer shows the correct one, I can't figure out where the "interact" part is even coming from
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.
Ohhh, I was rewatching the gif and it seems to replace the next field in the document that is a sibling of an object this is being added for
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.
ooo nice catch