mirror of
https://github.com/grafana/grafana.git
synced 2025-02-04 12:41:12 -06:00
47f8717149
* update eslint, tsconfig + esbuild to handle new jsx transform * remove thing that breaks the new jsx transform * remove react imports * adjust grafana-icons build * is this the correct syntax? * try this * well this was much easier than expected... * change grafana-plugin-configs webpack config * fixes * fix lockfile * fix 2 more violations * use path.resolve instead of require.resolve * remove react import * fix react imports * more fixes * remove React import * remove import React from docs * remove another react import
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
import { css } from '@emotion/css';
|
|
|
|
import { GrafanaTheme2, InternalTimeZones, StandardEditorProps } from '@grafana/data';
|
|
import { OptionsWithTimezones } from '@grafana/schema';
|
|
import { IconButton, TimeZonePicker, useStyles2 } from '@grafana/ui';
|
|
|
|
type Props = StandardEditorProps<string[], unknown, OptionsWithTimezones>;
|
|
|
|
export const TimezonesEditor = ({ value, onChange }: Props) => {
|
|
const styles = useStyles2(getStyles);
|
|
|
|
if (!value || value.length < 1) {
|
|
value = [''];
|
|
}
|
|
|
|
const addTimezone = () => {
|
|
onChange([...value, InternalTimeZones.default]);
|
|
};
|
|
|
|
const removeTimezone = (idx: number) => {
|
|
const copy = value.slice();
|
|
copy.splice(idx, 1);
|
|
onChange(copy);
|
|
};
|
|
|
|
const setTimezone = (idx: number, tz?: string) => {
|
|
const copy = value.slice();
|
|
copy[idx] = tz ?? InternalTimeZones.default;
|
|
if (copy.length === 0 || (copy.length === 1 && copy[0] === '')) {
|
|
onChange(undefined);
|
|
} else {
|
|
onChange(copy);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
{value.map((tz, idx) => (
|
|
<div className={styles.wrapper} key={`${idx}.${tz}`}>
|
|
<span className={styles.first}>
|
|
<TimeZonePicker
|
|
onChange={(v) => setTimezone(idx, v)}
|
|
includeInternal={true}
|
|
value={tz ?? InternalTimeZones.default}
|
|
/>
|
|
</span>
|
|
{idx === value.length - 1 ? (
|
|
<IconButton name="plus" onClick={addTimezone} tooltip="Add timezone" />
|
|
) : (
|
|
<IconButton name="times" onClick={() => removeTimezone(idx)} tooltip="Remove timezone" />
|
|
)}
|
|
</div>
|
|
))}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const getStyles = (theme: GrafanaTheme2) => ({
|
|
wrapper: css`
|
|
width: 100%;
|
|
display: flex;
|
|
flex-direction: rows;
|
|
align-items: center;
|
|
`,
|
|
first: css`
|
|
margin-right: 8px;
|
|
flex-grow: 2;
|
|
`,
|
|
});
|