Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(HMS-2496): add no permission empty state #322

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Components/ProvisioningWizard/ProvisioningWizard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('ProvisioningWizard', () => {
})
);

render(<ProvisioningWizard image={{ ...awsImage, sourceIDs: ['1'] }} />);
render(<ProvisioningWizard hasAccess image={{ ...awsImage, sourceIDs: ['1'] }} />);
// wait for the sources to load
await screen.findByText('Select account', undefined, { timeout: 10000 });

Expand All @@ -45,16 +45,23 @@ describe('ProvisioningWizard', () => {
}, 30000);

test('shows loading sources', () => {
render(<ProvisioningWizard image={awsImage} />);
render(<ProvisioningWizard hasAccess image={awsImage} />);
expect(screen.getByText(/Loading available Sources/i)).toBeInTheDocument();
});

test('shows empty state when no sources matching', async () => {
// the image has no source info, thus no match
render(<ProvisioningWizard image={awsImage} />);
render(<ProvisioningWizard hasAccess image={awsImage} />);
const createBtn = await screen.findByText('Create Source');

expect(createBtn).toBeInTheDocument();
});

test('shows no permissions modal', async () => {
render(<ProvisioningWizard onClose={jest.fn} hasAccess={false} image={{ ...awsImage, sourceIDs: ['1'] }} />);
const missingPermissionTitle = 'Access permissions needed';
const modal = await screen.findByText(missingPermissionTitle);
expect(modal).toBeInTheDocument();
});
});
});
10 changes: 7 additions & 3 deletions src/Components/ProvisioningWizard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import './steps/Pubkeys/pubkeys.scss';
import { v4 as uuidv4 } from 'uuid';
import axios from 'axios';
import { useEffectOnce } from '../Common/Hooks/useEffectOnce';
import PermissionMissing from './steps/NoPermission';

const DEFAULT_STEP_VALIDATION = {
sshStep: false,
awsStep: false,
};

const ProvisioningWizard = ({ onClose, image, ...props }) => {
const ProvisioningWizard = ({ onClose, hasAccess, image, ...props }) => {
const [stepIdReached, setStepIdReached] = React.useState(1);
const [stepValidation, setStepValidation] = React.useState(DEFAULT_STEP_VALIDATION);
const [isConfirming, setConfirming] = React.useState(false);
Expand Down Expand Up @@ -58,11 +59,14 @@ const ProvisioningWizard = ({ onClose, image, ...props }) => {
setLaunchSuccess,
});

const onNext = ({ id, name }, { prevId, prevName }) => {
console.debug(`current id: ${id}, current name: ${name}, previous id: ${prevId}, previous name: ${prevName}`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some old debug to clean...

const onNext = ({ id }) => {
setStepIdReached((prevID) => (prevID < id ? id : prevID));
};

if (!hasAccess) {
return <PermissionMissing onClose={onClose} image={image} />;
}

return (
<>
<Wizard
Expand Down
39 changes: 39 additions & 0 deletions src/Components/ProvisioningWizard/steps/NoPermission/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Button, EmptyState, EmptyStateBody, EmptyStateIcon, EmptyStateSecondaryActions, Title } from '@patternfly/react-core';
import { LockIcon } from '@patternfly/react-icons';
import DirectProviderLink from '../SourceMissing/DirectProviderLink';
import { imageProps } from '../../helpers';

const missingPermissionTitle = 'Access permissions needed';
const missingPermissionDescription = (
<>
<p>To launch this image, contact your org admin to adjust your launch permissions. </p>
<p>Alternatively, launch directly from the cloud provider console.</p>
</>
);

const PermissionMissing = ({ image, onClose }) => {
return (
<EmptyState>
<EmptyStateIcon icon={LockIcon} />
<Title headingLevel="h4" size="lg">
{missingPermissionTitle}
</Title>
<EmptyStateBody>{missingPermissionDescription}</EmptyStateBody>
<DirectProviderLink image={image} />
<EmptyStateSecondaryActions>
<Button variant="link" onClick={onClose}>
Close
</Button>
</EmptyStateSecondaryActions>
</EmptyState>
);
};

PermissionMissing.propTypes = {
image: imageProps,
onClose: PropTypes.func.isRequired,
};

export default PermissionMissing;
Loading