fleet/frontend/kolide/entities/labels.js
Zachary Wasserman 06832697d0
Fix deletion of labels in UI (#1848)
- Add endpoint for deletion of label by ID
- Use ID endpoint from frontend JS

Fixes #1847
2018-06-25 13:56:59 -07:00

49 lines
1.4 KiB
JavaScript

import endpoints from 'kolide/endpoints';
import helpers from 'kolide/helpers';
export default (client) => {
return {
create: ({ description, name, platform, query }) => {
const { LABELS } = endpoints;
return client.authenticatedPost(client._endpoint(LABELS), JSON.stringify({ description, name, platform, query }))
.then((response) => {
const { label } = response;
return {
...label,
slug: helpers.labelSlug(label),
type: 'custom',
};
});
},
destroy: (label) => {
const { LABELS } = endpoints;
const endpoint = client._endpoint(`${LABELS}/id/${label.id}`);
return client.authenticatedDelete(endpoint);
},
loadAll: () => {
const { LABELS } = endpoints;
return client.authenticatedGet(client._endpoint(LABELS))
.then(response => helpers.formatLabelResponse(response));
},
update: (label, updateAttrs) => {
const { LABELS } = endpoints;
const endpoint = client._endpoint(`${LABELS}/${label.id}`);
return client.authenticatedPatch(endpoint, JSON.stringify(updateAttrs))
.then((response) => {
const { label: updatedLabel } = response;
return {
...updatedLabel,
slug: helpers.labelSlug(updatedLabel),
type: 'custom',
};
});
},
};
};