Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Drilldows] Url Drilldown basic template helpers #80500

Merged
merged 9 commits into from
Oct 19, 2020
Prev Previous commit
Next Next commit
split helper
Dosant committed Oct 19, 2020
commit d1d92d0830a4d7d056ca2a8b7dba905193f19ea3
Original file line number Diff line number Diff line change
@@ -281,4 +281,19 @@ describe('basic string formatting helpers', () => {
compile(`https://elastic.co/{{concat valueArray}}`, { valueArray: ['1', '2', '3'] })
).toMatchInlineSnapshot(`"https://elastic.co/1,2,3"`);
});

test('split', () => {
expect(
compile(
`https://elastic.co/{{lookup (split value ",") 0 }}&{{lookup (split value ",") 1 }}`,
{
value: '47.766201,-122.257057',
}
)
).toMatchInlineSnapshot(`"https://elastic.co/47.766201&-122.257057"`);

expect(() =>
compile(`https://elastic.co/{{split value}}`, { value: '47.766201,-122.257057' })
).toThrowErrorMatchingInlineSnapshot(`"[split] \\"splitter\\" expected to be a string"`);
});
});
Original file line number Diff line number Diff line change
@@ -83,11 +83,6 @@ handlebars.registerHelper('uppercase', (rawValue: unknown) => String(rawValue).t
handlebars.registerHelper('trim', (rawValue: unknown) => String(rawValue).trim());
handlebars.registerHelper('trimLeft', (rawValue: unknown) => String(rawValue).trimLeft());
handlebars.registerHelper('trimRight', (rawValue: unknown) => String(rawValue).trimRight());
handlebars.registerHelper('concat', (...args) => {
const values = args.slice(0, -1) as unknown[];
return values.join('');
});

handlebars.registerHelper('left', (rawValue: unknown, numberOfChars: number) => {
if (typeof numberOfChars !== 'number')
throw new Error('[left]: expected "number of characters to extract" to be a number');
@@ -103,6 +98,15 @@ handlebars.registerHelper('mid', (rawValue: unknown, start: number, length: numb
if (typeof length !== 'number') throw new Error('[left]: expected "length" to be a number');
return String(rawValue).substr(start, length);
});
handlebars.registerHelper('concat', (...args) => {
const values = args.slice(0, -1) as unknown[];
return values.join('');
});
handlebars.registerHelper('split', (...args) => {
const [str, splitter] = args.slice(0, -1) as [string, string];
if (typeof splitter !== 'string') throw new Error('[split] "splitter" expected to be a string');
return String(str).split(splitter);
});
handlebars.registerHelper('replace', (...args) => {
const [str, searchString, valueString] = args.slice(0, -1) as [string, string, string];
if (typeof searchString !== 'string' || typeof valueString !== 'string')