-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
theme function #73451
theme function #73451
Changes from 4 commits
4a38577
64c4dcc
d90c347
e9bb13a
18acd74
19b2ab0
2658d66
73979df
9acb737
a384284
6fd6675
2265a21
3aef92a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { get } from 'lodash'; | ||
import { ExpressionFunctionDefinition } from '../types'; | ||
|
||
interface Arguments { | ||
variable: string; | ||
default: string | number | boolean; | ||
} | ||
|
||
type Output = string | number | boolean | undefined; | ||
|
||
export type ExpressionFunctionTheme = ExpressionFunctionDefinition< | ||
'theme', | ||
null, | ||
Arguments, | ||
Output | ||
>; | ||
Comment on lines
+31
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also get added to the mapping of all function definitions provided by the expressions plugin in (I'm wondering if we should just get rid of this mapping; it feels like something that will be easy to forget to update?) |
||
|
||
export const theme: ExpressionFunctionTheme = { | ||
name: 'theme', | ||
aliases: [], | ||
help: i18n.translate('expressions.functions.themeHelpText', { | ||
defaultMessage: 'Reads a theme setting.', | ||
}), | ||
inputTypes: ['null'], | ||
args: { | ||
variable: { | ||
aliases: ['_'], | ||
help: i18n.translate('expressions.functions.theme.args.variableHelpText', { | ||
defaultMessage: 'theme variable to read.', | ||
ppisljar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}), | ||
required: true, | ||
types: ['string'], | ||
}, | ||
default: { | ||
help: i18n.translate('expressions.functions.theme.args.defaultHelpText', { | ||
defaultMessage: 'default value in case theming info is not available.', | ||
}), | ||
}, | ||
}, | ||
fn: (input, args, handlers) => { | ||
// currently we use variable `theme`, but external theme service would be preferable | ||
const vars = handlers.variables.theme || {}; | ||
return get(vars, args.variable, args.default); | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit here -- it would be cool to add an integration test for
font
that actually validates the correct default value is applied viatheme
, based on whether or not you have set the appropriate variable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that won't be possible due to the way interpreter works:
here we are just testing the font function without interpreter and providing arguments in. to do integration test we would need interpreter service running (with the registries and everything) which i think is hard at the moment.