Unify market tickers and usage stats into one settings panel

Replace the separate Market Ticker and OpenRouter Stats settings sections
with a single Tickers & Stats section. It lists every active ticker/stat
with its settings and remove actions, and offers one Add integration button
that opens the generic integration list filtered to tickers and stats.

The add button is hidden once every single-instance integration is
connected, matching the old sections' behavior.
This commit is contained in:
raucao committed 2026-11-13 15:40:03 +04:00
1 parent 47906a0386
commit 7cad948c17
8 files changed
+236 -434

No files matched your search

@@ -1,97 +0,0 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { fn } from '@ember/helper';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
import { formFor } from '../../../../config/integration-forms';
import { USAGE_TYPES } from '../../../../config/usage';
import IntegrationGrid from './integration-grid.gjs';
// The OpenRouter usage stats, managed like the market tickers. New usage
// integrations are added to USAGE_TYPES.
export default class SettingsOpenRouterSection extends Component {
@service integrations;
@service modal;
get rows() {
return this.integrations.rows.filter((row) =>
USAGE_TYPES.includes(row.type)
);
}
// Usage integrations that are available and not connected yet.
get addable() {
return this.integrations.all.filter(
(integration) =>
USAGE_TYPES.includes(integration.id) &&
integration.available &&
!(
integration.supportsMultiple === false && integration.instances.length
)
);
}
@action
edit(row) {
const component = formFor(row.type);
if (!component) {
return;
}
this.modal.open({
component,
props: { mode: 'edit', integration: row },
size: 'md',
});
}
@action
async remove(row) {
await this.integrations.remove(row);
}
@action
add(integration) {
const component = formFor(integration.id);
if (!component) {
return;
}
this.modal.open({ component, props: { mode: 'add' }, size: 'md' });
}
<template>
<div class="min-h-0 flex-1 overflow-y-auto px-6 py-6">
<p class="max-w-prose text-sm text-gray-500">
Show your OpenRouter spend on the dashboard.
</p>
<div class="mt-4">
<IntegrationGrid
@rows={{this.rows}}
@onEdit={{this.edit}}
@onRemove={{this.remove}}
@emptyLabel="No OpenRouter stats enabled yet."
/>
</div>
{{#if this.addable.length}}
<div class="mt-6 flex flex-wrap gap-2">
{{#each this.addable as |integration|}}
<button
type="button"
data-test-add={{integration.id}}
{{on "click" (fn this.add integration)}}
class="rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
>
Add
{{integration.label}}
</button>
{{/each}}
</div>
{{/if}}
</div>
</template>
}
@@ -1,29 +1,32 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { fn } from '@ember/helper';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
import { formFor } from '../../../../config/integration-forms';
import { MARKET_TICKER_TYPES } from '../../../../config/market-ticker';
import { TICKER_STATS_TYPES } from '../../../../config/tickers-stats';
import AddList from '../../integrations/add-list.gjs';
import IntegrationGrid from './integration-grid.gjs';
// The dashboard market tickers (currently just Bitcoin), managed like the
// calendar sources. New asset integrations are added to MARKET_TICKER_TYPES.
export default class SettingsMarketTickerSection extends Component {
// The dashboard tickers and usage stats, managed together. Market tickers and
// usage stats share the same add/edit/remove flow, so they live in one section
// instead of separate ones. New types are added to TICKER_STATS_TYPES.
export default class SettingsTickersStatsSection extends Component {
@service integrations;
@service modal;
get rows() {
return this.integrations.rows.filter((row) =>
MARKET_TICKER_TYPES.includes(row.type)
TICKER_STATS_TYPES.includes(row.type)
);
}
// Market ticker integrations that are available and not connected yet.
// Ticker/stat integrations that are available and not connected yet. Both
// current types are single-instance, so this is empty once everything is
// connected and the Add button is hidden.
get addable() {
return this.integrations.all.filter(
(integration) =>
MARKET_TICKER_TYPES.includes(integration.id) &&
TICKER_STATS_TYPES.includes(integration.id) &&
integration.available &&
!(
integration.supportsMultiple === false && integration.instances.length
@@ -52,20 +55,18 @@ export default class SettingsMarketTickerSection extends Component {
}
@action
add(integration) {
const component = formFor(integration.id);
if (!component) {
return;
}
this.modal.open({ component, props: { mode: 'add' }, size: 'md' });
add() {
this.modal.open({
component: AddList,
props: { types: TICKER_STATS_TYPES },
size: 'md',
});
}
<template>
<div class="min-h-0 flex-1 overflow-y-auto px-6 py-6">
<p class="max-w-prose text-sm text-gray-500">
Track asset prices on your dashboard.
Track asset prices and usage stats on your dashboard.
</p>
<div class="mt-4">
@@ -73,23 +74,20 @@ export default class SettingsMarketTickerSection extends Component {
@rows={{this.rows}}
@onEdit={{this.edit}}
@onRemove={{this.remove}}
@emptyLabel="No market tickers enabled yet."
@emptyLabel="No tickers or stats enabled yet."
/>
</div>
{{#if this.addable.length}}
<div class="mt-6 flex flex-wrap gap-2">
{{#each this.addable as |integration|}}
<button
type="button"
data-test-add={{integration.id}}
{{on "click" (fn this.add integration)}}
class="rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
>
Add
{{integration.label}}
</button>
{{/each}}
<button
type="button"
data-test-add
{{on "click" this.add}}
class="rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
>
Add integration
</button>
</div>
{{/if}}
</div>
+2 -4
View File
@@ -1,9 +1,8 @@
import Events from '../components/settings/global-settings/sections/events.gjs';
import MarketTicker from '../components/settings/global-settings/sections/market-ticker.gjs';
import OpenRouter from '../components/settings/global-settings/sections/openrouter.gjs';
import Photos from '../components/settings/global-settings/sections/photos.gjs';
import ProtocolGateway from '../components/settings/global-settings/sections/protocol-gateway.gjs';
import SiteLinks from '../components/settings/global-settings/sections/site-links.gjs';
import TickersStats from '../components/settings/global-settings/sections/tickers-stats.gjs';
// Maps a settings section id to its content component. Sections without an
// entry fall back to the generic placeholder, so this grows one section at a
@@ -12,8 +11,7 @@ const CONTENT = {
photos: Photos,
'site-links': SiteLinks,
events: Events,
'market-ticker': MarketTicker,
openrouter: OpenRouter,
'tickers-stats': TickersStats,
'protocol-gateway': ProtocolGateway,
};
+3 -14
View File
@@ -43,9 +43,9 @@ export const SETTINGS_GROUPS = [
],
},
{
id: 'market-ticker',
label: 'Market Ticker',
description: 'Track asset prices on your dashboard.',
id: 'tickers-stats',
label: 'Tickers & Stats',
description: 'Track asset prices and usage stats on your dashboard.',
// Lucide chart-no-axes-combined.
icon: [
'M12 16v5',
@@ -56,17 +56,6 @@ export const SETTINGS_GROUPS = [
'M8 14.656V21',
],
},
{
id: 'openrouter',
label: 'OpenRouter Stats',
description: 'Show your OpenRouter spend on the dashboard.',
// Lucide circle-dollar-sign.
icon: [
'M12 2a10 10 0 1 0 0 20a10 10 0 1 0 0-20z',
'M12 7v10',
'M15.5 9.5a2.5 2.5 0 0 0-2.5-2.5h-1a2.5 2.5 0 0 0 0 5h1a2.5 2.5 0 0 1 0 5h-1a2.5 2.5 0 0 1-2.5-2.5',
],
},
],
},
{
+7
View File
@@ -0,0 +1,7 @@
import { MARKET_TICKER_TYPES } from './market-ticker';
import { USAGE_TYPES } from './usage';
// The integration types managed by the unified Tickers & Stats settings
// section. Market tickers and usage stats share the same add/edit/remove flow,
// so they are grouped here instead of in separate settings sections.
export const TICKER_STATS_TYPES = [...MARKET_TICKER_TYPES, ...USAGE_TYPES];
@@ -1,138 +0,0 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, click } from '@ember/test-helpers';
import { tracked } from '@glimmer/tracking';
import MarketTicker from 'dashtab/components/settings/global-settings/sections/market-ticker';
class FakeSitesService {
@tracked all = [];
integrationFor() {
return undefined;
}
async removeSource() {}
}
class FakeNotificationsService {
stateFor() {
return { error: null, errorType: null };
}
}
class FakeBitcoinService {
@tracked enabled = false;
@tracked interval = 30000;
@tracked provider = 'coingecko';
disabled = false;
async disable() {
this.disabled = true;
this.enabled = false;
}
}
class FakeCalendarService {
instancesFor() {
return [];
}
}
class FakeModalService {
opened = null;
open(descriptor) {
this.opened = descriptor;
}
replace(descriptor) {
this.opened = descriptor;
}
}
function register(owner, overrides = {}) {
const sites = overrides.sites ?? new FakeSitesService();
const notifications =
overrides.notifications ?? new FakeNotificationsService();
const bitcoin = overrides.bitcoin ?? new FakeBitcoinService();
const calendar = overrides.calendar ?? new FakeCalendarService();
const modal = overrides.modal ?? new FakeModalService();
owner.register('service:sites', sites, { instantiate: false });
owner.register('service:notifications', notifications, {
instantiate: false,
});
owner.register('service:bitcoin', bitcoin, { instantiate: false });
owner.register('service:calendar', calendar, { instantiate: false });
owner.register('service:modal', modal, { instantiate: false });
return { sites, notifications, bitcoin, calendar, modal };
}
module(
'Integration | Component | settings/global-settings/sections/market-ticker',
function (hooks) {
setupRenderingTest(hooks);
test('offers to add Bitcoin when it is not enabled', async function (assert) {
register(this.owner);
await render(<template><MarketTicker /></template>);
assert.dom('[data-test-add="bitcoin"]').exists();
assert
.dom('[data-test-add="bitcoin"]')
.hasText('Add Bitcoin Price Ticker');
assert.dom('[data-instance="bitcoin"]').doesNotExist();
});
test('shows the enabled ticker in the grid instead of the add button', async function (assert) {
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
register(this.owner, { bitcoin });
await render(<template><MarketTicker /></template>);
assert.dom('[data-instance="bitcoin"]').exists();
assert.dom('[data-instance="bitcoin"] [data-test-settings]').exists();
assert.dom('[data-instance="bitcoin"] [data-test-remove]').exists();
assert.dom('[data-test-add="bitcoin"]').doesNotExist();
});
test('editing the ticker opens its form', async function (assert) {
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
const { modal } = register(this.owner, { bitcoin });
await render(<template><MarketTicker /></template>);
await click('[data-instance="bitcoin"] [data-test-settings]');
assert.ok(modal.opened.component);
assert.strictEqual(modal.opened.props.mode, 'edit');
});
test('adding Bitcoin opens its form in add mode', async function (assert) {
const { modal } = register(this.owner);
await render(<template><MarketTicker /></template>);
await click('[data-test-add="bitcoin"]');
assert.ok(modal.opened.component);
assert.strictEqual(modal.opened.props.mode, 'add');
});
test('removing the ticker disables it', async function (assert) {
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
register(this.owner, { bitcoin });
await render(<template><MarketTicker /></template>);
await click('[data-instance="bitcoin"] [data-test-remove]');
assert.true(bitcoin.disabled);
});
}
);
@@ -1,152 +0,0 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, click } from '@ember/test-helpers';
import { tracked } from '@glimmer/tracking';
import OpenRouter from 'dashtab/components/settings/global-settings/sections/openrouter';
class FakeSitesService {
@tracked all = [];
integrationFor() {
return undefined;
}
async removeSource() {}
}
class FakeNotificationsService {
stateFor() {
return { error: null, errorType: null };
}
}
class FakeBitcoinService {
@tracked enabled = false;
@tracked interval = 30000;
@tracked provider = 'coingecko';
async disable() {}
}
class FakeOpenRouterService {
@tracked enabled = false;
@tracked apiKey = null;
@tracked keyIds = [];
@tracked interval = 300000;
@tracked granularity = 'today';
disabled = false;
async disable() {
this.disabled = true;
this.enabled = false;
}
}
class FakeCalendarService {
instancesFor() {
return [];
}
}
class FakeModalService {
opened = null;
open(descriptor) {
this.opened = descriptor;
}
replace(descriptor) {
this.opened = descriptor;
}
}
function register(owner, overrides = {}) {
const sites = overrides.sites ?? new FakeSitesService();
const notifications =
overrides.notifications ?? new FakeNotificationsService();
const bitcoin = overrides.bitcoin ?? new FakeBitcoinService();
const openrouter = overrides.openrouter ?? new FakeOpenRouterService();
const calendar = overrides.calendar ?? new FakeCalendarService();
const modal = overrides.modal ?? new FakeModalService();
owner.register('service:sites', sites, { instantiate: false });
owner.register('service:notifications', notifications, {
instantiate: false,
});
owner.register('service:bitcoin', bitcoin, { instantiate: false });
owner.register('service:openrouter', openrouter, { instantiate: false });
owner.register('service:calendar', calendar, { instantiate: false });
owner.register('service:modal', modal, { instantiate: false });
return { sites, notifications, bitcoin, openrouter, calendar, modal };
}
module(
'Integration | Component | settings/global-settings/sections/openrouter',
function (hooks) {
setupRenderingTest(hooks);
test('offers to add OpenRouter Stats when it is not enabled', async function (assert) {
register(this.owner);
await render(<template><OpenRouter /></template>);
assert.dom('[data-test-add="openrouter"]').exists();
assert
.dom('[data-test-add="openrouter"]')
.hasText('Add OpenRouter Stats');
assert.dom('[data-instance="openrouter"]').doesNotExist();
});
test('shows the enabled integration in the grid instead of the add button', async function (assert) {
const openrouter = new FakeOpenRouterService();
openrouter.enabled = true;
register(this.owner, { openrouter });
await render(<template><OpenRouter /></template>);
assert.dom('[data-instance="openrouter"]').exists();
assert.dom('[data-instance="openrouter"] [data-test-settings]').exists();
assert.dom('[data-instance="openrouter"] [data-test-remove]').exists();
assert.dom('[data-test-add="openrouter"]').doesNotExist();
// The glyph fills its square viewBox, so the row must inset it.
assert.dom('[data-instance="openrouter"] img').hasClass('object-contain');
});
test('editing the integration opens its form', async function (assert) {
const openrouter = new FakeOpenRouterService();
openrouter.enabled = true;
const { modal } = register(this.owner, { openrouter });
await render(<template><OpenRouter /></template>);
await click('[data-instance="openrouter"] [data-test-settings]');
assert.ok(modal.opened.component);
assert.strictEqual(modal.opened.props.mode, 'edit');
});
test('adding the integration opens its form in add mode', async function (assert) {
const { modal } = register(this.owner);
await render(<template><OpenRouter /></template>);
await click('[data-test-add="openrouter"]');
assert.ok(modal.opened.component);
assert.strictEqual(modal.opened.props.mode, 'add');
});
test('removing the integration disables it', async function (assert) {
const openrouter = new FakeOpenRouterService();
openrouter.enabled = true;
register(this.owner, { openrouter });
await render(<template><OpenRouter /></template>);
await click('[data-instance="openrouter"] [data-test-remove]');
assert.true(openrouter.disabled);
});
}
);
@@ -0,0 +1,197 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, click } from '@ember/test-helpers';
import { tracked } from '@glimmer/tracking';
import TickersStats from 'dashtab/components/settings/global-settings/sections/tickers-stats';
import AddList from 'dashtab/components/settings/integrations/add-list';
import BitcoinForm from 'dashtab/components/settings/integrations/bitcoin-form';
import OpenRouterForm from 'dashtab/components/settings/integrations/openrouter-form';
class FakeSitesService {
@tracked all = [];
integrationFor() {
return undefined;
}
async removeSource() {}
}
class FakeNotificationsService {
stateFor() {
return { error: null, errorType: null };
}
}
class FakeBitcoinService {
@tracked enabled = false;
@tracked interval = 30000;
@tracked provider = 'coingecko';
disabled = false;
async disable() {
this.disabled = true;
this.enabled = false;
}
}
class FakeOpenRouterService {
@tracked enabled = false;
@tracked apiKey = null;
@tracked keyIds = [];
@tracked interval = 300000;
@tracked granularity = 'today';
disabled = false;
async disable() {
this.disabled = true;
this.enabled = false;
}
}
class FakeCalendarService {
instancesFor() {
return [];
}
}
class FakeModalService {
opened = null;
open(descriptor) {
this.opened = descriptor;
}
replace(descriptor) {
this.opened = descriptor;
}
}
function register(owner, overrides = {}) {
const sites = overrides.sites ?? new FakeSitesService();
const notifications =
overrides.notifications ?? new FakeNotificationsService();
const bitcoin = overrides.bitcoin ?? new FakeBitcoinService();
const openrouter = overrides.openrouter ?? new FakeOpenRouterService();
const calendar = overrides.calendar ?? new FakeCalendarService();
const modal = overrides.modal ?? new FakeModalService();
owner.register('service:sites', sites, { instantiate: false });
owner.register('service:notifications', notifications, {
instantiate: false,
});
owner.register('service:bitcoin', bitcoin, { instantiate: false });
owner.register('service:openrouter', openrouter, { instantiate: false });
owner.register('service:calendar', calendar, { instantiate: false });
owner.register('service:modal', modal, { instantiate: false });
return { sites, notifications, bitcoin, openrouter, calendar, modal };
}
module(
'Integration | Component | settings/global-settings/sections/tickers-stats',
function (hooks) {
setupRenderingTest(hooks);
test('offers a single Add integration button when nothing is enabled', async function (assert) {
register(this.owner);
await render(<template><TickersStats /></template>);
assert.dom('[data-test-add]').exists();
assert.dom('[data-test-add]').hasText('Add integration');
assert.dom('[data-test-add="bitcoin"]').doesNotExist();
assert.dom('[data-test-add="openrouter"]').doesNotExist();
assert.dom('[data-instance="bitcoin"]').doesNotExist();
assert.dom('[data-instance="openrouter"]').doesNotExist();
});
test('adding opens the integration list filtered to tickers and stats', async function (assert) {
const { modal } = register(this.owner);
await render(<template><TickersStats /></template>);
await click('[data-test-add]');
assert.strictEqual(modal.opened.component, AddList);
assert.deepEqual(modal.opened.props.types, ['bitcoin', 'openrouter']);
});
test('hides the Add integration button when both integrations are connected', async function (assert) {
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
const openrouter = new FakeOpenRouterService();
openrouter.enabled = true;
register(this.owner, { bitcoin, openrouter });
await render(<template><TickersStats /></template>);
assert.dom('[data-test-add]').doesNotExist();
assert.dom('[data-instance="bitcoin"]').exists();
assert.dom('[data-instance="openrouter"]').exists();
});
test('shows active tickers and stats with settings and remove buttons', async function (assert) {
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
const openrouter = new FakeOpenRouterService();
openrouter.enabled = true;
register(this.owner, { bitcoin, openrouter });
await render(<template><TickersStats /></template>);
assert.dom('[data-instance="bitcoin"]').exists();
assert.dom('[data-instance="bitcoin"] [data-test-settings]').exists();
assert.dom('[data-instance="bitcoin"] [data-test-remove]').exists();
assert.dom('[data-instance="openrouter"]').exists();
assert.dom('[data-instance="openrouter"] [data-test-settings]').exists();
assert.dom('[data-instance="openrouter"] [data-test-remove]').exists();
});
test('editing a ticker opens its form', async function (assert) {
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
const { modal } = register(this.owner, { bitcoin });
await render(<template><TickersStats /></template>);
await click('[data-instance="bitcoin"] [data-test-settings]');
assert.strictEqual(modal.opened.component, BitcoinForm);
assert.strictEqual(modal.opened.props.mode, 'edit');
assert.strictEqual(modal.opened.props.integration.type, 'bitcoin');
});
test('editing a stat opens its form', async function (assert) {
const openrouter = new FakeOpenRouterService();
openrouter.enabled = true;
const { modal } = register(this.owner, { openrouter });
await render(<template><TickersStats /></template>);
await click('[data-instance="openrouter"] [data-test-settings]');
assert.strictEqual(modal.opened.component, OpenRouterForm);
assert.strictEqual(modal.opened.props.mode, 'edit');
assert.strictEqual(modal.opened.props.integration.type, 'openrouter');
});
test('removing a ticker or stat disables it', async function (assert) {
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
const openrouter = new FakeOpenRouterService();
openrouter.enabled = true;
register(this.owner, { bitcoin, openrouter });
await render(<template><TickersStats /></template>);
await click('[data-instance="bitcoin"] [data-test-remove]');
assert.true(bitcoin.disabled);
await click('[data-instance="openrouter"] [data-test-remove]');
assert.true(openrouter.disabled);
});
}
);