Skip to content

Commit

Permalink
Fixed issue 2437
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Oct 28, 2022
1 parent b47c71e commit 2947793
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 55 deletions.
31 changes: 0 additions & 31 deletions ui/src/app/admin/container/ApprovalActions.js

This file was deleted.

26 changes: 24 additions & 2 deletions ui/src/app/admin/container/MetadataActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { DeleteConfirmation } from '../../core/components/DeleteConfirmation';
import { useMetadataActivator, useMetadataEntity } from '../../metadata/hooks/api';
import { useMetadataActivator, useMetadataApprover, useMetadataEntity } from '../../metadata/hooks/api';

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

Expand Down Expand Up @@ -46,10 +46,32 @@ export function MetadataActions ({type, children}) {
}
}

const approver = useMetadataApprover('source');

async function approveEntity(entity, enabled, cb = () => {}) {
await approver.patch(`${type === 'source' ? entity.id : entity.resourceId}/${enabled ? 'approve' : 'unapprove'}`);
if (approver?.response.ok) {
dispatch(createNotificationAction(
`Metadata ${type} has been ${enabled ? 'approved' : 'unapproved'}.`
));
cb();
} else {
const { errorCode, errorMessage, cause } = approver?.response?.data;
dispatch(createNotificationAction(
`${errorCode}: ${errorMessage} ${cause ? `-${cause}` : ''}`,
NotificationTypes.ERROR
));
}
}

return (
<DeleteConfirmation title={`message.delete-${type}-title`} body={`message.delete-${type}-body`}>
{(block) =>
<>{children(enableEntity, (id, cb) => block(() => deleteEntity(id, cb)))}</>
<>{children({
enable: enableEntity,
remove: (id, cb) => block(() => deleteEntity(id, cb)),
approve: approveEntity
})}</>
}
</DeleteConfirmation>
);
Expand Down
17 changes: 10 additions & 7 deletions ui/src/app/dashboard/view/ActionsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Nav from 'react-bootstrap/Nav';
import { Switch, Route, useRouteMatch, Redirect } from 'react-router-dom';
import { NavLink } from 'react-router-dom';
import Badge from 'react-bootstrap/Badge';
import { ApprovalActions } from '../../admin/container/ApprovalActions';

export function ActionsTab({ sources, users, approvals, reloadSources, reloadUsers, reloadApprovals, loadingSources, loadingUsers, loadingApprovals }) {

Expand Down Expand Up @@ -62,19 +61,23 @@ export function ActionsTab({ sources, users, approvals, reloadSources, reloadUse
<Redirect to={`${url}/approve`} />
</Route>
<Route path={`${path}/approve`} render={() =>
<ApprovalActions entities={approvals} reloadUsers={reloadApprovals}>
{(approve) =>
<SourceList entities={approvals} onDelete={reloadSources} onApprove={(s, e) => approve(s, e, reloadApprovals)}>
<MetadataActions entities={approvals} type="source">
{({approve, remove}) =>
<SourceList entities={approvals}
onDelete={(id) => remove(id, reloadApprovals)}
onApprove={(s, e) => approve(s, e, reloadApprovals)}>
{loadingApprovals && <div className="d-flex justify-content-center text-primary"><Spinner size="4x" /></div> }
</SourceList>
}
</ApprovalActions>
</MetadataActions>
} />
<Route path={`${path}/enable`}>
<ProtectRoute redirectTo="/dashboard">
<MetadataActions type="source">
{(enable) =>
<SourceList entities={sources} onDelete={reloadSources} onEnable={(s, e) => enable(s, e, reloadSources)}>
{({enable, remove}) =>
<SourceList entities={sources}
onDelete={(id) => remove(id, reloadSources)}
onEnable={(s, e) => enable(s, e, reloadSources)}>
{loadingSources && <div className="d-flex justify-content-center text-primary"><Spinner size="4x" /></div> }
</SourceList>
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/dashboard/view/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function Dashboard () {
loadUsers();
}
loadApprovals();
}, [location]);
}, [location, isAdmin]);

React.useEffect(() => {
setActions((users?.length || 0) + (sources?.length || 0) + approvals.length);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/dashboard/view/SourcesTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function SourcesTab () {
<Search entities={sources} searchable={searchProps}>
{(searched) =>
<MetadataActions type="source">
{(enable, remove) =>
{({enable, remove}) =>
<SourceList
entities={searched}
onDelete={(id) => remove(id, loadSources)}
Expand Down
21 changes: 8 additions & 13 deletions ui/src/app/metadata/view/MetadataOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { MetadataFilterTypes } from '../domain/filter';
import { useMetadataSchema } from '../hooks/schema';
import { FilterableProviders } from '../domain/provider';
import { useCanEnable, useIsAdmin, useIsApprover } from '../../core/user/UserContext';
import { ApprovalActions } from '../../admin/container/ApprovalActions';

export function MetadataOptions ({reload}) {

Expand Down Expand Up @@ -59,7 +58,7 @@ export function MetadataOptions ({reload}) {

return (
<MetadataActions type={type}>
{(enable, remove) =>
{({enable, remove, approve}) =>
<>
<h2 className="mb-4" id="header">
<Translate value={`label.${type}-configuration`}>[{type}] configuration</Translate>
Expand All @@ -81,17 +80,13 @@ export function MetadataOptions ({reload}) {
</Button>
}
{canApprove &&
<ApprovalActions>
{(approve) =>
<Button variant={metadata.approved ? 'outline-success' : 'outline-success' } size="sm" className=""
onClick={() => approve(metadata, !metadata.approved, reload)}>
<span className=" me-1">
<Translate value={metadata.approved ? 'label.disapprove' : 'label.approve'} />
</span>
<FontAwesomeIcon size="lg" icon={metadata.approved ? faToggleOn : faToggleOff} />
</Button>
}
</ApprovalActions>
<Button variant={metadata.approved ? 'outline-success' : 'outline-success' } size="sm" className=""
onClick={() => approve(metadata, !metadata.approved, reload)}>
<span className=" me-1">
<Translate value={metadata.approved ? 'label.disapprove' : 'label.approve'} />
</span>
<FontAwesomeIcon size="lg" icon={metadata.approved ? faToggleOn : faToggleOff} />
</Button>
}
{type === 'source' && remove && isAdmin &&
<Button
Expand Down

0 comments on commit 2947793

Please sign in to comment.