feat(ui): new WorkflowList UI using antd

This commit is contained in:
Fu Diwei
2024-12-04 21:55:52 +08:00
parent 668f6ee36f
commit c522196029
28 changed files with 838 additions and 342 deletions

View File

@@ -1,10 +1,10 @@
import moment from "moment";
import { Access } from "@/domain/access";
import { getPb } from "./api";
import { getPocketBase } from "./pocketbase";
export const list = async () => {
return await getPb().collection("access").getFullList<Access>({
return await getPocketBase().collection("access").getFullList<Access>({
sort: "-created",
filter: "deleted = null",
});
@@ -12,12 +12,12 @@ export const list = async () => {
export const save = async (data: Access) => {
if (data.id) {
return await getPb().collection("access").update(data.id, data);
return await getPocketBase().collection("access").update(data.id, data);
}
return await getPb().collection("access").create(data);
return await getPocketBase().collection("access").create(data);
};
export const remove = async (data: Access) => {
data.deleted = moment.utc().format("YYYY-MM-DD HH:mm:ss");
return await getPb().collection("access").update(data.id, data);
return await getPocketBase().collection("access").update(data.id, data);
};

View File

@@ -1,5 +1,5 @@
import { Certificate } from "@/domain/certificate";
import { getPb } from "./api";
import { getPocketBase } from "./pocketbase";
import { RecordListOptions } from "pocketbase";
import { getTimeAfter } from "@/lib/time";
@@ -10,7 +10,7 @@ type CertificateListReq = {
};
export const list = async (req: CertificateListReq) => {
const pb = getPb();
const pb = getPocketBase();
let page = 1;
if (req.page) {

View File

@@ -1,5 +1,5 @@
import { Deployment, DeploymentListReq } from "@/domain/deployment";
import { getPb } from "./api";
import { getPocketBase } from "./pocketbase";
export const list = async (req: DeploymentListReq) => {
let page = 1;
@@ -17,7 +17,7 @@ export const list = async (req: DeploymentListReq) => {
filter = `domain="${req.domain}"`;
}
return await getPb().collection("deployments").getList<Deployment>(page, perPage, {
return await getPocketBase().collection("deployments").getList<Deployment>(page, perPage, {
filter: filter,
sort: "-deployedAt",
expand: "domain",

View File

@@ -1,6 +1,6 @@
import { getTimeAfter } from "@/lib/time";
import { Domain } from "@/domain/domain";
import { getPb } from "./api";
import { getPocketBase } from "./pocketbase";
type DomainListReq = {
domain?: string;
@@ -10,7 +10,7 @@ type DomainListReq = {
};
export const list = async (req: DomainListReq) => {
const pb = getPb();
const pb = getPocketBase();
let page = 1;
if (req.page) {
@@ -43,24 +43,24 @@ export const list = async (req: DomainListReq) => {
};
export const get = async (id: string) => {
const response = await getPb().collection("domains").getOne<Domain>(id);
const response = await getPocketBase().collection("domains").getOne<Domain>(id);
return response;
};
export const save = async (data: Domain) => {
if (data.id) {
return await getPb().collection("domains").update<Domain>(data.id, data);
return await getPocketBase().collection("domains").update<Domain>(data.id, data);
}
return await getPb().collection("domains").create<Domain>(data);
return await getPocketBase().collection("domains").create<Domain>(data);
};
export const remove = async (id: string) => {
return await getPb().collection("domains").delete(id);
return await getPocketBase().collection("domains").delete(id);
};
type Callback = (data: Domain) => void;
export const subscribeId = (id: string, callback: Callback) => {
return getPb()
return getPocketBase()
.collection("domains")
.subscribe<Domain>(
id,
@@ -76,5 +76,5 @@ export const subscribeId = (id: string, callback: Callback) => {
};
export const unsubscribeId = (id: string) => {
getPb().collection("domains").unsubscribe(id);
getPocketBase().collection("domains").unsubscribe(id);
};

View File

@@ -4,7 +4,7 @@ const apiDomain = import.meta.env.VITE_API_DOMAIN;
console.log(apiDomain);
let pb: PocketBase;
export const getPb = () => {
export const getPocketBase = () => {
if (pb) return pb;
pb = new PocketBase("/");
return pb;

View File

@@ -1,9 +1,9 @@
import { EmailsSetting, Setting } from "@/domain/settings";
import { getPb } from "./api";
import { getPocketBase } from "./pocketbase";
export const getEmails = async () => {
try {
const resp = await getPb().collection("settings").getFirstListItem<Setting<EmailsSetting>>("name='emails'");
const resp = await getPocketBase().collection("settings").getFirstListItem<Setting<EmailsSetting>>("name='emails'");
return resp;
} catch (e) {
return {
@@ -14,7 +14,7 @@ export const getEmails = async () => {
export const getSetting = async <T>(name: string) => {
try {
const resp = await getPb().collection("settings").getFirstListItem<Setting<T>>(`name='${name}'`);
const resp = await getPocketBase().collection("settings").getFirstListItem<Setting<T>>(`name='${name}'`);
return resp;
} catch (e) {
const rs: Setting<T> = {
@@ -25,7 +25,7 @@ export const getSetting = async <T>(name: string) => {
};
export const update = async <T>(setting: Setting<T>) => {
const pb = getPb();
const pb = getPocketBase();
let resp: Setting<T>;
if (setting.id) {
resp = await pb.collection("settings").update(setting.id, setting);

View File

@@ -1,77 +1,58 @@
import { Workflow, WorkflowNode, WorkflowRunLog } from "@/domain/workflow";
import { getPb } from "./api";
import { RecordListOptions } from "pocketbase";
import { type RecordListOptions } from "pocketbase";
import { type Workflow, type WorkflowNode, type WorkflowRunLog } from "@/domain/workflow";
import { getPocketBase } from "./pocketbase";
export type WorkflowListReq = {
page?: number;
perPage?: number;
enabled?: boolean;
};
export const list = async (req: WorkflowListReq) => {
const page = req.page || 1;
const perPage = req.perPage || 10;
const options: RecordListOptions = { sort: "-created" };
if (req.enabled != null) {
options.filter = getPocketBase().filter("enabled={:enabled}", { enabled: req.enabled });
}
return await getPocketBase().collection("workflow").getList<Workflow>(page, perPage, options);
};
export const get = async (id: string) => {
const response = await getPb().collection("workflow").getOne<Workflow>(id);
return response;
return await getPocketBase().collection("workflow").getOne<Workflow>(id);
};
export const save = async (data: Record<string, string | boolean | WorkflowNode>) => {
if (data.id) {
return await getPb()
return await getPocketBase()
.collection("workflow")
.update<Workflow>(data.id as string, data);
}
return await getPb().collection("workflow").create<Workflow>(data);
};
export type WorkflowListReq = {
page: number;
perPage?: number;
enabled?: boolean;
};
export const list = async (req: WorkflowListReq) => {
let page = 1;
if (req.page) {
page = req.page;
}
let perPage = 10;
if (req.perPage) {
perPage = req.perPage;
}
const options: RecordListOptions = {
sort: "-created",
};
if (req.enabled !== undefined) {
options.filter = getPb().filter("enabled={:enabled}", {
enabled: req.enabled,
});
}
const response = await getPb().collection("workflow").getList<Workflow>(page, perPage, options);
return response;
return await getPocketBase().collection("workflow").create<Workflow>(data);
};
export const remove = async (id: string) => {
return await getPb().collection("workflow").delete(id);
return await getPocketBase().collection("workflow").delete(id);
};
type WorkflowLogsReq = {
id: string;
page: number;
page?: number;
perPage?: number;
};
export const logs = async (req: WorkflowLogsReq) => {
let page = 1;
if (req.page) {
page = req.page;
}
let perPage = 10;
if (req.perPage) {
perPage = req.perPage;
}
const page = req.page || 1;
const perPage = req.perPage || 10;
const response = await getPb()
return await getPocketBase()
.collection("workflow_run_log")
.getList<WorkflowRunLog>(page, perPage, {
sort: "-created",
filter: getPb().filter("workflow={:workflowId}", { workflowId: req.id }),
filter: getPocketBase().filter("workflow={:workflowId}", { workflowId: req.id }),
});
return response;
};