-
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 all 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { ButtonHTMLAttributes } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { spacing, transitionDuration } from '@leafygreen-ui/tokens'; | ||
import { palette } from '@leafygreen-ui/palette'; | ||
|
||
const StyledDiagramIconButton = 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; | ||
} | ||
} | ||
`; | ||
|
||
// Use a custom button component instead of LeafyGreen's IconButton | ||
// to allow us to have a smaller focus ring and icon size without overwriting internal styles. | ||
export const DiagramIconButton = ({ | ||
children, | ||
...props | ||
}: ButtonHTMLAttributes<HTMLButtonElement> & { | ||
children?: React.ReactNode; | ||
}) => { | ||
return <StyledDiagramIconButton {...props}>{children}</StyledDiagramIconButton>; | ||
}; |
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,61 @@ | ||
import { useMemo } from 'react'; | ||
import styled from '@emotion/styled'; | ||
|
||
import { useEditableDiagramInteractions } from '@/hooks/use-editable-diagram-interactions'; | ||
import { PlusWithSquare } from '@/components/icons/plus-with-square'; | ||
import { DiagramIconButton } from '@/components/buttons/diagram-icon-button'; | ||
|
||
const ObjectTypeContainer = styled.div` | ||
display: flex; | ||
justify-content: flex-end; | ||
align-items: center; | ||
line-height: 20px; | ||
`; | ||
|
||
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') { | ||
return ( | ||
<ObjectTypeContainer> | ||
{'{}'} | ||
{onClickAddFieldToObject && ( | ||
<DiagramIconButton | ||
data-testid={`object-field-type-${nodeId}-${typeof id === 'string' ? id : id.join('.')}`} | ||
onClick={onClickAddFieldToObject} | ||
aria-label="Add new field" | ||
title="Add Field" | ||
> | ||
<PlusWithSquare /> | ||
</DiagramIconButton> | ||
)} | ||
</ObjectTypeContainer> | ||
); | ||
} | ||
|
||
if (type === 'array') { | ||
return '[]'; | ||
} | ||
|
||
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
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.
This shouldn't depend on the callback existence