Skip to content

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

chore: update sheet payload definition (#3359)

boojack12d94f91a7db
diff --git a/api/sheet.go b/api/sheet.go
index 0d619940d7..cf09a53221 100644
--- a/api/sheet.go
+++ b/api/sheet.go
@@ -37,6 +37,7 @@ const (
)
// SheetVCSPayload is the additional data payload of the VCS sheet.
+// The sheet source should be one of SheetFromGitLabSelfHost and SheetFromGitHubCom.
type SheetVCSPayload struct {
FileName string `json:"fileName"`
FilePath string `json:"filePath"`
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index c2dad9d98d..c4caff3c14 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -134,7 +134,6 @@ const prepareSheet = async () => {
instanceId: sheet.database?.instanceId || UNKNOWN_ID,
databaseId: sheet.databaseId || UNKNOWN_ID,
},
- mode: sheet.payload.tabMode,
});
}
diff --git a/frontend/src/store/modules/sheet.ts b/frontend/src/store/modules/sheet.ts
index ef186428e2..5e4cc87e5d 100644
--- a/frontend/src/store/modules/sheet.ts
+++ b/frontend/src/store/modules/sheet.ts
@@ -23,13 +23,13 @@ import { useAuthStore } from "./auth";
import { useDatabaseStore } from "./database";
import { useProjectStore } from "./project";
import { useTabStore } from "./tab";
-import { getDefaultSheetPayload, isSheetWritable } from "@/utils";
+import { getDefaultSheetPayloadWithSource, isSheetWritable } from "@/utils";
function convertSheetPayload(
resourceObj: ResourceObject,
includedList: ResourceObject[]
-): SheetPayload {
- const payload = getDefaultSheetPayload();
+) {
+ const payload = {};
try {
const payloadJSON = resourceObj.attributes.payload;
if (typeof payloadJSON === "string") {
@@ -78,7 +78,7 @@ function convertSheet(
) as Principal,
project,
database,
- payload,
+ payload: payload as SheetPayload,
};
}
@@ -160,7 +160,7 @@ export const useSheetStore = defineStore("sheet", {
}
return this.createSheet({
- payload: getDefaultSheetPayload(),
+ payload: getDefaultSheetPayloadWithSource("BYTEBASE"),
...sheetUpsert,
visibility: "PRIVATE",
});
diff --git a/frontend/src/types/sheet.ts b/frontend/src/types/sheet.ts
index e441073229..e5483d178f 100644
--- a/frontend/src/types/sheet.ts
+++ b/frontend/src/types/sheet.ts
@@ -7,7 +7,6 @@ import {
ProjectId,
RowStatus,
PrincipalId,
- TabMode,
} from ".";
export type SheetVisibility = "PRIVATE" | "PROJECT" | "PUBLIC";
@@ -16,9 +15,19 @@ export type SheetSource = "BYTEBASE" | "GITLAB_SELF_HOST" | "GITHUB_COM";
export type SheetType = "SQL";
-export type SheetPayload = {
- tabMode: TabMode;
-};
+interface SheetVCSPayload {
+ fileName: string;
+ filePath: string;
+ size: number;
+ author: string;
+ lastCommitId: string;
+ lastSyncTs: number;
+}
+
+// eslint-disable-next-line @typescript-eslint/ban-types
+type SheetEmptyPayload = {};
+
+export type SheetPayload = SheetVCSPayload | SheetEmptyPayload;
export interface Sheet {
id: SheetId;
diff --git a/frontend/src/utils/sheet.ts b/frontend/src/utils/sheet.ts
index 75ec21cb1f..286206eb2f 100644
--- a/frontend/src/utils/sheet.ts
+++ b/frontend/src/utils/sheet.ts
@@ -1,4 +1,4 @@
-import { Principal, Sheet, SheetPayload, TabMode } from "@/types";
+import { Principal, Sheet, SheetPayload, SheetSource } from "@/types";
import { hasProjectPermission, hasWorkspacePermission } from "../utils";
export const isSheetReadable = (sheet: Sheet, currentUser: Principal) => {
@@ -80,8 +80,16 @@ export const isSheetWritable = (sheet: Sheet, currentUser: Principal) => {
return false;
};
-export const getDefaultSheetPayload = (): SheetPayload => {
- return {
- tabMode: TabMode.ReadOnly,
- };
+// getDefaultSheetPayloadWithSource gets the default payload with sheet source.
+export const getDefaultSheetPayloadWithSource = (
+ sheetSource: SheetSource
+): SheetPayload => {
+ if (sheetSource === "BYTEBASE") {
+ // As we don't save any data for sheet from UI, return an empty payload.
+ return {};
+ }
+
+ // Shouldn't reach this line.
+ // For those sheet from VCS, we create and patch them in backend.
+ return {};
};
diff --git a/frontend/src/views/SheetDashboard.vue b/frontend/src/views/SheetDashboard.vue
index c66aacc15f..c3bda5e348 100644
--- a/frontend/src/views/SheetDashboard.vue
+++ b/frontend/src/views/SheetDashboard.vue
@@ -127,7 +127,7 @@ import dayjs from "@/plugins/dayjs";
import { useCurrentUser, useProjectStore, useSheetStore } from "@/store";
import { Sheet, SheetCreate, SheetOrganizerUpsert } from "@/types";
import {
- getDefaultSheetPayload,
+ getDefaultSheetPayloadWithSource,
isDev,
isSheetWritable,
sheetSlug,
@@ -338,7 +338,7 @@ const handleDropDownActionBtnClick = async (key: string, sheet: Sheet) => {
name: sheet.name,
statement: sheet.statement,
visibility: "PRIVATE",
- payload: getDefaultSheetPayload(),
+ payload: getDefaultSheetPayloadWithSource("BYTEBASE"),
};
if (sheet.databaseId) {
sheetCreate.databaseId = sheet.databaseId;
diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
index 49525c46b3..ce90045071 100644
--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
@@ -224,7 +224,7 @@ const handleSaveSheet = async (sheetName?: string) => {
}
isShowSaveSheetModal.value = false;
- const { name, statement, sheetId, mode } = tabStore.currentTab;
+ const { name, statement, sheetId } = tabStore.currentTab;
sheetName = sheetName ? sheetName : name;
const conn = tabStore.currentTab.connection;
@@ -235,9 +235,6 @@ const handleSaveSheet = async (sheetName?: string) => {
databaseId: conn.databaseId,
name: sheetName,
statement: statement,
- payload: {
- tabMode: mode,
- },
};
const sheet = await sheetStore.upsertSheet(sheetUpsert);
diff --git a/store/sheet.go b/store/sheet.go
index 3eb4d0c475..15e5c1eb94 100644
--- a/store/sheet.go
+++ b/store/sheet.go
@@ -38,8 +38,7 @@ type sheetRaw struct {
Visibility api.SheetVisibility
Source api.SheetSource
Type api.SheetType
- // Payload is in the json string format of SheetVCSPayload.
- Payload string
+ Payload string
}
// toSheet creates an instance of Sheet based on the sheetRaw.