-
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 2 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,66 @@ | ||
/* | ||
* 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 | ||
>; | ||
|
||
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.font.args.defaultHelpText', { | ||
ppisljar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
defaultMessage: 'default value in case theming info is not available.', | ||
}), | ||
types: ['string', 'number'], | ||
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. Can we just allow everything here? For palettes it might be nice at some point to return more than just a simple value at once - this would give us more flexibility in using theme variables. An example would be the palette params - the shape can be different for different palettes, so we can't always flatten them out into separate args Same for output type of course. 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. @ppisljar you gave a plus 1 but didn't change the code - do you have concerns with this? I'm open for discussion, but I'm not seeing why we shouldn't allow all types here 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. i did, for some reason clicking the link in above comment takes you to old code without this change. going to files to view all changes you can confirm that type limitation was removed. 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. Missed that, sorry. It seems like the |
||
}, | ||
}, | ||
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.
This should also get added to the mapping of all function definitions provided by the expressions plugin in
src/plugins/expressions/common/expression_functions/types.ts
(I'm wondering if we should just get rid of this mapping; it feels like something that will be easy to forget to update?)