mirror of https://github.com/buster-so/buster.git
update drag and drop logic for dashboard
This commit is contained in:
parent
b0699bf5be
commit
c85d51b7d2
|
@ -1,47 +0,0 @@
|
||||||
'use client';
|
|
||||||
|
|
||||||
import React from 'react';
|
|
||||||
import { FileIndeterminateLoader } from '@/components/features/FileIndeterminateLoader';
|
|
||||||
import { DashboardFileView, useChatLayoutContextSelector } from '@/layouts/ChatLayout';
|
|
||||||
import { DashboardViewComponents } from './config';
|
|
||||||
import { useGetDashboard } from '@/api/buster_rest/dashboards';
|
|
||||||
import { useDashboardContentStore } from '@/context/Dashboards';
|
|
||||||
import { AddToDashboardModal } from '@/components/features/modal/AddToDashboardModal';
|
|
||||||
import { canEdit } from '@/lib/share';
|
|
||||||
|
|
||||||
export const DashboardController: React.FC<{ dashboardId: string }> = ({ dashboardId }) => {
|
|
||||||
const { isFetched: isFetchedDashboard, data: permission } = useGetDashboard(
|
|
||||||
{ id: dashboardId },
|
|
||||||
(x) => x.permission
|
|
||||||
);
|
|
||||||
const chatId = useChatLayoutContextSelector((x) => x.chatId);
|
|
||||||
const selectedFileView = useChatLayoutContextSelector((x) => x.selectedFileView) || 'dashboard';
|
|
||||||
const isEditor = canEdit(permission);
|
|
||||||
|
|
||||||
const Component =
|
|
||||||
selectedFileView && isFetchedDashboard && selectedFileView in DashboardViewComponents
|
|
||||||
? DashboardViewComponents[selectedFileView as DashboardFileView]
|
|
||||||
: () => null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{!isFetchedDashboard && <FileIndeterminateLoader />}
|
|
||||||
<Component dashboardId={dashboardId} readOnly={!isEditor} chatId={chatId} />
|
|
||||||
|
|
||||||
{isEditor && <MemoizedAddToDashboardModal dashboardId={dashboardId} />}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const MemoizedAddToDashboardModal = React.memo(({ dashboardId }: { dashboardId: string }) => {
|
|
||||||
const { openAddContentModal, onCloseAddContentModal } = useDashboardContentStore();
|
|
||||||
return (
|
|
||||||
<AddToDashboardModal
|
|
||||||
open={openAddContentModal}
|
|
||||||
onClose={onCloseAddContentModal}
|
|
||||||
dashboardId={dashboardId}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
MemoizedAddToDashboardModal.displayName = 'MemoizedAddToDashboardModal';
|
|
|
@ -39,11 +39,8 @@ export const MetricTitle: React.FC<{
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link className="flex" href={metricLink} prefetch>
|
<Link className="flex" href={metricLink} prefetch {...attributes} {...listeners}>
|
||||||
<div
|
<div className={'flex cursor-pointer flex-col space-y-0.5 overflow-hidden'}>
|
||||||
{...attributes}
|
|
||||||
{...listeners}
|
|
||||||
className={'flex cursor-pointer flex-col space-y-0.5 overflow-hidden'}>
|
|
||||||
<div className="flex w-full justify-between space-x-0.5 overflow-hidden">
|
<div className="flex w-full justify-between space-x-0.5 overflow-hidden">
|
||||||
<Title
|
<Title
|
||||||
as="h4"
|
as="h4"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { useDebounceFn, useMemoizedFn } from '@/hooks';
|
import { useDebounceFn, useMemoizedFn } from '@/hooks';
|
||||||
import { EditableTitle } from '@/components/ui/typography/EditableTitle';
|
import { EditableTitle } from '@/components/ui/typography/EditableTitle';
|
||||||
import { Input } from '@/components/ui/inputs';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { type useUpdateDashboard } from '@/api/buster_rest/dashboards';
|
import { type useUpdateDashboard } from '@/api/buster_rest/dashboards';
|
||||||
import { InputTextArea } from '@/components/ui/inputs/InputTextArea';
|
import { InputTextArea } from '@/components/ui/inputs/InputTextArea';
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { DashboardViewProps } from '../config';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { DashboardEditTitles } from './DashboardEditTitle';
|
import { DashboardEditTitles } from './DashboardEditTitle';
|
||||||
import { DashboardContentController } from './DashboardContentController';
|
import { DashboardContentController } from './DashboardContentController';
|
||||||
|
@ -11,12 +10,13 @@ import {
|
||||||
} from '@/api/buster_rest/dashboards';
|
} from '@/api/buster_rest/dashboards';
|
||||||
import { useDashboardContentStore } from '@/context/Dashboards';
|
import { useDashboardContentStore } from '@/context/Dashboards';
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
import { canEdit } from '@/lib/share';
|
||||||
|
|
||||||
export const DashboardViewDashboardController: React.FC<DashboardViewProps> = ({
|
export const DashboardViewDashboardController: React.FC<{
|
||||||
dashboardId,
|
dashboardId: string;
|
||||||
chatId,
|
chatId: string | undefined;
|
||||||
readOnly = false
|
readOnly?: boolean;
|
||||||
}) => {
|
}> = ({ dashboardId, chatId, readOnly: readOnlyProp = false }) => {
|
||||||
const { data: dashboardResponse } = useGetDashboard({ id: dashboardId });
|
const { data: dashboardResponse } = useGetDashboard({ id: dashboardId });
|
||||||
const { mutateAsync: onUpdateDashboard } = useUpdateDashboard();
|
const { mutateAsync: onUpdateDashboard } = useUpdateDashboard();
|
||||||
const { mutateAsync: onUpdateDashboardConfig } = useUpdateDashboardConfig();
|
const { mutateAsync: onUpdateDashboardConfig } = useUpdateDashboardConfig();
|
||||||
|
@ -24,6 +24,7 @@ export const DashboardViewDashboardController: React.FC<DashboardViewProps> = ({
|
||||||
|
|
||||||
const metrics = dashboardResponse?.metrics;
|
const metrics = dashboardResponse?.metrics;
|
||||||
const dashboard = dashboardResponse?.dashboard;
|
const dashboard = dashboardResponse?.dashboard;
|
||||||
|
const readOnly = readOnlyProp || !canEdit(dashboardResponse?.permission);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollArea className="h-full">
|
<ScrollArea className="h-full">
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
import type { DashboardFileView } from '@/layouts/ChatLayout';
|
|
||||||
import { DashboardViewDashboardController } from './DashboardViewDashboardController';
|
|
||||||
import { DashboardViewFileController } from './DashboardViewFileController';
|
|
||||||
import React from 'react';
|
|
||||||
|
|
||||||
export interface DashboardViewProps {
|
|
||||||
dashboardId: string;
|
|
||||||
chatId: string | undefined;
|
|
||||||
readOnly?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const DashboardViewComponents: Record<DashboardFileView, React.FC<DashboardViewProps>> = {
|
|
||||||
dashboard: DashboardViewDashboardController,
|
|
||||||
file: DashboardViewFileController
|
|
||||||
};
|
|
|
@ -1 +0,0 @@
|
||||||
export * from './DashboardController';
|
|
|
@ -1,20 +0,0 @@
|
||||||
import { BusterMetricData, BusterChartConfigProps } from '@/api/asset_interfaces/metric';
|
|
||||||
import isEmpty from 'lodash/isEmpty';
|
|
||||||
import { isNumericColumnType } from '../messages';
|
|
||||||
|
|
||||||
export const canEditChart = (
|
|
||||||
metricId: string | undefined | null,
|
|
||||||
isFetchedMetricData: boolean,
|
|
||||||
metricData: BusterMetricData | undefined,
|
|
||||||
columnLabelFormats: BusterChartConfigProps['columnLabelFormats']
|
|
||||||
): boolean => {
|
|
||||||
return (
|
|
||||||
!!metricId &&
|
|
||||||
!isFetchedMetricData &&
|
|
||||||
!isEmpty(metricData?.data) &&
|
|
||||||
!columnLabelFormats &&
|
|
||||||
!!Object.values(columnLabelFormats! || {}).some((column) =>
|
|
||||||
isNumericColumnType(column.columnType)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
};
|
|
|
@ -1,4 +1,3 @@
|
||||||
export * from './resolve';
|
export * from './resolve';
|
||||||
export * from './canEditChart';
|
|
||||||
export * from './upgradeToIMetric';
|
export * from './upgradeToIMetric';
|
||||||
export * from './saveToServerHelpers';
|
export * from './saveToServerHelpers';
|
||||||
|
|
Loading…
Reference in New Issue