Files
baserow/web-frontend/modules/database/components/row/RowEditModalSidebar.vue
alamin-br 633f1c4b7d feat: remember last-opened row sidebar tab (comments/history) (#5687)
* feat: add helper to persist row edit modal sidebar tab

* test: spy on real localStorage so error-path tests exercise the catch

* feat: remember last-opened row edit modal sidebar tab (#2532)

* fix: persist the genuinely last-opened row sidebar tab

* chore: add changelog for remembered row sidebar tab

* refactor: tidy sidebar tab snapshot and assert no write on default mount

* refactor: address PR review — explicit no-op catch, shared localStorage test mock

* refactor: harden localStorage test mock with null-prototype store

* fix: keep sidebar tab preference when props deactivate it on a reused instance

* refactor: simplify sidebar tab persistence to a single reactive property
2026-07-09 15:56:41 +02:00

120 lines
2.8 KiB
Vue

<template>
<Tabs
:selected-index="selectedTabIndex"
full-height
grow-items
header-no-padding
content-no-x-padding
class="row-edit-modal-sidebar"
@update:selected-index="onTabSelected"
>
<Tab
v-for="sidebarType in sidebarTypes"
:key="sidebarType.getType()"
:title="sidebarType.getName()"
>
<component
:is="sidebarType.getComponent()"
:row="row"
:table="table"
:database="database"
:fields="fields"
:view="view"
></component>
</Tab>
</Tabs>
</template>
<script>
import Tabs from '@baserow/modules/core/components/Tabs.vue'
import Tab from '@baserow/modules/core/components/Tab.vue'
import {
getRowEditModalSidebarTab,
setRowEditModalSidebarTab,
} from '@baserow/modules/database/utils/rowEditModalSidebar'
export default {
name: 'RowEditModalSidebar',
components: {
Tabs,
Tab,
},
props: {
database: {
type: Object,
required: true,
},
table: {
type: Object,
required: true,
},
fields: {
type: Array,
required: true,
},
row: {
type: Object,
required: true,
},
view: {
type: Object,
required: false,
default: null,
},
readOnly: {
type: Boolean,
required: false,
default: false,
},
},
data() {
return {
// Remembered tab type, kept reactive so `selectedTabIndex` stays in sync.
rememberedType: getRowEditModalSidebarTab(),
}
},
computed: {
selectedTabIndex() {
const types = this.sidebarTypes
if (this.rememberedType) {
const rememberedIndex = types.findIndex(
(type) => type.getType() === this.rememberedType
)
if (rememberedIndex !== -1) {
return rememberedIndex
}
}
const index = types.findIndex((type) =>
type.isSelectedByDefault(this.database, this.table)
)
return Math.max(index, 0)
},
sidebarTypes() {
const allSidebarTypes = this.$registry.getOrderedList('rowModalSidebar')
return allSidebarTypes.filter(
(type) =>
type.isDeactivated(
this.database,
this.table,
this.readOnly,
this.view
) === false && type.getComponent()
)
},
},
methods: {
// Persist the user's tab choice. Programmatic emits (mount echo, or a
// fallback when the remembered tab is unavailable) carry the already
// selected index and are skipped, so they never overwrite the preference.
onTabSelected(index) {
const type = this.sidebarTypes[index]?.getType()
if (!type || index === this.selectedTabIndex) {
return
}
this.rememberedType = type
setRowEditModalSidebarTab(type)
},
},
}
</script>