-
Notifications
You must be signed in to change notification settings - Fork 1
refactor/COMPASS-9877 add editable node handlers and interactions #135
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
Anemy
merged 12 commits into
main
from
refactor/COMPASS-9877-add-editable-node-handlers-and-interactions
Sep 25, 2025
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f5f1409
feat/COMPASS-9792: Add renderName for custom field name rendering
Anemy 3950576
Merge branch 'main' into refactor/add-editable-node-interactions
Anemy 4e068ac
refactor: add editable node interactions, remove generic node actions
Anemy 4e6d3c8
refactor: add handler and button to add fields to objects
Anemy 725d591
fixup: update comment and index
Anemy e7c64bf
merge main
Anemy 16fa8a8
fixup: review comments, cleanup, add tests
Anemy d8595a8
fixup: remove object field type file, use field type content for it
Anemy be02b21
fixup: add array type
Anemy 2e2404d
fixup: remove icon-button from LG, use ours and share
Anemy c423dd5
fixup: move object render change if
Anemy 103c79c
Merge branch 'main' into refactor/COMPASS-9877-add-editable-node-hand…
Anemy 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { useMemo } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { spacing, transitionDuration } from '@leafygreen-ui/tokens'; | ||
import { palette } from '@leafygreen-ui/palette'; | ||
|
||
import { useEditableDiagramInteractions } from '@/hooks/use-editable-diagram-interactions'; | ||
import { PlusWithSquare } from '@/components/icons/plus-with-square'; | ||
|
||
const ObjectTypeContainer = styled.div` | ||
display: flex; | ||
justify-content: flex-end; | ||
align-items: center; | ||
line-height: 20px; | ||
`; | ||
|
||
const AddNestedFieldIconButton = styled.button` | ||
background: none; | ||
border: none; | ||
outline: none; | ||
padding: ${spacing[100]}px; | ||
margin: 0; | ||
margin-left: ${spacing[100]}px; | ||
cursor: pointer; | ||
color: inherit; | ||
display: flex; | ||
position: relative; | ||
color: ${props => props.theme.node.fieldIconButton}; | ||
|
||
&::before { | ||
content: ''; | ||
transition: ${transitionDuration.default}ms all ease-in-out; | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
border-radius: 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 { | ||
background-color: ${props => props.theme.node.fieldIconButtonHoverBackground}; | ||
} | ||
} | ||
|
||
// Focus ring styles. | ||
&::after { | ||
position: absolute; | ||
content: ''; | ||
pointer-events: none; | ||
top: 3px; | ||
right: 3px; | ||
bottom: 3px; | ||
left: 3px; | ||
border-radius: ${spacing[100]}px; | ||
box-shadow: 0 0 0 0 transparent; | ||
transition: box-shadow 0.16s ease-in; | ||
z-index: 1; | ||
} | ||
&:focus-visible { | ||
&::after { | ||
box-shadow: 0 0 0 3px ${palette.blue.light1} !important; | ||
transition-timing-function: ease-out; | ||
} | ||
} | ||
`; | ||
|
||
export const FieldTypeContent = ({ | ||
type, | ||
nodeId, | ||
id, | ||
}: { | ||
id: string | string[]; | ||
nodeId: string; | ||
type: React.ReactNode; | ||
}) => { | ||
const { onClickAddFieldToObjectField: _onClickAddFieldToObjectField } = useEditableDiagramInteractions(); | ||
|
||
const onClickAddFieldToObject = useMemo( | ||
() => | ||
_onClickAddFieldToObjectField | ||
? (event: React.MouseEvent<HTMLButtonElement>) => { | ||
// Don't click on the field element. | ||
event.stopPropagation(); | ||
_onClickAddFieldToObjectField(event, nodeId, Array.isArray(id) ? id : [id]); | ||
} | ||
: undefined, | ||
[_onClickAddFieldToObjectField, nodeId, id], | ||
); | ||
|
||
if (type === 'object' && !!onClickAddFieldToObject) { | ||
return ( | ||
<ObjectTypeContainer> | ||
{'{}'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't depend on the callback existence |
||
<AddNestedFieldIconButton | ||
data-testid={`object-field-type-${nodeId}-${typeof id === 'string' ? id : id.join('.')}`} | ||
onClick={onClickAddFieldToObject} | ||
aria-label="Add new field" | ||
title="Add Field" | ||
> | ||
<PlusWithSquare /> | ||
</AddNestedFieldIconButton> | ||
</ObjectTypeContainer> | ||
); | ||
} | ||
|
||
return <>{type}</>; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useTheme } from '@emotion/react'; | ||
|
||
export const PlusWithSquare: React.FunctionComponent = () => { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path | ||
d="M12 0.75H2C1.66848 0.75 1.35054 0.881696 1.11612 1.11612C0.881696 1.35054 0.75 1.66848 0.75 2V12C0.75 12.3315 0.881696 12.6495 1.11612 12.8839C1.35054 13.1183 1.66848 13.25 2 13.25H12C12.3315 13.25 12.6495 13.1183 12.8839 12.8839C13.1183 12.6495 13.25 12.3315 13.25 12V2C13.25 1.66848 13.1183 1.35054 12.8839 1.11612C12.6495 0.881696 12.3315 0.75 12 0.75ZM11.75 11.75H2.25V2.25H11.75V11.75ZM3.75 7C3.75 6.80109 3.82902 6.61032 3.96967 6.46967C4.11032 6.32902 4.30109 6.25 4.5 6.25H6.25V4.5C6.25 4.30109 6.32902 4.11032 6.46967 3.96967C6.61032 3.82902 6.80109 3.75 7 3.75C7.19891 3.75 7.38968 3.82902 7.53033 3.96967C7.67098 4.11032 7.75 4.30109 7.75 4.5V6.25H9.5C9.69891 6.25 9.88968 6.32902 10.0303 6.46967C10.171 6.61032 10.25 6.80109 10.25 7C10.25 7.19891 10.171 7.38968 10.0303 7.53033C9.88968 7.67098 9.69891 7.75 9.5 7.75H7.75V9.5C7.75 9.69891 7.67098 9.88968 7.53033 10.0303C7.38968 10.171 7.19891 10.25 7 10.25C6.80109 10.25 6.61032 10.171 6.46967 10.0303C6.32902 9.88968 6.25 9.69891 6.25 9.5V7.75H4.5C4.30109 7.75 4.11032 7.67098 3.96967 7.53033C3.82902 7.38968 3.75 7.19891 3.75 7Z" | ||
fill={theme.node.headerIcon} | ||
/> | ||
</svg> | ||
); | ||
}; |
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.
Uh oh!
There was an error while loading. Please reload this page.