Skip to content

Commit

Permalink
feat: status table tmpl vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Kav91 committed Nov 8, 2023
1 parent 054d5ad commit 8c11b44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
19 changes: 19 additions & 0 deletions visualizations/shared/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const subVariables = (query, variables) => {
if (Object.keys(variables).length > 0) {
let newQuery = query;

Object.keys(variables).forEach(varKey => {
const variable = variables[varKey];
if (Array.isArray(variable)) {
const subString = `'${variable.join("','")}'`;
newQuery = newQuery.replaceAll(`{{${varKey}}}`, subString);
} else {
newQuery = newQuery.replaceAll(`{{${varKey}}}`, variable);
}
});

return newQuery;
}

return query;
};
6 changes: 4 additions & 2 deletions visualizations/status-table/status-table-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'nr1';
import ErrorState from '../shared/errorState';
import { assessValue, discoverErrors, isEmpty } from './utils';
import { subVariables } from '../shared/utils';

const ignoreKeys = ['begin_time', 'end_time', 'x', 'y', 'events'];

Expand Down Expand Up @@ -55,7 +56,8 @@ function StatusTableWidget(props) {
showKey
} = props;
const { timeRange } = platformContext;
const { filters } = useContext(NerdletStateContext);
const nerdletContext = useContext(NerdletStateContext);
const { filters, selectedVariables } = nerdletContext;

const errors = discoverErrors(props);
if (errors.length > 0) {
Expand All @@ -70,7 +72,7 @@ function StatusTableWidget(props) {

const filterClause = filters ? `WHERE ${filters}` : '';

let finalQuery = query;
let finalQuery = subVariables(query, selectedVariables);
if (useTimeRange) {
finalQuery += ` ${timeRangeToNrql(timeRange)}`;
}
Expand Down

0 comments on commit 8c11b44

Please sign in to comment.