mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Move xss and sanitize packages to grafana-data
* Move text, url and location utils to grafana-data
* Move grafana config types to grafana-data
* Move field display value proxy to grafana-data
* Fix
* Move data links built in vars to grafana-data
* Attach links supplier to when applying field overrides
* Prep tests
* Use links suppliers attached via field overrides
* locationUtil dependencies type
* Move sanitize-url declaration to grafana-data
* Revert "Move sanitize-url declaration to grafana-data"
This reverts commit 11db9f5e55
.
* Fix typo
* fix ts vol1
* Remove import from runtime in data.... Make TS happy at the same time ;)
* Lovely TS, please shut up
* Lovely TS, please shut up vol2
* fix tests
* Fixes
* minor refactor
* Attach get links to FieldDisplayValue for seamless usage
* Update packages/grafana-data/src/field/fieldOverrides.ts
* Make storybook build
84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import React from 'react';
|
|
import { css } from 'emotion';
|
|
import { Button, stylesFactory, useTheme } from '@grafana/ui';
|
|
import { GrafanaTheme, VariableOrigin, DataLinkBuiltInVars } from '@grafana/data';
|
|
import { DataLinkConfig } from '../types';
|
|
import { DataLink } from './DataLink';
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme) => ({
|
|
infoText: css`
|
|
padding-bottom: ${theme.spacing.md};
|
|
color: ${theme.colors.textWeak};
|
|
`,
|
|
dataLink: css`
|
|
margin-bottom: ${theme.spacing.sm};
|
|
`,
|
|
}));
|
|
|
|
type Props = {
|
|
value?: DataLinkConfig[];
|
|
onChange: (value: DataLinkConfig[]) => void;
|
|
};
|
|
export const DataLinks = (props: Props) => {
|
|
const { value, onChange } = props;
|
|
const theme = useTheme();
|
|
const styles = getStyles(theme);
|
|
|
|
return (
|
|
<>
|
|
<h3 className="page-heading">Data links</h3>
|
|
|
|
<div className={styles.infoText}>
|
|
Add links to existing fields. Links will be shown in log row details next to the field value.
|
|
</div>
|
|
|
|
<div className="gf-form-group">
|
|
{value &&
|
|
value.map((field, index) => {
|
|
return (
|
|
<DataLink
|
|
className={styles.dataLink}
|
|
key={index}
|
|
value={field}
|
|
onChange={newField => {
|
|
const newDataLinks = [...value];
|
|
newDataLinks.splice(index, 1, newField);
|
|
onChange(newDataLinks);
|
|
}}
|
|
onDelete={() => {
|
|
const newDataLinks = [...value];
|
|
newDataLinks.splice(index, 1);
|
|
onChange(newDataLinks);
|
|
}}
|
|
suggestions={[
|
|
{
|
|
value: DataLinkBuiltInVars.valueRaw,
|
|
label: 'Raw value',
|
|
documentation: 'Raw value of the field',
|
|
origin: VariableOrigin.Value,
|
|
},
|
|
]}
|
|
/>
|
|
);
|
|
})}
|
|
<div>
|
|
<Button
|
|
variant={'secondary'}
|
|
className={css`
|
|
margin-right: 10px;
|
|
`}
|
|
icon="plus"
|
|
onClick={event => {
|
|
event.preventDefault();
|
|
const newDataLinks = [...(value || []), { field: '', url: '' }];
|
|
onChange(newDataLinks);
|
|
}}
|
|
>
|
|
Add
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
};
|