mirror of https://github.com/buster-so/buster.git
rename should navigate to different page
This commit is contained in:
parent
f3944a6dea
commit
6a507bd7ff
|
@ -49,7 +49,8 @@ import {
|
||||||
type MetricFileViewSecondary,
|
type MetricFileViewSecondary,
|
||||||
useChatLayoutContextSelector
|
useChatLayoutContextSelector
|
||||||
} from '@/layouts/ChatLayout/ChatLayoutContext';
|
} from '@/layouts/ChatLayout/ChatLayoutContext';
|
||||||
import { timeout } from '@/lib';
|
import { timeout } from '@/lib/timeout';
|
||||||
|
import { ensureElementExists } from '@/lib/element';
|
||||||
import { downloadElementToImage, exportJSONToCSV } from '@/lib/exportUtils';
|
import { downloadElementToImage, exportJSONToCSV } from '@/lib/exportUtils';
|
||||||
import { canEdit, getIsEffectiveOwner, getIsOwner } from '@/lib/share';
|
import { canEdit, getIsEffectiveOwner, getIsOwner } from '@/lib/share';
|
||||||
import { BusterRoutes } from '@/routes';
|
import { BusterRoutes } from '@/routes';
|
||||||
|
@ -435,15 +436,27 @@ const useDeleteMetricSelectMenu = ({ metricId }: { metricId: string }) => {
|
||||||
|
|
||||||
const useRenameMetricSelectMenu = ({ metricId }: { metricId: string }) => {
|
const useRenameMetricSelectMenu = ({ metricId }: { metricId: string }) => {
|
||||||
const onSetFileView = useChatLayoutContextSelector((x) => x.onSetFileView);
|
const onSetFileView = useChatLayoutContextSelector((x) => x.onSetFileView);
|
||||||
|
const onChangePage = useAppLayoutContextSelector((x) => x.onChangePage);
|
||||||
|
const chatId = useChatLayoutContextSelector((x) => x.chatId);
|
||||||
|
const dashboardId = useChatLayoutContextSelector((x) => x.dashboardId);
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
label: 'Rename metric',
|
label: 'Rename metric',
|
||||||
value: 'rename-metric',
|
value: 'rename-metric',
|
||||||
icon: <Pencil />,
|
icon: <Pencil />,
|
||||||
onClick: async () => {
|
onClick: async () => {
|
||||||
onSetFileView({ fileView: 'chart' });
|
const route = assetParamsToRoute({
|
||||||
await timeout(125);
|
type: 'metric',
|
||||||
const input = document.getElementById(METRIC_CHART_TITLE_INPUT_ID) as HTMLInputElement;
|
assetId: metricId,
|
||||||
|
chatId,
|
||||||
|
dashboardId,
|
||||||
|
page: 'chart'
|
||||||
|
});
|
||||||
|
await onChangePage(route);
|
||||||
|
await timeout(100);
|
||||||
|
const input = await ensureElementExists(
|
||||||
|
() => document.getElementById(METRIC_CHART_TITLE_INPUT_ID) as HTMLInputElement
|
||||||
|
);
|
||||||
if (input) {
|
if (input) {
|
||||||
input.focus();
|
input.focus();
|
||||||
input.select();
|
input.select();
|
||||||
|
|
|
@ -101,3 +101,25 @@ export const boldHighlights = (name: string, highlights: string[]): React.ReactN
|
||||||
return String(name);
|
return String(name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ensureElementExists = async <T extends HTMLElement>(
|
||||||
|
nodeCheck: () => T | null,
|
||||||
|
params?: { timeoutMs?: number; intervalMs?: number }
|
||||||
|
): Promise<T | null> => {
|
||||||
|
const { timeoutMs = 3000, intervalMs = 50 } = params || {};
|
||||||
|
const start = Date.now();
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const check = () => {
|
||||||
|
const el = nodeCheck();
|
||||||
|
if (el) {
|
||||||
|
resolve(el);
|
||||||
|
} else if (Date.now() - start < timeoutMs) {
|
||||||
|
setTimeout(check, intervalMs);
|
||||||
|
} else {
|
||||||
|
resolve(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
check();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue