Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if ( NodeTypes.STEP_GIVEN === step.nodeType
|| ( NodeTypes.STEP_AND == step.nodeType && true === lastWasGiven ) ) {
const hasPrecondition = isDefined( step.nlpResult )
&& nlpUtil.hasEntityNamed( Entities.STATE, step.nlpResult );
if ( hasPrecondition ) {
// Does not have prior GIVEN ? -> Make it a GIVEN
if ( preconditionCount < 1 ) {
newSteps[ index ].nodeType = NodeTypes.STEP_GIVEN;
}
if ( preconditionCount != index ) {
arrayMove.mut( newSteps, index, preconditionCount );
}
// Is the next step an AND step ?
if ( index + 1 < stepCount && newSteps[ index + 1 ].nodeType === NodeTypes.STEP_AND ) {
let nextStep = newSteps[ index + 1 ];
// Make it a GIVEN step
nextStep.nodeType = NodeTypes.STEP_GIVEN;
// Change the sentence content!
if ( !! nextStep.content ) {
const stepAndKeyword: string = ( keywords.stepAnd || [ 'and' ] )[ 0 ];
const stepGivenKeyword: string = ( keywords.stepGiven || [ 'given' ] )[ 0 ];
const regex = new RegExp( stepAndKeyword, 'i' );
nextStep.content = nextStep.content.replace( regex, convertCase( stepGivenKeyword, CaseType.PASCAL ) ); // Given ...
}
}
let lastWasGiven = null;
let index = 0, preconditionCount = 0;
const stepCount = steps.length;
let newSteps = deepcopy(steps); // << important
for (let step of steps) {
if (NodeTypes_1.NodeTypes.STEP_GIVEN === step.nodeType
|| (NodeTypes_1.NodeTypes.STEP_AND == step.nodeType && true === lastWasGiven)) {
const hasPrecondition = TypeChecking_1.isDefined(step.nlpResult)
&& nlpUtil.hasEntityNamed(nlp_1.Entities.STATE, step.nlpResult);
if (hasPrecondition) {
// Does not have prior GIVEN ? -> Make it a GIVEN
if (preconditionCount < 1) {
newSteps[index].nodeType = NodeTypes_1.NodeTypes.STEP_GIVEN;
}
if (preconditionCount != index) {
arrayMove.mut(newSteps, index, preconditionCount);
}
// Is the next step an AND step ?
if (index + 1 < stepCount && newSteps[index + 1].nodeType === NodeTypes_1.NodeTypes.STEP_AND) {
let nextStep = newSteps[index + 1];
// Make it a GIVEN step
nextStep.nodeType = NodeTypes_1.NodeTypes.STEP_GIVEN;
// Change the sentence content!
if (!!nextStep.content) {
const stepAndKeyword = (keywords.stepAnd || ['and'])[0];
const stepGivenKeyword = (keywords.stepGiven || ['given'])[0];
const regex = new RegExp(stepAndKeyword, 'i');
nextStep.content = nextStep.content.replace(regex, CaseConversor_1.convertCase(stepGivenKeyword, CaseType_1.CaseType.PASCAL)); // Given ...
}
}
++preconditionCount;
}
moveJob = async (job, direction) => {
// TODO only move job if ALL jobs are valid !!
// TODO otherwise some garbage data might be saved into those variables
// TODO or make a new endpoint which only moves the job, and does only change the pos
const { jobs } = this.state;
const idx = jobs.findIndex(x => x._id.$oid == job._id.$oid);
if (idx == -1) raiseError('could not locate job: ' + job);
arrayMove.mut(jobs, idx, idx + direction);
this.setState({ jobs });
// update all jobs since positioning changed
const updated_jobs = await ConfigService.updateJobs(jobs);
this.setJobs(updated_jobs);
}
move_down = building => {
const queues = this.state.queue;
var idx = queues.indexOf(building);
if (idx != -1) {
arrayMove.mut(queues, idx, idx + 1); // The second parameter is the number of elements to remove.
}
this.setState({ queue: [ ...queues ] });
}
move_up = building => {
const queues = this.state.queue;
var idx = queues.indexOf(building);
if (idx != -1) {
arrayMove.mut(queues, idx, idx - 1); // The second parameter is the number of elements to remove.
}
this.setState({ queue: [ ...queues ] });
}
down: function () {
var idx = state.posts.indexOf(post)
move(state.posts, idx, idx + 1)
update()
},
first: function () {
up: function () {
var idx = state.posts.indexOf(post)
move(state.posts, idx, idx - 1)
update()
},
down: function () {