From ef4a43452cf7522fee20525ea8b1ce80afd6c903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sun, 27 Sep 2026 12:47:37 +0200 Subject: [PATCH] Show "no data" for empty titled sections --- .../components/hledger-dashboard.gjs | 53 ++++++++++--------- assets/stylesheets/hledger.scss | 6 +++ config/locales/client.en.yml | 1 + test/javascripts/acceptance/hledger-test.js | 15 ++++++ 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/assets/javascripts/discourse/components/hledger-dashboard.gjs b/assets/javascripts/discourse/components/hledger-dashboard.gjs index 93ec24c..6c36037 100644 --- a/assets/javascripts/discourse/components/hledger-dashboard.gjs +++ b/assets/javascripts/discourse/components/hledger-dashboard.gjs @@ -3,7 +3,7 @@ import { tracked } from "@glimmer/tracking"; import { fn } from "@ember/helper"; import { action } from "@ember/object"; import { ajax } from "discourse/lib/ajax"; -import { eq } from "discourse/truth-helpers"; +import { and, eq, isEmpty } from "discourse/truth-helpers"; import DButton from "discourse/ui-kit/d-button"; import DConditionalLoadingSpinner from "discourse/ui-kit/d-conditional-loading-spinner"; import DDatePicker from "discourse/ui-kit/d-date-picker"; @@ -51,6 +51,7 @@ export default class HledgerDashboard extends Component { return { total: i18n("hledger.total"), net: i18n("hledger.net"), + noData: i18n("hledger.no_data"), holder: i18n("hledger.equity.holder"), amount: i18n("hledger.equity.amount"), share: i18n("hledger.equity.share"), @@ -198,29 +199,33 @@ export default class HledgerDashboard extends Component { class="hledger-dashboard__section-title" >{{section.title}} {{/if}} - - - {{#each section.rows as |row|}} - - - - - {{/each}} - {{#if section.total}} - - - - - {{/if}} - -
{{amountText - row.amounts - }}
{{this.labels.total}}{{amountText - section.total - }}
+ {{#if (and section.title (isEmpty section.rows))}} +

{{this.labels.noData}}

+ {{else}} + + + {{#each section.rows as |row|}} + + + + + {{/each}} + {{#if section.total}} + + + + + {{/if}} + +
{{amountText + row.amounts + }}
{{this.labels.total}}{{amountText + section.total + }}
+ {{/if}} {{/each}} {{#if this.report.net}} diff --git a/assets/stylesheets/hledger.scss b/assets/stylesheets/hledger.scss index fcdb092..7ce7889 100644 --- a/assets/stylesheets/hledger.scss +++ b/assets/stylesheets/hledger.scss @@ -108,6 +108,12 @@ color: var(--primary-medium); } + &__empty { + margin: 0.25em 0; + font-size: var(--font-down-1); + color: var(--primary-medium); + } + &__error { margin: 0; } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 50135b9..ec4876b 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -13,6 +13,7 @@ en: equity: "Equity" total: "Total" net: "Net" + no_data: "No data" filters: begin: "From" end: "To" diff --git a/test/javascripts/acceptance/hledger-test.js b/test/javascripts/acceptance/hledger-test.js index f755f17..456b46e 100644 --- a/test/javascripts/acceptance/hledger-test.js +++ b/test/javascripts/acceptance/hledger-test.js @@ -310,6 +310,21 @@ acceptance("Hledger plugin", function (needs) { "indents below the heading's first level" ); + assert + .dom(".hledger-dashboard__empty") + .exists({ count: 1 }, "shows a placeholder for the empty section"); + assert.dom(".hledger-dashboard__empty").hasText("No data"); + assert + .dom( + ".hledger-dashboard__section:nth-of-type(2) .hledger-dashboard__table" + ) + .doesNotExist("omits the table for the empty section"); + assert + .dom( + ".hledger-dashboard__section:nth-of-type(1) .hledger-dashboard__table" + ) + .exists("keeps the table for the populated section"); + await click(".hledger-dashboard__toolbar .btn:nth-of-type(3)"); assert