diff --git a/ui/src/views/Forecast.jsx b/ui/src/views/Forecast.jsx index 1717dad..1d76f19 100644 --- a/ui/src/views/Forecast.jsx +++ b/ui/src/views/Forecast.jsx @@ -948,6 +948,48 @@ export default function Forecast({ sources = [], sourceId, versions = [], versio } } + // Size every column to its contents. + // + // The datagrid already does this -- draw() calls regular_table.resetAutoSize() + // -- but only when _reset_column_size is set, and it restores any pinned widths + // immediately afterwards: + // + // const old_sizes = save_column_size_overrides.call(this); + // ... if (this._reset_column_size) { resetAutoSize() } + // restore_column_size_overrides.call(this, old_sizes); + // + // So a width pinned by dragging, or carried in a saved layout, wins over the + // measurement for good. Clearing the overrides is what actually releases them; + // the flag then makes the next draw measure rather than reuse. + // + // Order matters: the flag is set *after* restore(), because building the model + // recomputes it from what changed in the config and would clear it again. + async function fitColumns() { + const viewer = viewerRef.current + if (!viewer) return + try { + const { table: _t, ...cfg } = await viewer.save() + const pc = { ...(cfg.plugin_config || {}) } + if (pc.columns) { + pc.columns = Object.fromEntries( + Object.entries(pc.columns).map(([col, v]) => { + const { column_size_override, ...rest } = v || {} + return [col, rest] + }) + ) + } + await viewer.restore({ ...cfg, plugin_config: pc }) + + const plugin = await viewer.getPlugin() + if (plugin) plugin._reset_column_size = true + const view = await viewer.getView() + await plugin?.draw?.(view) + } catch (err) { + console.error('[fitColumns]', err) + flash(err.message || String(err), 'error') + } + } + // In rollup mode the datagrid emits a grand-total column group as well as the // subtotals. The subtotals are the point -- they are what per-branch collapse // needs -- but the grand total sums across the split, and when the split is @@ -1517,6 +1559,15 @@ export default function Forecast({ sources = [], sourceId, versions = [], versio
+ + + + {/* Expand group */}