From 3fb3e4dab28ef490b2c50771245ce540a5a9b8e9 Mon Sep 17 00:00:00 2001 From: Amir Fefer Date: Mon, 4 Sep 2023 17:34:07 +0300 Subject: [PATCH] feat(HMS-2496): add no permission empty state --- .../ProvisioningWizard.test.js | 14 +++++-- src/Components/ProvisioningWizard/index.js | 11 +++-- .../steps/NoPermission/index.js | 40 +++++++++++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 src/Components/ProvisioningWizard/steps/NoPermission/index.js diff --git a/src/Components/ProvisioningWizard/ProvisioningWizard.test.js b/src/Components/ProvisioningWizard/ProvisioningWizard.test.js index 3dd9b287..383aca8c 100644 --- a/src/Components/ProvisioningWizard/ProvisioningWizard.test.js +++ b/src/Components/ProvisioningWizard/ProvisioningWizard.test.js @@ -18,6 +18,14 @@ describe('ProvisioningWizard', () => { }) ); }); + describe('no permissions', () => { + test('shows no permissions modal', async () => { + render(); + const missingPermissionTitle = 'No permissions available'; + const modal = await screen.findByText(missingPermissionTitle); + expect(modal).toBeInTheDocument(); + }); + }); describe('Available source validation', () => { test('handles unreachable - invalid - source gracefuly', async () => { @@ -34,7 +42,7 @@ describe('ProvisioningWizard', () => { }) ); - render(); + render(); // wait for the sources to load await screen.findByText('Select account', undefined, { timeout: 10000 }); @@ -45,13 +53,13 @@ describe('ProvisioningWizard', () => { }, 30000); test('shows loading sources', () => { - render(); + render(); 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(); + render(); const createBtn = await screen.findByText('Create Source'); expect(createBtn).toBeInTheDocument(); diff --git a/src/Components/ProvisioningWizard/index.js b/src/Components/ProvisioningWizard/index.js index 7d09f23b..92defa5e 100644 --- a/src/Components/ProvisioningWizard/index.js +++ b/src/Components/ProvisioningWizard/index.js @@ -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); @@ -56,13 +57,17 @@ const ProvisioningWizard = ({ onClose, image, ...props }) => { stepValidation, setStepValidation, setLaunchSuccess, + hasAccess, }); - const onNext = ({ id, name }, { prevId, prevName }) => { - console.debug(`current id: ${id}, current name: ${name}, previous id: ${prevId}, previous name: ${prevName}`); + const onNext = ({ id }) => { setStepIdReached((prevID) => (prevID < id ? id : prevID)); }; + if (!hasAccess) { + return ; + } + return ( <> +

There are no permissions available for launching this image.

+

Contact your org admin for granting launch permissions.

+

or launch directly from the cloud provider console.

+ +); + +const PermissionMissing = ({ image, onClose }) => { + return ( + + + + {missingPermissionTitle} + + {missingPermissionDescription} + + + + + + ); +}; + +PermissionMissing.propTypes = { + image: imageProps, + onClose: PropTypes.func.isRequired, +}; + +export default PermissionMissing;