Skip to content

Commit

Permalink
Updated API calls for enable/disable metadata objects
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Aug 18, 2021
1 parent 6574cc2 commit 6ef03d3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
13 changes: 6 additions & 7 deletions ui/src/app/admin/container/MetadataActions.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import React from 'react';
import { DeleteConfirmation } from '../../core/components/DeleteConfirmation';
import { useMetadataEntity } from '../../metadata/hooks/api';
import { useMetadataActivator, useMetadataEntity } from '../../metadata/hooks/api';

import { NotificationContext, createNotificationAction } from '../../notifications/hoc/Notifications';

export function MetadataActions ({type, children}) {

const { dispatch } = React.useContext(NotificationContext);

const { del, put, response } = useMetadataEntity(type, {
const { del, response } = useMetadataEntity(type, {
cachePolicy: 'no-cache'
});

const activator = useMetadataActivator(type);

async function enableEntity(entity, enabled, cb = () => {}) {
await put(`/${type === 'source' ? entity.id : entity.resourceId}`, {
...entity,
[type === 'source' ? 'serviceEnabled' : 'enabled']: enabled
});
if (response.ok) {
await activator.patch(`/${type === 'source' ? entity.id : entity.resourceId}/${enabled ? 'enable' : 'disable'}`);
if (activator?.response.ok) {
dispatch(createNotificationAction(
`Metadata ${type} has been ${enabled ? 'enabled' : 'disabled'}.`
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import React from 'react';

import { Ordered } from '../../../../dashboard/component/Ordered';
import { Translate } from '../../../../i18n/components/translate';
import { MetadataFilters, MetadataFiltersContext } from './MetadataFilters';
import { MetadataFilters } from './MetadataFilters';

import { MetadataFilterConfigurationListItem } from './MetadataFilterConfigurationListItem';
import { MetadataFilterTypes } from '..';

export function MetadataFilterConfigurationList ({provider, onDelete, editable = true}) {
// const filters = React.useContext(MetadataFiltersContext);
export function MetadataFilterConfigurationList ({provider, editable = true}) {

return (
<MetadataFilters providerId={provider.resourceId} types={MetadataFilterTypes}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { useMetadataFilters } from '../../../hooks/api';
import { useMetadataFilters, useFilterActivator } from '../../../hooks/api';
import { DeleteConfirmation } from '../../../../core/components/DeleteConfirmation';
import { NotificationContext, createNotificationAction } from '../../../../notifications/hoc/Notifications';

Expand All @@ -13,6 +13,10 @@ export function MetadataFilters ({ providerId, types = [], filters, children })
cachePolicy: 'no-cache'
});

const { patch } = useFilterActivator(providerId, {
cachePolicy: 'no-cache'
});

const [filterData, setFilterData] = React.useState([]);

async function loadFilters(id) {
Expand All @@ -33,7 +37,7 @@ export function MetadataFilters ({ providerId, types = [], filters, children })
}

async function enableFilter(filter, enabled) {
await put(`/${filter.resourceId}`, {
await patch(`/${filter.resourceId}/${enabled ? 'enable' : 'disable'}`, {
...filter,
filterEnabled: enabled
});
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/domain/source/component/SourceList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Form from 'react-bootstrap/Form';
import OverlayTrigger from 'react-bootstrap/OverlayTrigger';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faTrash, faCheck } from '@fortawesome/free-solid-svg-icons';
import { faTrash } from '@fortawesome/free-solid-svg-icons';

import FormattedDate from '../../../../core/components/FormattedDate';
import Translate from '../../../../i18n/components/translate';
Expand Down
12 changes: 12 additions & 0 deletions ui/src/app/metadata/hooks/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ export function useMetadataUpdater (path, current) {
}
}

export function useMetadataActivator(type, opts = {
cachePolicy: 'no-cache'
}) {
return useFetch(`${API_BASE_PATH}/activate/${type === 'source' ? 'entityDescriptor' : 'MetadataResolvers'}/`, opts);
}

export function useFilterActivator(providerId, opts = {
cachePolicy: 'no-cache'
}) {
return useFetch(`${API_BASE_PATH}/activate${getMetadataPath('provider')}/${providerId}/Filter`, opts);
}

export function useMetadataAttributes (opts = {}, onMount) {
//
return useFetch(`${API_BASE_PATH}/custom/entity/attributes`, opts, onMount);
Expand Down

0 comments on commit 6ef03d3

Please sign in to comment.