1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
| import { get, post } from './base'
| import type {
| EndpointsResponse,
| } from '@/app/components/plugins/types'
| import {
| useMutation,
| useQuery,
| useQueryClient,
| } from '@tanstack/react-query'
|
| const NAME_SPACE = 'endpoints'
|
| export const useEndpointList = (pluginID: string) => {
| return useQuery({
| queryKey: [NAME_SPACE, 'list', pluginID],
| queryFn: () => get<EndpointsResponse>('/workspaces/current/endpoints/list/plugin', {
| params: {
| plugin_id: pluginID,
| page: 1,
| page_size: 100,
| },
| }),
| })
| }
|
| export const useInvalidateEndpointList = () => {
| const queryClient = useQueryClient()
| return (pluginID: string) => {
| queryClient.invalidateQueries(
| {
| queryKey: [NAME_SPACE, 'list', pluginID],
| })
| }
| }
|
| export const useCreateEndpoint = ({
| onSuccess,
| onError,
| }: {
| onSuccess?: () => void
| onError?: (error: any) => void
| }) => {
| return useMutation({
| mutationKey: [NAME_SPACE, 'create'],
| mutationFn: (payload: { pluginUniqueID: string, state: Record<string, any> }) => {
| const { pluginUniqueID, state } = payload
| const newName = state.name
| delete state.name
| return post('/workspaces/current/endpoints/create', {
| body: {
| plugin_unique_identifier: pluginUniqueID,
| settings: state,
| name: newName,
| },
| })
| },
| onSuccess,
| onError,
| })
| }
|
| export const useUpdateEndpoint = ({
| onSuccess,
| onError,
| }: {
| onSuccess?: () => void
| onError?: (error: any) => void
| }) => {
| return useMutation({
| mutationKey: [NAME_SPACE, 'update'],
| mutationFn: (payload: { endpointID: string, state: Record<string, any> }) => {
| const { endpointID, state } = payload
| const newName = state.name
| delete state.name
| return post('/workspaces/current/endpoints/update', {
| body: {
| endpoint_id: endpointID,
| settings: state,
| name: newName,
| },
| })
| },
| onSuccess,
| onError,
| })
| }
|
| export const useDeleteEndpoint = ({
| onSuccess,
| onError,
| }: {
| onSuccess?: () => void
| onError?: (error: any) => void
| }) => {
| return useMutation({
| mutationKey: [NAME_SPACE, 'delete'],
| mutationFn: (endpointID: string) => {
| return post('/workspaces/current/endpoints/delete', {
| body: {
| endpoint_id: endpointID,
| },
| })
| },
| onSuccess,
| onError,
| })
| }
|
| export const useEnableEndpoint = ({
| onSuccess,
| onError,
| }: {
| onSuccess?: () => void
| onError?: (error: any) => void
| }) => {
| return useMutation({
| mutationKey: [NAME_SPACE, 'enable'],
| mutationFn: (endpointID: string) => {
| return post('/workspaces/current/endpoints/enable', {
| body: {
| endpoint_id: endpointID,
| },
| })
| },
| onSuccess,
| onError,
| })
| }
|
| export const useDisableEndpoint = ({
| onSuccess,
| onError,
| }: {
| onSuccess?: () => void
| onError?: (error: any) => void
| }) => {
| return useMutation({
| mutationKey: [NAME_SPACE, 'disable'],
| mutationFn: (endpointID: string) => {
| return post('/workspaces/current/endpoints/disable', {
| body: {
| endpoint_id: endpointID,
| },
| })
| },
| onSuccess,
| onError,
| })
| }
|
|