Files
baserow/web-frontend/modules/database/components/sidebar/Sidebar.vue

108 lines
2.8 KiB
Vue

<template>
<SidebarApplication :workspace="workspace" :application="application">
<template #body>
<ul class="tree__subs">
<SidebarItem
v-for="table in orderedTables"
:key="table.id"
v-sortable="{
id: table.id,
update: orderTables,
marginTop: -1.5,
enabled: $hasPermission(
'database.order_tables',
application,
application.workspace.id
),
}"
:database="application"
:table="table"
></SidebarItem>
</ul>
<ul v-if="pendingJobs.length" class="tree__subs">
<component
:is="getPendingJobComponent(job)"
v-for="job in pendingJobs"
:key="job.id"
:job="job"
>
</component>
</ul>
<a
v-if="
$hasPermission(
'database.create_table',
application,
application.workspace.id
)
"
class="tree__sub-add"
:data-highlight="`create-table-${application.id}`"
@click="whenMounted(() => $refs.createTableModal.show())"
>
<i class="tree__sub-add-icon iconoir-plus"></i>
{{ $t('sidebar.createTable') }}
</a>
<CreateTableModal ref="createTableModal" :database="application" />
</template>
</SidebarApplication>
</template>
<script>
import { notifyIf } from '@baserow/modules/core/utils/error'
import SidebarItem from '@baserow/modules/database/components/sidebar/SidebarItem'
import SidebarApplication from '@baserow/modules/core/components/sidebar/SidebarApplication'
import CreateTableModal from '@baserow/modules/database/components/table/CreateTableModal'
import whenMounted from '@baserow/modules/core/mixins/whenMounted'
export default {
name: 'DBSidebar',
components: {
CreateTableModal,
SidebarApplication,
SidebarItem,
},
mixins: [whenMounted],
props: {
application: {
type: Object,
required: true,
},
workspace: {
type: Object,
required: true,
},
},
computed: {
orderedTables() {
return this.application.tables
.map((table) => table)
.sort((a, b) => a.order - b.order)
},
pendingJobs() {
return this.$store.getters['job/getAll'].filter((job) =>
this.$registry
.get('job', job.type)
.isJobPartOfApplication(job, this.application)
)
},
},
methods: {
async orderTables(order, oldOrder) {
try {
await this.$store.dispatch('table/order', {
database: this.application,
order,
oldOrder,
})
} catch (error) {
notifyIf(error, 'table')
}
},
getPendingJobComponent(job) {
return this.$registry.get('job', job.type).getSidebarComponent()
},
},
}
</script>