@gloom-sh/terminal 0.20.14 → 0.20.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/api-client/data.ts +13 -3
- package/src/api-client/index.ts +54 -0
- package/src/api-client/install-experiments.ts +8 -7
- package/src/api-client/paths.ts +2 -1
- package/src/api-client/product-waitlist.ts +63 -0
- package/src/api-client/request.ts +4 -2
- package/src/api-client/types/billing.ts +45 -0
- package/src/api-client/types/econ.ts +3 -0
- package/src/api-client/yearly-plan.ts +132 -0
- package/src/app/global-shortcuts.ts +5 -3
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/plugin-bindings.ts +3 -1
- package/src/app/pane-runtime/ticker-open-runtime.ts +6 -1
- package/src/app/since-last-visit/keys.ts +26 -0
- package/src/app/since-last-visit/model.ts +266 -0
- package/src/app/since-last-visit/strip.tsx +193 -0
- package/src/app/since-last-visit/use-since-last-visit.ts +289 -0
- package/src/app/since-last-visit/visit-tracker.ts +191 -0
- package/src/app.tsx +15 -0
- package/src/cli/commands/fred-series.ts +3 -1
- package/src/cli/commands/market.ts +8 -4
- package/src/cli/commands/overview.ts +65 -13
- package/src/cli/commands/system.ts +29 -1
- package/src/cli/commands/ticker.ts +12 -5
- package/src/cli/csv-export.ts +73 -0
- package/src/cli/desktop-pane-shot-api-policy.ts +4 -1
- package/src/cli/desktop-pane-shot-browser.ts +2 -1
- package/src/cli/desktop-pane-shot-view.ts +3 -7
- package/src/cli/desktop-pane-shot.ts +29 -30
- package/src/cli/help.ts +5 -2
- package/src/cli/history-rows.ts +24 -0
- package/src/cli/index.ts +4 -0
- package/src/cli/options.ts +29 -1
- package/src/cli/pane-functions/catalog.ts +41 -4
- package/src/cli/pane-functions/function-help.ts +1 -1
- package/src/cli/pane-functions/headless.ts +70 -3
- package/src/cli/pane-functions/index.ts +4 -4
- package/src/cli/pane-functions/resolver.ts +43 -0
- package/src/cli/pane-functions/screenshot-bridge.ts +4 -2
- package/src/cli/pane-functions/screenshot-payload.ts +3 -0
- package/src/cli/report-tables.ts +37 -8
- package/src/cli/result.ts +3 -6
- package/src/cli/shot-temp-dir.ts +30 -0
- package/src/cli/suffixed-listing-rows.ts +11 -0
- package/src/components/chart/composite/composite-chart.tsx +3 -3
- package/src/components/chart/composite/legend.tsx +37 -7
- package/src/components/command-bar/commands/direct/index.ts +31 -8
- package/src/components/command-bar/commands/registry.ts +7 -0
- package/src/components/command-bar/routes/root/command-items.ts +8 -0
- package/src/components/command-bar/routes/root/results.ts +16 -0
- package/src/components/company-logo.tsx +10 -3
- package/src/components/data-table/sections.ts +6 -1
- package/src/components/layout/pane/title.ts +6 -2
- package/src/components/layout/shell/index.tsx +5 -1
- package/src/components/layout/shell/ticker-link-menu.ts +12 -9
- package/src/components/ticker/badge/format.ts +12 -3
- package/src/components/ticker/badge/index.tsx +9 -3
- package/src/components/ticker/list-table-view.tsx +119 -17
- package/src/components/ui/data-table/display-columns.ts +19 -0
- package/src/components/ui/data-table/hooks.ts +2 -3
- package/src/components/ui/data-table/index.tsx +43 -9
- package/src/components/ui/data-table/types.ts +21 -0
- package/src/components/ui/data-table/visible-range.ts +11 -1
- package/src/core/state/app/layout-reducer.ts +3 -1
- package/src/core/state/app/layout.ts +2 -2
- package/src/data/config/layout.ts +14 -0
- package/src/data/config/store/normalize.ts +11 -1
- package/src/i18n/es.ts +38 -0
- package/src/i18n/ja.ts +38 -0
- package/src/i18n/ko.ts +38 -0
- package/src/i18n/zh-cn.ts +38 -0
- package/src/i18n/zh-tw.ts +38 -0
- package/src/layout/pane-follow.ts +141 -4
- package/src/layout/pane-layout-move.ts +10 -7
- package/src/layout/ticker-navigation.ts +13 -19
- package/src/layout/ticker-retarget.ts +3 -2
- package/src/market-data/market/index-level.ts +19 -0
- package/src/plugins/builtin/account-management/keyboard.ts +14 -0
- package/src/plugins/builtin/account-management/model.ts +2 -0
- package/src/plugins/builtin/account-management/pane.tsx +79 -7
- package/src/plugins/builtin/account-management/payment-recovery-row.tsx +97 -0
- package/src/plugins/builtin/account-management/yearly-plan-row.tsx +359 -0
- package/src/plugins/builtin/awards/pane.tsx +12 -10
- package/src/plugins/builtin/changelog/index.tsx +6 -44
- package/src/plugins/builtin/changelog/versions.ts +17 -68
- package/src/plugins/builtin/chart-composer/pane.tsx +4 -1
- package/src/plugins/builtin/cloud/askg/executor.ts +2 -1
- package/src/plugins/builtin/cloud/askg/sources.ts +2 -1
- package/src/plugins/builtin/cpi/pane.tsx +1 -1
- package/src/plugins/builtin/credit-conditions/series.ts +2 -2
- package/src/plugins/builtin/debt-maturities/model.ts +1 -1
- package/src/plugins/builtin/earnings/board-model.ts +12 -0
- package/src/plugins/builtin/earnings/board-table.ts +8 -5
- package/src/plugins/builtin/earnings/board.tsx +38 -18
- package/src/plugins/builtin/earnings/highlight.ts +47 -0
- package/src/plugins/builtin/earnings/history-table.ts +1 -1
- package/src/plugins/builtin/earnings/index.tsx +1 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +2 -2
- package/src/plugins/builtin/econ/calendar-model.ts +2 -0
- package/src/plugins/builtin/econ/fred-catalog.ts +1 -256
- package/src/plugins/builtin/econ-statistics/cache.ts +1 -1
- package/src/plugins/builtin/econ-statistics/client.ts +11 -10
- package/src/plugins/builtin/econ-statistics/detail.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/headless.ts +42 -6
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/pane.tsx +7 -2
- package/src/plugins/builtin/econ-statistics/stats.ts +2 -1
- package/src/plugins/builtin/econ-statistics/view.ts +9 -3
- package/src/plugins/builtin/estimate-revisions/model.ts +1 -1
- package/src/plugins/builtin/exposure/index.tsx +1 -1
- package/src/plugins/builtin/macro-day/model.ts +6 -4
- package/src/plugins/builtin/market-valuation/detail.tsx +3 -3
- package/src/plugins/builtin/market-valuation/headless.ts +11 -4
- package/src/plugins/builtin/market-valuation/pane.tsx +3 -1
- package/src/plugins/builtin/market-valuation/view.ts +14 -0
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +20 -8
- package/src/plugins/builtin/pe-band/pane.tsx +1 -1
- package/src/plugins/builtin/portfolio-list/cli/render.ts +8 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +176 -17
- package/src/plugins/builtin/portfolio-list/pane/groups.tsx +220 -0
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +90 -15
- package/src/plugins/builtin/portfolio-list/table.tsx +13 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +4 -2
- package/src/plugins/builtin/research/relative-valuation-headless.ts +15 -5
- package/src/plugins/builtin/research/relative-valuation-model.ts +7 -1
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +7 -4
- package/src/plugins/builtin/shared/fred-catalog.ts +256 -0
- package/src/plugins/builtin/shared/headless-options.ts +1 -1
- package/src/plugins/builtin/shared/series-cache.ts +3 -0
- package/src/plugins/builtin/shared/series-detail-chart.tsx +3 -0
- package/src/plugins/builtin/short-interest/watch-pane.tsx +7 -7
- package/src/plugins/builtin/social-mentions/model.ts +2 -2
- package/src/plugins/builtin/thirteenf/pane.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +16 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +8 -4
- package/src/plugins/builtin/ticker-detail/financials/model.ts +51 -16
- package/src/plugins/builtin/ticker-detail/financials/nopat.ts +16 -0
- package/src/plugins/builtin/ticker-detail/financials/ratios.ts +44 -13
- package/src/plugins/builtin/ticker-detail/financials/schema.ts +33 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +4 -2
- package/src/plugins/builtin/ticker-detail/headless-schema.ts +30 -4
- package/src/plugins/builtin/ticker-detail/headless.ts +254 -34
- package/src/plugins/builtin/ticker-detail/overview/model.ts +7 -3
- package/src/plugins/builtin/ticker-detail/pharma-signals/eligibility.ts +32 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/tab.tsx +162 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/waitlist.ts +126 -0
- package/src/plugins/builtin/ticker-detail/research-groups.ts +6 -4
- package/src/plugins/builtin/ticker-detail/research-tabs.ts +11 -0
- package/src/plugins/builtin/time-sales/headless.ts +4 -1
- package/src/plugins/builtin/time-sales/pane.tsx +2 -0
- package/src/plugins/builtin/time-sales/window.ts +12 -0
- package/src/plugins/builtin/treasury-auctions/client.ts +4 -0
- package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +2 -0
- package/src/plugins/builtin/treasury-daily/client.ts +23 -11
- package/src/portfolio/column-values.ts +20 -8
- package/src/portfolio/suffixed-listings.ts +3 -1
- package/src/portfolio/watchlist-groups.ts +212 -0
- package/src/react/ticker-source.ts +3 -1
- package/src/renderers/dom/styles.css +7 -0
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +2 -0
- package/src/sources/gloomberb-cloud/fred-publisher.ts +25 -0
- package/src/sources/gloomberb-cloud/fred-series.ts +1 -1
- package/src/state/app/bootstrap.ts +11 -0
- package/src/state/app/context/index.tsx +6 -0
- package/src/sync/collections-contributor.ts +5 -2
- package/src/sync/config-merge.ts +10 -2
- package/src/sync/sanitize.ts +28 -0
- package/src/telemetry/usage-counts.ts +17 -0
- package/src/time-series/base-series.ts +3 -0
- package/src/time-series/chart-seed.ts +1 -1
- package/src/time-series/financial-period-coverage.ts +4 -12
- package/src/time-series/ice-credit.ts +1 -0
- package/src/time-series/parsed-history-cache.ts +1 -1
- package/src/time-series/resolve.ts +1 -1
- package/src/time-series/types.ts +1 -0
- package/src/time-series/use-chart-resolution.ts +6 -1
- package/src/types/config.ts +32 -0
- package/src/types/headless.ts +9 -2
- package/src/types/plugin-context.ts +5 -0
- package/src/types/ticker.ts +14 -0
- package/src/ui/ascii-font.ts +1 -4
- package/src/utils/async-deadline.ts +2 -2
- package/src/utils/csv.ts +44 -5
- package/src/utils/futures-generic.ts +3 -0
- package/src/utils/throttled-fetch.ts +15 -1
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
2
|
+
import { ChoiceDialog, confirmDialog, TextPromptDialog, usePaneFooter, usePaneMenuItems } from "../../../../components";
|
|
3
|
+
import type { TickerTableGroup } from "../../../../components/ticker/list-table-view";
|
|
4
|
+
import { t, tf } from "../../../../i18n";
|
|
5
|
+
import {
|
|
6
|
+
renameWatchlistGroup,
|
|
7
|
+
sectionWatchlistItems,
|
|
8
|
+
setWatchlistGroup,
|
|
9
|
+
UNGROUPED_LABEL,
|
|
10
|
+
watchlistGroupOf,
|
|
11
|
+
watchlistGroups,
|
|
12
|
+
watchlistTakesGroups,
|
|
13
|
+
} from "../../../../portfolio/watchlist-groups";
|
|
14
|
+
import { syncConfigActiveLayoutState, useAppDispatch, useAppStateRef } from "../../../../state/app/context";
|
|
15
|
+
import { scheduleConfigSave } from "../../../../state/config-save-scheduler";
|
|
16
|
+
import type { AppConfig } from "../../../../types/config";
|
|
17
|
+
import type { ContextMenuItem } from "../../../../types/context-menu";
|
|
18
|
+
import type { TickerRecord, Watchlist } from "../../../../types/ticker";
|
|
19
|
+
import { useDialog, type PromptContext } from "../../../../ui/dialog";
|
|
20
|
+
import { logFailure } from "../../../../utils/log-failure";
|
|
21
|
+
import { usePluginAppActions } from "../../../runtime";
|
|
22
|
+
|
|
23
|
+
/** `g` moves the cursor row to a group: the row menu shows it beside Move to Group…. */
|
|
24
|
+
const MOVE_TO_GROUP_KEY = "g";
|
|
25
|
+
/** The section of the tickers in no group; no group's name is empty. */
|
|
26
|
+
const UNGROUPED_ID = "";
|
|
27
|
+
const NEW_GROUP_CHOICE = "\u0000new-group";
|
|
28
|
+
|
|
29
|
+
/** A section the pane shows collapsed, by its list: the group's name, or "" for Ungrouped. Kept in the pane's state. */
|
|
30
|
+
export interface CollapsedGroup {
|
|
31
|
+
list: string;
|
|
32
|
+
group: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A watchlist's rows under its groups, each group's rows in the order given
|
|
37
|
+
* (the table's sort), then Ungrouped. Undefined when no row is in a group, so
|
|
38
|
+
* a list without groups shows as it always has.
|
|
39
|
+
*/
|
|
40
|
+
export function buildWatchlistTableGroups(
|
|
41
|
+
watchlist: Pick<Watchlist, "id" | "groups"> | null,
|
|
42
|
+
sortedTickers: readonly TickerRecord[],
|
|
43
|
+
collapsed: readonly CollapsedGroup[],
|
|
44
|
+
): TickerTableGroup[] | undefined {
|
|
45
|
+
if (!watchlist) return undefined;
|
|
46
|
+
const sections = sectionWatchlistItems(watchlistGroups(watchlist), sortedTickers, (ticker) => ticker.metadata.ticker);
|
|
47
|
+
if (!sections) return undefined;
|
|
48
|
+
return sections.map(({ name, items }) => {
|
|
49
|
+
const id = name ?? UNGROUPED_ID;
|
|
50
|
+
return {
|
|
51
|
+
id,
|
|
52
|
+
label: name ?? t(UNGROUPED_LABEL),
|
|
53
|
+
tickers: items,
|
|
54
|
+
collapsed: collapsed.some((entry) => entry.list === watchlist.id && entry.group === id),
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The pane's collapsed sections with one of a list's flipped. */
|
|
60
|
+
export function toggleCollapsedGroup(collapsed: readonly CollapsedGroup[], list: string, group: string): CollapsedGroup[] {
|
|
61
|
+
const shown = collapsed.filter((entry) => entry.list !== list || entry.group !== group);
|
|
62
|
+
return shown.length < collapsed.length ? shown : [...collapsed, { list, group }];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Moving the rows of a personal watchlist between its groups: Move to Group…
|
|
67
|
+
* (`g`) and Remove from Group in a row's menu, and Rename Group… and Delete
|
|
68
|
+
* Group… in the pane menu while the cursor is on a group's header. `onMoved`
|
|
69
|
+
* hears the group a row went to, so the pane can show it.
|
|
70
|
+
*/
|
|
71
|
+
export function useWatchlistGroupActions({
|
|
72
|
+
watchlist,
|
|
73
|
+
cursorTicker,
|
|
74
|
+
cursorGroup,
|
|
75
|
+
enabled,
|
|
76
|
+
onMoved,
|
|
77
|
+
}: {
|
|
78
|
+
watchlist: Watchlist | null;
|
|
79
|
+
/** The ticker under the cursor, for `g`. */
|
|
80
|
+
cursorTicker: TickerRecord | null;
|
|
81
|
+
/** The named group whose header the cursor is on. */
|
|
82
|
+
cursorGroup: string | null;
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
onMoved: (symbol: string, group: string | null) => void;
|
|
85
|
+
}): ((ticker: TickerRecord) => ContextMenuItem[]) | undefined {
|
|
86
|
+
const dialog = useDialog();
|
|
87
|
+
const dispatch = useAppDispatch();
|
|
88
|
+
const stateRef = useAppStateRef();
|
|
89
|
+
const { notify } = usePluginAppActions();
|
|
90
|
+
const busyRef = useRef(false);
|
|
91
|
+
const takesGroups = !!watchlist && watchlistTakesGroups(watchlist);
|
|
92
|
+
const listId = takesGroups ? watchlist.id : null;
|
|
93
|
+
const onMovedRef = useRef(onMoved);
|
|
94
|
+
onMovedRef.current = onMoved;
|
|
95
|
+
|
|
96
|
+
// With the panes' live state in the layout, so the config keeps the cursor where the row went.
|
|
97
|
+
const save = useCallback((config: AppConfig) => {
|
|
98
|
+
const state = stateRef.current;
|
|
99
|
+
const synced = syncConfigActiveLayoutState(config, state.paneState, state.focusedPaneId);
|
|
100
|
+
dispatch({ type: "SET_CONFIG", config: synced });
|
|
101
|
+
scheduleConfigSave(synced);
|
|
102
|
+
}, [dispatch, stateRef]);
|
|
103
|
+
|
|
104
|
+
// The list as it is now, in case a sync changed it while a dialog was open.
|
|
105
|
+
const currentList = useCallback(() => (listId ? stateRef.current.config.watchlists.find((entry) => entry.id === listId) ?? null : null), [listId, stateRef]);
|
|
106
|
+
|
|
107
|
+
const fail = useCallback((error: unknown) => {
|
|
108
|
+
notify({ type: "error", body: error instanceof Error ? error.message : String(error) });
|
|
109
|
+
}, [notify]);
|
|
110
|
+
|
|
111
|
+
const moveTo = useCallback((symbol: string, group: string | null) => {
|
|
112
|
+
const list = currentList();
|
|
113
|
+
if (!list) return;
|
|
114
|
+
try {
|
|
115
|
+
const result = setWatchlistGroup(stateRef.current.config, list.id, [symbol], group);
|
|
116
|
+
if (result.moved.length > 0) save(result.config);
|
|
117
|
+
onMovedRef.current(symbol, result.group);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
fail(error);
|
|
120
|
+
}
|
|
121
|
+
}, [currentList, fail, save, stateRef]);
|
|
122
|
+
|
|
123
|
+
/** The name a new group is given, typed in a prompt; null when none was. */
|
|
124
|
+
const askName = useCallback(async (title: string, body: string | null, confirmLabel: string, initialValue = "") => {
|
|
125
|
+
const typed = await dialog.prompt<string>({
|
|
126
|
+
content: (context) => (
|
|
127
|
+
<TextPromptDialog {...context} title={title} body={body ? [body] : undefined} label={t("Name")} initialValue={initialValue}
|
|
128
|
+
placeholder={t("Energy")} confirmLabel={confirmLabel} width={52} />
|
|
129
|
+
),
|
|
130
|
+
});
|
|
131
|
+
return typed?.trim() ? typed : null;
|
|
132
|
+
}, [dialog]);
|
|
133
|
+
|
|
134
|
+
const promptMove = useCallback(async (symbol: string) => {
|
|
135
|
+
const list = currentList();
|
|
136
|
+
if (!list || busyRef.current) return;
|
|
137
|
+
busyRef.current = true;
|
|
138
|
+
try {
|
|
139
|
+
const current = watchlistGroupOf(list, symbol);
|
|
140
|
+
const others = watchlistGroups(list).filter((group) => group.name !== current);
|
|
141
|
+
let choice: string | undefined = NEW_GROUP_CHOICE;
|
|
142
|
+
if (others.length > 0) {
|
|
143
|
+
choice = await dialog.prompt<string>({
|
|
144
|
+
content: (context: PromptContext<string>) => (
|
|
145
|
+
<ChoiceDialog {...context} title={tf("Move {symbol} to Group", { symbol })} choices={[
|
|
146
|
+
...others.map((group) => ({ id: group.name, label: group.name })),
|
|
147
|
+
{ id: NEW_GROUP_CHOICE, label: t("New Group…") },
|
|
148
|
+
]} />
|
|
149
|
+
),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (choice == null) return;
|
|
153
|
+
const name = choice === NEW_GROUP_CHOICE
|
|
154
|
+
? await askName(t("New Group"), tf("{symbol} moves to it in {watchlist}.", { symbol, watchlist: list.name }), t("Move"))
|
|
155
|
+
: choice;
|
|
156
|
+
if (name != null) moveTo(symbol, name);
|
|
157
|
+
} finally {
|
|
158
|
+
busyRef.current = false;
|
|
159
|
+
}
|
|
160
|
+
}, [askName, currentList, dialog, moveTo]);
|
|
161
|
+
|
|
162
|
+
const startMove = useCallback((symbol: string) => {
|
|
163
|
+
promptMove(symbol).catch((error: unknown) => {
|
|
164
|
+
fail(error);
|
|
165
|
+
logFailure("portfolio-list.groups", "Move to group failed")(error);
|
|
166
|
+
});
|
|
167
|
+
}, [fail, promptMove]);
|
|
168
|
+
|
|
169
|
+
const rowMenuItems = useMemo(() => listId ? (ticker: TickerRecord): ContextMenuItem[] => {
|
|
170
|
+
const symbol = ticker.metadata.ticker;
|
|
171
|
+
const inGroup = watchlistGroupOf(currentList(), symbol) != null;
|
|
172
|
+
return [
|
|
173
|
+
{ id: "watchlist:move-to-group", label: t("Move to Group…"), accelerator: MOVE_TO_GROUP_KEY, onSelect: () => startMove(symbol) },
|
|
174
|
+
...inGroup ? [{ id: "watchlist:remove-from-group", label: t("Remove from Group"), onSelect: () => moveTo(symbol, null) }] : [],
|
|
175
|
+
];
|
|
176
|
+
// Built again when the list's groups change, so the cursor row's menu offers Remove from Group once it is in one.
|
|
177
|
+
} : undefined, [currentList, listId, moveTo, startMove, watchlist?.groups]);
|
|
178
|
+
|
|
179
|
+
const cursorSymbol = cursorTicker?.metadata.ticker ?? null;
|
|
180
|
+
usePaneFooter("portfolio-list-groups", () => enabled && listId && cursorSymbol ? {
|
|
181
|
+
keys: [{ id: "move-to-group", key: MOVE_TO_GROUP_KEY, label: "", title: t("Move to Group"), onPress: () => startMove(cursorSymbol) }],
|
|
182
|
+
} : null, [cursorSymbol, enabled, listId, startMove]);
|
|
183
|
+
|
|
184
|
+
const renameGroup = useCallback(async (group: string) => {
|
|
185
|
+
const list = currentList();
|
|
186
|
+
if (!list) return;
|
|
187
|
+
const name = await askName(t("Rename Group"), null, t("Rename"), group);
|
|
188
|
+
if (name == null) return;
|
|
189
|
+
try {
|
|
190
|
+
save(renameWatchlistGroup(stateRef.current.config, list.id, group, name));
|
|
191
|
+
} catch (error) {
|
|
192
|
+
fail(error);
|
|
193
|
+
}
|
|
194
|
+
}, [askName, currentList, fail, save, stateRef]);
|
|
195
|
+
|
|
196
|
+
const deleteGroup = useCallback(async (group: string) => {
|
|
197
|
+
const list = currentList();
|
|
198
|
+
const symbols = watchlistGroups(list).find((entry) => entry.name === group)?.symbols ?? [];
|
|
199
|
+
if (!list || symbols.length === 0) return;
|
|
200
|
+
const confirmed = await confirmDialog(dialog, {
|
|
201
|
+
title: tf("Delete the group {group}?", { group }),
|
|
202
|
+
body: [t("Its tickers stay in the list, in no group.")],
|
|
203
|
+
confirmLabel: t("Delete"),
|
|
204
|
+
});
|
|
205
|
+
if (!confirmed) return;
|
|
206
|
+
try {
|
|
207
|
+
const result = setWatchlistGroup(stateRef.current.config, list.id, symbols, null);
|
|
208
|
+
if (result.moved.length > 0) save(result.config);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
fail(error);
|
|
211
|
+
}
|
|
212
|
+
}, [currentList, dialog, fail, save, stateRef]);
|
|
213
|
+
|
|
214
|
+
usePaneMenuItems("portfolio-list-group-header", () => enabled && listId && cursorGroup ? [
|
|
215
|
+
{ id: "rename-group", label: t("Rename Group…"), onSelect: () => { renameGroup(cursorGroup).catch(logFailure("portfolio-list.groups", "Rename group failed")); } },
|
|
216
|
+
{ id: "delete-group", label: t("Delete Group…"), onSelect: () => { deleteGroup(cursorGroup).catch(logFailure("portfolio-list.groups", "Delete group failed")); } },
|
|
217
|
+
] : null, [cursorGroup, deleteGroup, enabled, listId, renameGroup]);
|
|
218
|
+
|
|
219
|
+
return rowMenuItems;
|
|
220
|
+
}
|
|
@@ -127,6 +127,10 @@ import {
|
|
|
127
127
|
} from "../../../../portfolio/allocation";
|
|
128
128
|
import { allocationSummaryRows, CASH_ROW_KEY } from "../allocation-rows";
|
|
129
129
|
import { useTargetWeightActions, type TargetRow } from "./target-weights";
|
|
130
|
+
import { groupIdOfRowKey, groupRowKey } from "../../../../components/ticker/list-table-view";
|
|
131
|
+
import { withoutWatchlistGroupSymbols } from "../../../../portfolio/watchlist-groups";
|
|
132
|
+
import { scheduleConfigSave } from "../../../../state/config-save-scheduler";
|
|
133
|
+
import { buildWatchlistTableGroups, toggleCollapsedGroup, useWatchlistGroupActions, type CollapsedGroup } from "./groups";
|
|
130
134
|
|
|
131
135
|
/** Columns that need the portfolio's total. */
|
|
132
136
|
const ALLOCATION_COLUMN_IDS = new Set(["weight", "drift", "trade", "trade_value"]);
|
|
@@ -142,6 +146,9 @@ const firstSortDirection = (columnId: string) => columnId === "drift" ? "desc" a
|
|
|
142
146
|
const NO_COLLECTION_SORTS: Record<string, CollectionSortPreference> = {};
|
|
143
147
|
/** What the pane's `cursorSummaryRow` holds while the cursor is on the CASH row. */
|
|
144
148
|
const CASH_SUMMARY_ROW = "cash";
|
|
149
|
+
/** What it holds, before the group's id, while the cursor is on a watchlist group's header. */
|
|
150
|
+
const GROUP_SUMMARY_ROW = "group:";
|
|
151
|
+
const NO_COLLAPSED_GROUPS: CollapsedGroup[] = [];
|
|
145
152
|
|
|
146
153
|
export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
147
154
|
const activateTicker = useTickerSourceActivate();
|
|
@@ -157,20 +164,29 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
157
164
|
|
|
158
165
|
const [currentCollectionId, setCurrentCollectionId] = usePaneStateValue<string>("collectionId", paneCollection.collectionId ?? "");
|
|
159
166
|
const [committedCursorSymbol, setCommittedCursorSymbol] = usePaneStateValue<string | null>("cursorSymbol", null);
|
|
160
|
-
// The CASH row's cursor
|
|
161
|
-
// read, only ever holds a ticker, and keeps the last one while the cursor is on
|
|
167
|
+
// The CASH row's and a group header's cursor have a key of their own: `cursorSymbol`, which followers, recent
|
|
168
|
+
// tickers and saved layouts read, only ever holds a ticker, and keeps the last one while the cursor is on them.
|
|
162
169
|
const [cursorSummaryRow, setCursorSummaryRow] = usePaneStateValue<string | null>("cursorSummaryRow", null);
|
|
163
|
-
const committedCursorRow = cursorSummaryRow === CASH_SUMMARY_ROW ? CASH_ROW_KEY
|
|
170
|
+
const committedCursorRow = cursorSummaryRow === CASH_SUMMARY_ROW ? CASH_ROW_KEY
|
|
171
|
+
: cursorSummaryRow?.startsWith(GROUP_SUMMARY_ROW) ? groupRowKey(cursorSummaryRow.slice(GROUP_SUMMARY_ROW.length))
|
|
172
|
+
: committedCursorSymbol;
|
|
164
173
|
const commitCursorRow = useCallback((row: string | null) => {
|
|
165
174
|
if (row === CASH_ROW_KEY) {
|
|
166
175
|
setCursorSummaryRow(CASH_SUMMARY_ROW);
|
|
167
176
|
return;
|
|
168
177
|
}
|
|
178
|
+
const group = groupIdOfRowKey(row);
|
|
179
|
+
if (group != null) {
|
|
180
|
+
setCursorSummaryRow(`${GROUP_SUMMARY_ROW}${group}`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
169
183
|
setCursorSummaryRow(null);
|
|
170
184
|
setCommittedCursorSymbol(row);
|
|
171
185
|
}, [setCommittedCursorSymbol, setCursorSummaryRow]);
|
|
172
186
|
const [collectionSorts, setCollectionSorts] = usePaneStateValue<Record<string, CollectionSortPreference>>("collectionSorts", NO_COLLECTION_SORTS);
|
|
173
187
|
const [cashDrawerExpanded, setCashDrawerExpanded] = usePaneStateValue<boolean>("cashDrawerExpanded", false);
|
|
188
|
+
// The watchlist groups this pane shows collapsed, of any list.
|
|
189
|
+
const [collapsedGroups, setCollapsedGroups] = usePaneStateValue<CollapsedGroup[]>("collapsedGroups", NO_COLLAPSED_GROUPS);
|
|
174
190
|
const [, setViewMode] = usePaneSettingValue<PortfolioViewMode>("viewMode", "table");
|
|
175
191
|
const updateColumnIds = useOptionalPaneSettingUpdater(paneInstance?.instanceId ?? null, "columnIds");
|
|
176
192
|
|
|
@@ -204,6 +220,9 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
204
220
|
? config.portfolios.find((portfolio) => portfolio.id === activeCollectionId) ?? null
|
|
205
221
|
: null
|
|
206
222
|
), [activeCollectionId, config.portfolios, isPortfolioTab]);
|
|
223
|
+
const currentWatchlist = useMemo(() => (
|
|
224
|
+
isPortfolioTab ? null : config.watchlists.find((watchlist) => watchlist.id === activeCollectionId) ?? null
|
|
225
|
+
), [activeCollectionId, config.watchlists, isPortfolioTab]);
|
|
207
226
|
const viewMode: PortfolioViewMode = isPortfolioTab ? paneSettings.viewMode : "table";
|
|
208
227
|
const valuationBasis = paneSettings.valueAtClose ? "regular-close" as const : "latest-print" as const;
|
|
209
228
|
|
|
@@ -421,6 +440,22 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
421
440
|
}),
|
|
422
441
|
[orderedSymbols, tickerBySymbol],
|
|
423
442
|
);
|
|
443
|
+
// A watchlist with groups shows its rows under them, each group sorted on its own; any other list has none.
|
|
444
|
+
const tableGroups = useMemo(
|
|
445
|
+
() => viewMode === "table" ? buildWatchlistTableGroups(currentWatchlist, sortedTickers, collapsedGroups) : undefined,
|
|
446
|
+
[collapsedGroups, currentWatchlist, sortedTickers, viewMode],
|
|
447
|
+
);
|
|
448
|
+
// The rows the table shows, in its order: a collapsed group's are left out.
|
|
449
|
+
const displayedTickers = useMemo(
|
|
450
|
+
() => tableGroups ? tableGroups.flatMap((group) => group.collapsed ? [] : group.tickers) : sortedTickers,
|
|
451
|
+
[sortedTickers, tableGroups],
|
|
452
|
+
);
|
|
453
|
+
// The order quotes stream in: the rows shown, which the visible range counts, then a collapsed group's, off screen.
|
|
454
|
+
const streamOrder = useMemo(
|
|
455
|
+
() => tableGroups ? [...displayedTickers, ...tableGroups.flatMap((group) => group.collapsed ? group.tickers : [])] : sortedTickers,
|
|
456
|
+
[displayedTickers, sortedTickers, tableGroups],
|
|
457
|
+
);
|
|
458
|
+
const shownGroupKeys = useMemo(() => new Set(tableGroups?.map((group) => groupRowKey(group.id))), [tableGroups]);
|
|
424
459
|
|
|
425
460
|
// What LAST shows for each row, snapshotted when the table goes out of sight.
|
|
426
461
|
const priceColumn = viewMode === "table" ? columns.find((column) => column.id === "price") : undefined;
|
|
@@ -454,7 +489,7 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
454
489
|
getSharedMarketDataCoordinator()?.warmTickerGaps(instrument);
|
|
455
490
|
}, []);
|
|
456
491
|
const noteCursorForPrefetch = useCursorNeighborPrefetch({
|
|
457
|
-
tickers:
|
|
492
|
+
tickers: displayedTickers,
|
|
458
493
|
cursorSymbol,
|
|
459
494
|
portfolioId: financialsInstrumentOptions.portfolioId,
|
|
460
495
|
enabled: appActive,
|
|
@@ -638,25 +673,27 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
638
673
|
return;
|
|
639
674
|
}
|
|
640
675
|
|
|
641
|
-
// The cash row
|
|
642
|
-
const hasSelection = cursorSymbol && ((cursorSymbol === CASH_ROW_KEY && cashRowShown)
|
|
643
|
-
||
|
|
676
|
+
// The cash row and a group's header take the cursor too, while they are shown.
|
|
677
|
+
const hasSelection = cursorSymbol && ((cursorSymbol === CASH_ROW_KEY && cashRowShown) || shownGroupKeys.has(cursorSymbol)
|
|
678
|
+
|| displayedTickers.some((ticker) => ticker.metadata.ticker === cursorSymbol));
|
|
644
679
|
if (!hasSelection) {
|
|
645
|
-
|
|
680
|
+
// Every group collapsed: the first header.
|
|
681
|
+
const first = displayedTickers[0]?.metadata.ticker ?? (tableGroups?.[0] ? groupRowKey(tableGroups[0].id) : null);
|
|
682
|
+
if (first) setCursorSymbol(first, { immediate: true });
|
|
646
683
|
}
|
|
647
|
-
}, [cashRowShown, cursorSymbol, setCursorSymbol, sortedTickers]);
|
|
684
|
+
}, [cashRowShown, cursorSymbol, displayedTickers, setCursorSymbol, shownGroupKeys, sortedTickers.length, tableGroups]);
|
|
648
685
|
|
|
649
686
|
const effectiveStreamWindow = useMemo(() => (
|
|
650
687
|
viewMode === "grid"
|
|
651
688
|
? { start: 0, end: Math.min(sortedTickers.length, 96) }
|
|
652
689
|
: {
|
|
653
690
|
start: streamWindow.start,
|
|
654
|
-
end: Math.min(
|
|
691
|
+
end: Math.min(displayedTickers.length, Math.max(streamWindow.end, height + 4)),
|
|
655
692
|
}
|
|
656
|
-
), [height, sortedTickers.length, streamWindow, viewMode]);
|
|
693
|
+
), [displayedTickers.length, height, sortedTickers.length, streamWindow, viewMode]);
|
|
657
694
|
|
|
658
695
|
const perpetualsInViewKey = showsPerpetuals
|
|
659
|
-
?
|
|
696
|
+
? displayedTickers.slice(effectiveStreamWindow.start, effectiveStreamWindow.end).map((ticker) => ticker.metadata.ticker).join("\u001f")
|
|
660
697
|
: "";
|
|
661
698
|
useEffect(() => {
|
|
662
699
|
setPerpetualsInView(new Set(perpetualsInViewKey ? perpetualsInViewKey.split("\u001f") : []));
|
|
@@ -665,7 +702,7 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
665
702
|
usePortfolioPaneStreaming({
|
|
666
703
|
appActive,
|
|
667
704
|
activeCollectionId: isPortfolioTab ? activeCollectionId : undefined,
|
|
668
|
-
sortedTickers,
|
|
705
|
+
sortedTickers: streamOrder,
|
|
669
706
|
cursorSymbol,
|
|
670
707
|
streamWindow: effectiveStreamWindow,
|
|
671
708
|
isPortfolioTab,
|
|
@@ -721,8 +758,8 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
721
758
|
[activeCollectionId, config],
|
|
722
759
|
);
|
|
723
760
|
const selectedTicker = cursorSymbol ? tickerBySymbol.get(cursorSymbol) : undefined;
|
|
724
|
-
const sortedTickersRef = useRef(
|
|
725
|
-
sortedTickersRef.current =
|
|
761
|
+
const sortedTickersRef = useRef(displayedTickers);
|
|
762
|
+
sortedTickersRef.current = displayedTickers;
|
|
726
763
|
const removingRef = useRef(false);
|
|
727
764
|
// Asks first: a manual portfolio's position goes with the row, and a stray
|
|
728
765
|
// key should not take either.
|
|
@@ -752,6 +789,15 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
752
789
|
const symbols = sortedTickersRef.current.map((ticker) => ticker.metadata.ticker);
|
|
753
790
|
setCursorSymbol(cursorAfterRemoval(symbols, symbol), { immediate: true });
|
|
754
791
|
dispatch({ type: "UPDATE_TICKER", ticker: result.ticker });
|
|
792
|
+
// Out of its group too: added back later, it starts in none.
|
|
793
|
+
if (collection.kind === "watchlist") {
|
|
794
|
+
const config = appStateRef.current.config;
|
|
795
|
+
const next = withoutWatchlistGroupSymbols(config, collection.id, [symbol]);
|
|
796
|
+
if (next !== config) {
|
|
797
|
+
dispatch({ type: "SET_CONFIG", config: next });
|
|
798
|
+
scheduleConfigSave(next);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
755
801
|
notify({ type: "success", body: tf("Removed {symbol} from {collection}.", { symbol, collection: collection.name }) });
|
|
756
802
|
} catch {
|
|
757
803
|
notify({ type: "error", body: tf("Failed to remove {symbol}.", { symbol }) });
|
|
@@ -796,6 +842,32 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
796
842
|
const listedSymbols = useMemo(() => new Set(collectionTickers.map((ticker) => ticker.metadata.ticker)), [collectionTickers]);
|
|
797
843
|
useTargetWeightActions({ portfolio: currentPortfolio, row: targetRow, listedSymbols, enabled: focused && viewMode === "table" && !quickAddFocused });
|
|
798
844
|
|
|
845
|
+
// A group's header collapses or expands its rows; one collapsing with the cursor in it leaves the cursor on it.
|
|
846
|
+
const toggleGroup = useCallback((id: string) => {
|
|
847
|
+
const group = tableGroups?.find((entry) => entry.id === id);
|
|
848
|
+
if (!group || !activeCollectionId) return;
|
|
849
|
+
if (!group.collapsed && group.tickers.some((ticker) => ticker.metadata.ticker === cursorSymbol)) {
|
|
850
|
+
setCursorSymbol(groupRowKey(id), { immediate: true });
|
|
851
|
+
}
|
|
852
|
+
setCollapsedGroups((current) => toggleCollapsedGroup(current, activeCollectionId, id));
|
|
853
|
+
}, [activeCollectionId, cursorSymbol, setCollapsedGroups, setCursorSymbol, tableGroups]);
|
|
854
|
+
// A row moved to a group that is collapsed opens it, so the cursor stays on the row.
|
|
855
|
+
const showMovedRow = useCallback((symbol: string, group: string | null) => {
|
|
856
|
+
if (!activeCollectionId) return;
|
|
857
|
+
const id = group ?? "";
|
|
858
|
+
setCollapsedGroups((current) => current.filter((entry) => entry.list !== activeCollectionId || entry.group !== id));
|
|
859
|
+
setCursorSymbol(symbol, { immediate: true });
|
|
860
|
+
}, [activeCollectionId, setCollapsedGroups, setCursorSymbol]);
|
|
861
|
+
const cursorGroupId = groupIdOfRowKey(cursorSymbol);
|
|
862
|
+
const groupRowMenuItems = useWatchlistGroupActions({
|
|
863
|
+
watchlist: currentWatchlist,
|
|
864
|
+
cursorTicker: selectedTicker ?? null,
|
|
865
|
+
// Ungrouped has no name to change.
|
|
866
|
+
cursorGroup: cursorGroupId ? cursorGroupId : null,
|
|
867
|
+
enabled: focused && viewMode === "table" && !quickAddFocused,
|
|
868
|
+
onMoved: showMovedRow,
|
|
869
|
+
});
|
|
870
|
+
|
|
799
871
|
usePaneFooter("portfolio-list", () => ({
|
|
800
872
|
info: [
|
|
801
873
|
...offlineBrokerFooter.asOf,
|
|
@@ -942,6 +1014,9 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
942
1014
|
exportName={activeCollectionEntry?.name}
|
|
943
1015
|
allocationRows={allocationRows}
|
|
944
1016
|
columnReorder={columnReorder}
|
|
1017
|
+
groups={tableGroups}
|
|
1018
|
+
onToggleGroup={toggleGroup}
|
|
1019
|
+
rowMenuItems={groupRowMenuItems}
|
|
945
1020
|
/>
|
|
946
1021
|
) : (
|
|
947
1022
|
<PortfolioGrid
|
|
@@ -8,7 +8,8 @@ import { useDataTableSortMenu } from "../../../components/data-table/sort-menu";
|
|
|
8
8
|
import { followLiveSparklinePrice } from "../../../components/price-sparkline/model";
|
|
9
9
|
import { PRICE_SPARKLINE_COLUMN_ID } from "../../../components/price-sparkline/view";
|
|
10
10
|
import type { QuoteFlashDirection } from "../../../components/quote-flash";
|
|
11
|
-
import type { TickerTableCell, TickerTableSummaryRow } from "../../../components/ticker/list-table-view";
|
|
11
|
+
import type { TickerTableCell, TickerTableGroup, TickerTableSummaryRow } from "../../../components/ticker/list-table-view";
|
|
12
|
+
import type { ContextMenuItem } from "../../../types/context-menu";
|
|
12
13
|
import { createRowValueCache } from "../../../components/ui/row-value-cache";
|
|
13
14
|
import type { DataTableColumnReorder } from "../../../components/ui";
|
|
14
15
|
import type { ColumnConfig } from "../../../types/config";
|
|
@@ -215,6 +216,9 @@ export function PortfolioTickerTable({
|
|
|
215
216
|
exportName,
|
|
216
217
|
allocationRows,
|
|
217
218
|
columnReorder,
|
|
219
|
+
groups,
|
|
220
|
+
onToggleGroup,
|
|
221
|
+
rowMenuItems,
|
|
218
222
|
}: {
|
|
219
223
|
columns: ColumnConfig[];
|
|
220
224
|
focused?: boolean;
|
|
@@ -253,6 +257,11 @@ export function PortfolioTickerTable({
|
|
|
253
257
|
allocationRows?: readonly TickerTableSummaryRow[];
|
|
254
258
|
/** Header drags rewrite the pane's Columns setting (`DataTableProps.columnReorder`). */
|
|
255
259
|
columnReorder?: DataTableColumnReorder;
|
|
260
|
+
/** A watchlist's groups, each holding its share of `sortedTickers` in their order. */
|
|
261
|
+
groups?: readonly TickerTableGroup[];
|
|
262
|
+
onToggleGroup?: (id: string) => void;
|
|
263
|
+
/** The pane's own items in a row's menu. */
|
|
264
|
+
rowMenuItems?: (ticker: TickerRecord) => ContextMenuItem[];
|
|
256
265
|
}) {
|
|
257
266
|
const cellCacheRef = useRef(createRowValueCache<string, ReturnType<typeof getColumnValue> & TickerTableCell>(5000));
|
|
258
267
|
const openPerpetualRef = useRef(onOpenPerpetual);
|
|
@@ -413,6 +422,9 @@ export function PortfolioTickerTable({
|
|
|
413
422
|
rootHeight={rootHeight}
|
|
414
423
|
exportName={exportName}
|
|
415
424
|
columnReorder={columnReorder}
|
|
425
|
+
groups={groups}
|
|
426
|
+
onToggleGroup={onToggleGroup}
|
|
427
|
+
rowMenuItems={rowMenuItems}
|
|
416
428
|
/>
|
|
417
429
|
);
|
|
418
430
|
}
|
|
@@ -164,8 +164,8 @@ export function buildEventColumns(width: number, unit?: string, variant: "corpor
|
|
|
164
164
|
{ id: "period", label: "PERIOD", width: 9, align: "left" },
|
|
165
165
|
{ id: "eps", label: "EPS", width: unit ? 7 : 11, align: "right" },
|
|
166
166
|
{ id: "revenue", label: "REVENUE", width: unit ? 9 : 13, align: "right" },
|
|
167
|
-
{ id: "surprise", label: "EPS SURP", width: 9, align: "right" },
|
|
168
|
-
{ id: "growth", label: "YOY GROWTH", width: 14, align: "right" },
|
|
167
|
+
{ id: "surprise", label: "EPS SURP", width: 9, align: "right", omitWhenEmpty: "visible" },
|
|
168
|
+
{ id: "growth", label: "YOY GROWTH", width: 14, align: "right", omitWhenEmpty: true },
|
|
169
169
|
{ id: "detail", label: "DETAIL", width: 9, align: "left", flexGrow: 1 },
|
|
170
170
|
], width, ["detail", "growth", "revenue"]);
|
|
171
171
|
}
|
|
@@ -713,6 +713,8 @@ export function CorporateActionsView({
|
|
|
713
713
|
onRootKeyDown={handleKeyDown}
|
|
714
714
|
columns={columns}
|
|
715
715
|
items={rows}
|
|
716
|
+
scrollToIndex={selectedIdx}
|
|
717
|
+
scrollToIndexVersion={rows.length}
|
|
716
718
|
sortColumnId={null}
|
|
717
719
|
sortDirection="asc"
|
|
718
720
|
getItemKey={eventRowKey}
|
|
@@ -6,6 +6,7 @@ import { EXTENDED_SESSION_LABELS, type ExtendedSession } from "../../../market-d
|
|
|
6
6
|
import { MISSING_VALUE, formatCompact, formatCurrency, formatLevelPercent, formatNumber, formatPercent, formatPercentRaw } from "../../../utils/format";
|
|
7
7
|
import { loadHeadlessFinancials, loadHeadlessSymbols } from "../shared/headless-market-data";
|
|
8
8
|
import { quoteFreshnessFields } from "../shared/report-freshness";
|
|
9
|
+
import { formatUtcWeekdayTime } from "../../../utils/utc-time";
|
|
9
10
|
import {
|
|
10
11
|
RELATIVE_VALUATION_STALE_FUNDAMENTALS_NOTICE, RELATIVE_VALUATION_STALE_QUOTE_NOTICE, relativeValuationValues, type RelativeValuationGapKey,
|
|
11
12
|
} from "./relative-valuation-model";
|
|
@@ -36,10 +37,13 @@ function gapText(row: Record<string, unknown>, key: RelativeValuationGapKey): st
|
|
|
36
37
|
function extendedColumn(session: ExtendedSession): HeadlessPaneColumn {
|
|
37
38
|
return {
|
|
38
39
|
key: "extendedPrice",
|
|
39
|
-
header:
|
|
40
|
+
// When the print was, in UTC as the header says: a Friday evening's after-hours print read on a Sunday says so.
|
|
41
|
+
header: `${EXTENDED_SESSION_LABELS[session]} UTC`,
|
|
42
|
+
literalHeader: true,
|
|
40
43
|
align: "right",
|
|
41
44
|
format: (value, row) => row.extendedSession === session && typeof value === "number"
|
|
42
|
-
? `${price(value, row)}${row.extendedMark ? " mid" : ""} ${percent(row.extendedChangePercent)}
|
|
45
|
+
? [`${price(value, row)}${row.extendedMark ? " mid" : ""} ${percent(row.extendedChangePercent)}`,
|
|
46
|
+
typeof row.quoteAsOf === "number" ? formatUtcWeekdayTime(row.quoteAsOf) : ""].filter(Boolean).join(" ")
|
|
43
47
|
: MISSING_VALUE,
|
|
44
48
|
};
|
|
45
49
|
}
|
|
@@ -99,10 +103,12 @@ const VALUATION_COLUMNS: HeadlessPaneColumn[] = [
|
|
|
99
103
|
const multiple = multipleOf(value, row);
|
|
100
104
|
return multiple == null ? gapText(row, key) : formatPriceEarnings(multiple);
|
|
101
105
|
},
|
|
102
|
-
// A P/E on a fiscal year's EPS, where no four newer quarters were filed, says which year
|
|
106
|
+
// A P/E on a fiscal year's EPS, where no four newer quarters were filed, says which year, and a forward P/E the
|
|
107
|
+
// year of its consensus; an export has them in P/E period and Fwd P/E period.
|
|
103
108
|
textFormat: (value: unknown, row: Record<string, unknown>) => {
|
|
104
109
|
const multiple = multipleOf(value, row);
|
|
105
|
-
const
|
|
110
|
+
const values = row as Partial<ReturnType<typeof relativeValuationValues>>;
|
|
111
|
+
const year = multiple === NOT_MEANINGFUL ? null : key === "trailingPE" ? values.trailingPEPeriod : values.forwardPEPeriod;
|
|
106
112
|
return multiple == null ? gapText(row, key) : year ? `${formatPriceEarnings(multiple)} ${year}` : formatPriceEarnings(multiple);
|
|
107
113
|
},
|
|
108
114
|
};
|
|
@@ -130,13 +136,17 @@ const VALUATION_COLUMNS: HeadlessPaneColumn[] = [
|
|
|
130
136
|
|
|
131
137
|
/**
|
|
132
138
|
* The period each export's figure is of, in a column after it, where the text
|
|
133
|
-
* table puts it beside the figure: a P/E on a fiscal year's EPS (`FY Mar-26`),
|
|
139
|
+
* table puts it beside the figure: a P/E on a fiscal year's EPS (`FY Mar-26`), a
|
|
140
|
+
* forward P/E's consensus year (`FY28`),
|
|
134
141
|
* a half's revenue growth (`H2 FY26 vs H2 FY25`) or a quarter's (`quarter to
|
|
135
142
|
* 2026-09-30`), a fiscal year's margin (`FY25`); `TTM` for a trailing figure.
|
|
136
143
|
*/
|
|
137
144
|
const VALUATION_PERIOD_COLUMNS: Record<string, HeadlessPaneColumn> = {
|
|
138
145
|
trailingPE: { key: "trailingPEPeriod", header: "P/E period",
|
|
139
146
|
format: (value, row) => row.trailingPE == null && !(row.reportedMultiples as Record<string, unknown> | undefined)?.trailingPE ? "" : typeof value === "string" && value ? value : "TTM" },
|
|
147
|
+
// Added after the export's other columns: it closes the row, so none of theirs moves.
|
|
148
|
+
forwardPE: { key: "forwardPEPeriod", header: "Fwd P/E period", exportLast: true,
|
|
149
|
+
format: (value, row) => row.forwardPE == null && !(row.reportedMultiples as Record<string, unknown> | undefined)?.forwardPE ? "" : typeof value === "string" ? value : "" },
|
|
140
150
|
revenueGrowth: { key: "revenueGrowthHalf", header: "Revenue YoY period",
|
|
141
151
|
format: (value, row) => row.revenueGrowth == null ? "" : typeof value === "string" && value ? value
|
|
142
152
|
: typeof row.revenueGrowthQuarter === "string" ? `quarter to ${row.revenueGrowthQuarter}` : "" },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MISSING_VALUE, formatCompact, formatCurrency } from "../../../utils/format";
|
|
2
|
-
import { comparablePriceEarnings, notMeaningfulMultiples } from "../../../utils/price-earnings";
|
|
2
|
+
import { comparablePriceEarnings, forwardFiscalYear, notMeaningfulMultiples } from "../../../utils/price-earnings";
|
|
3
3
|
import { marketCapBasisNote, viewMarketCapitalization, withheldMarketCap } from "../../../utils/market-capitalization";
|
|
4
4
|
import {
|
|
5
5
|
enterpriseValueNotMeaningful, enterpriseValueReconciliationNote, enterpriseValueWithdrawn, fundamentalsCurrency,
|
|
@@ -170,6 +170,10 @@ export function relativeValuationValues(snapshot: TickerFinancials | null) {
|
|
|
170
170
|
const trailingPEPeriod = reportedMultiples.trailingPE != null && !trailingNotMeaningful && financials
|
|
171
171
|
? trailingEpsFiscalYear(financials) ?? null : null;
|
|
172
172
|
const forwardPE = forwardNotMeaningful ? null : comparablePriceEarnings(reportedMultiples.forwardPE);
|
|
173
|
+
// The fiscal year the consensus is for, as `valuation` and DES name it (`FY28`): for a September filer, next year
|
|
174
|
+
// is two fiscal years out.
|
|
175
|
+
const forwardPEPeriod = (forwardPE != null || reportedMultiples.forwardPE != null) && !forwardNotMeaningful
|
|
176
|
+
? forwardFiscalYear(fundamentals?.forwardEpsPeriodEnd) : null;
|
|
173
177
|
// Every figure a row lacks says why, so an export's blank cell is never silent: N/M multiples say so themselves.
|
|
174
178
|
const gaps: Partial<Record<RelativeValuationGapKey, string>> = {};
|
|
175
179
|
if (session.price == null) gaps.price = quoteStale ? QUOTE_STALE : NOT_REPORTED;
|
|
@@ -218,6 +222,8 @@ export function relativeValuationValues(snapshot: TickerFinancials | null) {
|
|
|
218
222
|
/** The fiscal year the P/E's EPS is ("FY Mar-26") when it is a year's filed figure, not the trailing four quarters'; null otherwise. */
|
|
219
223
|
trailingPEPeriod,
|
|
220
224
|
forwardPE,
|
|
225
|
+
/** The fiscal year of the consensus EPS the forward P/E is on (`FY28`); null when unknown or there is none. */
|
|
226
|
+
forwardPEPeriod,
|
|
221
227
|
reportedMultiples,
|
|
222
228
|
/**
|
|
223
229
|
* Why a figure is N/M: a P/E's earnings base is zero or a loss, EV/S's enterprise value is at or below zero,
|
|
@@ -110,6 +110,7 @@ function buildRelativeColumns(
|
|
|
110
110
|
peNamesYear = false,
|
|
111
111
|
growthLabel = REVENUE_GROWTH_LABEL,
|
|
112
112
|
symbolWidth = SYMBOL_WIDTH,
|
|
113
|
+
forwardNamesYear = false,
|
|
113
114
|
): RelativeColumn[] {
|
|
114
115
|
// The name gives back what a wide ticker takes, so the figures keep their place.
|
|
115
116
|
const nameWidth = Math.max(10, 16 - (symbolWidth - SYMBOL_WIDTH));
|
|
@@ -129,7 +130,8 @@ function buildRelativeColumns(
|
|
|
129
130
|
{ id: "marketCap", label: `MCAP ${baseCurrency}`, width: capWidth, align: "right" },
|
|
130
131
|
// Wider while a peer's P/E is on its latest fiscal year's EPS and names it ("24.6 FY Mar-26").
|
|
131
132
|
{ id: "trailingPE", label: "P/E", width: peNamesYear ? 14 : metricWidth, align: "right" },
|
|
132
|
-
|
|
133
|
+
// Wider while a peer's forward P/E names the fiscal year of its consensus ("24.8 FY28").
|
|
134
|
+
{ id: "forwardPE", label: "FWD", width: forwardNamesYear ? 10 : metricWidth, align: "right" },
|
|
133
135
|
{ id: "evSales", label: "EV/S", width: metricWidth, align: "right" },
|
|
134
136
|
{ id: "fcfYield", label: "FCF%", width: metricWidth, align: "right" },
|
|
135
137
|
// Latest quarter against the year before, and a trailing-twelve-month margin.
|
|
@@ -284,11 +286,12 @@ export function RelativeValuationPane({ focused, width, height }: PaneProps) {
|
|
|
284
286
|
const extendedSessionsKey = extendedSessionsOf(rows).join(",");
|
|
285
287
|
const marginNamesYear = rows.some((row) => row.operatingMarginPeriod != null);
|
|
286
288
|
const peNamesYear = rows.some((row) => row.trailingPEPeriod != null);
|
|
289
|
+
const forwardNamesYear = rows.some((row) => row.forwardPEPeriod != null);
|
|
287
290
|
const growthLabel = revenueGrowthHeader(rows, REVENUE_GROWTH_LABEL, PERIOD_REVENUE_GROWTH_LABEL);
|
|
288
291
|
const columns = useMemo(
|
|
289
292
|
() => buildRelativeColumns(baseCurrency, extendedSessionsKey ? extendedSessionsKey.split(",") as ExtendedSession[] : [], marginNamesYear, peNamesYear,
|
|
290
|
-
growthLabel, symbolWidth),
|
|
291
|
-
[baseCurrency, extendedSessionsKey, marginNamesYear, peNamesYear, growthLabel, symbolWidth],
|
|
293
|
+
growthLabel, symbolWidth, forwardNamesYear),
|
|
294
|
+
[baseCurrency, extendedSessionsKey, marginNamesYear, peNamesYear, growthLabel, symbolWidth, forwardNamesYear],
|
|
292
295
|
);
|
|
293
296
|
|
|
294
297
|
const comparableRows = useMemo(() => rows.map((row) => ({
|
|
@@ -382,7 +385,7 @@ export function RelativeValuationPane({ focused, width, height }: PaneProps) {
|
|
|
382
385
|
return { text: `${formatPriceEarnings(row.reportedMultiples.trailingPE)}${row.trailingPEPeriod ? ` ${row.trailingPEPeriod}` : ""}`, color: colors.text };
|
|
383
386
|
case "forwardPE":
|
|
384
387
|
if (row.notMeaningful.forwardPE) return notMeaningfulCell();
|
|
385
|
-
return { text: formatPriceEarnings(row.reportedMultiples.forwardPE)
|
|
388
|
+
return { text: `${formatPriceEarnings(row.reportedMultiples.forwardPE)}${row.forwardPEPeriod ? ` ${row.forwardPEPeriod}` : ""}`, color: colors.text };
|
|
386
389
|
case "evSales":
|
|
387
390
|
// A withdrawn EV says so, one at or below zero reads N/M as a P/E over a loss does; the footer says why.
|
|
388
391
|
if (row.evSales == null && row.notMeaningful.evSales) return notMeaningfulCell();
|