Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: sheet dashboard UI (#1140)

STEVEN9282d182e5c4
diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vue
index 9240d76b3f..44cd233a29 100644
--- a/frontend/src/components/ProfileDropdown.vue
+++ b/frontend/src/components/ProfileDropdown.vue
@@ -123,10 +123,10 @@
<script lang="ts">
import { computed, defineComponent, ref } from "vue";
import { useRouter } from "vue-router";
-import PrincipalAvatar from "./PrincipalAvatar.vue";
-import { ServerInfo } from "../types";
-import { isDBAOrOwner } from "../utils";
-import { useLanguage } from "../composables/useLanguage";
+import { storeToRefs } from "pinia";
+import { ServerInfo } from "@/types";
+import { isDBAOrOwner } from "@/utils";
+import { useLanguage } from "@/composables/useLanguage";
import {
pushNotification,
useActuatorStore,
@@ -134,12 +134,11 @@ import {
useDebugStore,
useUIStateStore,
} from "@/store";
-import { storeToRefs } from "pinia";
+import PrincipalAvatar from "./PrincipalAvatar.vue";
export default defineComponent({
name: "ProfileDropdown",
components: { PrincipalAvatar },
- props: {},
setup() {
const actuatorStore = useActuatorStore();
const authStore = useAuthStore();
@@ -233,7 +232,7 @@ export default defineComponent({
pushNotification({
module: "bytebase",
style: "SUCCESS",
- title: info,
+ title: JSON.stringify(info, null, 4),
});
});
};
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index 56d507e052..b86ef19287 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -3,6 +3,9 @@
</template>
<script lang="ts" setup>
+import { reactive, onMounted } from "vue";
+import { useRoute } from "vue-router";
+import { useSQLEditorConnection } from "@/composables/useSQLEditorConnection";
import {
useCurrentUser,
useDatabaseStore,
@@ -10,9 +13,9 @@ import {
useProjectStore,
useTableStore,
useSQLEditorStore,
+ useTabStore,
useSheetStore,
} from "@/store";
-import { reactive, onMounted } from "vue";
import {
Instance,
Database,
@@ -23,10 +26,9 @@ import {
InstanceId,
DatabaseId,
Project,
-} from "../types";
+} from "@/types";
-const databaseStore = useDatabaseStore();
-const sheetStore = useSheetStore();
+const route = useRoute();
const state = reactive<{
projectList: Project[];
@@ -40,8 +42,12 @@ const state = reactive<{
const currentUser = useCurrentUser();
const projectStore = useProjectStore();
+const databaseStore = useDatabaseStore();
const tableStore = useTableStore();
const sqlEditorStore = useSQLEditorStore();
+const tabStore = useTabStore();
+const sheetStore = useSheetStore();
+const { setConnectionContextFromCurrentTab } = useSQLEditorConnection();
const prepareAccessibleConnectionByProject = async () => {
// It will also be called when user logout
@@ -120,11 +126,30 @@ const prepareSQLEditorContext = async () => {
sqlEditorStore.setConnectionTree(connectionTree);
sqlEditorStore.setConnectionContext({ isLoadingTree: false });
sqlEditorStore.fetchQueryHistoryList();
- sheetStore.fetchSheetList();
+};
+
+// Get sheetId from query.
+const prepareSheetFromQuery = async () => {
+ const sheetId = Number(route.query.sheetId);
+ if (!Number.isNaN(sheetId)) {
+ const sheet = await sheetStore.fetchSheetById(sheetId);
+ tabStore.updateCurrentTab({
+ sheetId: sheet.id,
+ name: sheet.name,
+ statement: sheet.statement,
+ isSaved: true,
+ });
+ setConnectionContextFromCurrentTab();
+ useSQLEditorStore().setSQLEditorState({
+ sharedSheet: sheet,
+ shouldSetContent: true,
+ });
+ }
};
onMounted(async () => {
await prepareAccessibleConnectionByProject();
await prepareSQLEditorContext();
+ await prepareSheetFromQuery();
});
</script>
diff --git a/frontend/src/composables/useSQLEditorConnection.ts b/frontend/src/composables/useSQLEditorConnection.ts
index 7cddbb23e1..f80a48958b 100644
--- a/frontend/src/composables/useSQLEditorConnection.ts
+++ b/frontend/src/composables/useSQLEditorConnection.ts
@@ -1,6 +1,6 @@
import { useRouter } from "vue-router";
-import { DEFAULT_PROJECT_ID, SheetState, UNKNOWN_ID } from "../types";
+import { DEFAULT_PROJECT_ID, Sheet, UNKNOWN_ID } from "../types";
import { connectionSlug } from "../utils";
import { getDefaultConnectionContext } from "@/store";
import {
@@ -18,32 +18,32 @@ const useSQLEditorConnection = () => {
/**
* Set the connection by tab info
- * @param param
- * @param payload
*/
const setConnectionContextFromCurrentTab = () => {
const currentTab = tabStore.currentTab;
- const sheetById = sheetStore.sheetById as SheetState["sheetById"];
+ const sheetById = sheetStore.sheetById;
if (currentTab.sheetId && sheetById.has(currentTab.sheetId)) {
- const sheet = sheetById.get(currentTab.sheetId);
+ const sheet = sheetById.get(currentTab.sheetId) as Sheet;
sqlEditorStore.setConnectionContext({
hasSlug: true,
- projectId: sheet?.database?.projectId || DEFAULT_PROJECT_ID,
- instanceId: sheet?.database?.instanceId || UNKNOWN_ID,
- databaseId: sheet?.databaseId || UNKNOWN_ID,
+ projectId: sheet.database?.projectId || DEFAULT_PROJECT_ID,
+ instanceId: sheet.database?.instanceId || UNKNOWN_ID,
+ databaseId: sheet.databaseId || UNKNOWN_ID,
});
- // deal with the sheet is without databaseId
- if (sheet?.databaseId) {
- const database = useDatabaseStore().getDatabaseById(sheet?.databaseId);
+ if (sheet.databaseId) {
+ const database = useDatabaseStore().getDatabaseById(sheet.databaseId);
router.replace({
name: "sql-editor.detail",
params: {
connectionSlug: connectionSlug(database),
},
+ query: {
+ sheetId: sheet.id,
+ },
});
}
} else {
diff --git a/frontend/src/layouts/SheetDashboardLayout.vue b/frontend/src/layouts/SheetDashboardLayout.vue
new file mode 100644
index 0000000000..5e4988062e
--- /dev/null
+++ b/frontend/src/layouts/SheetDashboardLayout.vue
@@ -0,0 +1,63 @@
+<template>
+ <div class="relative h-screen overflow-hidden flex flex-col">
+ <template v-if="isDemo">
+ <BannerDemo />
+ </template>
+ <template v-else-if="isNearTrialExpireTime">
+ <BannerTrial />
+ </template>
+
+ <nav class="bg-white border-b border-block-border">
+ <div class="max-w-full mx-auto px-4">
+ <EditorHeader />
+ </div>
+ </nav>
+
+ <!-- Suspense is experimental, be aware of the potential change -->
+ <Suspense>
+ <template #default>
+ <router-view />
+ </template>
+ <template #fallback>
+ <div class="flex flex-row justify-between p-4 space-x-2">
+ <span class="items-center flex">Loading...</span>
+ <button
+ class="items-center flex justify-center btn-normal"
+ @click.prevent="ping"
+ >
+ Ping
+ </button>
+ </div>
+ </template>
+ </Suspense>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { storeToRefs } from "pinia";
+import {
+ pushNotification,
+ useActuatorStore,
+ useSubscriptionStore,
+} from "@/store";
+import { ServerInfo } from "@/types";
+import BannerDemo from "@/views/BannerDemo.vue";
+import BannerTrial from "@/views/BannerTrial.vue";
+import EditorHeader from "@/views/sql-editor/EditorHeader.vue";
+
+const actuatorStore = useActuatorStore();
+const subscriptionStore = useSubscriptionStore();
+
+const ping = () => {
+ actuatorStore.fetchInfo().then((info: ServerInfo) => {
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: JSON.stringify(info, null, 4),
+ });
+ });
+};
+
+const { isDemo } = storeToRefs(actuatorStore);
+const { isNearTrialExpireTime } = storeToRefs(subscriptionStore);
+</script>
diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.yml
index 188e35f8ea..e357cfbfaf 100644
--- a/frontend/src/locales/en.yml
+++ b/frontend/src/locales/en.yml
@@ -181,6 +181,13 @@ common:
file-selector:
type-limit: Only support {extension} file
size-limit: File size should less than {size} MiB
+ no-data: No data
+ visibility: Visibility
+ star: Star
+ unstar: Unstar
+ starred: Starred
+ duplicate: Duplicate
+ clear-search: Clear search
enable: Enable
disable: Disable
error-page:
@@ -1195,7 +1202,6 @@ sql-editor:
search-sheets: Search Sheets
hint-tips:
confirm-to-delete-this-history: Confirm to delete this history?
- confirm-to-delete-this-sheet: Confirm to delete this sheet?
confirm-to-close-unsaved-tab: Confirm to close unsaved tab?
please-input-the-tab-label: Please input the tab label!
copy-code: Copy code
@@ -1206,7 +1212,7 @@ sql-editor:
view-all-tabs: View all Tabs
sheet: Sheet
sheets: Sheets
- connection-holder: Select a connection or select a sheet from left panel to get started
+ connection-holder: Select a connection from left panel to get started
link-access: Link access
private: Private
private-desc: Only you can access this sheet
@@ -1392,6 +1398,16 @@ subscription:
title: Enterprise Plan
label: Early access
desc: Large organization, has dedicated DBA group to manage database fleet
+sheet:
+ self: Sheets
+ my-sheets: My Sheets
+ shared-with-me: Shared with me
+ actions:
+ sync-from-vcs: Sync from VCS
+ hint-tips:
+ confirm-to-sync-sheet: Confirm to sync sheets?
+ confirm-to-delete-this-sheet: Confirm to delete this sheet?
+ confirm-to-duplicate-sheet: Confirm to duplicate this sheet?
engine:
mysql: MySQL
common: Common
diff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.yml
index 6f1fc661c0..f319c94bc8 100644
--- a/frontend/src/locales/zh-CN.yml
+++ b/frontend/src/locales/zh-CN.yml
@@ -181,6 +181,13 @@ common:
file-selector:
type-limit: 仅支持 {extension} 类型的文件
size-limit: 文件大小需小于 {size} MiB
+ no-data: 无数据
+ visibility: 可见性
+ star: 添加收藏
+ unstar: 取消收藏
+ starred: 已收藏
+ duplicate: 拷贝
+ clear-search: 清空搜索
enable: 开启
disable: 禁用
error-page:
@@ -1044,7 +1051,6 @@ sql-editor:
search-sheets: 搜索工作表
hint-tips:
confirm-to-delete-this-history: 确定删除这条记录?
- confirm-to-delete-this-sheet: 确定删除这条查询语句?
confirm-to-close-unsaved-tab: 确定关闭未保存的标签页?
please-input-the-tab-label: 请输入标签页名称!
copy-code: 复制代码
@@ -1055,7 +1061,7 @@ sql-editor:
view-all-tabs: 查看所有标签页
sheet: 工作表
sheets: 工作表
- connection-holder: 选择一个数据连接或者从左侧面板选择一个工作表以开始
+ connection-holder: 选择一个数据连接以开始
link-access: 链接访问权限
private: 私有
private-desc: 只有您自己可以访问此工作表
@@ -1221,6 +1227,17 @@ subscription:
title: 企业版
label: 预览版
desc: 大型组织,有专属 DBA 团队来管理数据库
+sheet:
+ self: 工作表
+ my-sheets: 我的工作表
+ shared-with-me: 与我共享
+ starred: 已加星标
+ actions:
+ sync-from-vcs: 从 VCS 同步数据
+ hint-tips:
+ confirm-to-sync-sheet: 确定要同步工作表?
+ confirm-to-delete-this-sheet: 确定删除这条工作表?
+ confirm-to-duplicate-sheet: 确定要复制这条工作表?
engine:
mysql: MySQL
common: 通用
diff --git a/frontend/src/plugins/naive-ui.ts b/frontend/src/plugins/naive-ui.ts
index 65d1005e2c..b5eeaf3bb3 100644
--- a/frontend/src/plugins/naive-ui.ts
+++ b/frontend/src/plugins/naive-ui.ts
@@ -22,6 +22,7 @@ import {
NTag,
NTooltip,
NTree,
+ NSelect,
NUpload,
NUploadDragger,
} from "naive-ui";
@@ -49,6 +50,7 @@ const naive = create({
NTag,
NTooltip,
NTree,
+ NSelect,
NUpload,
NUploadDragger,
],
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index f5e4dad907..834e328a60 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -11,6 +11,7 @@ import DatabaseLayout from "../layouts/DatabaseLayout.vue";
import InstanceLayout from "../layouts/InstanceLayout.vue";
import SplashLayout from "../layouts/SplashLayout.vue";
import SQLEditorLayout from "../layouts/SQLEditorLayout.vue";
+import SheetDashboardLayout from "../layouts/SheetDashboardLayout.vue";
import { t } from "../plugins/i18n";
import {
useAuthStore,
@@ -21,13 +22,7 @@ import {
usePrincipalStore,
useRouterStore,
} from "../store";
-import {
- Database,
- QuickActionType,
- Sheet,
- UNKNOWN_ID,
- SheetId,
-} from "../types";
+import { Database, QuickActionType, Sheet, UNKNOWN_ID } from "../types";
import { idFromSlug, isDBAOrOwner, isOwner } from "../utils";
// import PasswordReset from "../views/auth/PasswordReset.vue";
import Signin from "../views/auth/Signin.vue";
@@ -807,6 +802,37 @@ const routes: Array<RouteRecordRaw> = [
},
],
},
+ {
+ path: "/sheets",
+ name: "sheets",
+ component: SheetDashboardLayout,
+ children: [
+ {
+ path: "",
+ name: "sheets.dashboard",
+ meta: { title: () => "Sheets" },
+ component: () => import("../views/SheetDashboard.vue"),
+ },
+ {
+ path: "my",
+ name: "sheets.my",
+ meta: { title: () => "Sheets" },
+ component: () => import("../views/SheetDashboard.vue"),
+ },
+ {
+ path: "shared",
+ name: "sheets.shared",
+ meta: { title: () => "Sheets" },
+ component: () => import("../views/SheetDashboard.vue"),
+ },
+ {
+ path: "starred",
+ name: "sheets.starred",
+ meta: { title: () => "Sheets" },
+ component: () => import("../views/SheetDashboard.vue"),
+ },
+ ],
+ },
];
export const router = createRouter({
@@ -939,6 +965,7 @@ router.beforeEach((to, from, next) => {
to.name === "workspace.issue" ||
to.name === "workspace.environment" ||
to.name === "sql-editor.home" ||
+ to.name?.toString().startsWith("sheets") ||
(to.name?.toString().startsWith("setting") &&
to.name?.toString() != "setting.workspace.version-control.detail" &&
to.name?.toString() != "setting.workspace.schema-review-policy.detail")
diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.ts
index 1ab446d034..8f1586353e 100644
--- a/frontend/src/store/modules/project.ts
+++ b/frontend/src/store/modules/project.ts
@@ -156,6 +156,7 @@ export const useProjectStore = defineStore("project", {
return this.projectById.get(projectId) || (unknown("PROJECT") as Project);
},
+
async fetchProjectList() {
const data = (await axios.get(`/api/project`)).data;
const projectList = data.data.map((project: ResourceObject) => {
diff --git a/frontend/src/store/modules/sheet.ts b/frontend/src/store/modules/sheet.ts
index e5a499be15..99a3217d64 100644
--- a/frontend/src/store/modules/sheet.ts
+++ b/frontend/src/store/modules/sheet.ts
@@ -14,6 +14,10 @@ import {
ProjectMember,
unknown,
UNKNOWN_ID,
+ SheetFind,
+ SheetCreate,
+ SheetOrganizerUpsert,
+ ProjectId,
} from "@/types";
import { getPrincipalFromIncludedList } from "./principal";
import { useAuthStore } from "./auth";
@@ -69,7 +73,9 @@ export const useSheetStore = defineStore("sheet", {
currentSheet(state) {
const currentTab = useTabStore().currentTab;
- if (!currentTab || isEmpty(currentTab)) return unknown("SHEET") as Sheet;
+ if (!currentTab || isEmpty(currentTab)) {
+ return unknown("SHEET");
+ }
const sheetId = currentTab.sheetId || UNKNOWN_ID;
@@ -85,9 +91,9 @@ export const useSheetStore = defineStore("sheet", {
},
/**
* Check the sheet whether is read-only.
- * 1、If the sheet is not created yet, it can not be edited.
- * 2、If the sheet is created by the current user, it can be edited.
- * 3、If the sheet is created by other user, will be checked the visibility of the sheet.
+ * 1. If the sheet is not created yet, it can not be edited.
+ * 2. If the sheet is created by the current user, it can be edited.
+ * 3. If the sheet is created by other user, will be checked the visibility of the sheet.
* a) If the sheet's visibility is private or public, it can be edited only if the current user is the creator of the sheet.
* b) If the sheet's visibility is project, will be checked whether the current user is the `OWNER` of the project, only the current user is the `OWNER` of the project, it can be edited.
*/
@@ -133,9 +139,6 @@ export const useSheetStore = defineStore("sheet", {
},
actions: {
- setSheetState(payload: Partial<SheetState>) {
- Object.assign(this, payload);
- },
setSheetList(payload: Sheet[]) {
this.sheetList = payload;
},
@@ -146,16 +149,20 @@ export const useSheetStore = defineStore("sheet", {
}
this.sheetById.set(sheetId, sheet);
},
- deleteSheetById(sheetId: SheetId) {
- const idx = this.sheetList.findIndex((sheet) => sheet.id === sheetId);
- if (idx !== -1) this.sheetList.splice(idx, 1);
+ upsertSheet(payload: {
+ sheet: Pick<Sheet, "id" | "name" | "statement">;
+ currentTab: TabInfo;
+ }): Promise<Sheet> {
+ const { sheet, currentTab } = payload;
+ const hasSheet = this.sheetById.has(sheet.id);
- if (this.sheetById.has(sheetId)) {
- this.sheetById.delete(sheetId);
+ if (hasSheet) {
+ return this.patchSheetById(sheet);
}
+
+ return this.createSheetByTab(currentTab);
},
- // create
- async createSheet(currentTab: TabInfo): Promise<Sheet> {
+ async createSheetByTab(currentTab: TabInfo): Promise<Sheet> {
const sqlEditorStore = useSQLEditorStore();
const ctx = sqlEditorStore.connectionContext;
@@ -186,13 +193,39 @@ export const useSheetStore = defineStore("sheet", {
return sheet;
},
- // retrieve
- async fetchSheetList() {
- const sqlEditorStore = useSQLEditorStore();
- sqlEditorStore.setSQLEditorState({ isFetchingSheet: true });
- const data = (await axios.get(`/api/sheet`)).data;
- const sheetList: Sheet[] = data.data.map((rawData: ResourceObject) => {
- const sheet = convertSheet(rawData, data.included);
+ async createSheet(sheetCreate: SheetCreate): Promise<Sheet> {
+ const resData = (
+ await axios.post(`/api/sheet`, {
+ data: {
+ type: "createSheet",
+ attributes: sheetCreate,
+ },
+ })
+ ).data;
+ const sheet = convertSheet(resData.data, resData.included);
+
+ this.setSheetList(
+ this.sheetList.concat(sheet).sort((a, b) => b.createdTs - a.createdTs)
+ );
+ this.setSheetById({
+ sheetId: sheet.id,
+ sheet: sheet,
+ });
+
+ return sheet;
+ },
+ async fetchMySheetList(sheetFind?: SheetFind) {
+ const queryList = [];
+ if (sheetFind?.projectId) {
+ queryList.push(`projectId=${sheetFind.projectId}`);
+ }
+ if (sheetFind?.databaseId) {
+ queryList.push(`databaseId=${sheetFind.databaseId}`);
+ }
+ const resData = (await axios.get(`/api/sheet/my?${queryList.join("&")}`))
+ .data;
+ const sheetList: Sheet[] = resData.data.map((rawData: ResourceObject) => {
+ const sheet = convertSheet(rawData, resData.included);
this.setSheetById({
sheetId: sheet.id,
sheet: sheet,
@@ -200,8 +233,60 @@ export const useSheetStore = defineStore("sheet", {
return sheet;
});
- this.setSheetList(sheetList.sort((a, b) => b.createdTs - a.createdTs));
- sqlEditorStore.setSQLEditorState({ isFetchingSheet: false });
+ sheetList.sort((a, b) => b.createdTs - a.createdTs);
+ this.setSheetList(sheetList);
+
+ return sheetList;
+ },
+ async fetchSharedSheetList(sheetFind?: SheetFind) {
+ const queryList = [];
+ if (sheetFind?.projectId) {
+ queryList.push(`projectId=${sheetFind.projectId}`);
+ }
+ if (sheetFind?.databaseId) {
+ queryList.push(`databaseId=${sheetFind.databaseId}`);
+ }
+ const resData = (
+ await axios.get(`/api/sheet/shared?${queryList.join("&")}`)
+ ).data;
+ const sheetList: Sheet[] = resData.data.map((rawData: ResourceObject) => {
+ const sheet = convertSheet(rawData, resData.included);
+ this.setSheetById({
+ sheetId: sheet.id,
+ sheet: sheet,
+ });
+ return sheet;
+ });
+
+ sheetList.sort((a, b) => b.createdTs - a.createdTs);
+ this.setSheetList(sheetList);
+
+ return sheetList;
+ },
+ async fetchStarredSheetList(sheetFind?: SheetFind) {
+ const queryList = [];
+ if (sheetFind?.projectId) {
+ queryList.push(`projectId=${sheetFind.projectId}`);
+ }
+ if (sheetFind?.databaseId) {
+ queryList.push(`databaseId=${sheetFind.databaseId}`);
+ }
+ const resData = (
+ await axios.get(`/api/sheet/starred?${queryList.join("&")}`)
+ ).data;
+ const sheetList: Sheet[] = resData.data.map((rawData: ResourceObject) => {
+ const sheet = convertSheet(rawData, resData.included);
+ this.setSheetById({
+ sheetId: sheet.id,
+ sheet: sheet,
+ });
+ return sheet;
+ });
+
+ sheetList.sort((a, b) => b.createdTs - a.createdTs);
+ this.setSheetList(sheetList);
+
+ return sheetList;
},
async fetchSheetById(sheetId: SheetId) {
const data = (await axios.get(`/api/sheet/${sheetId}`)).data;
@@ -213,34 +298,17 @@ export const useSheetStore = defineStore("sheet", {
return sheet;
},
- // update
- async patchSheetById({
- id,
- name,
- statement,
- visibility,
- }: SheetPatch): Promise<Sheet> {
- const attributes: Omit<SheetPatch, "id"> = {};
- if (name) {
- attributes.name = name;
- }
- if (statement) {
- attributes.statement = statement;
- }
- if (visibility) {
- attributes.visibility = visibility;
- }
-
- const result = (
- await axios.patch(`/api/sheet/${id}`, {
+ async patchSheetById(sheetPatch: SheetPatch): Promise<Sheet> {
+ const resData = (
+ await axios.patch(`/api/sheet/${sheetPatch.id}`, {
data: {
type: "sheetPatch",
- attributes,
+ attributes: sheetPatch,
},
})
).data;
- const sheet = convertSheet(result.data, result.included);
+ const sheet = convertSheet(resData.data, resData.included);
this.setSheetById({
sheetId: sheet.id,
@@ -249,25 +317,28 @@ export const useSheetStore = defineStore("sheet", {
return sheet;
},
- // delete
- async deleteSheet(id: number) {
- await axios.delete(`/api/sheet/${id}`);
-
- this.deleteSheetById(id);
+ async upsertSheetOrganizer(sheetOrganizerUpsert: SheetOrganizerUpsert) {
+ await axios.patch(`/api/sheet/${sheetOrganizerUpsert.sheeId}/organizer`, {
+ data: {
+ type: "sheetOrganizerUpsert",
+ attributes: sheetOrganizerUpsert,
+ },
+ });
},
- // upsert
- async upsertSheet(payload: {
- sheet: Pick<Sheet, "id" | "name" | "statement">;
- currentTab: TabInfo;
- }): Promise<Sheet> {
- const { sheet, currentTab } = payload;
- const hasSheet = this.sheetById.has(sheet.id);
+ async deleteSheetById(sheetId: SheetId) {
+ await axios.delete(`/api/sheet/${sheetId}`);
- if (hasSheet) {
- return this.patchSheetById(sheet);
- } else {
- return this.createSheet(currentTab);
+ const idx = this.sheetList.findIndex((sheet) => sheet.id === sheetId);
+ if (idx !== -1) {
+ this.sheetList.splice(idx, 1);
}
+
+ if (this.sheetById.has(sheetId)) {
+ this.sheetById.delete(sheetId);
+ }
+ },
+ async syncSheetFromVCS(projectId: ProjectId) {
+ await axios.post(`/api/sheet/project/${projectId}/sync`);
},
},
});
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index c5ec716d39..851649f2be 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -39,4 +39,5 @@ export * from "./sqlEditor";
export * from "./tab";
export * from "./subscription";
export * from "./sheet";
+export * from "./sheetOrganizer";
export * from "./schemaSystem";
diff --git a/frontend/src/types/sheet.ts b/frontend/src/types/sheet.ts
index d51549ad17..8b714bb548 100644
--- a/frontend/src/types/sheet.ts
+++ b/frontend/src/types/sheet.ts
@@ -5,15 +5,23 @@ import {
Principal,
Project,
ProjectId,
+ RowStatus,
+ PrincipalId,
} from ".";
export type SheetVisibility = "PRIVATE" | "PROJECT" | "PUBLIC";
+export type SheetSource = "BYTEBASE" | "GITLAB_SELF_HOST" | "GITHUB_COM";
+
+export type SheetType = "SQL";
+
export interface Sheet {
id: SheetId;
// Standard fields
+ rowStatus: RowStatus;
creator: Principal;
+ creatorId: PrincipalId;
createdTs: number;
updater: Principal;
updatedTs: number;
@@ -28,20 +36,36 @@ export interface Sheet {
name: string;
statement: string;
visibility: SheetVisibility;
+ source: SheetSource;
+ type: SheetType;
+ starred: boolean;
+ pinned: boolean;
}
-export type CreateSheetState = Omit<
- Sheet,
- "id" | "creator" | "createdTs" | "updater" | "updatedTs"
->;
+export interface SheetCreate {
+ projectId: ProjectId;
+ databaseId?: DatabaseId;
+ name: string;
+ statement: string;
+ visibility: SheetVisibility;
+}
-export type SheetPatch = Partial<
- Pick<Sheet, "id" | "name" | "statement" | "visibility">
->;
+export interface SheetPatch {
+ id: SheetId;
+ name?: string;
+ statement?: string;
+ visibility?: SheetVisibility;
+ rowStatus?: RowStatus;
+}
-export type SheetFind = Partial<
- Pick<Sheet, "projectId" | "databaseId" | "visibility">
->;
+export interface SheetFind {
+ creatorId?: PrincipalId;
+ rowStatus?: RowStatus;
+ projectId?: ProjectId;
+ databaseId?: DatabaseId;
+ visibility?: SheetVisibility;
+ organizerId?: PrincipalId;
+}
export type AccessOption = {
label: string;
diff --git a/frontend/src/types/sheetOrganizer.ts b/frontend/src/types/sheetOrganizer.ts
new file mode 100644
index 0000000000..c12ec84859
--- /dev/null
+++ b/frontend/src/types/sheetOrganizer.ts
@@ -0,0 +1,7 @@
+import { SheetId } from ".";
+
+export type SheetOrganizerUpsert = {
+ sheeId: SheetId;
+ starred?: boolean;
+ pinned?: boolean;
+};
diff --git a/frontend/src/views/SheetDashboard.vue b/frontend/src/views/SheetDashboard.vue
new file mode 100644
index 0000000000..d417aa4fa5
--- /dev/null
+++ b/frontend/src/views/SheetDashboard.vue
@@ -0,0 +1,458 @@
+<template>
+ <div class="w-full h-full grid grid-cols-[212px_1fr] gap-0">
+ <div
+ class="w-full h-auto flex flex-col justify-start items-start px-4 pl-6 py-2 border-r"
+ >
+ <router-link
+ v-for="nav in navigationList"
+ :key="nav.path"
+ :to="nav.path"
+ class="text-base p-2 px-3 rounded-lg mt-1 select-none hover:bg-gray-100"
+ active-class="actived-link"
+ exact-active-class="actived-link"
+ >{{ nav.label }}</router-link
+ >
+ </div>
+ <div
+ class="w-full h-full flex flex-col justify-start items-start overflow-y-auto px-4 py-4"
+ >
+ <div class="w-full px-4 mb-2 flex flex-row justify-between items-center">
+ <div class="flex flex-row justify-start items-center">
+ <div class="grow flex flex-row justify-start items-center">
+ <span class="text-sm mr-2 whitespace-nowrap"
+ >{{ $t("common.project") }}:
+ </span>
+ <n-select
+ v-model:value="projectSeletorValue"
+ :consistent-menu-width="false"
+ :options="projectSelectOptions"
+ />
+ </div>
+ <div class="ml-4">
+ <n-input
+ v-model:value="sheetSearchValue"
+ type="text"
+ :placeholder="t('common.search')"
+ >
+ <template #prefix>
+ <heroicons-outline:search class="w-4 h-auto text-gray-300" />
+ </template>
+ </n-input>
+ </div>
+ <div class="ml-4">
+ <n-button
+ v-show="shouldShowClearSearchBtn"
+ text
+ @click="handleClearSearchBtnClick"
+ >
+ {{ $t("common.clear-search") }}
+ </n-button>
+ </div>
+ </div>
+ <div>
+ <n-button
+ v-if="isDev() && selectedProject?.workflowType === 'VCS'"
+ @click="handleSyncSheetFromVCS"
+ >
+ <heroicons-outline:refresh class="w-4 h-auto mr-1" />
+ {{ $t("sheet.actions.sync-from-vcs") }}
+ </n-button>
+ </div>
+ </div>
+ <div class="w-full grid grid-cols-1">
+ <div
+ class="sheet-list-container text-sm text-gray-400"
+ :class="currentSubPath"
+ >
+ <span
+ v-for="header in getSheetTableHeaderLabelList()"
+ :key="header.key"
+ >{{ header.label }}</span
+ >
+ </div>
+ <div
+ v-if="state.isLoading"
+ class="w-full flex flex-col py-6 justify-start items-center"
+ >
+ <span class="text-sm leading-6 text-gray-500">{{
+ $t("sql-editor.loading-data")
+ }}</span>
+ </div>
+ <div
+ v-for="sheet in shownSheetList"
+ :key="sheet.id"
+ class="sheet-list-container text-sm cursor-pointer hover:bg-gray-100"
+ :class="currentSubPath"
+ @click="handleSheetClick(sheet)"
+ >
+ <span
+ v-for="value in getSheetTableContentValueList(sheet)"
+ :key="value.key"
+ class="truncate w-5/6"
+ >{{ value.value }}</span
+ >
+ <div class="flex flex-row justify-end items-center" @click.stop>
+ <n-dropdown
+ trigger="click"
+ :options="getSheetDropDownOptions(sheet)"
+ @select="(key: string) => handleDropDownActionBtnClick(key, sheet)"
+ >
+ <heroicons-outline:dots-horizontal
+ class="w-6 h-auto border border-gray-300 bg-white p-1 rounded outline-none shadow"
+ />
+ </n-dropdown>
+ </div>
+ </div>
+ <div
+ v-show="!state.isLoading && shownSheetList.length === 0"
+ class="w-full flex flex-col py-6 justify-start items-center"
+ >
+ <heroicons-outline:inbox class="w-12 h-auto text-gray-500" />
+ <span class="text-sm leading-6 text-gray-500">{{
+ $t("common.no-data")
+ }}</span>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed, onMounted, reactive, ref, watch } from "vue";
+import { useRoute, useRouter } from "vue-router";
+import { last } from "lodash";
+import { useDialog } from "naive-ui";
+import { t } from "@/plugins/i18n";
+import dayjs from "@/plugins/dayjs";
+import { useCurrentUser, useProjectStore, useSheetStore } from "@/store";
+import { Sheet, SheetCreate, SheetOrganizerUpsert } from "@/types";
+import { isDev } from "@/utils";
+
+interface LocalState {
+ isLoading: boolean;
+ sheetList: Sheet[];
+}
+
+const route = useRoute();
+const router = useRouter();
+const dialog = useDialog();
+const state = reactive<LocalState>({
+ isLoading: true,
+ sheetList: [],
+});
+const currentUser = useCurrentUser();
+const projectStore = useProjectStore();
+const sheetStore = useSheetStore();
+
+const projectSeletorValue = ref("");
+const sheetSearchValue = ref("");
+
+const navigationList = computed(() => {
+ return [
+ {
+ path: "/sheets/my",
+ label: t("sheet.my-sheets"),
+ },
+ {
+ path: "/sheets/shared",
+ label: t("sheet.shared-with-me"),
+ },
+ {
+ path: "/sheets/starred",
+ label: t("common.starred"),
+ },
+ ];
+});
+
+const shownSheetList = computed(() => {
+ return state.sheetList
+ .filter((sheet) => {
+ let t = true;
+
+ if (
+ projectSeletorValue.value !== "" &&
+ projectSeletorValue.value !== sheet.project.name
+ ) {
+ t = false;
+ }
+ if (sheetSearchValue.value !== "") {
+ if (
+ !sheet.name.includes(sheetSearchValue.value) &&
+ !sheet.statement.includes(sheetSearchValue.value)
+ ) {
+ t = false;
+ }
+ }
+
+ return t;
+ })
+ .sort((a, b) => b.updatedTs - a.updatedTs);
+});
+
+const projectList = computed(() => {
+ return projectStore.getProjectListByUser(currentUser.value.id);
+});
+
+const selectedProject = computed(() => {
+ for (const project of projectList.value) {
+ if (project.name === projectSeletorValue.value) {
+ return project;
+ }
+ }
+
+ return null;
+});
+
+const projectSelectOptions = computed(() => {
+ return [
+ {
+ label: t("common.all"),
+ value: "",
+ },
+ ].concat(
+ projectList.value.map((project) => {
+ return {
+ label: project.name,
+ value: project.name,
+ };
+ })
+ );
+});
+
+const shouldShowClearSearchBtn = computed(() => {
+ return projectSeletorValue.value !== "" || sheetSearchValue.value !== "";
+});
+
+const currentSubPath = computed(() => {
+ const { path } = route;
+ return last(path.split("/")) || "";
+});
+
+const fetchSheetData = async () => {
+ if (currentSubPath.value === "my") {
+ state.sheetList = await sheetStore.fetchMySheetList();
+ } else if (currentSubPath.value === "starred") {
+ state.sheetList = await sheetStore.fetchStarredSheetList();
+ } else if (currentSubPath.value === "shared") {
+ state.sheetList = await sheetStore.fetchSharedSheetList();
+ }
+};
+
+onMounted(async () => {
+ await projectStore.fetchProjectListByUser({
+ userId: currentUser.value.id,
+ });
+ await fetchSheetData();
+ state.isLoading = false;
+});
+
+watch(
+ () => route.path,
+ async () => {
+ await fetchSheetData();
+ }
+);
+
+const handleSheetClick = (sheet: Sheet) => {
+ router.push({
+ name: "sql-editor.home",
+ query: {
+ sheetId: sheet.id,
+ },
+ });
+};
+
+const handleClearSearchBtnClick = () => {
+ projectSeletorValue.value = "";
+ sheetSearchValue.value = "";
+};
+
+const handleSyncSheetFromVCS = () => {
+ if (
+ selectedProject.value === null ||
+ selectedProject.value.workflowType !== "VCS"
+ ) {
+ return;
+ }
+
+ const selectedProjectId = selectedProject.value.id;
+ const dialogInstance = dialog.create({
+ title: t("sheet.hint-tips.confirm-to-sync-sheet"),
+ type: "info",
+ async onPositiveClick() {
+ dialogInstance.closable = false;
+ dialogInstance.loading = true;
+ await sheetStore.syncSheetFromVCS(selectedProjectId);
+ await fetchSheetData();
+ dialogInstance.destroy();
+ },
+ positiveText: t("common.confirm"),
+ showIcon: true,
+ maskClosable: false,
+ });
+};
+
+const handleDropDownActionBtnClick = async (key: string, sheet: Sheet) => {
+ if (key === "delete") {
+ const dialogInstance = dialog.create({
+ title: t("sheet.hint-tips.confirm-to-delete-this-sheet"),
+ type: "info",
+ async onPositiveClick() {
+ await sheetStore.deleteSheetById(sheet.id);
+ dialogInstance.destroy();
+ },
+ onNegativeClick() {
+ dialogInstance.destroy();
+ },
+ negativeText: t("common.cancel"),
+ positiveText: t("common.confirm"),
+ showIcon: true,
+ });
+ } else if (key === "star" || key === "unstar") {
+ const sheetOrganizerUpsert: SheetOrganizerUpsert = {
+ sheeId: sheet.id,
+ };
+
+ if (key === "star") {
+ sheetOrganizerUpsert.starred = true;
+ } else if (key === "unstar") {
+ sheetOrganizerUpsert.starred = false;
+ }
+
+ await sheetStore.upsertSheetOrganizer(sheetOrganizerUpsert);
+ await fetchSheetData();
+ } else if (key === "duplicate") {
+ const dialogInstance = dialog.create({
+ title: t("sheet.hint-tips.confirm-to-duplicate-sheet"),
+ type: "info",
+ async onPositiveClick() {
+ const sheetCreate: SheetCreate = {
+ projectId: sheet.projectId,
+ name: sheet.name,
+ statement: sheet.statement,
+ visibility: "PRIVATE",
+ };
+ if (sheet.databaseId) {
+ sheetCreate.databaseId = sheet.databaseId;
+ }
+ await sheetStore.createSheet(sheetCreate);
+ dialogInstance.destroy();
+ },
+ onNegativeClick() {
+ dialogInstance.destroy();
+ },
+ negativeText: t("common.cancel"),
+ positiveText: t("common.confirm"),
+ showIcon: true,
+ });
+ }
+};
+
+const getSheetDropDownOptions = (sheet: Sheet) => {
+ const options = [];
+
+ if (sheet.starred) {
+ options.push({
+ key: "unstar",
+ label: t("common.unstar"),
+ });
+ } else {
+ options.push({
+ key: "star",
+ label: t("common.star"),
+ });
+ }
+
+ if (currentSubPath.value === "my" || currentSubPath.value === "starred") {
+ options.push({
+ key: "delete",
+ label: t("common.delete"),
+ });
+ } else if (currentSubPath.value === "shared") {
+ options.push({
+ key: "duplicate",
+ label: t("common.duplicate"),
+ });
+ }
+
+ return options;
+};
+
+const getSheetTableHeaderLabelList = () => {
+ const labelList = [
+ {
+ key: "name",
+ label: t("common.name").toUpperCase(),
+ },
+ {
+ key: "project",
+ label: t("common.project").toUpperCase(),
+ },
+ {
+ key: "visibility",
+ label: t("common.visibility").toUpperCase(),
+ },
+ ];
+
+ if (currentSubPath.value === "shared" || currentSubPath.value === "starred") {
+ labelList.push({
+ key: "creator",
+ label: t("common.creator").toUpperCase(),
+ });
+ }
+
+ labelList.push({
+ key: "updated",
+ label: t("common.updated-at").toUpperCase(),
+ });
+
+ return labelList;
+};
+
+const getSheetTableContentValueList = (sheet: Sheet) => {
+ const valueList = [
+ {
+ key: "name",
+ value: sheet.name,
+ },
+ {
+ key: "project",
+ value: sheet.project.name,
+ },
+ {
+ key: "visibility",
+ value: sheet.visibility,
+ },
+ ];
+
+ if (currentSubPath.value === "shared" || currentSubPath.value === "starred") {
+ valueList.push({
+ key: "creator",
+ value: sheet.creator.name,
+ });
+ }
+
+ valueList.push({
+ key: "updated",
+ value: dayjs.duration(sheet.updatedTs * 1000 - Date.now()).humanize(true),
+ });
+
+ return valueList;
+};
+</script>
+
+<style scoped>
+.actived-link {
+ @apply bg-gray-100 text-accent;
+}
+.sheet-list-container {
+ @apply w-full grid py-3 px-4 border-b text-sm leading-6 select-none;
+}
+.sheet-list-container.my {
+ grid-template-columns: 2fr repeat(3, 1fr) 32px;
+}
+.sheet-list-container.shared,
+.sheet-list-container.starred {
+ grid-template-columns: 2fr repeat(4, 1fr) 32px;
+}
+</style>
diff --git a/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue b/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue
index 49623d39f0..3f1acc226b 100644
--- a/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue
@@ -1,7 +1,7 @@
<template>
<div class="aside-panel h-full">
- <NTabs type="segment" default-value="databases" class="h-full">
- <NTabPane name="databases" :tab="$t('common.databases')">
+ <n-tabs type="segment" default-value="databases" class="h-full">
+ <n-tab-pane name="databases" :tab="$t('common.databases')">
<Splitpanes
horizontal
class="default-theme"
@@ -16,25 +16,21 @@
<TableSchema @close-pane="handleCloseTableSchemaPane" />
</Pane>
</Splitpanes>
- </NTabPane>
- <NTabPane name="sheets" :tab="$t('sql-editor.sheets')">
- <SheetContainer />
- </NTabPane>
- <NTabPane name="history" :tab="$t('common.history')">
+ </n-tab-pane>
+ <n-tab-pane name="history" :tab="$t('common.history')">
<QueryHistoryContainer />
- </NTabPane>
- </NTabs>
+ </n-tab-pane>
+ </n-tabs>
</div>
</template>
<script lang="ts" setup>
import { ref, watch } from "vue";
-
+import { useSQLEditorStore } from "@/store";
import DatabaseTree from "./DatabaseTree.vue";
import QueryHistoryContainer from "./QueryHistoryContainer.vue";
-import SheetContainer from "./SheetContainer.vue";
import TableSchema from "./TableSchema.vue";
-import { useSQLEditorStore } from "@/store";
+import { Splitpanes, Pane } from "splitpanes";
const FULL_HEIGHT = 100;
const DATABASE_PANE_SIZE = 60;
diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
index fcf3a79c1c..cb5a805178 100644
--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
@@ -4,17 +4,17 @@
class="databases-tree p-2 space-y-2 h-full"
>
<div class="databases-tree--input">
- <NInput
+ <n-input
v-model:value="searchPattern"
:placeholder="$t('sql-editor.search-databases')"
>
<template #prefix>
<heroicons-outline:search class="h-5 w-5 text-gray-300" />
</template>
- </NInput>
+ </n-input>
</div>
<div class="databases-tree--tree overflow-y-auto">
- <NTree
+ <n-tree
block-line
:data="treeData"
:pattern="searchPattern"
@@ -29,7 +29,7 @@
trigger="manual"
placement="bottom-start"
:show="showDropdown"
- :options="(dropdownOptions as any)"
+ :options="dropdownOptions"
:x="x"
:y="y"
@select="handleSelect"
@@ -54,17 +54,17 @@ import {
Database,
UNKNOWN_ID,
} from "@/types";
-import { connectionSlug, getHighlightHTMLByKeyWords } from "@/utils";
-import InstanceEngineIconVue from "@/components/InstanceEngineIcon.vue";
-import HeroiconsOutlineDatabase from "~icons/heroicons-outline/database.vue";
-import HeroiconsOutlineTable from "~icons/heroicons-outline/table.vue";
-import HeroiconsSolidDotsHorizontal from "~icons/heroicons-solid/dots-horizontal.vue";
import {
useDatabaseStore,
useInstanceStore,
useTabStore,
useSQLEditorStore,
} from "@/store";
+import { connectionSlug, getHighlightHTMLByKeyWords } from "@/utils";
+import InstanceEngineIconVue from "@/components/InstanceEngineIcon.vue";
+import HeroiconsOutlineDatabase from "~icons/heroicons-outline/database.vue";
+import HeroiconsOutlineTable from "~icons/heroicons-outline/table.vue";
+import HeroiconsSolidDotsHorizontal from "~icons/heroicons-solid/dots-horizontal.vue";
const router = useRouter();
const instanceStore = useInstanceStore();
@@ -77,55 +77,53 @@ const x = ref(0);
const y = ref(0);
const selectedKeys = ref<string[] | number[]>([]);
const sheetContext = ref<DropdownOption>();
+
const dropdownOptions = computed(() => {
if (!sheetContext.value) {
return [];
- }
- if (sheetContext.value.type === "table") {
+ } else if (sheetContext.value.type === "table") {
return [
{
label: "Alter table",
key: "editor.sheet.alter-table",
item: sheetContext.value,
},
- // TODO Just a thought
- // {
- // label: "Copy name",
- // key: "editor.sheet.copy-name",
- // item: sheetContext.value,
- // },
+ ];
+ } else {
+ return [
+ {
+ label: "Open in new tab",
+ key: "editor.sheet.new",
+ item: sheetContext.value,
+ },
+ {
+ label: "Set as context",
+ key: "editor.sheet.set-context",
+ item: sheetContext.value,
+ },
];
}
- return [
- {
- label: "Open in new tab",
- key: "editor.sheet.new",
- item: sheetContext.value,
- },
- {
- label: "Set as context",
- key: "editor.sheet.set-context",
- item: sheetContext.value,
- },
- ];
});
const treeData = computed(() => {
const tree = cloneDeep(sqlEditorStore.connectionTree);
- // mapping the prefix icons
return tree.map((instanceItem) => {
const instance = instanceStore.getInstanceById(instanceItem.id);
return {
...instanceItem,
- children: instanceItem?.children?.map((databaseItem) => {
+ children: instanceItem.children?.map((databaseItem) => {
return {
...databaseItem,
- children: databaseItem?.children?.map((tableItem) => {
+ children: databaseItem.children?.map((tableItem) => {
return {
...tableItem,
- prefix: () => h(HeroiconsOutlineTable, { class: "h-4 w-4" }),
+ isLeaf: true,
+ prefix: () =>
+ h(HeroiconsOutlineTable, {
+ class: "h-4 w-4",
+ }),
};
}),
prefix: () =>
@@ -134,7 +132,10 @@ const treeData = computed(() => {
}),
};
}),
- prefix: () => h(InstanceEngineIconVue, { instance }),
+ prefix: () =>
+ h(InstanceEngineIconVue, {
+ instance,
+ }),
};
});
});
@@ -192,7 +193,7 @@ const getFlattenConnectionTree = () => {
const setSheetContext = (option: any) => {
if (option) {
- let ctx: ConnectionContext = cloneDeep(sqlEditorStore.connectionContext);
+ let ctx = cloneDeep(sqlEditorStore.connectionContext) as ConnectionContext;
const { instanceList, databaseList } = getFlattenConnectionTree();
const getInstanceNameByInstanceId = (id: number) => {
@@ -213,10 +214,8 @@ const setSheetContext = (option: any) => {
ctx.databaseType = getInstanceEngineByInstanceId(option.id);
ctx.tableId = UNKNOWN_ID;
ctx.tableName = "";
- }
-
- // If selected item is database node
- if (option.type === "database") {
+ } else if (option.type === "database") {
+ // If selected item is database node
const instanceId = option.parentId;
ctx.instanceId = instanceId;
ctx.instanceName = getInstanceNameByInstanceId(instanceId);
@@ -225,10 +224,8 @@ const setSheetContext = (option: any) => {
ctx.databaseType = getInstanceEngineByInstanceId(instanceId);
ctx.tableId = UNKNOWN_ID;
ctx.tableName = "";
- }
-
- // If selected item is table node
- if (option.type === "table") {
+ } else if (option.type === "table") {
+ // If selected item is table node
const databaseId = option.parentId;
const databaseInfo = databaseList?.find((item) => item.id === databaseId);
const databaseName = databaseInfo?.label || "";
@@ -294,15 +291,18 @@ const renderSuffix = ({ option }: { option: TreeOption }) => {
};
const gotoAlterSchema = (option: any) => {
- console.log(option);
const databaseId = option.parentId;
const projectId = sqlEditorStore.findProjectIdByDatabaseId(databaseId);
const databaseList =
sqlEditorStore.connectionInfo.databaseListByProjectId.get(projectId);
- const databaseName = databaseList.find(
+ const database = databaseList?.find(
(database: Database) => database.id === databaseId
- ).name;
+ );
+ if (!database) {
+ return;
+ }
+ const databaseName = database.name;
router.push({
name: "workspace.issue.detail",
params: {
@@ -322,18 +322,18 @@ const handleSelect = (key: string) => {
const option = dropdownOptions.value.find(
(item) => item.key === key
) as DropdownOption;
+
if (key === "editor.sheet.alter-table") {
gotoAlterSchema(option.item);
- }
- if (key === "editor.sheet.set-context") {
+ } else if (key === "editor.sheet.set-context") {
setSheetContext(option.item);
- }
- if (key === "editor.sheet.new") {
+ } else if (key === "editor.sheet.new") {
// set the sheet context first
setSheetContext(option.item);
// and then create a new tab
tabStore.addTab();
}
+
showDropdown.value = false;
};
@@ -341,14 +341,16 @@ const handleClickoutside = () => {
showDropdown.value = false;
};
-const nodeProps = ({ option }: { option: TreeOption }) => {
+const nodeProps = (info: { option: TreeOption }) => {
+ const { option } = info;
+
return {
- onClick: (e: any) => {
- if (e?.target?.id === "tree-node-suffix") return;
- if (option) {
- let ctx: ConnectionContext = cloneDeep(
+ onClick: (e: MouseEvent) => {
+ const targetEl = e.target as HTMLElement;
+ if (option && targetEl.className === "n-tree-node-content__text") {
+ let ctx = cloneDeep(
sqlEditorStore.connectionContext
- );
+ ) as ConnectionContext;
ctx.option = option;
sqlEditorStore.setConnectionContext(ctx);
}
diff --git a/frontend/src/views/sql-editor/AsidePanel/TableSchema.vue b/frontend/src/views/sql-editor/AsidePanel/TableSchema.vue
index 1cc885d437..b44219e153 100644
--- a/frontend/src/views/sql-editor/AsidePanel/TableSchema.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/TableSchema.vue
@@ -67,7 +67,7 @@
import { ref, watch } from "vue";
import { useRouter } from "vue-router";
-import type { Database, DatabaseId } from "@/types";
+import { Database, DatabaseId, UNKNOWN_ID } from "@/types";
import { useSQLEditorStore, useTableStore } from "@/store";
const emit = defineEmits<{
@@ -82,7 +82,12 @@ const ctx = sqlEditorStore.connectionContext;
const router = useRouter();
const gotoAlterSchema = () => {
- const databaseId = ctx.databaseId as DatabaseId;
+ let databaseId = ctx.databaseId as DatabaseId;
+ if (databaseId === UNKNOWN_ID) {
+ const option = ctx.option;
+ databaseId = option.parentId as number;
+ }
+
const projectId = sqlEditorStore.findProjectIdByDatabaseId(databaseId);
const databaseList =
sqlEditorStore.connectionInfo.databaseListByProjectId.get(projectId) as any;
diff --git a/frontend/src/views/sql-editor/EditorHeader.vue b/frontend/src/views/sql-editor/EditorHeader.vue
index 4f5510eaaa..2b4c74d755 100644
--- a/frontend/src/views/sql-editor/EditorHeader.vue
+++ b/frontend/src/views/sql-editor/EditorHeader.vue
@@ -12,9 +12,18 @@
</div>
<div class="hidden sm:block">
<div class="ml-6 flex items-baseline space-x-1">
- <a href="#" class="bar-link px-2 py-2 rounded-md" @click="goBack">
- {{ $t("sql-editor.go-back") }}
- </a>
+ <router-link
+ to="/sql-editor"
+ class="text-base truncate mr-2"
+ exact-active-class="anchor-link"
+ >{{ $t("sql-editor.self") }}</router-link
+ >
+ <router-link
+ to="/sheets/my"
+ class="text-base ml-2 truncate"
+ exact-active-class="anchor-link"
+ >{{ $t("sheet.self") }}</router-link
+ >
</div>
</div>
</div>
@@ -97,6 +106,7 @@ import { computed, reactive, watchEffect, defineComponent } from "vue";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
import { useLocalStorage } from "@vueuse/core";
+import { storeToRefs } from "pinia";
import ProfileDropdown from "@/components/ProfileDropdown.vue";
import { UNKNOWN_ID } from "@/types";
import { isDBAOrOwner, isDev } from "@/utils";
@@ -106,7 +116,6 @@ import {
useInboxStore,
useSubscriptionStore,
} from "@/store";
-import { storeToRefs } from "pinia";
interface LocalState {
showMobileMenu: boolean;
diff --git a/frontend/src/views/sql-editor/TablePanel/TablePanel.vue b/frontend/src/views/sql-editor/TablePanel/TablePanel.vue
index 1c1db9c3b1..7a5e678beb 100644
--- a/frontend/src/views/sql-editor/TablePanel/TablePanel.vue
+++ b/frontend/src/views/sql-editor/TablePanel/TablePanel.vue
@@ -8,4 +8,5 @@
<script lang="ts" setup>
import TableView from "./TableView.vue";
+import { Splitpanes, Pane } from "splitpanes";
</script>