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

fix(form): hide select options for disabled engines #2534

Merged
merged 2 commits into from
Oct 29, 2021
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
2 changes: 2 additions & 0 deletions client/src/app/TabsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ export default class TabsProvider {

if (Flags.get(DISABLE_ZEEBE)) {
this.providersByFileType.bpmn = this.providersByFileType.bpmn.filter(p => p !== this.providers['cloud-bpmn']);
this.providersByFileType.form = this.providersByFileType.form.filter(p => p !== this.providers['cloud-form']);
delete this.providers['cloud-bpmn'];
delete this.providers['cloud-form'];
}

if (Flags.get(DISABLE_PLATFORM)) {
Expand Down
56 changes: 46 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 All @@ -139,6 +143,15 @@ function EngineProfileSelection(props) {
return;
}

if (enabledEngineOptions.length === 1 && isEngineDisabled(selectedEngineProfile)) {
const allowedEngine = filterEngineOptions()[0];

props.setEngineProfile({
executionPlatform: allowedEngine.executionPlatform,
executionPlatformVersion: allowedEngine.executionPlatformVersions[0]
});
}

if (!engineProfilesEqual(selectedEngineProfile, engineProfile)) {
props.setEngineProfile(selectedEngineProfile);
}
Expand All @@ -154,12 +167,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 } />;
})
}
{ error && <div className="error">Select one option.</div> }
Expand All @@ -177,7 +191,8 @@ function EngineProfileOption(props) {
const {
engineProfile,
onSelectEngineProfile,
selectedEngineProfile
selectedEngineProfile,
onlyEngine
} = props;

const {
Expand All @@ -203,13 +218,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 +319,22 @@ 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'
));
}

function isEngineDisabled(engineProfile) {
return !filterEngineOptions().includes(engineProfile);
}

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('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