mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
import React, { useEffect, useState } from 'react';
|
|
|
|
import { Button, ConfirmModal } from '@grafana/ui';
|
|
|
|
type Props = {
|
|
isRaw: boolean;
|
|
onChange: (newIsRaw: boolean) => void;
|
|
};
|
|
|
|
export const QueryEditorModeSwitcher = ({ isRaw, onChange }: Props): JSX.Element => {
|
|
const [isModalOpen, setModalOpen] = useState(false);
|
|
|
|
useEffect(() => {
|
|
// if the isRaw changes, we hide the modal
|
|
setModalOpen(false);
|
|
}, [isRaw]);
|
|
|
|
if (isRaw) {
|
|
return (
|
|
<>
|
|
<Button
|
|
aria-label="Switch to visual editor"
|
|
icon="pen"
|
|
variant="secondary"
|
|
type="button"
|
|
onClick={() => {
|
|
// we show the are-you-sure modal
|
|
setModalOpen(true);
|
|
}}
|
|
></Button>
|
|
<ConfirmModal
|
|
isOpen={isModalOpen}
|
|
title="Switch to visual editor mode"
|
|
body="Are you sure to switch to visual editor mode? You will lose the changes done in raw query mode."
|
|
confirmText="Yes, switch to editor mode"
|
|
dismissText="No, stay in raw query mode"
|
|
onConfirm={() => {
|
|
onChange(false);
|
|
}}
|
|
onDismiss={() => {
|
|
setModalOpen(false);
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
} else {
|
|
return (
|
|
<Button
|
|
aria-label="Switch to text editor"
|
|
icon="pen"
|
|
variant="secondary"
|
|
type="button"
|
|
onClick={() => {
|
|
onChange(true);
|
|
}}
|
|
></Button>
|
|
);
|
|
}
|
|
};
|