mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08:00

* Replace icons in dashboard and settings * Replace icons in alerting * Update batch of icons * Implement icons accross various files * Style updates * Search: Fix recent and starred icons * Update styling and details * Replace new icon created by unicons * Fix e2e test, styling * Minor styling updates Co-authored-by: Clarity-89 <homes89@ukr.net>
59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
import React, { FunctionComponent } from 'react';
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { Segment, Icon } from '@grafana/ui';
|
|
import { labelsToGroupedOptions } from '../functions';
|
|
import { systemLabels } from '../constants';
|
|
|
|
export interface Props {
|
|
values: string[];
|
|
onChange: (values: string[]) => void;
|
|
variableOptionGroup: SelectableValue<string>;
|
|
groupBys: string[];
|
|
}
|
|
|
|
const removeText = '-- remove group by --';
|
|
const removeOption: SelectableValue<string> = { label: removeText, value: removeText };
|
|
|
|
export const GroupBys: FunctionComponent<Props> = ({ groupBys = [], values = [], onChange, variableOptionGroup }) => {
|
|
const options = [removeOption, variableOptionGroup, ...labelsToGroupedOptions([...groupBys, ...systemLabels])];
|
|
return (
|
|
<div className="gf-form-inline">
|
|
<label className="gf-form-label query-keyword width-9">Group By</label>
|
|
{values &&
|
|
values.map((value, index) => (
|
|
<Segment
|
|
allowCustomValue
|
|
key={value + index}
|
|
value={value}
|
|
options={options}
|
|
onChange={({ value = '' }) =>
|
|
onChange(
|
|
value === removeText
|
|
? values.filter((_, i) => i !== index)
|
|
: values.map((v, i) => (i === index ? value : v))
|
|
)
|
|
}
|
|
/>
|
|
))}
|
|
{values.length !== groupBys.length && (
|
|
<Segment
|
|
Component={
|
|
<a className="gf-form-label query-part">
|
|
<Icon name="plus-circle" />
|
|
</a>
|
|
}
|
|
allowCustomValue
|
|
onChange={({ value = '' }) => onChange([...values, value])}
|
|
options={[
|
|
variableOptionGroup,
|
|
...labelsToGroupedOptions([...groupBys.filter(groupBy => !values.includes(groupBy)), ...systemLabels]),
|
|
]}
|
|
/>
|
|
)}
|
|
<div className="gf-form gf-form--grow">
|
|
<label className="gf-form-label gf-form-label--grow"></label>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|