Skip to content

Commit 987bbc2

Browse files
fix(tables): live layout on save-as-view, reset it per view, ignore inherited param when embedded
1 parent 8a52f80 commit 987bbc2

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/tables/[tableId]

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,11 @@ export function Table({
447447
if (!viewsEnabled || !viewsLoaded) return
448448

449449
if (seededViewIdRef.current === undefined) {
450-
if (activeViewId === null) {
450+
// Embedded tables bind these parsers to the HOST page's URL, which the
451+
// mothership panel keeps across resource switches. A param left by the
452+
// previously-open table must not decide this one's initial view, so the
453+
// first resolve ignores it and lets this table pick its own default.
454+
if (activeViewId === null || embedded) {
451455
const defaultView = views.find((view) => view.isDefault)
452456
if (defaultView) {
453457
seededViewIdRef.current = defaultView.id
@@ -458,6 +462,7 @@ export function Table({
458462
// No view to adopt. Deliberately does NOT apply an empty config — that
459463
// would clear a deep-linked `?sort=` on mount.
460464
seededViewIdRef.current = null
465+
if (embedded && activeViewId !== null) setTableParams({ view: ALL_VIEW_PARAM })
461466
return
462467
}
463468
if (activeViewId === ALL_VIEW_PARAM) {
@@ -507,6 +512,7 @@ export function Table({
507512
views,
508513
activeView,
509514
activeViewId,
515+
embedded,
510516
sortColumn,
511517
applyViewConfig,
512518
setTableParams,
@@ -545,9 +551,26 @@ export function Table({
545551
* order / pins the grid is rendering (they live in the table's shared metadata
546552
* until a view owns them) instead of creating a layout-less view that then
547553
* resets the grid. Updates never send this — they send a merge patch. */
554+
/** Last layout the grid reported, patch by patch. View layout writes have no
555+
* optimistic cache update, so `activeView.config` lags an in-flight resize —
556+
* this is what a new view copies so the grid can't snap back.
557+
*
558+
* Declared above the consumers that read it during render, and reset on every
559+
* view change: it holds patches for ONE view, so carrying them across a switch
560+
* would let a new view inherit the previous view's widths/order/pins. */
561+
const liveLayoutRef = useRef<TableMetadata>({})
562+
563+
useEffect(() => {
564+
liveLayoutRef.current = {}
565+
}, [activeView?.id])
566+
548567
const currentViewConfig = useMemo<TableViewConfig>(
549568
() => ({
569+
// `liveLayoutRef` after the cached config for the same reason the blank-view
570+
// payload does it: a resize/reorder/pin still in flight would otherwise be
571+
// captured at its pre-drag value and snap back when the view is selected.
550572
...(activeView?.config ?? tableData?.metadata),
573+
...liveLayoutRef.current,
551574
filter: effectiveFilter,
552575
sort: sortQuery,
553576
hiddenColumns: effectiveHiddenColumns,
@@ -609,11 +632,6 @@ export function Table({
609632
* a `configPatch` so the server merges it — two overlapping layout writes must
610633
* not each replace the whole blob from their own snapshot. With no view active
611634
* the grid keeps writing the table's shared metadata. */
612-
/** Last layout the grid reported, patch by patch. View layout writes have no
613-
* optimistic cache update, so `activeView.config` lags an in-flight resize —
614-
* this is what a blank "New view" copies so the grid can't snap back. */
615-
const liveLayoutRef = useRef<TableMetadata>({})
616-
617635
const handlePersistLayout = useCallback(
618636
(patch: TableMetadata) => {
619637
liveLayoutRef.current = { ...liveLayoutRef.current, ...patch }

0 commit comments

Comments
 (0)