Skip to content
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

[1988] Add support for optional help text on widgets #2011

Merged
merged 2 commits into from Jun 19, 2023

Conversation

pcdavid
Copy link
Member

@pcdavid pcdavid commented May 31, 2023

Pull request template

General purpose

What is the main goal of this pull request?

  • Bug fixes
  • New features
  • Documentation
  • Cleanup
  • Tests
  • Build / releng

Project management

  • Has the pull request been added to the relevant project and milestone? (Only if you know that your work is part of a specific iteration such as the current one)
  • Have the priority: and pr: labels been added to the pull request? (In case of doubt, start with the labels priority: low and pr: to review later)
  • Have the relevant issues been added to the pull request?
  • Have the relevant labels been added to the issues? (area:, difficulty:, type:)
  • Have the relevant issues been added to the same project and milestone as the pull request?
  • Has the CHANGELOG.adoc been updated to reference the relevant issues?
  • Have the relevant API breaks been described in the CHANGELOG.adoc? (Including changes in the GraphQL API)
  • In case of a change with a visual impact, are there any screenshots in the CHANGELOG.adoc? For example in doc/screenshots/2022.5.0-my-new-feature.png

Architectural decision records (ADR)

  • Does the title of the commit contributing the ADR start with [doc]?
  • Are the ADRs mentioned in the relevant section of the CHANGELOG.adoc?

Dependencies

  • Are the new / upgraded dependencies mentioned in the relevant section of the CHANGELOG.adoc?
  • Are the new dependencies justified in the CHANGELOG.adoc?

Frontend

This section is not relevant if your contribution does not come with changes to the frontend.

General purpose

  • Is the code properly tested? (Plain old JavaScript tests for business code and tests based on React Testing Library for the components)

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).

  • Variables have a proper type
  • Functions’ arguments have a proper type
  • Functions’ return type are specified
  • Hooks are properly typed:
    • useMutation<DATA_TYPE, VARIABLE_TYPE>(…)
    • useQuery<DATA_TYPE, VARIABLE_TYPE>(…)
    • useSubscription<DATA_TYPE, VARIABLE_TYPE>(…)
    • useMachine<CONTEXT_TYPE, EVENTS_TYPE>(…)
    • useState<STATE_TYPE>(…)
  • All components have a proper typing for their props
  • No useless optional chaining with ?. (if the GraphQL API specifies that a field cannot be null, do not treat it has potentially null for example)
  • Nullable values have a proper type (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

  • Are all the event handlers tested?
  • Are the event processor tested?
  • Is the business code (services) tested?
  • Are diagram layout changes tested?

Architecture

  • Are data structure classes properly separated from behavioral classes?
  • Are all the relevant fields final?
  • Is any data structure mutable? If so, please write a comment indicating why
  • Are behavioral classes either stateless or side effect free?

Review

How to test this PR?

Please describe here the various use cases to test this pull request

  • Has the Kiwi TCMS test suite been updated with tests for this contribution?

@pcdavid pcdavid changed the title Add support for optional help text on widgets [1988] Add support for optional help text on widgets May 31, 2023
@pcdavid pcdavid added this to the 2023.8.0 milestone May 31, 2023
@pcdavid pcdavid linked an issue May 31, 2023 that may be closed by this pull request
11 tasks
@pcdavid pcdavid force-pushed the pcd/enh/widget-help branch 3 times, most recently from 351349f to 12128fb Compare June 5, 2023 08:00
@pcdavid pcdavid marked this pull request as ready for review June 5, 2023 08:01
@pcdavid pcdavid force-pushed the pcd/enh/widget-help branch 9 times, most recently from 281a777 to cb34647 Compare June 7, 2023 06:53
@frouene
Copy link
Contributor

frouene commented Jun 9, 2023

The helpExpression doesn't work for slider, I think the helpTextProvider is missing from the builder of Slider.java.

@frouene
Copy link
Contributor

frouene commented Jun 9, 2023

The helpExpression is not display for toolbarAction widget, but it seems to be the same behavior as for the label.

Copy link
Member

@sbegaudeau sbegaudeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested it but what is that git all file exactly?

git all Outdated Show resolved Hide resolved
@@ -96,6 +96,8 @@ public static final class Builder {

private List<Diagnostic> diagnostics;

private Supplier<String> helpTextProvider;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this is what you were talking about with the modification of dozens of files with widgets, components, descriptions to set that up. In the diagram representation, we went the other way by removing the description as the sole mean to carry information for a service and instead try to use its content only for the rendering.

You could have introduced something like that to ask for the help text and use it in the handler:

public interface IWidgetHelpTextProvider {
    String getHelpText(...)
}

When the frontend would ask for the help text, you would just ask this service which could then leverage the view model to find the relevant information. Here, the converters needs to setup everything first. Which is why you have to make the help text provider optional because it needs to carry two pieces of informations at once:

  • is there some help text? (for the rendering)
  • what is the value of the help text?

You could have simply used a boolean to carry the information relevant for the rendering.

We could also introduce a common AbstractWidgetBuilder which would be inherited by all the Builders of the widgets. It could encapsulate things like the id, presence of help text, diagnostics, label. I don't see any issues with having some simple inheritance for builders like that since builders are 99% data structure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have simply used a boolean to carry the information relevant for the rendering.

Yes, but I would still have needed about the same amount of changes to carry the boolean (instead of the Supplier<String>), wouldn't I?

I don't see any issues with having some simple inheritance for builders like that since builders are 99% data structure.

AFAICT, it's forbidden by the rules you setup: immutableClassesShouldHaveANestedBuilder, and HaveAValidBuilderCondition requires the builder class to be final.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the frontend would ask for the help text, you would just ask this service which could then leverage the view model

What about widgets created programatically which do not come from a View model?

@pcdavid
Copy link
Member Author

pcdavid commented Jun 9, 2023

The helpExpression doesn't work for slider, I think the helpTextProvider is missing from the builder of Slider.java.

There was a little more missing, but done.

@sbegaudeau sbegaudeau dismissed their stale review June 9, 2023 14:42

The Git all file has been removed :)

@pcdavid pcdavid force-pushed the pcd/enh/widget-help branch 2 times, most recently from 42bf953 to e21eda7 Compare June 12, 2023 09:45
@pcdavid
Copy link
Member Author

pcdavid commented Jun 12, 2023

The helpExpression is not display for toolbarAction widget, but it seems to be the same behavior as for the label.

I've added help support for toolbarActions. The tooltip is associated to the button itself instead of a separate "?" icon (there is not really any room for such an icon in this case).

pcdavid and others added 2 commits June 19, 2023 16:04
Bug: #1988
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
editingContextId: string;
formId: string;
widgetId: string;
children?: any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React.ReactElement would work here

Comment on lines 37 to 38
const [open, setOpen] = useState(false);
const [content, setContent] = useState<JSX.Element>(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consolidate both state into one.

Comment on lines 56 to 68
{lines.map((line) => (
<>
{line}
<br />
</>
))}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use React.Fragment to have access to the key props to remove the warning

Comment on lines 86 to 100
<Tooltip
open={open && content !== null}
onClose={handleClose}
onOpen={handleOpen}
title={content || ''}
arrow
placement={'top'}>
{props.children || <HelpOutlineOutlined color="secondary" style={{ marginLeft: 8, fontSize: 16 }} />}
</Tooltip>
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure why but moving the cursor a tiny bit can trigger a lot of HTTP request to reload the tooltip. I wonder if there is some options in MUI which would prevent so many open/close events

@sbegaudeau sbegaudeau merged commit 34a9725 into master Jun 19, 2023
4 checks passed
@pcdavid pcdavid deleted the pcd/enh/widget-help branch June 30, 2023 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for optional help text on widgets
3 participants