mirror of
https://github.com/getredash/redash.git
synced 2026-03-23 04:00:09 -04:00
* Refine Auth service: remove dead code and fix race condition * Export services in CommonJS style * Refine Users, Events and OfflineListener services * Refactor Notifications service - rewrite to CommonJS * Replace Angular service injection with imports in React components * Fix Footer tests * Events service -> recordEvent function * CR1
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
import React from 'react';
|
|
import Tooltip from 'antd/lib/tooltip';
|
|
import PropTypes from 'prop-types';
|
|
import '@/redash-font/style.less';
|
|
import recordEvent from '@/services/recordEvent';
|
|
|
|
export default function AutocompleteToggle({ state, disabled, onToggle }) {
|
|
let tooltipMessage = 'Live Autocomplete Enabled';
|
|
let icon = 'icon-flash';
|
|
if (!state) {
|
|
tooltipMessage = 'Live Autocomplete Disabled';
|
|
icon = 'icon-flash-off';
|
|
}
|
|
|
|
if (disabled) {
|
|
tooltipMessage = 'Live Autocomplete Not Available (Use Ctrl+Space to Trigger)';
|
|
icon = 'icon-flash-off';
|
|
}
|
|
|
|
const toggle = (newState) => {
|
|
recordEvent('toggle_autocomplete', 'screen', 'query_editor', { state: newState });
|
|
onToggle(newState);
|
|
};
|
|
|
|
return (
|
|
<Tooltip placement="top" title={tooltipMessage}>
|
|
<button
|
|
type="button"
|
|
className={'btn btn-default m-r-5' + (disabled ? ' disabled' : '')}
|
|
onClick={() => toggle(!state)}
|
|
disabled={disabled}
|
|
>
|
|
<i className={'icon ' + icon} />
|
|
</button>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
|
|
AutocompleteToggle.propTypes = {
|
|
state: PropTypes.bool.isRequired,
|
|
disabled: PropTypes.bool.isRequired,
|
|
onToggle: PropTypes.func.isRequired,
|
|
};
|