mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* Move workspace plan badge to the overview and rename workspaces instantly * Keep the overview add button visible on narrow screens.
65 lines
1.9 KiB
JavaScript
65 lines
1.9 KiB
JavaScript
import { notifyIf } from '@baserow/modules/core/utils/error'
|
|
import {
|
|
nameContainsNoSpam,
|
|
nameContainsNoUrl,
|
|
} from '@baserow/modules/core/validators'
|
|
|
|
/**
|
|
* Some helper methods to modify workspaces used by the dashboard.
|
|
*/
|
|
export default {
|
|
methods: {
|
|
setLoading(workspace, value) {
|
|
this.$store.dispatch('workspace/setItemLoading', { workspace, value })
|
|
},
|
|
enableRename() {
|
|
this.$refs.context.hide()
|
|
this.$refs.rename.edit()
|
|
},
|
|
async renameWorkspace(workspace, event) {
|
|
// The name is edited inline without a form, so there is no place to show
|
|
// a validation error. Show a toast notification instead and revert the
|
|
// name.
|
|
const invalidNameMessage = !nameContainsNoUrl(event.value)
|
|
? this.$t('error.nameContainsUrl')
|
|
: !nameContainsNoSpam(event.value)
|
|
? this.$t('error.nameContainsSpam')
|
|
: null
|
|
if (invalidNameMessage) {
|
|
this.$refs.rename.set(event.oldValue)
|
|
this.$store.dispatch('toast/error', {
|
|
title: this.$t('editWorkspace.invalidNameTitle'),
|
|
message: invalidNameMessage,
|
|
})
|
|
return
|
|
}
|
|
|
|
this.setLoading(workspace, true)
|
|
// Show the new name right away, otherwise the old one is shown again
|
|
// between the end of editing and the response. The `Editable` follows the
|
|
// store, so reverting the store also reverts the name that is shown.
|
|
this.$store.dispatch('workspace/forceUpdate', {
|
|
workspace,
|
|
values: { name: event.value },
|
|
})
|
|
|
|
try {
|
|
await this.$store.dispatch('workspace/update', {
|
|
workspace,
|
|
values: {
|
|
name: event.value,
|
|
},
|
|
})
|
|
} catch (error) {
|
|
this.$store.dispatch('workspace/forceUpdate', {
|
|
workspace,
|
|
values: { name: event.oldValue },
|
|
})
|
|
notifyIf(error, 'workspace')
|
|
}
|
|
|
|
this.setLoading(workspace, false)
|
|
},
|
|
},
|
|
}
|