This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ae6954
commit 42482a3
Showing
10 changed files
with
424 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
export const trimInput = (input, caretPosition) => { | ||
let currentExp = inputText.slice(0,caretPosition)+"<<caret_position>>"; | ||
// const leftIndex = Math.max(currentExp.lastIndexOf('AND'), currentExp.lastIndexOf('OR'), 0); | ||
let currentExp = input.slice(0,caretPosition)+"<<caret_position>>"; | ||
const leftIndex = Math.max(currentExp.lastIndexOf('AND'), currentExp.lastIndexOf('OR'), 0); | ||
// const rightIndex = [inputText.indexOf('AND', caretPosition-3), inputText.indexOf('OR', caretPosition-2)].reduce((a,b) => b > 0 ? (a < b ? a : b) : a, inputText.length-1); | ||
return currentExp.slice(leftIndex).replace(/AND|OR/,''); | ||
} | ||
|
||
export const replaceToken = (input, caretPosition) => { | ||
const leftIndex = Math.max(currentExp.lastIndexOf('AND'), currentExp.lastIndexOf('OR'), 0); | ||
const arr = [] | ||
arr.reduce((acc, i) => i[0] <= caretPosition && i[1] >= caretPosition ? i[1] : acc, 0); | ||
} | ||
|
||
const ast = value => ({ | ||
toString: () => value.map(x=> x.type === 'entity' ? x.value + '.' : x.value + ' ').reduce((acc, i) => acc+i, ''), | ||
positionTokenIndex: (index) => value.reduce((acc, i) => (acc.length+i.value.length < index ? {index: acc.index+1, length: acc.length+i.value.length} : acc),{length: 0, index:-1}).index, | ||
value, | ||
last: value.slice(-1)[0] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import './sass/style.scss'; | ||
import ExpressionEditor from './expression-editor'; | ||
export { ExpressionEditor }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
@import "~@patternfly/patternfly/components/Select/select.css"; | ||
@import "~@patternfly/patternfly/patternfly-variables.css"; | ||
|
||
.expression-options ul { | ||
padding-left: 0px; | ||
li { | ||
display: block; | ||
} | ||
} | ||
|
||
li { | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,104 @@ | ||
import { trimInput } from '..helper'; | ||
import { trimInput } from '../helper'; | ||
|
||
let input; | ||
describe('trim to caret: vm.name = knedlik, caret', () => { | ||
beforeAll(() => { input = "vm.name = knedlik";} ); | ||
|
||
it('position 5', () => { | ||
const expectedOutput = "vm.na<<caret_position>>"; | ||
expect(trimInput(input, 5)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 10', () => { | ||
const expectedOutput = "vm.name = <<caret_position>>"; | ||
expect(trimInput(input, 10)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 15', () => { | ||
const expectedOutput = "vm.name = knedl<<caret_position>>"; | ||
expect(trimInput(input, 15)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 30', () => { | ||
const expectedOutput = "vm.name = knedlik<<caret_position>>"; | ||
expect(trimInput(input, 30)).toEqual(expectedOutput); | ||
}); | ||
}); | ||
|
||
describe('trim to caret: "Virtual Machine"."Date Created" = "10.5.2018"', () => { | ||
beforeAll(() => { input = '"Virtual Machine"."Date Created" = "10.5.2018"';} ); | ||
|
||
it('position 5', () => { | ||
const expectedOutput = '"Virt<<caret_position>>'; | ||
expect(trimInput(input, 5)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 10', () => { | ||
const expectedOutput = '"Virtual M<<caret_position>>'; | ||
expect(trimInput(input, 10)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 15', () => { | ||
const expectedOutput = '"Virtual Machin<<caret_position>>'; | ||
expect(trimInput(input, 15)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 20', () => { | ||
const expectedOutput = '"Virtual Machine"."D<<caret_position>>'; | ||
expect(trimInput(input, 20)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 30 ', () => { | ||
const expectedOutput = '"Virtual Machine"."Date Create<<caret_position>>'; | ||
expect(trimInput(input, 30)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 40 ', () => { | ||
const expectedOutput = '"Virtual Machine"."Date Created" = "10.5<<caret_position>>'; | ||
expect(trimInput(input, 40)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position input.lenght ', () => { | ||
const expectedOutput = '"Virtual Machine"."Date Created" = "10.5.2018"<<caret_position>>'; | ||
expect(trimInput(input, input.length)).toEqual(expectedOutput); | ||
}); | ||
}); | ||
|
||
describe('trim to caret: vm.name = knedlik OR vm.status = active AND vm.parent INCLUDES bla', () => { | ||
beforeAll(() => { input = 'vm.name = knedlik OR vm.status = active AND vm.parent INCLUDES bla';} ); | ||
|
||
it('position 5 ', () => { | ||
const expectedOutput = 'vm.na<<caret_position>>'; | ||
expect(trimInput(input, 5)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 19 ', () => { | ||
const expectedOutput = 'vm.name = knedlik O<<caret_position>>'; | ||
expect(trimInput(input, 19)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 20 ', () => { | ||
const expectedOutput = '<<caret_position>>'; | ||
expect(trimInput(input, 20)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 21 ', () => { | ||
const expectedOutput = ' <<caret_position>>'; | ||
expect(trimInput(input, 21)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 22 ', () => { | ||
const expectedOutput = ' v<<caret_position>>'; | ||
expect(trimInput(input, 22)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 30 ', () => { | ||
const expectedOutput = ' vm.status<<caret_position>>'; | ||
expect(trimInput(input, 30)).toEqual(expectedOutput); | ||
}); | ||
|
||
it('position 66 ', () => { | ||
const expectedOutput = ' vm.parent INCLUDES bla<<caret_position>>'; | ||
expect(trimInput(input, 66)).toEqual(expectedOutput); | ||
}); | ||
}); |