diff --git a/web/src/controllers/DashboardController/DashboardController.tsx b/web/src/controllers/DashboardController/DashboardController.tsx deleted file mode 100644 index 4b983ed87..000000000 --- a/web/src/controllers/DashboardController/DashboardController.tsx +++ /dev/null @@ -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 && } - - - {isEditor && } - - ); -}; - -const MemoizedAddToDashboardModal = React.memo(({ dashboardId }: { dashboardId: string }) => { - const { openAddContentModal, onCloseAddContentModal } = useDashboardContentStore(); - return ( - - ); -}); - -MemoizedAddToDashboardModal.displayName = 'MemoizedAddToDashboardModal'; diff --git a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardMetricItem/MetricTitle.tsx b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardMetricItem/MetricTitle.tsx index 4ef6fb797..56ef41ffc 100644 --- a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardMetricItem/MetricTitle.tsx +++ b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardMetricItem/MetricTitle.tsx @@ -39,11 +39,8 @@ export const MetricTitle: React.FC<{ }); return ( - -
+ +
= ({ - dashboardId, - chatId, - readOnly = false -}) => { +export const DashboardViewDashboardController: React.FC<{ + dashboardId: string; + chatId: string | undefined; + readOnly?: boolean; +}> = ({ dashboardId, chatId, readOnly: readOnlyProp = false }) => { const { data: dashboardResponse } = useGetDashboard({ id: dashboardId }); const { mutateAsync: onUpdateDashboard } = useUpdateDashboard(); const { mutateAsync: onUpdateDashboardConfig } = useUpdateDashboardConfig(); @@ -24,6 +24,7 @@ export const DashboardViewDashboardController: React.FC<DashboardViewProps> = ({ const metrics = dashboardResponse?.metrics; const dashboard = dashboardResponse?.dashboard; + const readOnly = readOnlyProp || !canEdit(dashboardResponse?.permission); return ( <ScrollArea className="h-full"> diff --git a/web/src/controllers/DashboardController/config.ts b/web/src/controllers/DashboardController/config.ts deleted file mode 100644 index afaf52063..000000000 --- a/web/src/controllers/DashboardController/config.ts +++ /dev/null @@ -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 -}; diff --git a/web/src/controllers/DashboardController/index.ts b/web/src/controllers/DashboardController/index.ts deleted file mode 100644 index 902045c22..000000000 --- a/web/src/controllers/DashboardController/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './DashboardController'; diff --git a/web/src/lib/metrics/canEditChart.ts b/web/src/lib/metrics/canEditChart.ts deleted file mode 100644 index 38427570d..000000000 --- a/web/src/lib/metrics/canEditChart.ts +++ /dev/null @@ -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) - ) - ); -}; diff --git a/web/src/lib/metrics/index.ts b/web/src/lib/metrics/index.ts index 313f6a172..cbe9a62f2 100644 --- a/web/src/lib/metrics/index.ts +++ b/web/src/lib/metrics/index.ts @@ -1,4 +1,3 @@ export * from './resolve'; -export * from './canEditChart'; export * from './upgradeToIMetric'; export * from './saveToServerHelpers';