diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /app/assets/javascripts/api/alert_management_alerts_api.js | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) | |
download | gitlab-ce-3cccd102ba543e02725d247893729e5c73b38295.tar.gz |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'app/assets/javascripts/api/alert_management_alerts_api.js')
-rw-r--r-- | app/assets/javascripts/api/alert_management_alerts_api.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/app/assets/javascripts/api/alert_management_alerts_api.js b/app/assets/javascripts/api/alert_management_alerts_api.js new file mode 100644 index 00000000000..fa66ca5b3dd --- /dev/null +++ b/app/assets/javascripts/api/alert_management_alerts_api.js @@ -0,0 +1,62 @@ +import axios from '~/lib/utils/axios_utils'; +import { buildApiUrl } from '~/api/api_utils'; +import { ContentTypeMultipartFormData } from '~/lib/utils/headers'; + +const ALERT_METRIC_IMAGES_PATH = + '/api/:version/projects/:id/alert_management_alerts/:alert_iid/metric_images'; +const ALERT_SINGLE_METRIC_IMAGE_PATH = + '/api/:version/projects/:id/alert_management_alerts/:alert_iid/metric_images/:image_id'; + +export function fetchAlertMetricImages({ alertIid, id }) { + const metricImagesUrl = buildApiUrl(ALERT_METRIC_IMAGES_PATH) + .replace(':id', encodeURIComponent(id)) + .replace(':alert_iid', encodeURIComponent(alertIid)); + + return axios.get(metricImagesUrl); +} + +export function uploadAlertMetricImage({ alertIid, id, file, url = null, urlText = null }) { + const options = { headers: { ...ContentTypeMultipartFormData } }; + const metricImagesUrl = buildApiUrl(ALERT_METRIC_IMAGES_PATH) + .replace(':id', encodeURIComponent(id)) + .replace(':alert_iid', encodeURIComponent(alertIid)); + + // Construct multipart form data + const formData = new FormData(); + formData.append('file', file); + if (url) { + formData.append('url', url); + } + if (urlText) { + formData.append('url_text', urlText); + } + + return axios.post(metricImagesUrl, formData, options); +} + +export function updateAlertMetricImage({ alertIid, id, imageId, url = null, urlText = null }) { + const metricImagesUrl = buildApiUrl(ALERT_SINGLE_METRIC_IMAGE_PATH) + .replace(':id', encodeURIComponent(id)) + .replace(':alert_iid', encodeURIComponent(alertIid)) + .replace(':image_id', encodeURIComponent(imageId)); + + // Construct multipart form data + const formData = new FormData(); + if (url != null) { + formData.append('url', url); + } + if (urlText != null) { + formData.append('url_text', urlText); + } + + return axios.put(metricImagesUrl, formData); +} + +export function deleteAlertMetricImage({ alertIid, id, imageId }) { + const individualMetricImageUrl = buildApiUrl(ALERT_SINGLE_METRIC_IMAGE_PATH) + .replace(':id', encodeURIComponent(id)) + .replace(':alert_iid', encodeURIComponent(alertIid)) + .replace(':image_id', encodeURIComponent(imageId)); + + return axios.delete(individualMetricImageUrl); +} |