Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV-46535 Grafana 10 saving profile preferences fails with 400 bad request #59

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 6 additions & 35 deletions public/app/core/components/SharedPreferences/SharedPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import { DashboardPicker } from 'app/core/components/Select/DashboardPicker';
import { t, Trans } from 'app/core/internationalization';
import { LANGUAGES } from 'app/core/internationalization/constants';
import { PreferencesService } from 'app/core/services/PreferencesService';
import { backendSrv } from "app/core/services/backend_srv";// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
import { changeTheme } from 'app/core/services/theme';
import { DashboardSearchItem } from 'app/features/search/types';

export interface Props {
resourceUri: string;
Expand All @@ -31,7 +29,7 @@ export interface Props {
onConfirm?: () => Promise<boolean>;
}

export type State = UserPreferencesDTO & { homeDashboardId?: number; dashboards: Array<DashboardSearchItem & {id?: number}>}; // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
export type State = UserPreferencesDTO;

function getLanguageOptions(): Array<SelectableValue<string>> {
const languageOptions = LANGUAGES.map((v) => ({
Expand Down Expand Up @@ -64,7 +62,6 @@ export class SharedPreferences extends PureComponent<Props, State> {
weekStart: '',
language: '',
queryHistory: { homeTab: '' },
dashboards: [],
};

this.themeOptions = getBuiltInThemes(config.featureToggles.extraThemes).map((theme) => ({
Expand All @@ -77,51 +74,25 @@ export class SharedPreferences extends PureComponent<Props, State> {
}

async componentDidMount() {
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
const prefs = await backendSrv.get(`/api/${this.props.resourceUri.toLowerCase()}/preferences`);
const dashboards = await backendSrv.search({ starred: true });
//
// this.setState({
// homeDashboardUID: prefs.homeDashboardUID,
// theme: prefs.theme,
// timezone: prefs.timezone,
// weekStart: prefs.weekStart,
// language: prefs.language,
// queryHistory: prefs.queryHistory,
// });

if (prefs.homeDashboardId > 0 && !dashboards.find((d) => d.id === prefs.homeDashboardId)) {
const missing = await backendSrv.search({ dashboardIds: [prefs.homeDashboardId] });
if (missing && missing.length > 0) {
dashboards.push(missing[0]);
}
}
const prefs = await this.service.load();

this.setState({
homeDashboardId: prefs.homeDashboardId,
homeDashboardUID: prefs.homeDashboardUID,
theme: prefs.theme,
timezone: prefs.timezone,
weekStart: prefs.weekStart,
dashboards,
language: prefs.language,
queryHistory: prefs.queryHistory,
});
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Remove default dashboard end
}

onSubmitForm = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
const confirmationResult = this.props.onConfirm ? await this.props.onConfirm() : true;

if (confirmationResult) {
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
const { homeDashboardUID, theme, timezone } = this.state;
const homeDashboard = this.state.dashboards.find(d => d.uid === homeDashboardUID);
await backendSrv.put(`/api/${this.props.resourceUri.toLowerCase()}/preferences`, {
homeDashboardId: homeDashboard?.id || null,
theme,
timezone,
});
// LOGZ.IO GRAFANA CHANGE :: end
const { homeDashboardUID, theme, timezone, weekStart, language, queryHistory } = this.state;
await this.service.update({ homeDashboardUID, theme, timezone, weekStart, language, queryHistory });
window.location.reload();
}
};
Expand Down