1
0
Fork 0
mirror of synced 2024-06-14 00:14:39 +12:00
budibase/packages/builder/src/components/backend/DataTable/modals/CreateViewModal.svelte

38 lines
897 B
Svelte

<script>
import { Input, notifications, ModalContent } from "@budibase/bbui"
import { goto } from "@roxi/routify"
import { views as viewsStore } from "stores/backend"
import { tables } from "stores/backend"
let name
let field
$: views = $tables.list.flatMap(table => Object.keys(table.views || {}))
function saveView() {
if (views.includes(name)) {
notifications.error(`View exists with name ${name}`)
return
}
try {
viewsStore.save({
name,
tableId: $tables.selected._id,
field,
})
notifications.success(`View ${name} created`)
$goto(`../../view/${name}`)
} catch (error) {
notifications.error("Error creating view")
}
}
</script>
<ModalContent
title="Create View"
confirmText="Create View"
onConfirm={saveView}
>
<Input label="View Name" thin bind:value={name} />
</ModalContent>