Files
raucao 7cad948c17 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.
2026-11-13 15:40:03 +04:00

96 lines
2.6 KiB
Plaintext

import Component from '@glimmer/component';
import { action } from '@ember/object';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
import { formFor } from '../../../../config/integration-forms';
import { TICKER_STATS_TYPES } from '../../../../config/tickers-stats';
import AddList from '../../integrations/add-list.gjs';
import IntegrationGrid from './integration-grid.gjs';
// 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) =>
TICKER_STATS_TYPES.includes(row.type)
);
}
// 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) =>
TICKER_STATS_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() {
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 and usage stats on your dashboard.
</p>
<div class="mt-4">
<IntegrationGrid
@rows={{this.rows}}
@onEdit={{this.edit}}
@onRemove={{this.remove}}
@emptyLabel="No tickers or stats enabled yet."
/>
</div>
{{#if this.addable.length}}
<div class="mt-6 flex flex-wrap gap-2">
<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>
</template>
}