From 0345c0c037a811ed653f5ec0b8b06d73e2704b32 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 | 10 +++-- .../steps/NoPermission/index.js | 39 +++++++++++++++++++ 3 files changed, 57 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..d0381aad 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 = 'Access permissions needed'; + 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..88f9704c 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); @@ -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}`); + const onNext = ({ id }) => { setStepIdReached((prevID) => (prevID < id ? id : prevID)); }; + if (!hasAccess) { + return ; + } + return ( <> +

To launch this image, contact your org admin to adjust your launch permissions.

+

Alternatively, 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;