The personal finance app for everyone (by everyone)
Ruby
<%# locals: (period:, legacy_data:) %>
<% feedback = feedback_config(:sankey) %>
<% if feedback[:api_key].present? %>
<%= render "shared/posthog_bootstrap" %>
<% end %>
<section id="cashflow-preview" class="mt-4 space-y-4 ph-no-capture group/sankey-preview"
data-controller="sankey-preview"
data-sankey-preview-sure-version-value="<%= Sure.version.to_s %>"
data-sankey-preview-legacy-data-value="<%= legacy_data.to_json %>"
data-sankey-preview-self-hosted-value="<%= self_hosted? %>"
data-sankey-preview-feedback-key-value="<%= feedback[:api_key] %>"
data-sankey-preview-feedback-host-value="<%= feedback[:host] %>"
data-sankey-preview-survey-id-value="<%= feedback[:survey_id] %>"
data-action="cash-flow:state->sankey-preview#update posthog:ready@document->sankey-preview#trackDisplay visibilitychange@document->sankey-preview#trackDisplay turbo:before-cache@document->sankey-preview#clear turbo:morph@document->sankey-preview#resume keydown->sankey-preview#stopKeydown">
<header class="px-4 flex flex-wrap items-center justify-between gap-2">
<div class="flex flex-wrap items-center gap-2">
<h3 class="font-medium text-primary"><%= t("pages.dashboard.cashflow_preview.title") %></h3>
<%= render DS::Pill.new(label: t("pages.dashboard.cashflow_preview.preview"), title: t("pages.dashboard.cashflow_preview.preview_tooltip")) %>
</div>
<%= render DS::Button.new(icon: "maximize-2", text: nil, variant: :ghost, disabled: true, aria: { label: t("global.expand") },
data: { action: "sankey-preview#expand", sankey_preview_target: "expandButton" }) %>
</header>
<%# A morph refresh (the sync toast's) puts the server markup back inside, loading state and all,
with the controllers still connected, so the graph is fetched again and tracking resumes. %>
<div data-controller="cash-flow" data-sankey-preview-target="display" class="ph-no-capture"
data-action="turbo:before-cache@document->cash-flow#clear turbo:morph@document->cash-flow#load"
data-cash-flow-url-value="<%= dashboard_cash_flow_path(start_date: period.start_date.iso8601, end_date: period.end_date.iso8601) %>"
data-cash-flow-group-by-value="<%= Current.user.cashflow_sankey_group_by %>">
<%# Outside the loading/content states, so the grouping can be switched back from an empty graph. %>
<div class="px-4 flex flex-wrap items-center justify-end gap-2">
<span class="text-xs text-secondary"><%= t("pages.dashboard.cashflow_preview.group_by_label") %></span>
<%= render DS::SegmentedControl.new(aria_label: t("pages.dashboard.cashflow_preview.group_by_label")) do |sc| %>
<% User::CASHFLOW_SANKEY_GROUPINGS.each do |group_by| %>
<% sc.with_segment(
t("pages.dashboard.cashflow_preview.group_by_#{group_by}"),
active: Current.user.cashflow_sankey_group_by == group_by,
class: "text-xs",
data: { cash_flow_target: "groupBySegment", group_by: group_by, action: "cash-flow#groupBy" }
) %>
<% end %>
<% end %>
</div>
<p data-cash-flow-target="loading" role="status" class="p-4 text-secondary"><%= t("pages.dashboard.cashflow_sankey.loading") %></p>
<div data-cash-flow-target="error" hidden role="alert" class="p-4 space-y-3">
<p><%= t("pages.dashboard.cashflow_sankey.load_error") %></p>
<%= render DS::Button.new(text: t("pages.dashboard.cashflow_sankey.retry"), data: { action: "cash-flow#load" }) %>
</div>
<div data-cash-flow-target="content" hidden>
<div class="w-full h-96 overflow-x-auto overscroll-x-contain" tabindex="0" role="region" aria-label="<%= t("pages.dashboard.cashflow_preview.title") %>"><%= render "pages/dashboard/cashflow_preview_chart", period: period %></div>
<%= render DS::Dialog.new(id: "cashflow-preview-expanded-dialog", auto_open: false, width: "expanded", disable_frame: true,
data: { sankey_preview_target: "expandedDialog", action: "close->sankey-preview#restoreDrag" }) do |dialog| %>
<% dialog.with_header(title: t("pages.dashboard.cashflow_preview.title")) %>
<% dialog.with_body do %>
<div class="w-full h-[85dvh] max-h-[90dvh] overflow-auto overscroll-contain" tabindex="0" role="region" aria-label="<%= t("pages.dashboard.cashflow_preview.title") %>">
<%= render "pages/dashboard/cashflow_preview_chart", period: period %>
</div>
<% end %>
<% end %>
</div>
<p data-cash-flow-target="empty" hidden class="p-4 text-secondary"><%= t("pages.dashboard.cashflow_sankey.no_data_title") %></p>
</div>
<div class="px-4 space-y-2 ph-no-capture">
<p class="text-sm text-secondary"><%= t("pages.dashboard.cashflow_preview.feedback_prompt") %></p>
<div class="flex items-center justify-end gap-2">
<%= render DS::Button.new(icon: "thumbs-down", text: t("pages.dashboard.cashflow_preview.negative"), variant: :outline,
class: "group-data-[sankey-comparison=mismatch]/sankey-preview:bg-destructive/10 group-data-[sankey-comparison=mismatch]/sankey-preview:text-destructive group-data-[sankey-comparison=mismatch]/sankey-preview:border-destructive group-data-[sankey-comparison=mismatch]/sankey-preview:hover:bg-destructive/20 group-data-[sankey-comparison=mismatch]/sankey-preview:[&_svg]:text-destructive",
data: { action: "sankey-preview#feedback", sankey_preview_rating_param: "negative" }) %>
<%= render DS::Button.new(icon: "thumbs-up", text: t("pages.dashboard.cashflow_preview.positive"), variant: :outline,
class: "group-data-[sankey-comparison=match]/sankey-preview:bg-success/10 group-data-[sankey-comparison=match]/sankey-preview:text-success group-data-[sankey-comparison=match]/sankey-preview:border-success group-data-[sankey-comparison=match]/sankey-preview:hover:bg-success/20 group-data-[sankey-comparison=match]/sankey-preview:[&_svg]:text-success",
data: { action: "sankey-preview#feedback", sankey_preview_rating_param: "positive" }) %>
</div>
</div>
<%= render DS::Dialog.new(id: "cashflow-preview-feedback-dialog", auto_open: false, disable_frame: true,
data: { sankey_preview_target: "feedbackDialog", action: "close->sankey-preview#dismiss" }) do |dialog| %>
<% dialog.with_header(title: t("pages.dashboard.cashflow_preview.feedback_title")) %>
<% dialog.with_body do %>
<p role="status" data-sankey-preview-target="status"
data-loading="<%= t("pages.dashboard.cashflow_preview.feedback_loading") %>"
data-unavailable="<%= t("pages.dashboard.cashflow_preview.feedback_unavailable") %>"
data-thanks="<%= t("pages.dashboard.cashflow_preview.feedback_thanks") %>"></p>
<form hidden data-sankey-preview-target="form" data-action="submit->sankey-preview#submit" class="space-y-4 ph-no-capture">
<label for="cashflow-preview-feedback" class="block text-sm font-medium" data-feedback-question></label>
<textarea id="cashflow-preview-feedback" name="feedback" rows="4" maxlength="2000"
aria-describedby="cashflow-preview-feedback-privacy"
class="w-full rounded-lg border border-primary bg-container text-primary ph-no-capture"></textarea>
<p id="cashflow-preview-feedback-privacy" class="text-xs text-secondary"><%= t("pages.dashboard.cashflow_preview.feedback_privacy") %></p>
<%= render DS::Button.new(text: t("pages.dashboard.cashflow_preview.feedback_submit"), type: :submit) %>
</form>
<% end %>
<% end %>
</section>