mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Convert remaining profile bits to React (#24310)
* reactify user sessions * all reactified * more cleanup * comment edit * Profile: Fix casing * Profile: Add Page wrapper * Profile: New form styles for UserProfileEditForm * Profile: Use new form styles for SharedPreferences * Profile: Use radioButtonGroup for SharedPreferences * Grafana UI: Add FieldSet * Grafana UI: Add story * Grafana UI: Add docs * Grafana UI: Export FieldSet * Profile: USe FieldSet * Profile: Sort sessions Co-authored-by: Clarity-89 <homes89@ukr.net>
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import { css } from 'emotion';
|
||||
|
||||
import { InlineFormLabel, LegacyForms } from '@grafana/ui';
|
||||
const { Select } = LegacyForms;
|
||||
import {
|
||||
Select,
|
||||
Field,
|
||||
Form,
|
||||
Tooltip,
|
||||
Icon,
|
||||
stylesFactory,
|
||||
Label,
|
||||
Button,
|
||||
RadioButtonGroup,
|
||||
FieldSet,
|
||||
} from '@grafana/ui';
|
||||
import { getTimeZoneGroups, SelectableValue } from '@grafana/data';
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
|
||||
import { DashboardSearchHit, DashboardSearchItemType } from 'app/features/search/types';
|
||||
import { backendSrv } from 'app/core/services/backend_srv';
|
||||
import { getTimeZoneGroups, SelectableValue } from '@grafana/data';
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
|
||||
export interface Props {
|
||||
resourceUri: string;
|
||||
@@ -19,7 +30,7 @@ export interface State {
|
||||
dashboards: DashboardSearchHit[];
|
||||
}
|
||||
|
||||
const themes = [
|
||||
const themes: SelectableValue[] = [
|
||||
{ value: '', label: 'Default' },
|
||||
{ value: 'dark', label: 'Dark' },
|
||||
{ value: 'light', label: 'Light' },
|
||||
@@ -86,9 +97,7 @@ export class SharedPreferences extends PureComponent<Props, State> {
|
||||
});
|
||||
}
|
||||
|
||||
onSubmitForm = async (event: React.SyntheticEvent) => {
|
||||
event.preventDefault();
|
||||
|
||||
onSubmitForm = async () => {
|
||||
const { homeDashboardId, theme, timezone } = this.state;
|
||||
|
||||
await backendSrv.put(`/api/${this.props.resourceUri}/preferences`, {
|
||||
@@ -99,11 +108,8 @@ export class SharedPreferences extends PureComponent<Props, State> {
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
onThemeChanged = (theme: SelectableValue<string>) => {
|
||||
if (!theme || typeof theme.value !== 'string') {
|
||||
return;
|
||||
}
|
||||
this.setState({ theme: theme.value });
|
||||
onThemeChanged = (value: string) => {
|
||||
this.setState({ theme: value });
|
||||
};
|
||||
|
||||
onTimeZoneChanged = (timezone: SelectableValue<string>) => {
|
||||
@@ -126,55 +132,66 @@ export class SharedPreferences extends PureComponent<Props, State> {
|
||||
|
||||
render() {
|
||||
const { theme, timezone, homeDashboardId, dashboards } = this.state;
|
||||
const styles = getStyles();
|
||||
|
||||
return (
|
||||
<form className="section gf-form-group" onSubmit={this.onSubmitForm}>
|
||||
<h3 className="page-heading">Preferences</h3>
|
||||
<div className="gf-form">
|
||||
<span className="gf-form-label width-11">UI Theme</span>
|
||||
<Select
|
||||
isSearchable={false}
|
||||
value={themes.find(item => item.value === theme)}
|
||||
options={themes}
|
||||
onChange={this.onThemeChanged}
|
||||
width={20}
|
||||
/>
|
||||
</div>
|
||||
<div className="gf-form">
|
||||
<InlineFormLabel
|
||||
width={11}
|
||||
tooltip="Not finding dashboard you want? Star it first, then it should appear in this select box."
|
||||
>
|
||||
Home Dashboard
|
||||
</InlineFormLabel>
|
||||
<Select
|
||||
value={dashboards.find(dashboard => dashboard.id === homeDashboardId)}
|
||||
getOptionValue={i => i.id}
|
||||
getOptionLabel={this.getFullDashName}
|
||||
onChange={(dashboard: DashboardSearchHit) => this.onHomeDashboardChanged(dashboard.id)}
|
||||
options={dashboards}
|
||||
placeholder="Choose default dashboard"
|
||||
width={20}
|
||||
/>
|
||||
</div>
|
||||
<div className="gf-form" aria-label={selectors.components.TimeZonePicker.container}>
|
||||
<label className="gf-form-label width-11">Timezone</label>
|
||||
<Select
|
||||
isSearchable={true}
|
||||
value={timeZones.find(item => item.value === timezone)}
|
||||
onChange={this.onTimeZoneChanged}
|
||||
options={timeZones}
|
||||
width={20}
|
||||
/>
|
||||
</div>
|
||||
<div className="gf-form-button-row">
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<Form onSubmit={this.onSubmitForm}>
|
||||
{() => {
|
||||
return (
|
||||
<FieldSet label="Preferences">
|
||||
<Field label="UI Theme">
|
||||
<RadioButtonGroup
|
||||
options={themes}
|
||||
value={themes.find(item => item.value === theme)?.value}
|
||||
onChange={this.onThemeChanged}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field
|
||||
label={
|
||||
<Label>
|
||||
<span className={styles.labelText}>Home Dashboard</span>
|
||||
<Tooltip content="Not finding dashboard you want? Star it first, then it should appear in this select box.">
|
||||
<Icon name="info-circle" />
|
||||
</Tooltip>
|
||||
</Label>
|
||||
}
|
||||
>
|
||||
<Select
|
||||
value={dashboards.find(dashboard => dashboard.id === homeDashboardId)}
|
||||
getOptionValue={i => i.id}
|
||||
getOptionLabel={this.getFullDashName}
|
||||
onChange={(dashboard: DashboardSearchHit) => this.onHomeDashboardChanged(dashboard.id)}
|
||||
options={dashboards}
|
||||
placeholder="Choose default dashboard"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="Timezone" aria-label={selectors.components.TimeZonePicker.container}>
|
||||
<Select
|
||||
isSearchable={true}
|
||||
value={timeZones.find(item => item.value === timezone)}
|
||||
onChange={this.onTimeZoneChanged}
|
||||
options={timeZones}
|
||||
/>
|
||||
</Field>
|
||||
<div className="gf-form-button-row">
|
||||
<Button variant="primary">Save</Button>
|
||||
</div>
|
||||
</FieldSet>
|
||||
);
|
||||
}}
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default SharedPreferences;
|
||||
|
||||
const getStyles = stylesFactory(() => {
|
||||
return {
|
||||
labelText: css`
|
||||
margin-right: 6px;
|
||||
`,
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user