Skip to content

Commit

Permalink
Merge pull request #1584 from undb-xyz/release/v0.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Oct 1, 2023
2 parents 23dd8a9 + 5e5a77c commit ce09110
Show file tree
Hide file tree
Showing 102 changed files with 1,717 additions and 891 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## v0.10.1

## v0.10.0


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- :city_sunset: Different types of views, including grid, kanban, gantt, tree, calendar and more
- 💡 Light / Dark theme
- 🗑️ records trash / restore
- 📜 Templates

## 📚 Tech Stack

Expand Down
10 changes: 8 additions & 2 deletions apps/backend/src/base/commands/create-base.command-handler.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { CommandHandler } from '@nestjs/cqrs'
import { type BaseRepository, type ITableRepository } from '@undb/core'
import type { ClsStore, IClsService } from '@undb/core'
import { type BaseRepository, type IRecordRepository, type ITableRepository } from '@undb/core'
import { CreateBaseCommand, CreateBaseCommandHandler } from '@undb/cqrs'
import { ClsService } from 'nestjs-cls'
import { InjectRecordRepository } from '../../core/table/adapters/sqlite/record-sqlite.repository.js'
import { InjectTableRepository } from '../../core/table/adapters/sqlite/table-sqlite.repository.js'
import { InjectBaseRepository } from '../adapters/base-sqlite.repository.js'

@CommandHandler(CreateBaseCommand)
export class NestCreateBaseCommandHandler extends CreateBaseCommandHandler {
constructor(
cls: ClsService<ClsStore>,
@InjectBaseRepository()
repo: BaseRepository,
@InjectTableRepository()
tableRepo: ITableRepository,
@InjectRecordRepository()
recordRepo: IRecordRepository,
) {
super(repo, tableRepo)
super(cls as IClsService<ClsStore>, repo, tableRepo, recordRepo)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CommandHandler } from '@nestjs/cqrs'
import { ExportBaseTemplateCommand, ExportBaseTemplateCommandHandler } from '@undb/cqrs'
import { NestTemplateService } from '../template.service.js'

@CommandHandler(ExportBaseTemplateCommand)
export class NestExportBaseTemplateCommandHandler extends ExportBaseTemplateCommandHandler {
constructor(svc: NestTemplateService) {
super(svc)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CommandHandler } from '@nestjs/cqrs'
import { ExportTableTemplateCommand, ExportTableTemplateCommandHandler } from '@undb/cqrs'
import { NestTemplateService } from '../template.service.js'

@CommandHandler(ExportTableTemplateCommand)
export class NestExportTableTemplateCommandHandler extends ExportTableTemplateCommandHandler {
constructor(svc: NestTemplateService) {
super(svc)
}
}

This file was deleted.

9 changes: 7 additions & 2 deletions apps/backend/src/template/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { NestExportTemplateCommandHandler } from './export-template.command-handler.js'
import { NestExportBaseTemplateCommandHandler } from './export-base-template.command-handler.js'
import { NestExportTableTemplateCommandHandler } from './export-table-template.command-handler.js'
import { NestImportTemplateCommandHandler } from './import-template.command-handler.js'

export const commandHandlers = [NestExportTemplateCommandHandler, NestImportTemplateCommandHandler]
export const commandHandlers = [
NestExportTableTemplateCommandHandler,
NestImportTemplateCommandHandler,
NestExportBaseTemplateCommandHandler,
]
19 changes: 16 additions & 3 deletions apps/backend/src/template/template.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Body, Controller, Param, Post, Res } from '@nestjs/common'
import { CommandBus } from '@nestjs/cqrs'
import { ExportTemplateCommand } from '@undb/cqrs'
import { ExportBaseTemplateCommand, ExportTableTemplateCommand } from '@undb/cqrs'
import type { Template } from '@undb/template'
import { type Response } from 'express'
import type { Option } from 'oxide.ts'
Expand All @@ -11,8 +11,21 @@ export class TemplateController {

@Post('export/tables/:tableId')
async exportTable(@Param('tableId') tableId: string, @Body('recordIds') recordIds: string[], @Res() res: Response) {
const template: Option<Template> = await this.commandBus.execute<ExportTemplateCommand>(
new ExportTemplateCommand({ tableId, recordIds }),
const template: Option<Template> = await this.commandBus.execute<ExportTableTemplateCommand>(
new ExportTableTemplateCommand({ tableId, recordIds }),
)

if (template.isNone()) return

const buffer = Buffer.from(JSON.stringify(template.unwrap()))
res.header('Content-Type', 'application/json')
return res.send(buffer)
}

@Post('export/bases/:baseId')
async exportBase(@Param('baseId') baseId: string, @Res() res: Response) {
const template: Option<Template> = await this.commandBus.execute<ExportBaseTemplateCommand>(
new ExportBaseTemplateCommand({ baseId }),
)

if (template.isNone()) return
Expand Down
6 changes: 2 additions & 4 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"@event-calendar/core": "^2.3.3",
"@event-calendar/day-grid": "^2.3.3",
"@event-calendar/interaction": "^2.3.3",
"@event-calendar/time-grid": "^2.3.3",
"@playwright/test": "^1.38.1",
"@popperjs/core": "^2.11.8",
"@revolist/revogrid": "^3.6.16",
Expand All @@ -24,6 +20,7 @@
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.25.1",
"@tanstack/svelte-query": "^4.35.3",
"@toast-ui/calendar": "^2.1.3",
"@trpc/client": "^10.38.4",
"@trpc/server": "^10.38.4",
"@types/js-cookie": "^3.0.4",
Expand Down Expand Up @@ -81,6 +78,7 @@
"svelte-jsoneditor": "^0.18.4",
"svelte-preprocess": "^5.0.4",
"svelte-previous": "^2.1.4",
"svelte-sonner": "^0.3.0",
"svelte-tiny-virtual-list": "^2.0.5",
"sveltekit-search-params": "^1.0.15",
"sveltekit-superforms": "^0.8.7",
Expand Down
15 changes: 5 additions & 10 deletions apps/frontend/src/lib/authz/fls/FLSCreate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { t } from '$lib/i18n'
import { getValidFilters } from '$lib/filter/filter.util'
import type { FLS, IFLSAction } from '@undb/authz'
import Toast from '$components/ui/toast/toast.svelte'
import { toast } from 'svelte-sonner'
const table = getTable()
Expand All @@ -21,11 +21,15 @@
const createFLS = trpc().authz.fls.create.mutation({
async onSettled(variables) {
toast.success($t('TABLE.FLS_CREATED', { ns: 'success' }))
await invalidate(`table:${$table.id.value}`)
filter = []
userIds = []
createMode = false
},
onError(error, variables, context) {
toast.error(error.message)
},
})
</script>

Expand Down Expand Up @@ -67,12 +71,3 @@
</Button>
</div>
{/if}

{#if $createFLS.error}
<Toast class="z-[99999] !bg-red-500 border-0 text-white font-semibold">
<span class="inline-flex items-center gap-3">
<i class="ti ti-exclamation-circle text-lg" />
{$createFLS.error.message}
</span>
</Toast>
{/if}
9 changes: 9 additions & 0 deletions apps/frontend/src/lib/authz/fls/FLSItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { invalidate } from '$app/navigation'
import { trpc } from '$lib/trpc/client'
import { getTable } from '$lib/store/table'
import { toast } from 'svelte-sonner'
const table = getTable()
export let fls: FLS
Expand All @@ -19,14 +20,22 @@
const updateFLS = trpc().authz.fls.update.mutation({
async onSuccess(data, variables, context) {
toast.success($t('TABLE.FLS_UPDATED', { ns: 'success' }))
await invalidate(`table:${$table.id.value}`)
},
onError(error, variables, context) {
toast.error(error.message)
},
})
const deleteFLS = trpc().authz.fls.delete.mutation({
async onSuccess(data, variables, context) {
toast.success($t('TABLE.FLS_DELETED', { ns: 'success' }))
await invalidate(`table:${$table.id.value}`)
},
onError(error, variables, context) {
toast.error(error.message)
},
})
</script>

Expand Down
16 changes: 15 additions & 1 deletion apps/frontend/src/lib/authz/member/MemberListItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import * as Avatar from '$lib/components/ui/avatar'
import * as DropdownMenu from '$lib/components/ui/dropdown-menu'
import { Button } from '$lib/components/ui/button'
import { toast } from 'svelte-sonner'
export let member: IQueryMember
Expand All @@ -21,7 +22,20 @@
{ value: 'viewer', name: $t('viewer', { ns: 'authz' }) },
] as const
const updateRoleMutation = trpc().authz.member.updateRole.mutation({})
const updateRoleMutation = trpc().authz.member.updateRole.mutation({
onSuccess(data, variables, context) {
toast.success(
$t('MEMBER.ROLE_UPDATED', {
ns: 'success',
username: member.userProfile.username,
role: $t(variables.role, { ns: 'authz' }),
}),
)
},
onError(error, variables, context) {
toast.error(error.message)
},
})
const updateRole = (value: IRolesWithoutOwner) => {
$updateRoleMutation.mutate({
memberId: member.id,
Expand Down
15 changes: 5 additions & 10 deletions apps/frontend/src/lib/authz/rls/RLSCreate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { IRLSAction, RLS } from '@undb/authz'
import { t } from '$lib/i18n'
import { getValidFilters } from '$lib/filter/filter.util'
import Toast from '$components/ui/toast/toast.svelte'
import { toast } from 'svelte-sonner'
const table = getTable()
Expand All @@ -23,6 +23,7 @@
const createRLS = trpc().authz.rls.create.mutation({
async onSettled(variables) {
toast.success($t('TABLE.RLS_CREATED', { ns: 'success' }))
await invalidate(`table:${$table.id.value}`)
filter = []
userIds = []
Expand All @@ -31,6 +32,9 @@
await $data.refetch()
}
},
onError(error, variables, context) {
toast.error(error.message)
},
})
</script>

Expand Down Expand Up @@ -73,12 +77,3 @@
</Button>
</div>
{/if}

{#if $createRLS.error}
<Toast class="z-[99999] !bg-red-500 border-0 text-white font-semibold">
<span class="inline-flex items-center gap-3">
<i class="ti ti-exclamation-circle text-lg" />
{$createRLS.error.message}
</span>
</Toast>
{/if}
9 changes: 9 additions & 0 deletions apps/frontend/src/lib/authz/rls/RLSItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import type { ISubjectType } from './rls.type'
import { hasPermission } from '$lib/store/authz'
import { Button } from '$lib/components/ui/button'
import { toast } from 'svelte-sonner'
export let rls: RLS
Expand All @@ -22,20 +23,28 @@
const deleteRLS = trpc().authz.rls.delete.mutation({
async onSuccess(data, variables, context) {
toast.success($t('TABLE.RLS_DELETED', { ns: 'success' }))
await invalidate(`table:${$table.id.value}`)
if (rls.policy.action === 'list') {
await $data.refetch()
}
},
onError(error, variables, context) {
toast.error(error.message)
},
})
const updateRLS = trpc().authz.rls.update.mutation({
async onSuccess(data, variables, context) {
toast.success($t('TABLE.RLS_UPDATED', { ns: 'success' }))
await invalidate(`table:${$table.id.value}`)
if (rls.policy.action === 'list') {
await $data.refetch()
}
},
onError(error, variables, context) {
toast.error(error.message)
},
})
</script>

Expand Down
15 changes: 9 additions & 6 deletions apps/frontend/src/lib/base/BaseCardTablesCard.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import * as HoverCard from '$lib/components/ui/hover-card'
import CreateTableButton from '$lib/table/CreateTableButton.svelte'
import { t } from '$lib/i18n'
import { baseTables } from '$lib/store/table'
import { cn } from '$lib/utils'
Expand All @@ -14,11 +15,11 @@
<HoverCard.Trigger>
<span class="text-xs text-gray-400">
<i class="ti ti-table"></i>
{$t('n tables', { ns: 'base', n: tables.length })}</span
>
{$t('n tables', { ns: 'base', n: tables.length })}
</span>
</HoverCard.Trigger>
{#if tables.length}
<HoverCard.Content class="py-2 px-1.5">
<HoverCard.Content class="py-2 px-1.5">
{#if tables.length}
{#each tables as table}
<a
href={`/t/${table.id}`}
Expand All @@ -35,6 +36,8 @@
{table.name}
</a>
{/each}
</HoverCard.Content>
{/if}
{:else}
<CreateTableButton class="w-full" variant="outline" />
{/if}
</HoverCard.Content>
</HoverCard.Root>
31 changes: 31 additions & 0 deletions apps/frontend/src/lib/base/BaseMenu.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script lang="ts">
import { Button } from '$components/ui/button'
import * as DropdownMenu from '$components/ui/dropdown-menu'
import { t } from '$lib/i18n'
import ConfirmExportBaseAsTemplate from './ConfirmExportBaseAsTemplate.svelte'
import { confirmDeleteBase, confirmExportBaseTemplate } from '$lib/store/modal'
</script>

<DropdownMenu.Root>
<DropdownMenu.Trigger asChild let:builder>
<Button variant="ghost" size="icon" builders={[builder]}>
<i class="ti ti-dots"></i>
</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content class="w-56">
<DropdownMenu.Item class="text-xs gap-2" on:click={() => confirmExportBaseTemplate.open()}>
<i class="ti ti-file-export"></i>
<span>
{$t('Export Base Template', { ns: 'base' })}
</span>
</DropdownMenu.Item>
<DropdownMenu.Item class="text-red-500 text-xs gap-2" on:click={() => ($confirmDeleteBase = true)}>
<i class="ti ti-trash"></i>
<span>
{$t('Delete Base', { ns: 'base' })}
</span>
</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu.Root>

<ConfirmExportBaseAsTemplate />
2 changes: 1 addition & 1 deletion apps/frontend/src/lib/base/Bases.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
variant="ghost"
size="icon"
href={`/bases/${base.id}`}
class="text-gray-600 flex opacity-0 group-hover:opacity-100 items-center transition"
class="text-gray-500 flex opacity-0 group-hover:opacity-100 items-center transition"
>
<i class="ti ti-settings"></i>
</Button>
Expand Down
Loading

0 comments on commit ce09110

Please sign in to comment.