generated from RedHatInsights/frontend-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(HMS-2301): add query search for instance types select
- Loading branch information
Showing
9 changed files
with
512 additions
and
365 deletions.
There are no files selected for viewing
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
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
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,25 @@ | ||
const jsonata = require('jsonata'); | ||
|
||
const OPERATORS = ['<', '>', '=']; | ||
|
||
const parseQuery = (query) => { | ||
query = query.replace('memory', 'memory_mib'); | ||
query = query.replace('storage', 'storage_gb'); | ||
if (OPERATORS.every((operator) => !query.includes(operator))) { | ||
query = `name ~> /${query}/i`; | ||
} | ||
return `types[${query}]`; | ||
}; | ||
|
||
export const evaluateQuery = async (query, data) => { | ||
const q = parseQuery(query); | ||
const d = { types: data }; | ||
try { | ||
const expression = jsonata(q); | ||
const result = await expression.evaluate(d); | ||
if (!result) return { error: false, result: [] }; | ||
return { error: false, result }; | ||
} catch (e) { | ||
return { error: true, result: e }; | ||
} | ||
}; |
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