mirror of
https://github.com/portainer/portainer.git
synced 2025-08-04 21:35:23 +02:00
refactor(docker/services): convert services table to react [EE-4675] (#10289)
This commit is contained in:
parent
6b5c24faff
commit
0dc1805881
46 changed files with 969 additions and 850 deletions
4
app/react/docker/services/webhooks/build-url.ts
Normal file
4
app/react/docker/services/webhooks/build-url.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export function buildUrl(webhookId?: string) {
|
||||
const baseUrl = '/webhooks';
|
||||
return webhookId ? `${baseUrl}/${webhookId}` : baseUrl;
|
||||
}
|
19
app/react/docker/services/webhooks/getWebhooks.ts
Normal file
19
app/react/docker/services/webhooks/getWebhooks.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { buildUrl } from './build-url';
|
||||
import { Webhook } from './types';
|
||||
|
||||
export async function getWebhooks(
|
||||
environmentId: EnvironmentId,
|
||||
serviceId: string
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get<Array<Webhook>>(buildUrl(), {
|
||||
params: { filters: { EndpointID: environmentId, ResourceID: serviceId } },
|
||||
});
|
||||
return data;
|
||||
} catch (error) {
|
||||
throw parseAxiosError(error);
|
||||
}
|
||||
}
|
25
app/react/docker/services/webhooks/removeWebhook.ts
Normal file
25
app/react/docker/services/webhooks/removeWebhook.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { promiseSequence } from '@/portainer/helpers/promise-utils';
|
||||
|
||||
import { getWebhooks } from './getWebhooks';
|
||||
import { Webhook } from './types';
|
||||
import { buildUrl } from './build-url';
|
||||
|
||||
export async function removeWebhooksForService(
|
||||
environmentId: EnvironmentId,
|
||||
serviceId: string
|
||||
) {
|
||||
const webhooks = await getWebhooks(environmentId, serviceId);
|
||||
return promiseSequence(
|
||||
webhooks.map((webhook) => () => removeWebhook(webhook.Id))
|
||||
);
|
||||
}
|
||||
|
||||
export async function removeWebhook(webhookId: Webhook['Id']) {
|
||||
try {
|
||||
await axios.delete(buildUrl(webhookId));
|
||||
} catch (err) {
|
||||
throw parseAxiosError(err);
|
||||
}
|
||||
}
|
16
app/react/docker/services/webhooks/types.ts
Normal file
16
app/react/docker/services/webhooks/types.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { Environment } from '@/react/portainer/environments/types';
|
||||
import { Registry } from '@/react/portainer/registries/types';
|
||||
|
||||
enum WebhookType {
|
||||
Service = 1,
|
||||
Container = 2,
|
||||
}
|
||||
|
||||
export interface Webhook {
|
||||
Id: string;
|
||||
Token: string;
|
||||
ResourceId: string;
|
||||
EndpointId: Environment['Id'];
|
||||
RegistryId: Registry['Id'];
|
||||
Type: WebhookType;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue