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
[2589] Improve the label component API to facilitate its customization #2590
base: master
Are you sure you want to change the base?
Conversation
29d1f42
to
23a83d6
Compare
23a83d6
to
1d1348b
Compare
Bug: #2589 Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
1d1348b
to
98726c8
Compare
<Label diagramElementId={id} label={data.label}> | ||
<div style={labelStyle(data.faded, !!data.label.iconURL)}> | ||
<LabelIcon /> | ||
<LabelText /> | ||
</div> | ||
</Label> |
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.
Why are you changing the behavior of the label here. We were using the exact same Label
component as in other nodes like ImageNode
, no need to change that as part of this PR.
minWidth: ({ iconWidth }) => `${iconWidth}px`, | ||
minHeight: ({ iconHeight }) => `${iconHeight}px`, |
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 has nothing to do with this PR
@@ -82,6 +82,7 @@ export interface Label { | |||
text: string; | |||
iconURL: string[]; | |||
style: React.CSSProperties; | |||
borderStyle?: React.CSSProperties; |
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.
The properties of the border can be defined in style
why do you need a new property for that?
)} | ||
{label && ( | ||
<Label diagramElementId={id} transform={`translate(${labelX}px,${labelY}px)`} label={label} faded={false} /> | ||
<div style={{ transform: `translate(${labelX}px,${labelY}px)` }}> | ||
<DiagramLabel diagramElementId={id} label={label} faded={false} /> |
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 label should probably be faded when it's relevant just like the other labels
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: borderStyle?.justifyContent ?? 'flex-start', |
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.
If someone needs the label at the start of some div, they can just move the whole DiagramLabel
component. This option is not necessary.
export const DiagramLabel = ({ diagramElementId, label, faded }: DiagramLabelProps) => { | ||
return ( | ||
<Label diagramElementId={diagramElementId} label={label}> | ||
<div style={labelStyle(faded, !!label.iconURL, label.borderStyle)}> |
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 don't think we need to consider the style of the label object, that's not relevant in the props of our component. If someone needs a border, they can add it the div containing DiagramLabel
. Because tomorrow, someone else will come and ask for the customization of the CSS of the borderTop
, or borderLeft
or anything else. Just like transform
was an issue related specifically to MultiLabelEdge
, we have no need for a border or flex-start
here.
}; | ||
|
||
if (label.id === currentlyEditedLabelId) { | ||
return <DiagramDirectEditInput editingKey={editingKey} onClose={handleClose} labelId={label.id} transform={''} />; |
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.
Is that transform
still needed?
import React from 'react'; | ||
import { Label } from '../DiagramRenderer.types'; | ||
|
||
export const LabelContext = React.createContext<Label | undefined>(undefined); |
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.
Just put an empty Label here and remove the undefined
it will simplify tons of code below that should never be used if the label is not there. In case you need to explicitly handle the lack of value, prefer null
next time to help distinguish values which do not exist.
Pull request template
General purpose
What is the main goal of this pull request?
Project management
priority:
andpr:
labels been added to the pull request? (In case of doubt, start with the labelspriority: low
andpr: to review later
)area:
,difficulty:
,type:
)CHANGELOG.adoc
been updated to reference the relevant issues?CHANGELOG.adoc
? (Including changes in the GraphQL API)CHANGELOG.adoc
? For example indoc/screenshots/2022.5.0-my-new-feature.png
Architectural decision records (ADR)
[doc]
?CHANGELOG.adoc
?Dependencies
CHANGELOG.adoc
?CHANGELOG.adoc
?Frontend
This section is not relevant if your contribution does not come with changes to the frontend.
General purpose
Typing
We need to improve the typing of our code, as such, we require every contribution to come with proper TypeScript typing for both changes contributing new files and those modifying existing files.
Please ensure that the following statements are true for each file created or modified (this may require you to improve code outside of your contribution).
useMutation<DATA_TYPE, VARIABLE_TYPE>(…)
useQuery<DATA_TYPE, VARIABLE_TYPE>(…)
useSubscription<DATA_TYPE, VARIABLE_TYPE>(…)
useMachine<CONTEXT_TYPE, EVENTS_TYPE>(…)
useState<STATE_TYPE>(…)
?.
(if the GraphQL API specifies that a field cannot benull
, do not treat it has potentiallynull
for example)let diagram: Diagram | null = null;
)Backend
This section is not relevant if your contribution does not come with changes to the backend.
General purpose
Architecture
Review
How to test this PR?
Please describe here the various use cases to test this pull request