2020-04-20 08:48:38 -05:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2021-04-01 07:15:23 -05:00
|
|
|
import { css } from '@emotion/css';
|
2020-04-21 04:42:21 -05:00
|
|
|
import { Button, DataLinkInput, stylesFactory, LegacyForms } from '@grafana/ui';
|
2020-02-11 06:48:36 -06:00
|
|
|
import { VariableSuggestion } from '@grafana/data';
|
2021-03-18 04:44:26 -05:00
|
|
|
import { DataSourcePicker } from '@grafana/runtime';
|
2019-11-06 09:15:08 -06:00
|
|
|
import { DerivedFieldConfig } from '../types';
|
2020-04-20 08:48:38 -05:00
|
|
|
import { usePrevious } from 'react-use';
|
2019-11-06 09:15:08 -06:00
|
|
|
|
2020-12-04 07:24:55 -06:00
|
|
|
const { Switch, FormField } = LegacyForms;
|
|
|
|
|
2019-11-06 09:15:08 -06:00
|
|
|
const getStyles = stylesFactory(() => ({
|
2020-03-25 06:25:39 -05:00
|
|
|
row: css`
|
2019-11-06 09:15:08 -06:00
|
|
|
display: flex;
|
2019-11-21 11:15:40 -06:00
|
|
|
align-items: baseline;
|
2019-11-06 09:15:08 -06:00
|
|
|
`,
|
|
|
|
nameField: css`
|
|
|
|
flex: 2;
|
|
|
|
`,
|
|
|
|
regexField: css`
|
|
|
|
flex: 3;
|
|
|
|
`,
|
2021-07-29 13:42:20 -05:00
|
|
|
urlField: css`
|
|
|
|
flex: 1;
|
|
|
|
`,
|
|
|
|
urlDisplayLabelField: css`
|
|
|
|
flex: 1;
|
|
|
|
`,
|
2019-11-06 09:15:08 -06:00
|
|
|
}));
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
value: DerivedFieldConfig;
|
|
|
|
onChange: (value: DerivedFieldConfig) => void;
|
|
|
|
onDelete: () => void;
|
|
|
|
suggestions: VariableSuggestion[];
|
|
|
|
className?: string;
|
|
|
|
};
|
|
|
|
export const DerivedField = (props: Props) => {
|
|
|
|
const { value, onChange, onDelete, suggestions, className } = props;
|
|
|
|
const styles = getStyles();
|
2020-04-20 08:48:38 -05:00
|
|
|
const [showInternalLink, setShowInternalLink] = useState(!!value.datasourceUid);
|
|
|
|
const previousUid = usePrevious(value.datasourceUid);
|
|
|
|
|
|
|
|
// Force internal link visibility change if uid changed outside of this component.
|
|
|
|
useEffect(() => {
|
|
|
|
if (!previousUid && value.datasourceUid && !showInternalLink) {
|
|
|
|
setShowInternalLink(true);
|
|
|
|
}
|
|
|
|
if (previousUid && !value.datasourceUid && showInternalLink) {
|
|
|
|
setShowInternalLink(false);
|
|
|
|
}
|
|
|
|
}, [previousUid, value.datasourceUid, showInternalLink]);
|
2019-11-06 09:15:08 -06:00
|
|
|
|
|
|
|
const handleChange = (field: keyof typeof value) => (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
onChange({
|
|
|
|
...value,
|
|
|
|
[field]: event.currentTarget.value,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={className}>
|
2020-03-25 06:25:39 -05:00
|
|
|
<div className={styles.row}>
|
2019-11-06 09:15:08 -06:00
|
|
|
<FormField
|
|
|
|
className={styles.nameField}
|
|
|
|
labelWidth={5}
|
|
|
|
// A bit of a hack to prevent using default value for the width from FormField
|
|
|
|
inputWidth={null}
|
|
|
|
label="Name"
|
|
|
|
type="text"
|
|
|
|
value={value.name}
|
|
|
|
onChange={handleChange('name')}
|
|
|
|
/>
|
|
|
|
<FormField
|
|
|
|
className={styles.regexField}
|
|
|
|
inputWidth={null}
|
|
|
|
label="Regex"
|
|
|
|
type="text"
|
|
|
|
value={value.matcherRegex}
|
|
|
|
onChange={handleChange('matcherRegex')}
|
|
|
|
tooltip={
|
|
|
|
'Use to parse and capture some part of the log message. You can use the captured groups in the template.'
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Button
|
2020-03-26 05:50:27 -05:00
|
|
|
variant="destructive"
|
2019-11-06 09:15:08 -06:00
|
|
|
title="Remove field"
|
@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 07:33:31 -05:00
|
|
|
icon="times"
|
2021-01-20 00:59:48 -06:00
|
|
|
onClick={(event) => {
|
2019-11-06 09:15:08 -06:00
|
|
|
event.preventDefault();
|
|
|
|
onDelete();
|
|
|
|
}}
|
2019-11-21 11:15:40 -06:00
|
|
|
className={css`
|
|
|
|
margin-left: 8px;
|
|
|
|
`}
|
2019-11-06 09:15:08 -06:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2021-07-29 13:42:20 -05:00
|
|
|
<div className={styles.row}>
|
|
|
|
<FormField
|
|
|
|
label={showInternalLink ? 'Query' : 'URL'}
|
|
|
|
inputEl={
|
|
|
|
<DataLinkInput
|
|
|
|
placeholder={showInternalLink ? '${__value.raw}' : 'http://example.com/${__value.raw}'}
|
|
|
|
value={value.url || ''}
|
|
|
|
onChange={(newValue) =>
|
|
|
|
onChange({
|
|
|
|
...value,
|
|
|
|
url: newValue,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
suggestions={suggestions}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
className={styles.urlField}
|
|
|
|
/>
|
|
|
|
<FormField
|
|
|
|
className={styles.urlDisplayLabelField}
|
|
|
|
inputWidth={null}
|
|
|
|
label="URL Label"
|
|
|
|
type="text"
|
|
|
|
value={value.urlDisplayLabel}
|
|
|
|
onChange={handleChange('urlDisplayLabel')}
|
|
|
|
tooltip={'Use to override the button label when this derived field is found in a log.'}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-03-25 06:25:39 -05:00
|
|
|
|
2020-04-23 13:46:42 -05:00
|
|
|
<div className={styles.row}>
|
|
|
|
<Switch
|
|
|
|
label="Internal link"
|
|
|
|
checked={showInternalLink}
|
|
|
|
onChange={() => {
|
|
|
|
if (showInternalLink) {
|
|
|
|
onChange({
|
|
|
|
...value,
|
|
|
|
datasourceUid: undefined,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
setShowInternalLink(!showInternalLink);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{showInternalLink && (
|
2020-12-04 07:24:55 -06:00
|
|
|
<DataSourcePicker
|
|
|
|
tracing={true}
|
2021-01-20 00:59:48 -06:00
|
|
|
onChange={(ds) =>
|
2020-04-23 13:46:42 -05:00
|
|
|
onChange({
|
|
|
|
...value,
|
2020-12-04 07:24:55 -06:00
|
|
|
datasourceUid: ds.uid,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
current={value.datasourceUid}
|
2020-03-25 06:25:39 -05:00
|
|
|
/>
|
2020-04-23 13:46:42 -05:00
|
|
|
)}
|
|
|
|
</div>
|
2019-11-06 09:15:08 -06:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|