Skip to content

Commit

Permalink
Separated enabled functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jul 22, 2021
1 parent 2b0511f commit 5b04398
Show file tree
Hide file tree
Showing 23 changed files with 248 additions and 221 deletions.
2 changes: 2 additions & 0 deletions backend/src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ action.advanced=Advanced
action.add-new-attribute=Add new attribute
action.add-attribute=Add Attribute
action.custom-entity-attributes=Custom Entity Attributes
action.enable=Enable
action.disable=Disable

value.enabled=Enabled
value.disabled=Disabled
Expand Down
45 changes: 45 additions & 0 deletions ui/src/app/admin/container/MetadataActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { DeleteConfirmation } from '../../metadata/component/DeleteConfirmation';
import { 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, {
cachePolicy: 'no-cache'
});

async function enableEntity(entity, enabled, cb = () => {}) {
await put(`/${type === 'source' ? entity.id : entity.resourceId}`, {
...entity,
[type === 'source' ? 'serviceEnabled' : 'enabled']: enabled
});
if (response.ok) {
dispatch(createNotificationAction(
`Metadata ${type} has been ${enabled ? 'enabled' : 'disabled'}.`
));
cb();
}
}

async function deleteEntity(id, cb = () => {}) {
await del(`/${id}`);
if (response.ok) {
dispatch(createNotificationAction(
`Metadata ${type} has been deleted.`
));
cb();
}
}

return (
<DeleteConfirmation title={`message.delete-${type}-title`} body={`message.delete-${type}-body`}>
{(block) =>
<>{children(enableEntity, (id, cb) => block(() => deleteEntity(id, cb)))}</>
}
</DeleteConfirmation>
);
}
31 changes: 0 additions & 31 deletions ui/src/app/admin/container/SourcesActions.js

This file was deleted.

9 changes: 7 additions & 2 deletions ui/src/app/dashboard/view/ActionsTab.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { SourcesActions } from '../../admin/container/SourcesActions';
import { MetadataActions } from '../../admin/container/MetadataActions';
import UserActions from '../../admin/container/UserActions';

import Translate from '../../i18n/components/translate';
import SourceList from '../../metadata/domain/source/component/SourceList';

export function ActionsTab({ sources, users, reloadSources, reloadUsers }) {

Expand All @@ -18,7 +19,11 @@ export function ActionsTab({ sources, users, reloadSources, reloadUsers }) {
</div>
</div>
<div className="p-3">
<SourcesActions sources={sources} reloadSources={reloadSources} />
<MetadataActions type="source">
{(enable) =>
<SourceList entities={sources} onDelete={reloadSources} onEnable={(s, e) => enable(s, e, reloadSources)} />
}
</MetadataActions>
</div>
</div>
</section>
Expand Down
23 changes: 15 additions & 8 deletions ui/src/app/dashboard/view/ProvidersTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Search} from '../component/Search';
import { Ordered } from '../component/Ordered';
import { useIsAdmin } from '../../core/user/UserContext';
import Alert from 'react-bootstrap/Alert';

import { MetadataActions } from '../../admin/container/MetadataActions';
const searchProps = ['name', '@type', 'createdBy'];

export function ProvidersTab () {
Expand Down Expand Up @@ -44,13 +44,20 @@ export function ProvidersTab () {
<Ordered entities={providers} prop="resourceIds">
{(ordered, first, last, onOrderUp, onOrderDown) =>
<Search entities={ordered} searchable={searchProps}>
{(searched) => <ProviderList
entities={searched}
reorder={providers.length === searched.length}
first={first}
last={last}
onOrderUp={onOrderUp}
onOrderDown={onOrderDown}></ProviderList>}
{(searched) =>
<MetadataActions type="provider">
{(enable) =>
<ProviderList
entities={searched}
reorder={providers.length === searched.length}
first={first}
last={last}
onEnable={(p, e) => enable(p, e, loadProviders)}
onOrderUp={onOrderUp}
onOrderDown={onOrderDown}></ProviderList>
}
</MetadataActions>
}
</Search>
}
</Ordered>
Expand Down
14 changes: 11 additions & 3 deletions ui/src/app/dashboard/view/SourcesTab.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { MetadataActions } from '../../admin/container/MetadataActions';
import Translate from '../../i18n/components/translate';

import SourceList from '../../metadata/domain/source/component/SourceList';
Expand All @@ -22,8 +23,6 @@ export function SourcesTab () {
}
}

const updateSources = () => loadSources();

/*eslint-disable react-hooks/exhaustive-deps*/
React.useEffect(() => { loadSources() }, []);

Expand All @@ -37,7 +36,16 @@ export function SourcesTab () {
</div>
<div className="p-3">
<Search entities={sources} searchable={searchProps}>
{(searched) => <SourceList entities={ searched } onDelete={ updateSources }></SourceList>}
{(searched) =>
<MetadataActions type="source">
{(enable, remove) =>
<SourceList
entities={sources}
onDelete={(id) => remove(id, loadSources)}
onEnable={(s, e) => enable(s, e, loadSources) } />
}
</MetadataActions>
}
</Search>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/metadata/Metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export function Metadata () {
return (
<>
<MetadataSelector>
{(entity) =>
{(entity, reload) =>
<MetadataXmlLoader>
<MetadataSchema type={entity['@type'] ? entity['@type'] : 'source'}>
<Switch>
<Route path={`${path}/configuration/options`} render={ () =>
<MetadataDetail>
<MetadataOptions></MetadataOptions>
<MetadataOptions reload={reload}></MetadataOptions>
</MetadataDetail>
} />
<Route path={`${path}/configuration/xml`} render={() =>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/component/MetadataHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function MetadataHeader ({ model, current = true, enabled = true, childre
<div className="card enabled-status" {...props}>
<div className="card-body">
<div className="d-flex justify-content-between">
<h5 className="card-title version-title">
<h5 className="card-title version-title flex-grow-1">
<Translate value="label.saved">Saved</Translate>:&nbsp;
<span className="save-date">
<FormattedDate date={model.modifiedDate} time={true} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export const EntityAttributesFilterEditor= {
'name',
'@type',
'resourceId',
'filterEnabled',
'entityAttributesFilterTarget'
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export const NameIDFilterEditor = {
index: 1,
fields: [
'name',
'filterEnabled',
'@type',
'resourceId',
'nameIdFormatFilterTarget'
Expand Down
31 changes: 26 additions & 5 deletions ui/src/app/metadata/domain/provider/component/ProviderList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ import React from 'react';
import { Link } from 'react-router-dom';
import Badge from 'react-bootstrap/Badge';
import Button from 'react-bootstrap/Button';
import Form from 'react-bootstrap/Form';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faChevronCircleDown, faChevronCircleUp } from '@fortawesome/free-solid-svg-icons';

import FormattedDate from '../../../../core/components/FormattedDate';
import Translate from '../../../../i18n/components/translate';
import { Scroller } from '../../../../dashboard/component/Scroller';
import { useIsAdmin } from '../../../../core/user/UserContext';
import { useTranslator } from '../../../../i18n/hooks';

export function ProviderList({ entities, reorder = true, first, last, onEnable, onOrderUp, onOrderDown }) {

const isAdmin = useIsAdmin();
const translator = useTranslator();

export function ProviderList({ entities, reorder = true, first, last, onOrderUp, onOrderDown }) {
return (
<Scroller entities={entities}>
{(limited) => <div className="table-responsive mt-3 provider-list!">
Expand Down Expand Up @@ -61,10 +68,24 @@ export function ProviderList({ entities, reorder = true, first, last, onOrderUp,
<td className="align-middle">{ provider['@type'] }</td>
<td className="align-middle">{ provider.createdBy }</td>
<td className="align-middle"><FormattedDate date={provider.createdDate} /></td>
<td className="text-right align-middle">
<Badge variant={provider.enabled ? 'success' : 'danger'}>
<Translate value={provider.enabled ? 'value.enabled' : 'value.disabled'}></Translate>
</Badge>
<td className="">
<span className="d-flex justify-content-end">
{onEnable && isAdmin ?
<Form.Check
size="lg"
type="switch"
id="custom-switch"
aria-label={translator(provider.enabled ? 'label.disable' : 'label.enable')}
onChange={({ target: { checked } }) => onEnable(provider, checked)}
checked={provider.enabled}
>
</Form.Check>
:
<Badge variant={provider.enabled ? 'success' : 'danger'}>
<Translate value={provider.enabnled ? 'value.enabled' : 'value.disabled'}></Translate>
</Badge>
}
</span>
</td>
</tr>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export const DynamicHttpMetadataProviderWizard = {
label: 'label.finished',
index: 5,
initialValues: [],
fields: [
'enabled'
]
fields: []
}
],
uiSchema: defaultsDeep({
Expand Down Expand Up @@ -191,7 +189,6 @@ export const DynamicHttpMetadataProviderEditor = {
'@type',
'xmlId',
'metadataRequestURLConstructionScheme',
'enabled',
'requireValidMetadata',
'failFastInitialization'
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export const FileBackedHttpMetadataProviderWizard = {
label: 'label.finished',
index: 5,
initialValues: [],
fields: [
'enabled'
]
fields: []
}
],
uiSchema: defaultsDeep({
Expand All @@ -68,12 +66,6 @@ export const FileBackedHttpMetadataProviderWizard = {
'@type'
]
},
{
size: 8,
fields: [
'enabled'
]
},
{
size: 8,
fields: [
Expand Down Expand Up @@ -181,7 +173,6 @@ export const FileBackedHttpMetadataProviderEditor = {
fields: [
'name',
'@type',
'enabled',
'xmlId',
'metadataURL',
'initializeFromBackupFile',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export const FileSystemMetadataProviderWizard = {
label: 'label.finished',
index: 4,
initialValues: [],
fields: [
'enabled'
]
fields: []
}
],
uiSchema: defaultsDeep({
Expand All @@ -51,12 +49,6 @@ export const FileSystemMetadataProviderWizard = {
'@type'
]
},
{
size: 8,
fields: [
'enabled'
]
},
{
size: 8,
fields: [
Expand Down Expand Up @@ -115,7 +107,6 @@ export const FileSystemMetadataProviderEditor = {
'xmlId',
'@type',
'metadataFile',
'enabled',
'doInitialization'
],
override: {
Expand All @@ -140,7 +131,6 @@ export const FileSystemMetadataProviderEditor = {
type: 'group-lg',
class: ['col-12'],
fields: [
'enabled',
'xmlId',
'metadataFile',
'doInitialization'
Expand Down
Loading

0 comments on commit 5b04398

Please sign in to comment.