mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
chore(sqllab): Add logging for actions (#28876)
This commit is contained in:
@@ -100,6 +100,17 @@ import {
|
||||
} from 'src/utils/localStorageHelpers';
|
||||
import { EmptyStateBig } from 'src/components/EmptyState';
|
||||
import getBootstrapData from 'src/utils/getBootstrapData';
|
||||
import useLogAction from 'src/logger/useLogAction';
|
||||
import {
|
||||
LOG_ACTIONS_SQLLAB_CREATE_TABLE_AS,
|
||||
LOG_ACTIONS_SQLLAB_CREATE_VIEW_AS,
|
||||
LOG_ACTIONS_SQLLAB_ESTIMATE_QUERY_COST,
|
||||
LOG_ACTIONS_SQLLAB_FORMAT_SQL,
|
||||
LOG_ACTIONS_SQLLAB_LOAD_TAB_STATE,
|
||||
LOG_ACTIONS_SQLLAB_RUN_QUERY,
|
||||
LOG_ACTIONS_SQLLAB_STOP_QUERY,
|
||||
Logger,
|
||||
} from 'src/logger/LogUtils';
|
||||
import TemplateParamsEditor from '../TemplateParamsEditor';
|
||||
import SouthPane from '../SouthPane';
|
||||
import SaveQuery, { QueryPayload } from '../SaveQuery';
|
||||
@@ -273,6 +284,7 @@ const SqlEditor: FC<Props> = ({
|
||||
};
|
||||
}, shallowEqual);
|
||||
|
||||
const logAction = useLogAction({ queryEditorId: queryEditor.id });
|
||||
const isActive = currentQueryEditorId === queryEditor.id;
|
||||
const [height, setHeight] = useState(0);
|
||||
const [autorun, setAutorun] = useState(queryEditor.autorun);
|
||||
@@ -319,9 +331,15 @@ const SqlEditor: FC<Props> = ({
|
||||
[ctas, database, defaultQueryLimit, dispatch, queryEditor],
|
||||
);
|
||||
|
||||
const formatCurrentQuery = useCallback(() => {
|
||||
dispatch(formatQuery(queryEditor));
|
||||
}, [dispatch, queryEditor]);
|
||||
const formatCurrentQuery = useCallback(
|
||||
(useShortcut?: boolean) => {
|
||||
logAction(LOG_ACTIONS_SQLLAB_FORMAT_SQL, {
|
||||
shortcut: Boolean(useShortcut),
|
||||
});
|
||||
dispatch(formatQuery(queryEditor));
|
||||
},
|
||||
[dispatch, queryEditor, logAction],
|
||||
);
|
||||
|
||||
const stopQuery = useCallback(() => {
|
||||
if (latestQuery && ['running', 'pending'].indexOf(latestQuery.state) >= 0) {
|
||||
@@ -360,6 +378,7 @@ const SqlEditor: FC<Props> = ({
|
||||
descr: KEY_MAP[KeyboardShortcut.CtrlR],
|
||||
func: () => {
|
||||
if (queryEditor.sql.trim() !== '') {
|
||||
logAction(LOG_ACTIONS_SQLLAB_RUN_QUERY, { shortcut: true });
|
||||
startQuery();
|
||||
}
|
||||
},
|
||||
@@ -370,6 +389,7 @@ const SqlEditor: FC<Props> = ({
|
||||
descr: KEY_MAP[KeyboardShortcut.CtrlEnter],
|
||||
func: () => {
|
||||
if (queryEditor.sql.trim() !== '') {
|
||||
logAction(LOG_ACTIONS_SQLLAB_RUN_QUERY, { shortcut: true });
|
||||
startQuery();
|
||||
}
|
||||
},
|
||||
@@ -386,6 +406,7 @@ const SqlEditor: FC<Props> = ({
|
||||
descr: KEY_MAP[KeyboardShortcut.CtrlT],
|
||||
}),
|
||||
func: () => {
|
||||
Logger.markTimeOrigin();
|
||||
dispatch(addNewQueryEditor());
|
||||
},
|
||||
},
|
||||
@@ -400,14 +421,17 @@ const SqlEditor: FC<Props> = ({
|
||||
key: KeyboardShortcut.CtrlE,
|
||||
descr: KEY_MAP[KeyboardShortcut.CtrlE],
|
||||
}),
|
||||
func: stopQuery,
|
||||
func: () => {
|
||||
logAction(LOG_ACTIONS_SQLLAB_STOP_QUERY, { shortcut: true });
|
||||
stopQuery();
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'formatQuery',
|
||||
key: KeyboardShortcut.CtrlShiftF,
|
||||
descr: KEY_MAP[KeyboardShortcut.CtrlShiftF],
|
||||
func: () => {
|
||||
formatCurrentQuery();
|
||||
formatCurrentQuery(true);
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -505,6 +529,13 @@ const SqlEditor: FC<Props> = ({
|
||||
!queryEditor.loaded;
|
||||
|
||||
const loadQueryEditor = useEffectEvent(() => {
|
||||
const duration = Logger.getTimestamp();
|
||||
logAction(LOG_ACTIONS_SQLLAB_LOAD_TAB_STATE, {
|
||||
duration,
|
||||
queryEditorId: queryEditor.id,
|
||||
inLocalStorage: Boolean(queryEditor.inLocalStorage),
|
||||
hasLoaded: !shouldLoadQueryEditor,
|
||||
});
|
||||
if (shouldLoadQueryEditor) {
|
||||
dispatch(fetchQueryEditor(queryEditor, displayLimit));
|
||||
}
|
||||
@@ -602,6 +633,7 @@ const SqlEditor: FC<Props> = ({
|
||||
});
|
||||
|
||||
const getQueryCostEstimate = () => {
|
||||
logAction(LOG_ACTIONS_SQLLAB_ESTIMATE_QUERY_COST, { shortcut: false });
|
||||
if (database) {
|
||||
dispatch(estimateQueryCost(queryEditor));
|
||||
}
|
||||
@@ -668,7 +700,9 @@ const SqlEditor: FC<Props> = ({
|
||||
/>
|
||||
</Menu.Item>
|
||||
)}
|
||||
<Menu.Item onClick={formatCurrentQuery}>{t('Format SQL')}</Menu.Item>
|
||||
<Menu.Item onClick={() => formatCurrentQuery()}>
|
||||
{t('Format SQL')}
|
||||
</Menu.Item>
|
||||
{!isEmpty(scheduledQueriesConf) && (
|
||||
<Menu.Item>
|
||||
<ScheduleQueryButton
|
||||
@@ -706,6 +740,9 @@ const SqlEditor: FC<Props> = ({
|
||||
{allowCTAS && (
|
||||
<Menu.Item
|
||||
onClick={() => {
|
||||
logAction(LOG_ACTIONS_SQLLAB_CREATE_TABLE_AS, {
|
||||
shortcut: false,
|
||||
});
|
||||
setShowCreateAsModal(true);
|
||||
setCreateAs(CtasEnum.Table);
|
||||
}}
|
||||
@@ -717,6 +754,9 @@ const SqlEditor: FC<Props> = ({
|
||||
{allowCVAS && (
|
||||
<Menu.Item
|
||||
onClick={() => {
|
||||
logAction(LOG_ACTIONS_SQLLAB_CREATE_VIEW_AS, {
|
||||
shortcut: false,
|
||||
});
|
||||
setShowCreateAsModal(true);
|
||||
setCreateAs(CtasEnum.View);
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user