-
Notifications
You must be signed in to change notification settings - Fork 292
fix(insights): correct the budget card's figure, badge noise and toast a11y #2799
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
Open
gariasf
wants to merge
3
commits into
main
Choose a base branch
from
fix/insights-card-hierarchy-bugs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+296
−107
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
f75b401
fix(insights): correct the budget card's figure, badge noise and toas…
gariasf 336ee11
feat(insights): acknowledge instead of dismiss, on both surfaces (#2800)
gariasf ea09b46
fix(insights): guard unacknowledge! against non-acknowledged insights
gariasf 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 |
|---|---|---|
| @@ -1,46 +1,62 @@ | ||
| <%# locals: (insight:, unread: false) %> | ||
|
|
||
| <div id="<%= dom_id(insight) %>" class="bg-container rounded-xl shadow-border-xs p-4 flex gap-3"> | ||
| <div class="shrink-0 mt-0.5"> | ||
| <%= icon(insight_icon_key(insight), color: insight_icon_color(insight)) %> | ||
| </div> | ||
| <div id="<%= dom_id(insight) %>" class="bg-container rounded-xl shadow-border-xs"> | ||
| <div class="p-4 flex gap-3"> | ||
| <div class="shrink-0 mt-0.5"> | ||
| <%= icon(insight_icon_key(insight), color: insight_icon_color(insight)) %> | ||
| </div> | ||
|
|
||
| <div class="min-w-0 grow space-y-1"> | ||
| <p class="text-xs text-secondary"><%= insight_meta_line(insight) %></p> | ||
| <div class="min-w-0 grow space-y-1"> | ||
| <p class="text-xs text-secondary"><%= insight_meta_line(insight) %></p> | ||
|
|
||
| <div class="flex items-start justify-between gap-3"> | ||
| <h3 class="text-sm font-medium text-primary inline-flex items-center gap-2 min-w-0"> | ||
| <%= insight.title %> | ||
| <% if unread %> | ||
| <%= render DS::Pill.new(label: t("insights.card.new"), tone: :info, size: :sm) %> | ||
| <% end %> | ||
| </h3> | ||
| <div class="flex items-start justify-between gap-3"> | ||
| <h3 class="text-sm font-medium text-primary inline-flex items-center gap-2 min-w-0"> | ||
| <%= insight.title %> | ||
| <% if unread %> | ||
| <%# A dot, not a labelled chip. Visiting this page marks every insight | ||
| read in one go, so at first paint the badge is on *every* row and | ||
| differentiates nothing — an uppercase tracked chip that heavy just | ||
| steals weight from the title it sits beside. %> | ||
| <%= render DS::Pill.new(label: t("insights.card.new"), tone: :info, dot_only: true) %> | ||
| <% end %> | ||
| </h3> | ||
|
|
||
| <div class="flex items-start gap-1 shrink-0"> | ||
| <%# The figure now owns this corner outright. It used to share it with the | ||
| acknowledge control, so the card's data and its escape hatch competed | ||
| for the same spot. %> | ||
| <% if (figure = insight_key_figure(insight)) %> | ||
| <div class="text-right mr-1"> | ||
| <div class="text-right shrink-0"> | ||
| <p class="text-sm font-mono font-medium privacy-sensitive <%= insight_sentiment(insight) == :positive ? "text-success" : "text-primary" %>"><%= figure.first %></p> | ||
| <p class="text-xs text-subdued"><%= figure.last %></p> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <%= render DS::Button.new( | ||
| variant: "icon", | ||
| icon: "x", | ||
| href: dismiss_insight_path(insight), | ||
| method: :patch, | ||
| title: t("insights.card.dismiss"), | ||
| aria_label: t("insights.card.dismiss") | ||
| ) %> | ||
| </div> | ||
| </div> | ||
|
|
||
| <p class="text-sm text-secondary"><%= insight.body %></p> | ||
| <p class="text-sm text-secondary"><%= insight.body %></p> | ||
| </div> | ||
| </div> | ||
|
|
||
| <%# Both actions in a footer strip, which fixes an inverted action pyramid: the | ||
| escape hatch used to be a chromed icon button in the top-right corner while | ||
| the card's actual purpose ("View budget") was a borderless ghost link | ||
| buried under the body text. The subject action gets the chrome now, and | ||
| acknowledging is labelled text beside it — quieter, and honest about being | ||
| an acknowledgement rather than a deletion. %> | ||
| <div class="px-4 py-2.5 bg-container-inset rounded-b-xl flex items-center justify-between gap-3"> | ||
| <% if (action = insight_action(insight)) %> | ||
| <div class="pt-1"> | ||
| <%= render DS::Link.new(text: action[:text], href: action[:href], variant: "ghost", size: "sm") %> | ||
| </div> | ||
| <%= render DS::Link.new(text: action[:text], href: action[:href], variant: "outline", size: "sm") %> | ||
| <% else %> | ||
| <span></span> | ||
| <% end %> | ||
|
|
||
| <%= render DS::Button.new( | ||
| text: t("insights.card.acknowledge"), | ||
| icon: "check", | ||
| variant: "ghost", | ||
| size: "sm", | ||
| href: acknowledge_insight_path(insight), | ||
| method: :patch, | ||
| title: t("insights.card.acknowledge_title") | ||
| ) %> | ||
| </div> | ||
| </div> |
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 |
|---|---|---|
| @@ -1,19 +1,35 @@ | ||
| <%# locals: (insight:) %> | ||
|
|
||
| <%# The card leaves the page via a Turbo `remove`, which is silent to a screen | ||
| reader — this toast is the only announcement of what happened, so it carries | ||
| the live region (same contract as shared/notifications/_sync_toast). %> | ||
| <div id="<%= dom_id(insight, :undo) %>" | ||
| role="status" | ||
| aria-live="polite" | ||
| class="relative flex items-center gap-3 rounded-lg bg-container p-4 group w-full md:max-w-80 shadow-border-xs" | ||
| data-controller="element-removal"> | ||
| <p class="text-primary text-sm font-medium grow"><%= t("insights.card.dismissed") %></p> | ||
| <p class="text-primary text-sm font-medium grow"><%= t("insights.card.acknowledged") %></p> | ||
|
|
||
| <%# autofocus so Undo is one keystroke away: the acknowledged card is gone from | ||
| the DOM, which drops focus to <body>, and Turbo focuses the first | ||
| [autofocus] element in stream-rendered content. %> | ||
| <%= render DS::Button.new( | ||
| text: t("insights.card.undo"), | ||
| variant: "ghost", | ||
| size: "sm", | ||
| href: undismiss_insight_path(insight), | ||
| method: :patch | ||
| href: unacknowledge_insight_path(insight), | ||
| method: :patch, | ||
| autofocus: true | ||
| ) %> | ||
|
|
||
| <%= icon "x", | ||
| class: "p-0.5 rounded-lg text-subdued hover:text-primary cursor-pointer shrink-0", | ||
| data: { action: "click->element-removal#remove" } %> | ||
| <%# A real button, not a bare icon with a click action: the glyph alone is | ||
| neither focusable nor named, so the toast could only be closed by mouse. %> | ||
| <%= render DS::Button.new( | ||
| variant: "icon", | ||
| size: "sm", | ||
| icon: "x", | ||
| type: "button", | ||
| "aria-label": t("defaults.common.close"), | ||
| data: { action: "click->element-removal#remove" } | ||
| ) %> | ||
| </div> |
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,16 @@ | ||
| <%# Acknowledging is reachable from two surfaces now, so this response carries | ||
| the update for both and each applies only the streams whose targets it has — | ||
| Turbo silently ignores a stream whose target is absent. %> | ||
|
|
||
| <%# /insights: drop the card. %> | ||
| <%= turbo_stream.remove dom_id(@insight) %> | ||
|
|
||
| <%# Dashboard: re-render the well rather than removing a row, so the next | ||
| insight is promoted into the freed slot instead of leaving a gap. %> | ||
| <%= turbo_stream.replace "insights-feed" do %> | ||
| <%= render "pages/dashboard/insights_feed", insights: @feed_insights %> | ||
| <% end %> | ||
|
|
||
| <%= turbo_stream.append "notification-tray" do %> | ||
| <%= render "insights/undo_toast", insight: @insight %> | ||
| <% end %> |
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
| <%= turbo_stream.remove dom_id(@insight, :undo) %> | ||
|
|
||
| <%= turbo_stream.replace "insights-list" do %> | ||
| <%= render "insights/list", insights: @insights, unread_ids: @unread_ids %> | ||
| <% end %> | ||
|
|
||
| <%# Undo can be pressed from the dashboard, where the toast is the only part of | ||
| this flow on screen — so the well needs restoring there too. %> | ||
| <%= turbo_stream.replace "insights-feed" do %> | ||
| <%= render "pages/dashboard/insights_feed", insights: @feed_insights %> | ||
| <% end %> |
This file was deleted.
Oops, something went wrong.
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.
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.