- Added `workflowLastModifiedAt` function to retrieve the last modified timestamp of workflow YAML files. - Introduced `encodeBinaryForWire` and `reviveBinaryFromWire` functions for better handling of binary data in JSON. - Implemented `useDeleteKv` hook for deleting key-value pairs in the web API. - Enhanced `scriptsPluginFactory` to support dry-run evaluations with JSONata expressions. - Added `set-dry-run-smoke.js` test to validate dry-run functionality. - Updated profile configuration to include `overlayFromMerged` for better profile management. - Introduced try-session management in the web components to handle step execution states. - Improved various components to support new try-session features and maintain UI consistency. Co-authored-by: Nasyarobby Putra <nasyarobby@gmail.com>
109 lines
2.9 KiB
JavaScript
109 lines
2.9 KiB
JavaScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { api } from "../client.js";
|
|
|
|
export function useScripts() {
|
|
return useQuery({
|
|
queryKey: ["scripts"],
|
|
queryFn: async () => (await api.get("/scripts")).data.scripts,
|
|
});
|
|
}
|
|
|
|
export function useScript(name, enabled = true) {
|
|
return useQuery({
|
|
queryKey: ["scripts", name],
|
|
queryFn: async () => (await api.get(`/scripts/${encodeURIComponent(name)}`)).data,
|
|
enabled: Boolean(name) && enabled,
|
|
});
|
|
}
|
|
|
|
export function useSaveScript() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: async ({ name, content }) =>
|
|
(await api.put(`/scripts/${encodeURIComponent(name)}`, { content })).data,
|
|
onSuccess: (_data, vars) => {
|
|
qc.invalidateQueries({ queryKey: ["scripts"] });
|
|
qc.invalidateQueries({ queryKey: ["scripts", vars.name] });
|
|
qc.invalidateQueries({ queryKey: ["dashboard"] });
|
|
qc.invalidateQueries({ queryKey: ["ops-status"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useCreatePlugin() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: async ({ id, content, description }) =>
|
|
(await api.post("/plugins/create", { id, content, description })).data,
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: ["scripts"] });
|
|
qc.invalidateQueries({ queryKey: ["ops-status"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useForkScript() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: async ({ name, id, description }) =>
|
|
(
|
|
await api.post(`/scripts/${encodeURIComponent(name)}/fork`, {
|
|
id,
|
|
description,
|
|
})
|
|
).data,
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: ["scripts"] });
|
|
qc.invalidateQueries({ queryKey: ["ops-status"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useInstallPlugin() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: async (body) => (await api.post("/plugins/install", body)).data,
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: ["scripts"] });
|
|
qc.invalidateQueries({ queryKey: ["ops-status"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteScript() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: async (name) =>
|
|
(await api.delete(`/scripts/${encodeURIComponent(name)}`)).data,
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: ["scripts"] });
|
|
qc.invalidateQueries({ queryKey: ["dashboard"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDryRunScript() {
|
|
return useMutation({
|
|
mutationFn: async ({
|
|
name,
|
|
content,
|
|
expression,
|
|
data,
|
|
context,
|
|
config,
|
|
owner,
|
|
}) =>
|
|
(
|
|
await api.post(`/scripts/${encodeURIComponent(name)}/dry-run`, {
|
|
...(content != null ? { content } : {}),
|
|
...(expression != null ? { expression } : {}),
|
|
data,
|
|
context,
|
|
config,
|
|
owner,
|
|
})
|
|
).data,
|
|
});
|
|
}
|
|
|