|
11 | 11 |
|
12 | 12 | import type { ColumnSummary } from '@objectstack/spec/ui'; |
13 | 13 | import type { ListColumn } from '@object-ui/types'; |
14 | | -import { columnsWithSummary } from './columnSummaryWrite.js'; |
| 14 | +import { columnsWithSummary, declaredColumnFields } from './columnSummaryWrite.js'; |
15 | 15 | import { useMemo, useState, useCallback, useEffect, useRef, lazy, Suspense } from 'react'; |
16 | 16 | import { useParams, useSearchParams, useNavigate, useLocation, useHref, createSearchParams } from 'react-router-dom'; |
17 | 17 | import { resolveAffordance, type FilterTokenScope, type SchemaLike } from '@object-ui/core'; |
@@ -824,20 +824,35 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co |
824 | 824 | activeViewId, |
825 | 825 | baseView, |
826 | 826 | }); |
827 | | - const handlePickPersonalViewSummary = (field: string, summary: ColumnSummary | null, drawnFields: readonly string[]) => { |
828 | | - if (!activeView) return; |
829 | | - const row = personalViews.views.find((v) => v.id === activeView.id); |
830 | | - if (!row) return; |
831 | | - const columns = columnsWithSummary(row.config.columns as ListColumn[] | string[] | undefined, field, summary, drawnFields); |
832 | | - personalViews.update(row.id, { ...row.config, columns }).catch((err) => { |
| 827 | + // objectstack#35702 — a footer pick saves the column's calculation and |
| 828 | + // nothing else (L1 7048239634): the stored view's own columns are the |
| 829 | + // base, so the reader's unsaved hides, order or added columns never ride |
| 830 | + // along, and a column the view does not declare is not offered. Each |
| 831 | + // resolves whether the pick was saved; on `false` the grid takes it back. |
| 832 | + const personalViewRow = activeView ? personalViews.views.find((v) => v.id === activeView.id) : undefined; |
| 833 | + const handlePickPersonalViewSummary = async (field: string, summary: ColumnSummary | null): Promise<boolean> => { |
| 834 | + if (!personalViewRow) return false; |
| 835 | + const columns = columnsWithSummary(personalViewRow.config.columns as ListColumn[] | string[] | undefined, field, summary); |
| 836 | + if (!columns) return false; |
| 837 | + try { |
| 838 | + await personalViews.update(personalViewRow.id, { ...personalViewRow.config, columns }); |
| 839 | + return true; |
| 840 | + } catch (err) { |
833 | 841 | console.error('[ObjectView] Failed to save a footer calculation:', err); |
834 | 842 | toast.error(t('form.saveError'), { description: err instanceof Error ? err.message : String(err) }); |
835 | | - }); |
| 843 | + return false; |
| 844 | + } |
836 | 845 | }; |
837 | | - const handlePickSharedViewSummary = (field: string, summary: ColumnSummary | null, drawnFields: readonly string[]) => { |
838 | | - if (!activeView) return; |
839 | | - const columns = columnsWithSummary(activeView.columns as ListColumn[] | string[] | undefined, field, summary, drawnFields); |
840 | | - void handleViewConfigSave({ ...activeView, columns }); |
| 846 | + const handlePickSharedViewSummary = async (field: string, summary: ColumnSummary | null): Promise<boolean> => { |
| 847 | + if (!activeView) return false; |
| 848 | + const columns = columnsWithSummary(activeView.columns as ListColumn[] | string[] | undefined, field, summary); |
| 849 | + if (!columns) return false; |
| 850 | + const priorDraft = viewDraft; |
| 851 | + const saved = await handleViewConfigSave({ ...activeView, columns }); |
| 852 | + // The panel's save keeps a refused draft on screen (the panel stays |
| 853 | + // dirty); a refused pick is taken back instead. |
| 854 | + if (!saved) setViewDraft(priorDraft); |
| 855 | + return saved; |
841 | 856 | }; |
842 | 857 |
|
843 | 858 | // objectstack#29635 — creating one of the reader's own views, and Rename |
@@ -1119,13 +1134,21 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co |
1119 | 1134 | pickSummary: isEnvironmentList || !activeView |
1120 | 1135 | ? undefined |
1121 | 1136 | : activeIsPersonal |
1122 | | - ? (canUpdatePersonalView ? handlePickPersonalViewSummary : undefined) |
1123 | | - // Only a view the metadata door stores: a package view |
1124 | | - // (a qualified, dotted name) or a saved one, never the |
1125 | | - // fallback tab an object with no views is drawn with. |
1126 | | - : isAdmin && (String(activeView.id).includes('.') || isSavedViewId(savedViews, String(activeView.id))) |
| 1137 | + ? (canUpdatePersonalView && personalViewRow ? handlePickPersonalViewSummary : undefined) |
| 1138 | + // Only a view the metadata door stores (one the overlay |
| 1139 | + // read lists), never the fallback tab an object with no |
| 1140 | + // views is drawn with. Every stored view has a qualified, |
| 1141 | + // dotted name, the console's own saved views included |
| 1142 | + // (`object.key` in the custom package), so the name cannot |
| 1143 | + // tell a view a read-only package ships; the door refuses |
| 1144 | + // that save by design (it goes to the custom package) and |
| 1145 | + // the refused pick is taken back, as the panel's save is. |
| 1146 | + : isAdmin && isSavedViewId(savedViews, String(activeView.id)) |
1127 | 1147 | ? handlePickSharedViewSummary |
1128 | 1148 | : undefined, |
| 1149 | + summaryPickFields: declaredColumnFields( |
| 1150 | + (activeIsPersonal ? personalViewRow?.config.columns : activeView?.columns) as ListColumn[] | string[] | undefined, |
| 1151 | + ), |
1129 | 1152 | }, |
1130 | 1153 | }); |
1131 | 1154 |
|
|
0 commit comments