2020-02-14 13:46:08 +01:00
|
|
|
import React, { useCallback } from 'react';
|
|
|
|
|
import {
|
|
|
|
|
ConfigOverrideRule,
|
|
|
|
|
DataFrame,
|
|
|
|
|
DynamicConfigValue,
|
2020-04-06 16:24:41 +02:00
|
|
|
FieldConfigOptionsRegistry,
|
2020-02-14 13:46:08 +01:00
|
|
|
VariableSuggestionsScope,
|
|
|
|
|
GrafanaTheme,
|
|
|
|
|
} from '@grafana/data';
|
|
|
|
|
import { fieldMatchersUI, stylesFactory, useTheme, ValuePicker, selectThemeVariant } from '@grafana/ui';
|
|
|
|
|
import { DynamicConfigValueEditor } from './DynamicConfigValueEditor';
|
2020-03-19 12:28:05 +01:00
|
|
|
|
2020-02-14 13:46:08 +01:00
|
|
|
import { getDataLinksVariableSuggestions } from '../../../panel/panellinks/link_srv';
|
|
|
|
|
import { css } from 'emotion';
|
2020-03-19 12:28:05 +01:00
|
|
|
import { FieldConfigItemHeaderTitle } from '@grafana/ui/src/components/FieldConfigs/FieldConfigItemHeaderTitle';
|
2020-02-14 13:46:08 +01:00
|
|
|
|
|
|
|
|
interface OverrideEditorProps {
|
|
|
|
|
data: DataFrame[];
|
|
|
|
|
override: ConfigOverrideRule;
|
|
|
|
|
onChange: (config: ConfigOverrideRule) => void;
|
|
|
|
|
onRemove: () => void;
|
2020-04-06 16:24:41 +02:00
|
|
|
registry: FieldConfigOptionsRegistry;
|
2020-02-14 13:46:08 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-06 16:24:41 +02:00
|
|
|
export const OverrideEditor: React.FC<OverrideEditorProps> = ({ data, override, onChange, onRemove, registry }) => {
|
2020-02-14 13:46:08 +01:00
|
|
|
const theme = useTheme();
|
|
|
|
|
const onMatcherConfigChange = useCallback(
|
|
|
|
|
(matcherConfig: any) => {
|
|
|
|
|
override.matcher.options = matcherConfig;
|
|
|
|
|
onChange(override);
|
|
|
|
|
},
|
|
|
|
|
[override, onChange]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const onDynamicConfigValueChange = useCallback(
|
|
|
|
|
(index: number, value: DynamicConfigValue) => {
|
|
|
|
|
override.properties[index].value = value;
|
|
|
|
|
onChange(override);
|
|
|
|
|
},
|
|
|
|
|
[override, onChange]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const onDynamicConfigValueRemove = useCallback(
|
|
|
|
|
(index: number) => {
|
|
|
|
|
override.properties.splice(index, 1);
|
|
|
|
|
onChange(override);
|
|
|
|
|
},
|
|
|
|
|
[override, onChange]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const onDynamicConfigValueAdd = useCallback(
|
2020-04-07 15:02:08 +02:00
|
|
|
(id: string) => {
|
2020-02-14 13:46:08 +01:00
|
|
|
const propertyConfig: DynamicConfigValue = {
|
2020-04-06 16:24:41 +02:00
|
|
|
id,
|
2020-02-14 13:46:08 +01:00
|
|
|
};
|
|
|
|
|
if (override.properties) {
|
|
|
|
|
override.properties.push(propertyConfig);
|
|
|
|
|
} else {
|
|
|
|
|
override.properties = [propertyConfig];
|
|
|
|
|
}
|
|
|
|
|
onChange(override);
|
|
|
|
|
},
|
|
|
|
|
[override, onChange]
|
|
|
|
|
);
|
|
|
|
|
|
2020-04-06 16:24:41 +02:00
|
|
|
let configPropertiesOptions = registry.list().map(item => {
|
|
|
|
|
return {
|
|
|
|
|
label: item.name,
|
|
|
|
|
value: item.id,
|
|
|
|
|
description: item.description,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2020-02-14 13:46:08 +01:00
|
|
|
const matcherUi = fieldMatchersUI.get(override.matcher.id);
|
|
|
|
|
const styles = getStyles(theme);
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.wrapper}>
|
2020-03-19 12:28:05 +01:00
|
|
|
<FieldConfigItemHeaderTitle onRemove={onRemove} title={matcherUi.name} description={matcherUi.description}>
|
2020-02-14 13:46:08 +01:00
|
|
|
<div className={styles.matcherUi}>
|
|
|
|
|
<matcherUi.component
|
|
|
|
|
matcher={matcherUi.matcher}
|
|
|
|
|
data={data}
|
|
|
|
|
options={override.matcher.options}
|
|
|
|
|
onChange={option => onMatcherConfigChange(option)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2020-03-19 12:28:05 +01:00
|
|
|
</FieldConfigItemHeaderTitle>
|
2020-02-14 13:46:08 +01:00
|
|
|
<div>
|
|
|
|
|
{override.properties.map((p, j) => {
|
2020-04-06 16:24:41 +02:00
|
|
|
const item = registry.getIfExists(p.id);
|
2020-02-14 13:46:08 +01:00
|
|
|
|
|
|
|
|
if (!item) {
|
2020-04-06 16:24:41 +02:00
|
|
|
return <div>Unknown property: {p.id}</div>;
|
2020-02-14 13:46:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2020-04-06 16:24:41 +02:00
|
|
|
<div key={`${p.id}/${j}`}>
|
2020-02-14 13:46:08 +01:00
|
|
|
<DynamicConfigValueEditor
|
|
|
|
|
onChange={value => onDynamicConfigValueChange(j, value)}
|
|
|
|
|
onRemove={() => onDynamicConfigValueRemove(j)}
|
|
|
|
|
property={p}
|
2020-04-06 16:24:41 +02:00
|
|
|
registry={registry}
|
2020-02-14 13:46:08 +01:00
|
|
|
context={{
|
|
|
|
|
data,
|
|
|
|
|
getSuggestions: (scope?: VariableSuggestionsScope) => getDataLinksVariableSuggestions(data, scope),
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
<div className={styles.propertyPickerWrapper}>
|
|
|
|
|
<ValuePicker
|
|
|
|
|
label="Set config property"
|
@grafana/ui: Create Icon component and replace part of the icons (#23402)
* Part1: Unicons implementation (#23197)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179)
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Remove color prop from icon, remove color implemetation in mono icons
* Update navbar styling
* Move toPascalCase to utils/string
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Resolve type errors resulted from merge
* Part2: Unicons implementation (#23266)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Implment icons in Tabs
* Implement icons in search items and empty list
* Update buttons
* Update button-related snapshot tests
* Update icons in modals and page headers
* Create anfular wrapper and update all icons on search screen
* Update sizing, remove colors, update snapshot tests
* Remove color prop from icon, remove color implemetation in mono icons
* Remove color props from monochrome icons
* Complete update of icons for search screen
* Update icons for infor tooltips, playlist, permissions
* Support temporarly font awesome icons used in enterprise grafana
* Part1: Unicons implementation (#23197)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179)
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Remove color prop from icon, remove color implemetation in mono icons
* Update navbar styling
* Move toPascalCase to utils/string
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Icons update
* Add optional chaining to for isFontAwesome variable
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Part3: Unicons implementation (#23356)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Implment icons in Tabs
* Implement icons in search items and empty list
* Update buttons
* Update button-related snapshot tests
* Update icons in modals and page headers
* Create anfular wrapper and update all icons on search screen
* Update sizing, remove colors, update snapshot tests
* Remove color prop from icon, remove color implemetation in mono icons
* Remove color props from monochrome icons
* Complete update of icons for search screen
* Update icons for infor tooltips, playlist, permissions
* Support temporarly font awesome icons used in enterprise grafana
* Part1: Unicons implementation (#23197)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179)
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Remove color prop from icon, remove color implemetation in mono icons
* Update navbar styling
* Move toPascalCase to utils/string
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Update icons in Explore
* Update icons in alerting
* Update + and x buttons
* Update icons in configurations and settings
* Update close icons
* Update icons in rich history
* Update alert messages
* Add optional chaining to for isFontAwesome variable
* Remove icon mock, set up jest.config
* Fix navbar plus icon
* Fir enable-bacground to enableBackgournd
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Merge remote branch origin master to icons-unicons
* Revert "Merge remote branch origin master to icons-unicons"
This reverts commit 3f25d50a39a940883fefe73ce51219139c1ed37f.
* Size-up dashnav icons
* Fix alerting icons, panel headers, update tests
* Fix typecheck error
* Adjustments - add panel icon, spacing
* Set TerserPlugin sourceMap to false to prevent running out of memory when publishing storybook
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2020-04-08 14:33:31 +02:00
|
|
|
icon="plus-circle"
|
2020-02-14 13:46:08 +01:00
|
|
|
options={configPropertiesOptions}
|
|
|
|
|
variant={'link'}
|
|
|
|
|
onChange={o => {
|
2020-04-07 15:02:08 +02:00
|
|
|
onDynamicConfigValueAdd(o.value);
|
2020-02-14 13:46:08 +01:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme) => {
|
|
|
|
|
const borderColor = selectThemeVariant(
|
|
|
|
|
{
|
2020-04-12 15:05:49 +02:00
|
|
|
light: theme.palette.gray85,
|
|
|
|
|
dark: theme.palette.dark9,
|
2020-02-14 13:46:08 +01:00
|
|
|
},
|
|
|
|
|
theme.type
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const shadow = selectThemeVariant(
|
|
|
|
|
{
|
2020-04-12 15:05:49 +02:00
|
|
|
light: theme.palette.gray85,
|
|
|
|
|
dark: theme.palette.black,
|
2020-02-14 13:46:08 +01:00
|
|
|
},
|
|
|
|
|
theme.type
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
wrapper: css`
|
|
|
|
|
border: 1px dashed ${borderColor};
|
|
|
|
|
margin-bottom: ${theme.spacing.md};
|
|
|
|
|
transition: box-shadow 0.5s cubic-bezier(0.19, 1, 0.22, 1);
|
|
|
|
|
box-shadow: none;
|
|
|
|
|
&:hover {
|
|
|
|
|
box-shadow: 0 0 10px ${shadow};
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
matcherUi: css`
|
|
|
|
|
padding: ${theme.spacing.sm};
|
|
|
|
|
`,
|
|
|
|
|
propertyPickerWrapper: css`
|
|
|
|
|
border-top: 1px solid ${borderColor};
|
|
|
|
|
`,
|
|
|
|
|
};
|
|
|
|
|
});
|