-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Ezra Odio
committed
Jul 24, 2024
1 parent
c244e75
commit 142b872
Showing
12 changed files
with
205 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.input-error { | ||
border-color: red !important; | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { toString, isNull } from "lodash"; | ||
import Parameter from "./Parameter"; | ||
|
||
class TextPatternParameter extends Parameter { | ||
constructor(parameter, parentQueryId) { | ||
super(parameter, parentQueryId); | ||
this.regex = parameter.regex; | ||
this.setValue(parameter.value); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
normalizeValue(value) { | ||
const normalizedValue = toString(value); | ||
if (isNull(normalizedValue)) { | ||
return null; | ||
} | ||
|
||
var re = new RegExp(this.regex); | ||
|
||
if (re !== null) { | ||
if (re.test(normalizedValue)) { | ||
return normalizedValue; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
export default TextPatternParameter; |
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
21 changes: 21 additions & 0 deletions
21
client/app/services/parameters/tests/TextPatternParameter.test.js
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createParameter } from ".."; | ||
|
||
describe("TextPatternParameter", () => { | ||
let param; | ||
|
||
beforeEach(() => { | ||
param = createParameter({ name: "param", title: "Param", type: "text-pattern", regex: "a+" }); | ||
}); | ||
|
||
describe("noramlizeValue", () => { | ||
test("converts matching strings", () => { | ||
const normalizedValue = param.normalizeValue("art"); | ||
expect(normalizedValue).toBe("art"); | ||
}); | ||
|
||
test("returns null when string does not match pattern", () => { | ||
const normalizedValue = param.normalizeValue("brt"); | ||
expect(normalizedValue).toBeNull(); | ||
}); | ||
}); | ||
}); |
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
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