update: save version
This commit is contained in:
@@ -220,6 +220,8 @@ export function useApi(): WorkspaceBoundApi {
|
||||
rawApi.releaseFileLockOnUnload(workspaceId, session),
|
||||
createJupyterAccessTicket: (session) =>
|
||||
rawApi.createJupyterAccessTicket(workspaceId, session),
|
||||
getLatestScriptVersion: (scriptId) =>
|
||||
rawApi.getLatestScriptVersion(workspaceId, scriptId),
|
||||
listScriptVersions: (scriptId) => rawApi.listScriptVersions(workspaceId, scriptId),
|
||||
publishScriptVersion: (input) => rawApi.publishScriptVersion(workspaceId, input),
|
||||
listSchedules: () => rawApi.listSchedules(workspaceId),
|
||||
|
||||
@@ -11,6 +11,7 @@ import { useLocation, useNavigate } from "react-router";
|
||||
|
||||
import {
|
||||
type ActiveEditSession,
|
||||
type LatestVersion,
|
||||
type ScriptItem,
|
||||
type ScriptType,
|
||||
type StableVersion,
|
||||
@@ -163,6 +164,10 @@ function AuthenticatedModelPlatformApp() {
|
||||
} | null>(null);
|
||||
const [versions, setVersions] = useState<StableVersion[]>([]);
|
||||
const [versionsLoading, setVersionsLoading] = useState(false);
|
||||
const [latestVersion, setLatestVersion] = useState<LatestVersion | null>(
|
||||
null,
|
||||
);
|
||||
const [latestVersionLoading, setLatestVersionLoading] = useState(false);
|
||||
const [publishTarget, setPublishTarget] = useState<ScriptItem | null>(null);
|
||||
const [releaseNote, setReleaseNote] = useState("");
|
||||
const [publishVisibility, setPublishVisibility] =
|
||||
@@ -244,10 +249,30 @@ function AuthenticatedModelPlatformApp() {
|
||||
useEffect(() => {
|
||||
if (!selectedId) {
|
||||
setVersions([]);
|
||||
setLatestVersion(null);
|
||||
return;
|
||||
}
|
||||
let ignore = false;
|
||||
setVersionsLoading(true);
|
||||
setLatestVersionLoading(true);
|
||||
void api.getLatestScriptVersion(selectedId)
|
||||
.then((item) => {
|
||||
if (!ignore) setLatestVersion(item);
|
||||
})
|
||||
.catch((error) => {
|
||||
if (!ignore) {
|
||||
setToast({
|
||||
tone: "error",
|
||||
message:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: "最新版本加载失败",
|
||||
});
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
if (!ignore) setLatestVersionLoading(false);
|
||||
});
|
||||
void api.listScriptVersions(selectedId)
|
||||
.then((items) => {
|
||||
if (!ignore) setVersions(items);
|
||||
@@ -1007,8 +1032,8 @@ function AuthenticatedModelPlatformApp() {
|
||||
? editorOpenError.message
|
||||
: null
|
||||
}
|
||||
latestVersion={versions[0] ?? null}
|
||||
versionsLoading={versionsLoading}
|
||||
latestVersion={latestVersion}
|
||||
versionsLoading={latestVersionLoading}
|
||||
onOpenEditor={() => void openScriptEditor(selected)}
|
||||
onEndEditing={() => void endEditing()}
|
||||
onClose={() => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import Icon from "../../components/Icon";
|
||||
import type {
|
||||
ActiveEditSession,
|
||||
LatestVersion,
|
||||
ScriptItem,
|
||||
StableVersion,
|
||||
} from "../../services/api";
|
||||
import { scriptIcon } from "./WorkspaceTree";
|
||||
|
||||
@@ -17,7 +17,7 @@ type ScriptWorkspaceProps = {
|
||||
jupyterUrl: string | null;
|
||||
editBusy: boolean;
|
||||
openError: string | null;
|
||||
latestVersion: StableVersion | null;
|
||||
latestVersion: LatestVersion | null;
|
||||
versionsLoading: boolean;
|
||||
onOpenEditor: () => void;
|
||||
onEndEditing: () => void;
|
||||
|
||||
@@ -558,6 +558,23 @@ export async function createJupyterAccessTicket(
|
||||
};
|
||||
}
|
||||
|
||||
export type LatestVersion = {
|
||||
versions_id: string;
|
||||
version_label: string;
|
||||
};
|
||||
|
||||
export async function getLatestScriptVersion(
|
||||
workspaceId: string,
|
||||
scriptId: string,
|
||||
): Promise<LatestVersion | null> {
|
||||
const resp = await apiRequest<{ data: LatestVersion | null }>(
|
||||
`/api/v1/scripts/${scriptId}/latest-version`,
|
||||
{},
|
||||
workspaceId,
|
||||
);
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
export async function listScriptVersions(
|
||||
workspaceId: string,
|
||||
scriptId: string,
|
||||
@@ -1102,6 +1119,7 @@ export type WorkspaceBoundApi = {
|
||||
createJupyterAccessTicket: (
|
||||
session: ActiveEditSession,
|
||||
) => Promise<JupyterAccessTicket>;
|
||||
getLatestScriptVersion: (scriptId: string) => Promise<LatestVersion | null>;
|
||||
listScriptVersions: (scriptId: string) => Promise<StableVersion[]>;
|
||||
publishScriptVersion: (
|
||||
input: Parameters<typeof publishScriptVersion>[1],
|
||||
|
||||
Reference in New Issue
Block a user