-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
323 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget-share-table.gql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
query GetDashboardWidgetShareTable($shareId: ID!, $tableId: ID!) { | ||
tableByShareDashboard(shareId: $shareId, tableId: $tableId) { | ||
id | ||
name | ||
|
||
base { | ||
id | ||
name | ||
} | ||
|
||
schema { | ||
id | ||
name | ||
type | ||
defaultValue | ||
display | ||
constraint | ||
option | ||
} | ||
|
||
views { | ||
id | ||
name | ||
type | ||
filter | ||
color | ||
sort | ||
aggregate | ||
fields | ||
} | ||
} | ||
} |
15 changes: 10 additions & 5 deletions
15
apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
<script lang="ts"> | ||
import { TableFactory, type IWidgetDTO } from "@undb/table" | ||
import { GetDashboardWidgetTableStore } from "$houdini" | ||
import { onMount } from "svelte" | ||
import { GetDashboardWidgetShareTableStore, GetDashboardWidgetTableStore } from "$houdini" | ||
import Widget from "../widget/widget.svelte" | ||
import { setTable } from "$lib/store/table.store" | ||
import { writable } from "svelte/store" | ||
export let tableId: string | undefined | ||
export let shareId: string | undefined = undefined | ||
export let widget: IWidgetDTO | ||
export let movePointerDown: ((e: Event) => void) | undefined = undefined | ||
export let resizePointerDown: ((e: Event) => void) | undefined = undefined | ||
const store = new GetDashboardWidgetTableStore() | ||
const shareStore = new GetDashboardWidgetShareTableStore() | ||
$: if (tableId) { | ||
store.fetch({ variables: { tableId } }) | ||
if (shareId) { | ||
shareStore.fetch({ variables: { shareId, tableId } }) | ||
} else { | ||
store.fetch({ variables: { tableId } }) | ||
} | ||
} | ||
$: table = $store.data?.table | ||
$: table = shareId ? $shareStore.data?.tableByShareDashboard : $store.data?.table | ||
$: tableDo = table ? new TableFactory().fromJSON(table) : undefined | ||
$: if (tableDo) { | ||
setTable(writable(tableDo)) | ||
} | ||
</script> | ||
|
||
<Widget table={tableDo} {widget} {tableId} {movePointerDown} {resizePointerDown} /> | ||
<Widget table={tableDo} {widget} {tableId} {shareId} {movePointerDown} {resizePointerDown} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
apps/frontend/src/routes/(share)/s/[d]/[shareId]/+layout.gql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
query GetDashboardByShare($shareId: ID!) { | ||
dashboardByShare(shareId: $shareId) { | ||
id | ||
name | ||
description | ||
baseId | ||
spaceId | ||
layout | ||
share { | ||
enabled | ||
id | ||
} | ||
widgets { | ||
table { | ||
id | ||
} | ||
widget { | ||
id | ||
name | ||
item | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
apps/frontend/src/routes/(share)/s/[d]/[shareId]/+layout.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script lang="ts"> | ||
import { DashboardFactory } from "@undb/dashboard" | ||
import type { LayoutData } from "./$types" | ||
import { setDashboard } from "$lib/store/dashboard.store" | ||
import { writable } from "svelte/store" | ||
import { shareStore } from "$lib/store/share.store" | ||
export let data: LayoutData | ||
$: dashboardStore = data.dashboardStore | ||
$: dashboard = $dashboardStore.data?.dashboardByShare | ||
$: share = dashboard?.share | ||
$: if (dashboard) { | ||
const dashboardDo = DashboardFactory.fromJSON(dashboard) | ||
setDashboard(writable(dashboardDo)) | ||
} | ||
$: if (share && dashboard) { | ||
shareStore.set(dashboard.id, { | ||
enabled: share.enabled, | ||
id: share.id, | ||
target: { type: "dashboard", id: dashboard.id }, | ||
}) | ||
} | ||
</script> | ||
|
||
<svelte:head> | ||
<title>{dashboard?.name || "undb"} - undb</title> | ||
</svelte:head> | ||
|
||
<main> | ||
{#if dashboard} | ||
<slot /> | ||
{/if} | ||
</main> |
23 changes: 23 additions & 0 deletions
23
apps/frontend/src/routes/(share)/s/[d]/[shareId]/+layout.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { GetDashboardByShareStore } from "$houdini" | ||
import { redirect } from "@sveltejs/kit" | ||
import type { LayoutLoad } from "./$types" | ||
|
||
export const prerender = "auto" | ||
|
||
export const load: LayoutLoad = async (event) => { | ||
const { shareId } = event.params | ||
|
||
event.depends(`undb:dashboard:${shareId}`) | ||
|
||
const store = new GetDashboardByShareStore() | ||
|
||
const data = await store.fetch({ event, variables: { shareId }, policy: "NetworkOnly" }) | ||
|
||
if (data.errors?.length) { | ||
throw redirect(302, "/") | ||
} | ||
|
||
return { | ||
dashboardStore: store, | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
apps/frontend/src/routes/(share)/s/[d]/[shareId]/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<script lang="ts"> | ||
import { page } from "$app/stores" | ||
import DashboardWidgets from "$lib/components/blocks/dashboard/dashboard-widgets.svelte" | ||
import { getDashboard } from "$lib/store/dashboard.store" | ||
import { GaugeIcon } from "lucide-svelte" | ||
const dashboard = getDashboard() | ||
const shareId = $page.params.shareId | ||
</script> | ||
|
||
<div class="flex h-full flex-col"> | ||
<header class="flex items-center justify-between border-b px-4 py-2"> | ||
<h1 class="flex items-center text-lg font-medium"> | ||
<GaugeIcon class="mr-2 size-5" /> | ||
{$dashboard.name.value} | ||
</h1> | ||
</header> | ||
<main class="px-4 py-4"> | ||
<DashboardWidgets {shareId} /> | ||
</main> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Query, type QueryProps } from "@undb/domain" | ||
import { shareIdSchema } from "@undb/share" | ||
import { z } from "@undb/zod" | ||
|
||
export const getDashboardByShareQuery = z.object({ | ||
shareId: shareIdSchema, | ||
}) | ||
|
||
export type IGetDashboardByShareQuery = z.infer<typeof getDashboardByShareQuery> | ||
|
||
export class GetDashboardByShareQuery extends Query implements IGetDashboardByShareQuery { | ||
public readonly shareId: string | ||
|
||
constructor(query: QueryProps<IGetDashboardByShareQuery>) { | ||
super() | ||
this.shareId = query.shareId | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/queries/src/get-table-by-share-dashboard.query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Query, type QueryProps } from "@undb/domain" | ||
import { shareIdSchema } from "@undb/share" | ||
import { tableId } from "@undb/table" | ||
import { z } from "@undb/zod" | ||
|
||
export const getTableByShareDashboardQuery = z.object({ | ||
shareId: shareIdSchema, | ||
tableId: tableId, | ||
}) | ||
|
||
export type IGetTableByShareDashboardQuery = z.infer<typeof getTableByShareDashboardQuery> | ||
|
||
export class GetTableByShareDashboardQuery extends Query implements IGetTableByShareDashboardQuery { | ||
public readonly shareId: string | ||
public readonly tableId: string | ||
|
||
constructor(props: QueryProps<IGetTableByShareDashboardQuery>) { | ||
super() | ||
this.shareId = props.shareId | ||
this.tableId = props.tableId | ||
} | ||
} |
Oops, something went wrong.