Files
Jonathan Adelineandpeter_baserow a8bf3b73ae feat: redesign app sidebar (#6798)
* feat: redesign sidebar workspace navigation

* feat: redesign the sidebar footer and account menu

Match the account menu to the sidebar prototype and reuse the admin
navigation in a submenu. Keep Add new above the footer while the
application list scrolls.

* fix: show the sortable indicator only when dragging

* feat: refine workspace sidebar application navigation

* feat: reorganize workspace sidebar shortcuts

* fix: isolate workspace sidebar menus and actions

* fix: cancel sortable drops on hidden lists

* fix(enterprise): allow retrying Direct support

* feat: simplify the workspace overview header

* fix: prevent horizontal overflow around the sidebar

Constrain animated tree groups to the width of the sidebar so long labels truncate. On narrow screens, let the sidebar expand over the content instead of reducing the usable page width.

* fix: fit workspace cards and creation menus on mobile

* test: keep the current table selected after reload

* fix: undo and redo edits across expanded sidebar applications

* fix: keep sidebar groups out of the tab order

* fix: highlight the active database in the tables tour

* feat: label workspace integrations in the settings menu

* fix: keep the workspace sidebar and guided tour usable on phones

* fix: undo sidebar row imports in the destination database

* fix: keep the guided tour highlight on the current step

* fix: show an empty state in the workspace picker

* fix: confirm workspace deletion before moving it to trash

* feat: open registered workspace settings tabs from the sidebar

* fix: keep the sidebar logo the same size across workspaces

---------

Co-authored-by: peter_baserow <peter@baserow.io>
2026-11-23 20:42:20 +04:00

169 lines
4.9 KiB
JavaScript

import UndoRedoService from '@baserow/modules/core/services/undoRedo'
import {
UNDO_REDO_RESULT_CODES,
UNDO_REDO_STATES,
} from '@baserow/modules/core/utils/undoRedoConstants'
export const state = () => ({
undoing: false,
redoing: false,
// A stack of objects, each object representing a set of visible action scopes.
// The last object in the stack is the current set of scopes which are visible.
actionScopesStack: [{}],
})
export const mutations = {
SET_UNDOING(state, value) {
state.undoing = value
},
SET_REDOING(state, value) {
state.redoing = value
},
RESET_ACTION_SCOPE_SET_STACK(state, newScopeSet) {
state.actionScopesStack = [newScopeSet]
},
PUSH_NEW_ACTION_SCOPE_SET(state, newScopeSet) {
state.actionScopesStack.push(newScopeSet)
},
POP_CURRENT_ACTION_SCOPE_SET(state) {
state.actionScopesStack.pop()
},
UPDATE_CURRENT_SCOPE_SET(state, newScope) {
const current = state.actionScopesStack[state.actionScopesStack.length - 1]
// FIXME: different application types might have different sub-scopes, so we should
// clear them when updating parent scopes instead of just merging.
for (const [key, value] of Object.entries(newScope)) {
current[key] = value
}
},
}
let hideTimeout = null
export const actions = {
async undo({ dispatch }, { showLoadingToast }) {
return await dispatch('action', {
showLoadingToast,
serviceMethod: 'undo',
doingToastState: UNDO_REDO_STATES.UNDOING,
doneToastState: UNDO_REDO_STATES.UNDONE,
nothingToDoToastState: UNDO_REDO_STATES.NO_MORE_UNDO,
skippedDueToErrorToastState: UNDO_REDO_STATES.ERROR_WITH_UNDO,
commitName: 'SET_UNDOING',
})
},
async redo({ dispatch }, { showLoadingToast }) {
return await dispatch('action', {
showLoadingToast,
serviceMethod: 'redo',
doingToastState: UNDO_REDO_STATES.REDOING,
doneToastState: UNDO_REDO_STATES.REDONE,
nothingToDoToastState: UNDO_REDO_STATES.NO_MORE_REDO,
skippedDueToErrorToastState: UNDO_REDO_STATES.ERROR_WITH_REDO,
commitName: 'SET_REDOING',
})
},
async action(
{ getters, commit, dispatch },
{
showLoadingToast,
serviceMethod,
doingToastState,
doneToastState,
nothingToDoToastState,
skippedDueToErrorToastState,
commitName,
}
) {
if (getters.isUndoing || getters.isRedoing) {
return
}
clearTimeout(hideTimeout)
commit(commitName, true)
await dispatch(
'toast/setUndoRedoState',
showLoadingToast ? doingToastState : UNDO_REDO_STATES.HIDDEN,
{ root: true }
)
try {
const { data } = await UndoRedoService(this.$client)[serviceMethod](
getters.getCurrentScope
)
const resultCodeToToastState = {
[UNDO_REDO_RESULT_CODES.SUCCESS]: doneToastState,
[UNDO_REDO_RESULT_CODES.NOTHING_TO_DO]: nothingToDoToastState,
[UNDO_REDO_RESULT_CODES.SKIPPED_DUE_TO_ERROR]:
skippedDueToErrorToastState,
}
await dispatch(
'toast/setUndoRedoState',
resultCodeToToastState[data.result_code],
{
root: true,
}
)
} finally {
hideTimeout = setTimeout(
() =>
dispatch('toast/setUndoRedoState', UNDO_REDO_STATES.HIDDEN, {
root: true,
}),
2000
)
commit(commitName, false)
}
},
resetScopeSetStack({ commit }, scopeSet) {
// TODO do we need this? Perhaps when switching route entirely?
commit('RESET_ACTION_SCOPE_SET_STACK', scopeSet)
},
pushNewScopeSet({ commit }, scopeSet) {
// For use in modals. A modal will push a new scope set when opened restricting
// the actions available for undo/redo to just those visible from the modal.
// When the modal closes it should then call popCurrentScopeSet to reset to
// previous scope set.
commit('PUSH_NEW_ACTION_SCOPE_SET', scopeSet)
},
popCurrentScopeSet({ commit }) {
commit('POP_CURRENT_ACTION_SCOPE_SET')
},
updateCurrentScopeSet({ commit }, scope) {
commit('UPDATE_CURRENT_SCOPE_SET', scope)
},
}
export const getters = {
isUndoing(state) {
return state.undoing
},
isRedoing(state) {
return state.redoing
},
getCurrentScope(state, getters, rootState) {
const scope = state.actionScopesStack.at(-1)
// A modal has its own undo history, independent of the workspace sidebar.
if (state.actionScopesStack.length !== 1 || !scope.workspace) {
return scope
}
const applications = Object.entries(
rootState.application.expandedSidebarApplications
)
.filter(
([id, workspaceId]) =>
workspaceId === scope.workspace && Number(id) !== scope.application
)
.map(([id]) => Number(id))
return applications.length ? { ...scope, applications } : scope
},
}
export default {
namespaced: true,
state,
getters,
actions,
mutations,
}