Skip to content

Commit

Permalink
fix(form): hide select options for disabled engines
Browse files Browse the repository at this point in the history
Closes #2512
  • Loading branch information
smbea committed Oct 26, 2021
1 parent 8e87a27 commit 574da44
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 10 deletions.
43 changes: 33 additions & 10 deletions client/src/app/tabs/EngineProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { Fill } from '../slot-fill';
import Arrow from '../../../resources/icons/Arrow.svg';
import LinkArrow from '../../../resources/icons/LinkArrow.svg';

import Flags, { DISABLE_ZEEBE, DISABLE_PLATFORM } from '../../util/Flags';

import css from './EngineProfile.less';

export const engineProfiles = [
Expand Down Expand Up @@ -114,6 +116,8 @@ function EngineProfileSelection(props) {

const [ error, setError ] = useState(null);

const enabledEngineOptions = filterEngineOptions();

const onSelectEngineProfile = (newExecutionPlatform, newExecutionPlatformVersion) => {
const newEngineProfile = {
executionPlatform: newExecutionPlatform,
Expand Down Expand Up @@ -154,12 +158,13 @@ function EngineProfileSelection(props) {
<Overlay.Body className={ css.EngineProfileSelection }>
<div className="form-group form-inline">
{
engineProfiles.map((engineProfile) => {
enabledEngineOptions.map((engineProfile) => {
return <EngineProfileOption
engineProfile={ engineProfile }
key={ engineProfile.executionPlatform }
onSelectEngineProfile={ onSelectEngineProfile }
selectedEngineProfile={ selectedEngineProfile } />;
selectedEngineProfile={ selectedEngineProfile }
onlyEngine={ enabledEngineOptions.length>1 ? false : true } />;
})
}
{ error && <div className="error">Select one option.</div> }
Expand All @@ -177,7 +182,8 @@ function EngineProfileOption(props) {
const {
engineProfile,
onSelectEngineProfile,
selectedEngineProfile
selectedEngineProfile,
onlyEngine
} = props;

const {
Expand All @@ -203,13 +209,18 @@ function EngineProfileOption(props) {
return <div
className="custom-control custom-radio platform"
key={ executionPlatform }>
<input
id={ id }
className="custom-control-input"
type="radio"
checked={ checked }
onChange={ () => {} }
onClick={ () => onSelectEngineProfile(executionPlatform, selectedExecutionPlatformVersion) } />

{ onlyEngine ? null
: (
<input
id={ id }
className="custom-control-input"
type="radio"
checked={ checked }
onChange={ () => {} }
onClick={ () => onSelectEngineProfile(executionPlatform, selectedExecutionPlatformVersion) } />
)
}
<label className="custom-control-label" htmlFor={ id }>
{ `${ executionPlatform }${ executionPlatformVersions.length === 1 ? ` ${ executionPlatformVersions[ 0 ] }` : '' }` }
</label>
Expand Down Expand Up @@ -299,6 +310,18 @@ function Link(props) {
);
}

function filterEngineOptions() {

if (!Flags.get(DISABLE_PLATFORM) && ! Flags.get(DISABLE_ZEEBE))
return engineProfiles;

return engineProfiles.filter(
option => (
Flags.get(DISABLE_PLATFORM) && option.executionPlatform != 'Camunda Platform' ||
Flags.get(DISABLE_ZEEBE) && option.executionPlatform != 'Camunda Cloud'
));
}

export function engineProfilesEqual(a, b) {
return !isNil(a)
&& !isNil(b)
Expand Down
66 changes: 66 additions & 0 deletions client/src/app/tabs/__tests__/EngineProfileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { engineProfile as bpmnEngineProfile } from '../bpmn/BpmnEditor';
import { engineProfile as cloudBpmnEngineProfile } from '../cloud-bpmn/BpmnEditor';
import { engineProfile as dmnEngineProfile } from '../dmn/DmnEditor';

import Flags, { DISABLE_ZEEBE, DISABLE_PLATFORM } from '../../../util/Flags';

const spy = sinon.spy;

const allEngineProfiles = engineProfiles.reduce((allEngineProfiles, engineProfile) => {
Expand Down Expand Up @@ -237,6 +239,70 @@ describe('<EngineProfile>', function() {
});


describe('show not show disabled engine profile', function() {

afterEach(sinon.restore);

it('should not show Cloud if DISABLE_ZEEBE ', function() {

// given
sinon.stub(Flags, 'get').withArgs(DISABLE_ZEEBE).returns(true);

wrapper = renderEngineProfile({
type: 'form',
engineProfile: {
executionPlatform:'Camunda Platform',
executionPlatformVersion:'7.16'
}
});

// when
wrapper.find('button').simulate('click');

// then
expect(wrapper.find('EngineProfileOverlay').exists()).to.be.true;
expect(wrapper.find('EngineProfileSelection').exists()).to.be.true;

const platformInput = wrapper.find('label').filterWhere((item) => item.prop('htmlFor') === `execution-platform-${ toKebapCase('Camunda Platform') }`);
expect(platformInput.exists()).to.be.true;

const cloudInput = wrapper.find('label').filterWhere((item) => item.prop('htmlFor') === `execution-platform-${ toKebapCase('Camunda Cloud') }`);
expect(cloudInput.exists()).to.be.false;

});


it('should not show Platform if DISABLE_PLATFORM ', function() {

// given
sinon.stub(Flags, 'get').withArgs(DISABLE_PLATFORM).returns(true);

wrapper = renderEngineProfile({
type: 'form',
engineProfile: {
executionPlatform:'Camunda Cloud',
executionPlatformVersion:'1.2'
}
});

// when
wrapper.find('button').simulate('click');

// then
expect(wrapper.find('EngineProfileOverlay').exists()).to.be.true;
expect(wrapper.find('EngineProfileSelection').exists()).to.be.true;


const cloudInput = wrapper.find('label').filterWhere((item) => item.prop('htmlFor') === `execution-platform-${ toKebapCase('Camunda Cloud') }`);
expect(cloudInput.exists()).to.be.true;

const platformInput = wrapper.find('label').filterWhere((item) => item.prop('htmlFor') === `execution-platform-${ toKebapCase('Camunda Platform') }`);
expect(platformInput.exists()).to.be.false;
});

});


describe('set engine profile', function() {

allEngineProfiles.forEach(({ executionPlatform, executionPlatformVersion }) => {
Expand Down

0 comments on commit 574da44

Please sign in to comment.