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

"view as" banner: add a tooltip so that users understand better what the screen does #1418

Merged
merged 5 commits into from
Feb 10, 2025

Conversation

manuhabitela
Copy link
Collaborator

@manuhabitela manuhabitela commented Feb 3, 2025

Context

Fixes #1328.

Proposed solution

  • I'm not that familiar with grain-js and how translation strings are handled in the project still so I hope I coded this the good way!
  • I allowed myself to add translation strings for this component as they were missing.

Has this been tested?

Added a very small test, just making sure the new tooltip icon is there. Should I be more specific?

  • 👍 yes, I added tests to the test suite
  • 💭 no, because this PR is a draft and still needs work
  • 🙅 no, because this is not relevant here
  • 🙋 no, because I need help

Screenshots / Screencasts

viewasbannertooltip

@manuhabitela manuhabitela changed the title Issue 1328 view as info "view as" banner: add a tooltip so that users understand better what the screen does Feb 3, 2025
@@ -18,6 +18,7 @@ import {waitGrainObs} from 'app/common/gutil';
import noop from 'lodash/noop';

const t = makeT("ViewAsDropdown");
const userT = makeT('UserManagerModel');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I allowed myself to use translation strings that are "out" of the components (here in ACLUser and below in ViewAsBanner), as they fit the use-case. Is it okay?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I added a preview tag to the PR to have a way to easily check the result of this userT() when app is in french.

Copy link
Collaborator Author

@manuhabitela manuhabitela Feb 4, 2025

Choose a reason for hiding this comment

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

It looks like this below.

The "Owner", "Editor 1", "Editor 2" fake user names are hardcoded strings that are not in the translation system, I figured it was good enough as is with the now translated actual roles.

image

"UnknownUser": "Utilisateur inconnu"
"UnknownUser": "Utilisateur inconnu",
"View as Yourself": "Voir en tant que vous-même",
"You are viewing this document as": "Vous voyez ce document en tant que"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I directly updated the fr locale file instead of going through weblate. Is that okay?

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO it is good as it does the same than the weblate result.
If I'm wrong please correct me dear gristlabs fellows.

@hexaltation hexaltation added the preview Launch preview deployment of this PR label Feb 3, 2025
Copy link
Contributor

github-actions bot commented Feb 3, 2025

Deployed commit a03d366c29923f22d7b1df90df3466f862a2f8b4 as https://grist-manuhabitela-grist-core-issue-1328-view-as-info.fly.dev (until 2025-03-05T19:21:14.371Z)

Copy link
Collaborator

@hexaltation hexaltation left a comment

Choose a reason for hiding this comment

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

Hello
and thank you for the job.

A little ask for a change :

  • When over the tooltip, as it do not really change it's not very clear that it's a clickable element. (seems to imperceptibly change from really dark gray to black)

Elsewhere LGTM

@manuhabitela
Copy link
Collaborator Author

When over the tooltip, as it do not really change it's not very clear that it's a clickable element. (seems to imperceptibly change from really dark gray to black)

Yeah I originally put a lighter gray color but ended up just following the mockup. What do you think Lucie? I can change to do something like this:

hover.mp4

@manuhabitela
Copy link
Collaborator Author

Stumbled upon a tiny color bug in dark theme on the eye icon on the left, allowed myself to add the small fix in this PR 👀

@hexaltation
Copy link
Collaborator

Yeah I originally put a lighter gray color but ended up just following the mockup. What do you think @lusebille ? I can change to do something like this:
hover.mp4

I had lucie's pseudo so she will have a notification

Copy link
Contributor

github-actions bot commented Feb 4, 2025

Deployed commit e56acd54894c0101c23e6b9331c84c97175740a5 as https://grist-manuhabitela-grist-core-issue-1328-view-as-info.fly.dev (until 2025-03-06T10:29:17.737Z)

@manuhabitela manuhabitela force-pushed the issue-1328-view-as-info branch from e56acd5 to 32300a7 Compare February 4, 2025 13:49
@manuhabitela
Copy link
Collaborator Author

After talking with Lucie:

I kept the blackish icon color, to have this interactive icon more pronounced than the non-interactive, gray eye on the left.
And I set the hover color to be green to better tell it's interactive.

Right now the green on yellow is not that great contrast-wise but this will change soon with the wcag-compliance changes planned after the themes rework.

Copy link
Contributor

github-actions bot commented Feb 4, 2025

Deployed commit 32300a78458162d7da210046e00b721a338345cf as https://grist-manuhabitela-grist-core-issue-1328-view-as-info.fly.dev (until 2025-03-06T13:54:14.069Z)

Copy link
Collaborator

@hexaltation hexaltation left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks :)

@manuhabitela manuhabitela self-assigned this Feb 5, 2025
Copy link
Member

@dsagal dsagal left a comment

Choose a reason for hiding this comment

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

Thanks @manuhabitela ! Looks good overall, but I have a couple comments about colors.

app/client/components/ViewAsBanner.ts Outdated Show resolved Hide resolved
@@ -596,6 +612,17 @@ const cssInfoTooltipButton = styled(cssInfoTooltipIcon, `
}
`);

/* styling variant for tooltips displayed in info banners (where background is light yellow) */
export const cssInfoTooltipButtonInBannerInfo = styled(cssInfoTooltipIcon, `
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we actually want the style of the tooltip icon in the banner to be different from that elsewhere. I see that contrast is poor with the current style, but it's as poor in the banner as in the creator panel. It seems best to me to either stick to the same style as currently used elsewhere (and worry about contrast later), or to update that style to have more contrast everywhere now (perhaps the dark + green-on-hover that you have for the banner).

Wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added this because the banner, contrary to most other places like the creator panel, doesn't change colors when in dark mode. Without this specific style, it then looks like this:

tooltip-colors.mp4

And if I applied this new style everywhere, tooltips would now be barely visible in most places in dark theme.

Instead of creating this tooltip variant, I could just update the Banner css, like for the --icon-color stuff above. But I felt it started to be weird having a few tooltip-related styles in a totally different part of the code, instead of being explicit and creating an actual tooltip style variant.

Or maybe I could rename this style variant to be more generic and not namely tied to the banner, like 'always-dark'?

Now it looks like this:

newtooltip.mp4

Maybe I'm missing something and this could be done in another way?

Copy link
Member

Choose a reason for hiding this comment

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

I understand the issue now, thanks for explaining. Yes, there is a simpler way, to avoid passing a new argument through so much of the code. Since there is already an argument to customize style of the tooltip button using iconDomArgs (which I see you using in this revision), you can add style variants like so:

In ViewAsBanner.ts:

import { cssInfoTooltipButton, withInfoTooltip } from 'app/client/ui/tooltips';
withInfoTooltip(
  cssPrimaryButtonLink(...),
  'viewAsBanner',
  {
    iconDomArgs: [
      cssInfoTooltipButton.cls('-in-banner'),  // <-- this is what adds a css class variant to the button
      testId('view-as-help-tooltip'),
    ],
...)

In tooltips.ts:

export const cssInfoTooltipButton = styled(cssInfoTooltipIcon, `
  cursor: pointer;

  &:hover {
    border: 1px solid ${theme.controlSecondaryHoverFg};
    color: ${theme.controlSecondaryHoverFg};
  }
  &-in-banner {
    color: ${colors.dark};
    border-color: ${colors.dark};
  }
  &-in-banner:hover {
    border-color: ${colors.lightGreen};
    color: ${colors.lightGreen};
  }
`);

The &-in-banner blocks define this variant. It's simply another CSS class applied to the tooltip-button element.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, why not :)

Feels like the solution with more code allowed for more isolated code, like you don't have to know about the internals, the specific classes to apply; you just know you can apply a different look. But for sure this solution is more straightforward for this pretty specific case.

@manuhabitela manuhabitela force-pushed the issue-1328-view-as-info branch from 32300a7 to 09340b6 Compare February 7, 2025 10:55
@manuhabitela
Copy link
Collaborator Author

manuhabitela commented Feb 7, 2025

I added a very small test, just making sure the new help tooltip is there in the DOM.

Figured I wouldn't test the actual tooltip behavior here. Should I make my test more specific? Ie making sure it's clickable, have correct help text…?

Some tests don't pass (Importer), pretty sure they are completely unrelated to this PR code?

Copy link
Contributor

github-actions bot commented Feb 7, 2025

Deployed commit 09340b68df0d15d2d0e8506fcc01832c188c39ee as https://grist-manuhabitela-grist-core-issue-1328-view-as-info.fly.dev (until 2025-03-09T11:00:36.645Z)

@manuhabitela manuhabitela force-pushed the issue-1328-view-as-info branch from 09340b6 to 0748453 Compare February 7, 2025 11:09
Copy link
Contributor

github-actions bot commented Feb 7, 2025

Deployed commit 074845301fd6d66031255cfe9599916f88f2a8b3 as https://grist-manuhabitela-grist-core-issue-1328-view-as-info.fly.dev (until 2025-03-09T11:14:42.494Z)

@@ -122,6 +122,7 @@ const cssBanner = styled('div', `

&-info {
color: black;
Copy link
Member

Choose a reason for hiding this comment

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

I suggest changing this to ${colors.dark} along the way, for consistency.

@@ -596,6 +612,17 @@ const cssInfoTooltipButton = styled(cssInfoTooltipIcon, `
}
`);

/* styling variant for tooltips displayed in info banners (where background is light yellow) */
export const cssInfoTooltipButtonInBannerInfo = styled(cssInfoTooltipIcon, `
Copy link
Member

Choose a reason for hiding this comment

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

I understand the issue now, thanks for explaining. Yes, there is a simpler way, to avoid passing a new argument through so much of the code. Since there is already an argument to customize style of the tooltip button using iconDomArgs (which I see you using in this revision), you can add style variants like so:

In ViewAsBanner.ts:

import { cssInfoTooltipButton, withInfoTooltip } from 'app/client/ui/tooltips';
withInfoTooltip(
  cssPrimaryButtonLink(...),
  'viewAsBanner',
  {
    iconDomArgs: [
      cssInfoTooltipButton.cls('-in-banner'),  // <-- this is what adds a css class variant to the button
      testId('view-as-help-tooltip'),
    ],
...)

In tooltips.ts:

export const cssInfoTooltipButton = styled(cssInfoTooltipIcon, `
  cursor: pointer;

  &:hover {
    border: 1px solid ${theme.controlSecondaryHoverFg};
    color: ${theme.controlSecondaryHoverFg};
  }
  &-in-banner {
    color: ${colors.dark};
    border-color: ${colors.dark};
  }
  &-in-banner:hover {
    border-color: ${colors.lightGreen};
    color: ${colors.lightGreen};
  }
`);

The &-in-banner blocks define this variant. It's simply another CSS class applied to the tooltip-button element.

@@ -109,6 +109,7 @@ describe("AccessRules2", function() {
assert.equal(await driver.findWait('.test-view-as-banner', 2000).isPresent(), true);
assert.match(await driver.find('.test-view-as-banner .test-select-open').getText(),
new RegExp(gu.translateUser('user3').name, 'i'));
assert.equal(await driver.find('.test-info-tooltip.test-view-as-help-tooltip').isPresent(), true);
Copy link
Member

Choose a reason for hiding this comment

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

You can change isPresent to isDisplayed to make this check a tiny bit stricter: isPresent only checks if an element is present in the DOM, while isDisplayed checks that it's visible (e.g. doesn't have display: none style).

@manuhabitela manuhabitela force-pushed the issue-1328-view-as-info branch from 0748453 to ff18f89 Compare February 10, 2025 11:36
@manuhabitela
Copy link
Collaborator Author

Thanks @dsagal, updated with your feedback (will just need a rebase to merge the fixup commit correctly).

Copy link
Contributor

Deployed commit ff18f89ca7b912a72863906e7bcd9ad12f15e842 as https://grist-manuhabitela-grist-core-issue-1328-view-as-info.fly.dev (until 2025-03-12T11:41:19.711Z)

Copy link
Member

@dsagal dsagal left a comment

Choose a reason for hiding this comment

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

Looks good, thank you @manuhabitela !

in the "view as" banner, the role strings (owner, editor, viewer) were
not translated and we can re-use the ones defined in the
UserManagerModel (i guess?).
eye icon was light grey on yellow in dark theme, making it basically
invisible, forcing dark color all the time
@manuhabitela manuhabitela force-pushed the issue-1328-view-as-info branch from ff18f89 to cbd2813 Compare February 10, 2025 16:55
@manuhabitela
Copy link
Collaborator Author

Thanks, I rebased and cleaned the commits 👌

Copy link
Contributor

Deployed commit cbd281348e1f1759ce74da5cc6ffb8a452f46e4d as https://grist-manuhabitela-grist-core-issue-1328-view-as-info.fly.dev (until 2025-03-12T17:00:31.082Z)

@dsagal dsagal merged commit c4b4b53 into gristlabs:main Feb 10, 2025
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gouv.fr preview Launch preview deployment of this PR
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Improve understanding for 'view as 'name of user'' banner
3 participants