Commit f031af0f authored by Jaden's avatar Jaden

[js][algorithm] restrict alg param types, closes #205

parent a19a5822
Pipeline #28389 passed with stages
in 17 minutes and 58 seconds
......@@ -10,7 +10,7 @@ import {
InputGroup, InputGroupAddon,
} from 'reactstrap';
import { BUILTIN_TYPES, ANALYZER_RESULT_TYPES } from '@helpers/beat';
import { BUILTIN_TYPES } from '@helpers/beat';
import TypedField from './TypedField.jsx';
......@@ -70,7 +70,7 @@ export default class ParameterCreate extends React.Component<Props, State> {
placeholder='Parameter name...'
name={name}
type={param.type}
types={BUILTIN_TYPES.filter(d => !d.startsWith('complex'))}
types={BUILTIN_TYPES}
existingFields={params.map(([n, v]) => n)}
nameUpdateFunc={str => updateParameter(str, param, name)}
typeUpdateFunc={(str) => {
......
......@@ -18,7 +18,7 @@ import { connect } from 'react-redux';
import cn from 'classnames';
import { changeObjFieldName, generateNewKey, copyObj } from '@helpers';
import { algorithmValidator, BUILTIN_TYPES, ANALYZER_RESULT_TYPES, getValidAlgorithmObj as getValidObj } from '@helpers/beat';
import { algorithmValidator, ANALYZER_RESULT_TYPES, getValidAlgorithmObj as getValidObj } from '@helpers/beat';
import type { AlgorithmValidatorObject, BeatObject } from '@helpers/beat';
import * as Selectors from '@store/selectors.js';
......
......@@ -790,5 +790,51 @@ describe('<AlgorithmEditor />', () => {
expect(wrapper.find('.badge-success').exists());
});
it.only(`limits parameter types to simple, non-complex types`, () => {
const saveFunc = sinon.spy();
const _updateFunc = (obj) => {
wrapper.setProps && wrapper.setProps({ data: obj });
};
const updateFunc = sinon.spy(_updateFunc);
const algName = aTestAlg.name;
wrapper = mount(
<C
data={aTestAlg}
algorithms={[]}
dataformats={testDfs}
libraries={testLibs}
saveFunc={saveFunc}
updateFunc={updateFunc}
/>
);
wrapper.find('a')
.findWhere(w => {
const html = w.html();
return html && html.includes('Parameters');
})
.at(0)
.simulate('click');
const typeSelect = wrapper.find('ParameterCreate select.custom-select');
const typeOptions = [
<option>Type...</option>,
<option value="int8">int8</option>,
<option value="int16">int16</option>,
<option value="int32">int32</option>,
<option value="int64">int64</option>,
<option value="uint8">uint8</option>,
<option value="uint16">uint16</option>,
<option value="uint32">uint32</option>,
<option value="uint64">uint64</option>,
<option value="float32">float32</option>,
<option value="float64">float64</option>,
<option value="bool">bool</option>,
<option value="string">string</option>,
];
expect(typeSelect.children()).to.have.lengthOf(typeOptions.length);
expect(typeSelect.containsAllMatchingElements(typeOptions)).to.equal(true);
});
});
});
......@@ -32,7 +32,7 @@ import DeleteInputBtn from '../DeleteInputBtn.jsx';
import TypedField from '../TypedField.jsx';
import * as Actions from '@store/actions.js';
import { BUILTIN_TYPES, getValidDataformatObj as getValidObj } from '@helpers/beat';
import { DATAFORMAT_TYPES, getValidDataformatObj as getValidObj } from '@helpers/beat';
import type {
BeatObject,
} from '@helpers/beat.js';
......@@ -236,7 +236,7 @@ export class DataformatEditor extends React.Component<Props> {
});
}
allDfs = () => this.props.dataformats.map(d => d.name).concat(BUILTIN_TYPES);
allDfs = () => this.props.dataformats.map(d => d.name).concat(DATAFORMAT_TYPES);
filteredContents = (obj: any = this.props.data.contents) => Object.entries(obj).filter(([n, v]) => n !== '#description').reduce((o, [n, v]) => ({...o, [n]: v}), {});
......
......@@ -18,7 +18,7 @@ import { connect } from 'react-redux';
import cn from 'classnames';
import { changeObjFieldName, generateNewKey, copyObj } from '@helpers';
import { BUILTIN_TYPES, ANALYZER_RESULT_TYPES, getValidPlotterObj as getValidObj } from '@helpers/beat';
import { getValidPlotterObj as getValidObj } from '@helpers/beat';
import type { BeatObject } from '@helpers/beat';
import * as Selectors from '@store/selectors.js';
......
......@@ -18,7 +18,7 @@ import { connect } from 'react-redux';
import cn from 'classnames';
import { changeObjFieldName, generateNewKey, copyObj } from '@helpers';
import { BUILTIN_TYPES, ANALYZER_RESULT_TYPES, getValidPlotterparameterObj as getValidObj, expGetDefaultParameterValue as getDefaultParameterValue } from '@helpers/beat';
import { getValidPlotterparameterObj as getValidObj, expGetDefaultParameterValue as getDefaultParameterValue } from '@helpers/beat';
import type { BeatObject } from '@helpers/beat';
import * as Selectors from '@store/selectors.js';
......
......@@ -64,10 +64,16 @@ export const BUILTIN_TYPES = [
'uint64',
'float32',
'float64',
'complex64',
'complex128',
'bool',
'string',
];
// extra types that are supported by
// some parameters/editors
export const DATAFORMAT_TYPES = [
...BUILTIN_TYPES,
'complex64',
'complex128',
'array',
'object',
];
......@@ -82,6 +88,7 @@ export const ANALYZER_RESULT_TYPES = [
Object.freeze(BEAT_ENTITIES);
Object.freeze(BUILTIN_TYPES);
Object.freeze(DATAFORMAT_TYPES);
Object.freeze(ANALYZER_RESULT_TYPES);
// get toolchain name from experiment name
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment