Skip to content

Commit

Permalink
Test if the button now always appears
Browse files Browse the repository at this point in the history
  • Loading branch information
danburonline committed Dec 6, 2023
1 parent a287a9c commit 0144c8c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 43 deletions.
5 changes: 4 additions & 1 deletion src/shared/components/ResourceActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type ActionType = {
name: string; // A unique name for your action type
// predicate: This function will be called with the resource passed
// to test if we want to display this Action Button
predicate: (resource: Resource) => Promise<boolean>;
predicate?: (resource: Resource) => Promise<boolean>;
title: string; // A long title displayed on the confirm popup or tooltip
shortTitle: string; // Displayed on Button
// message: a longer message to be displayed on on the confirmation popup
Expand Down Expand Up @@ -67,6 +67,9 @@ const makeActionButtons = async (
) => {
const appliedActions = await Promise.all(
actionTypes.map(async action => {
if (!action.predicate) {
return true;
}
return await action.predicate(resource);
})
);
Expand Down
43 changes: 1 addition & 42 deletions src/shared/containers/ResourceActionsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@ import ResourceActions from '../components/ResourceActions';
import useNotification from '../hooks/useNotification';
import { getOrgAndProjectFromResource, getResourceLabel } from '../utils';
import { download } from '../utils/download';
import {
chainPredicates,
isDefaultElasticView,
isDeprecated,
isFile,
isView,
not,
toPromise,
} from '../utils/nexusMaybe';
import { isFile, isView, toPromise } from '../utils/nexusMaybe';
import RemoveTagButton from './RemoveTagButtonContainer';
import ResourceDownloadButton from './ResourceDownloadContainer';

Expand Down Expand Up @@ -59,39 +51,6 @@ const ResourceActionsContainer: React.FunctionComponent<{
const actionTypes = [
{
name: 'deprecateResource',
predicate: async (resource: Resource) => {
const isLatest = await isLatestResource(resource);
return (
isLatest &&
chainPredicates([isDefaultElasticView, not(isDeprecated)])(resource)
);
},
title: 'Deprecate this resource',
shortTitle: 'Dangerously Deprecate',
message: (
<div>
<h3>Warning!</h3>
<p>
This is your default ElasticSearch View. Deprecating this resource
will break this application for this project. Are you sure you want
to deprecate it?
</p>
</div>
),
icon: <DeleteOutlined />,
danger: true,
},
{
name: 'deprecateResource',
predicate: async (resource: Resource) => {
const isLatest = await isLatestResource(resource);
return (
isLatest &&
chainPredicates([not(isDeprecated), not(isDefaultElasticView)])(
resource
)
);
},
title: 'Deprecate this resource',
message: "Are you sure you'd like to deprecate this resource?",
shortTitle: 'Deprecate',
Expand Down

0 comments on commit 0144c8c

Please sign in to comment.