Skip to content

Commit

Permalink
chore: add more data service impl
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Dec 8, 2024
1 parent 640718c commit 86bfd7a
Show file tree
Hide file tree
Showing 26 changed files with 234 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import { hasPermission } from "$lib/store/space-member.store"
import { CircleCheckBigIcon } from "lucide-svelte"
import { LL } from "@undb/i18n/client"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
import { type IUpdateViewCommand } from "@undb/commands"
export let readonly = false
Expand Down Expand Up @@ -49,8 +52,14 @@
const { enhance, form: formData } = form
const isLocal = getIsLocal()
const isPlayground = getIsPlayground()
const updateViewMutation = createMutation({
mutationFn: trpc.table.view.update.mutate,
mutationFn: async (command: IUpdateViewCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.view.updateView(command)
},
mutationKey: ["updateView"],
async onSuccess(data, variables, context) {
toast.success($LL.table.view.updated())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import { getTable } from "$lib/store/table.store"
import { invalidate } from "$app/navigation"
import { type ICalendarViewDTO } from "@undb/table"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
import { type IUpdateViewCommand } from "@undb/commands"
export let view: CalendarView
const table = getTable()
Expand All @@ -38,8 +41,14 @@
})
}
const isLocal = getIsLocal()
const isPlayground = getIsPlayground()
const updateViewMutation = createMutation({
mutationFn: trpc.table.view.update.mutate,
mutationFn: async (command: IUpdateViewCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.view.updateView(command)
},
mutationKey: ["updateView"],
async onSuccess(data, variables, context) {
await invalidate(`undb:table:${$table.id.value}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import { CircleCheckBigIcon } from "lucide-svelte"
import * as Form from "$lib/components/ui/form"
import { LL } from "@undb/i18n/client"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
import { type IUpdateViewCommand } from "@undb/commands"
export let readonly = false
Expand Down Expand Up @@ -61,8 +64,14 @@
const { enhance, form: formData, validateForm } = form
const isLocal = getIsLocal()
const isPlayground = getIsPlayground()
const updateViewMutation = createMutation({
mutationFn: trpc.table.view.update.mutate,
mutationFn: async (command: IUpdateViewCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.view.updateView(command)
},
mutationKey: ["updateView"],
async onSuccess(data, variables, context) {
toast.success($LL.table.view.updated())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<script lang="ts">
import { goto, invalidateAll } from "$app/navigation"
import { GetTableForeignTablesStore } from "$houdini"
import * as AlertDialog from "$lib/components/ui/alert-dialog"
import * as Alert from "$lib/components/ui/alert"
import { closeModal, DELETE_TABLE_MODAL, isModalOpen } from "$lib/store/modal.store"
import { getTable } from "$lib/store/table.store"
import { trpc } from "$lib/trpc/client"
import { createMutation } from "@tanstack/svelte-query"
import { TrashIcon } from "lucide-svelte"
import { toast } from "svelte-sonner"
import { Input } from "$lib/components/ui/input"
import { Label } from "$lib/components/ui/label"
import { page } from "$app/stores"
import { LL } from "@undb/i18n/client"
import { type IDeleteTableCommand } from "@undb/commands"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
export let table = getTable()
const isLocal = getIsLocal()
const isPlayground = getIsPlayground()
// const foreignTableStore = new GetTableForeignTablesStore()
// $: $isModalOpen(DELETE_TABLE_MODAL) &&
// foreignTableStore.fetch({
Expand All @@ -25,7 +27,10 @@
// $: foreignTables = $foreignTableStore.data?.tableForeignTables ?? []
const deleteTableMutation = createMutation({
mutationFn: trpc.table.delete.mutate,
mutationFn: async (command: IDeleteTableCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.deleteTable(command)
},
async onSuccess(data, variables, context) {
await goto("/")
await invalidateAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import { invalidate } from "$app/navigation"
import { CircleCheckBigIcon } from "lucide-svelte"
import { LL } from "@undb/i18n/client"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
import { type IUpdateViewCommand } from "@undb/commands"
const table = getTable()
export let readonly = false
Expand Down Expand Up @@ -47,8 +50,14 @@
const { enhance, form: formData } = form
const isLocal = getIsLocal()
const isPlayground = getIsPlayground()
const updateViewMutation = createMutation({
mutationFn: trpc.table.view.update.mutate,
mutationFn: async (command: IUpdateViewCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.view.updateView(command)
},
mutationKey: ["updateView"],
async onSuccess(data, variables, context) {
toast.success($LL.table.view.updated())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import { hasPermission } from "$lib/store/space-member.store"
import { CircleCheckBigIcon } from "lucide-svelte"
import { LL } from "@undb/i18n/client"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
import { type IUpdateViewCommand } from "@undb/commands"
export let readonly = false
Expand Down Expand Up @@ -49,8 +52,14 @@
const { enhance, form: formData } = form
const isLocal = getIsLocal()
const isPlayground = getIsPlayground()
const updateViewMutation = createMutation({
mutationFn: trpc.table.view.update.mutate,
mutationFn: async (command: IUpdateViewCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.view.updateView(command)
},
mutationKey: ["updateView"],
async onSuccess(data, variables, context) {
toast.success($LL.table.view.updated())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import { derived } from "svelte/store"
import * as Tooltip from "$lib/components/ui/tooltip"
import { LL } from "@undb/i18n/client"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
import { type IUpdateViewCommand } from "@undb/commands"
const table = getTable()
export let readonly = false
Expand Down Expand Up @@ -69,8 +72,14 @@
isValidColumnLabel(rowField) &&
isValidRowLabel(columnField)
const isLocal = getIsLocal()
const isPlayground = getIsPlayground()
const updateViewMutation = createMutation({
mutationFn: trpc.table.view.update.mutate,
mutationFn: async (command: IUpdateViewCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.view.updateView(command)
},
mutationKey: ["updateView"],
async onSuccess(data, variables, context) {
toast.success($LL.table.view.updated())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { FieldIdVo } from "@undb/table"
import { ListIcon, GripVerticalIcon, SearchIcon, ChevronDownIcon } from "lucide-svelte"
import { createMutation, useQueryClient } from "@tanstack/svelte-query"
import { trpc } from "$lib/trpc/client"
import { tick } from "svelte"
import { invalidate } from "$app/navigation"
import { SortableList } from "@jhubbardsf/svelte-sortablejs"
Expand All @@ -22,7 +21,7 @@
import { EyeIcon, EyeOffIcon } from "lucide-svelte"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
import { type ISetViewFieldsCommand } from "@undb/commands"
import { type ISetViewFieldsCommand, type ISetViewOptionCommand } from "@undb/commands"
export let readonly = false
export let viewId: Readable<string | undefined>
Expand Down Expand Up @@ -85,7 +84,10 @@
$: viewOption = $table.getViewOption($viewId)
const setViewOptionMutation = createMutation({
mutationFn: trpc.table.view.setOption.mutate,
mutationFn: async (command: ISetViewOptionCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.view.setOption(command)
},
mutationKey: ["table", $table.id.value, "setOption"],
async onSuccess(data, variables, context) {
await invalidate(`undb:table:${$table.id.value}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
import { hasPermission } from "$lib/store/space-member.store"
import { LoaderCircleIcon } from "lucide-svelte"
import ViewTypePicker from "./view-type-picker.svelte"
import { goto, invalidate } from "$app/navigation"
import { goto, invalidate, invalidateAll } from "$app/navigation"
import { getTable } from "$lib/store/table.store"
import FieldPicker from "../field-picker/field-picker.svelte"
import * as Tooltip from "$lib/components/ui/tooltip"
import { CircleHelpIcon } from "lucide-svelte"
import { LL } from "@undb/i18n/client"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
import { type ICreateViewCommand } from "@undb/commands"
let open = false
Expand All @@ -29,15 +32,26 @@
export let tableId: string
export let viewNames: string[]
const isLocal = getIsLocal()
const isPlayground = getIsPlayground()
const createViewMutation = createMutation({
mutationFn: trpc.table.view.create.mutate,
mutationFn: async (command: ICreateViewCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.view.createView(command)
},
mutationKey: ["table", tableId, "createView"],
async onSuccess(data) {
viewNames = [...viewNames, $formData.name]
toast.success("created view successfully")
toast.success($LL.table.view.created())
reset()
await invalidate(`undb:table:${tableId}`)
await goto(`/t/${tableId}/${data.viewId}`)
if (isPlayground) {
await invalidateAll()
await goto(`/playground/bases/${data.baseId}/t/${tableId}/${data.viewId}`)
} else {
await invalidate(`undb:table:${tableId}`)
await goto(`/t/${tableId}/${data.viewId}`)
}
},
onError(e) {
toast.error(e.message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
<script lang="ts">
import * as AlertDialog from "$lib/components/ui/alert-dialog"
import { DELETE_VIEW, isModalOpen, toggleModal } from "$lib/store/modal.store"
import { trpc } from "$lib/trpc/client"
import { createMutation } from "@tanstack/svelte-query"
import { getTable } from "$lib/store/table.store"
import { toast } from "svelte-sonner"
import { goto, invalidate } from "$app/navigation"
import { page } from "$app/stores"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
import type { IDeleteViewCommand } from "@undb/commands"
import { type Readable } from "svelte/store"
const table = getTable()
export let viewId: Readable<string | undefined>
const isLocal = getIsLocal()
const isPlayground = getIsPlayground()
const deleteViewMutation = createMutation({
mutationKey: ["table", $viewId, "deleteView"],
mutationFn: trpc.table.view.delete.mutate,
mutationFn: async (command: IDeleteViewCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.view.deleteView(command)
},
async onSuccess(data, variables, context) {
await invalidate(`undb:table:${$table.id.value}`)
await goto(`/t/${$table.id.value}`)
if (isPlayground) {
await goto(`/playground/bases/${$table.baseId}/t/${$table.id.value}`, { replaceState: true })
} else {
await goto(`/t/${$table.id.value}`, { replaceState: true })
}
},
onError(error) {
toast.error(error.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@
import { toast } from "svelte-sonner"
import { invalidate, goto } from "$app/navigation"
import type { Readable } from "svelte/store"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
import type { IDuplicateViewCommand } from "@undb/commands"
const table = getTable()
export let viewId: Readable<string | undefined>
const isLocal = getIsLocal()
const isPlayground = getIsPlayground()
const duplicateViewMutation = createMutation({
mutationFn: async (command: IDuplicateViewCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.view.duplicateView(command)
},
mutationKey: ["table", $viewId, "duplicateView"],
mutationFn: trpc.table.view.duplicate.mutate,
async onSuccess(data, variables, context) {
closeModal(DUPLICATE_VIEW)
toast.success("View duplicated")
Expand Down
11 changes: 10 additions & 1 deletion apps/frontend/src/lib/components/blocks/view/update-view.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@
import type { Readable } from "svelte/store"
import { invalidate } from "$app/navigation"
import { LL } from "@undb/i18n/client"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"
import { getIsPlayground } from "$lib/store/playground.svelte"
import { type IUpdateViewCommand } from "@undb/commands"
const table = getTable()
export let viewId: Readable<string | undefined>
const isLocal = getIsLocal()
const isPlayground = getIsPlayground()
const updateViewMutation = createMutation({
mutationKey: ["table", $viewId, "updateView"],
mutationFn: trpc.table.view.update.mutate,
mutationFn: async (command: IUpdateViewCommand) => {
const dataService = await getDataService(isLocal, isPlayground)
return dataService.table.view.updateView(command)
},
async onSuccess(data, variables, context) {
toggleModal(UPDATE_VIEW)
toast.success($LL.table.view.updated())
Expand Down
Loading

0 comments on commit 86bfd7a

Please sign in to comment.