mirror of https://github.com/buster-so/buster.git
hide or disable Edit with AI if they can't edit
This commit is contained in:
parent
2b634f91ea
commit
48b3c62cd0
|
@ -14,7 +14,7 @@ import { DASHBOARD_TITLE_INPUT_ID } from '@/controllers/DashboardController/Dash
|
|||
import { useMemoizedFn } from '@/hooks/useMemoizedFn';
|
||||
import { onOpenDashboardContentModal } from '../../../context/Dashboards/dashboard-content-store';
|
||||
import { ensureElementExists } from '../../../lib/element';
|
||||
import { getIsEffectiveOwner } from '../../../lib/share';
|
||||
import { canEdit, getIsEffectiveOwner } from '../../../lib/share';
|
||||
import type { IDropdownItem, IDropdownItems } from '../../ui/dropdown';
|
||||
import { createDropdownItem, DropdownContent } from '../../ui/dropdown';
|
||||
import {
|
||||
|
@ -283,6 +283,9 @@ export const useShareMenuSelectMenu = ({ dashboardId }: { dashboardId: string })
|
|||
};
|
||||
|
||||
export const useEditDashboardWithAI = ({ dashboardId }: { dashboardId: string }) => {
|
||||
const { data: dashboard } = useGetDashboard({ id: dashboardId }, { select: getShareAssetConfig });
|
||||
const isEditor = canEdit(dashboard?.permission);
|
||||
|
||||
const { onCreateFileClick, loading } = useStartChatFromAsset({
|
||||
assetId: dashboardId,
|
||||
assetType: 'dashboard',
|
||||
|
@ -295,8 +298,9 @@ export const useEditDashboardWithAI = ({ dashboardId }: { dashboardId: string })
|
|||
value: 'edit-with-ai',
|
||||
icon: <PenSparkle />,
|
||||
onClick: onCreateFileClick,
|
||||
disabled: !isEditor,
|
||||
loading,
|
||||
}),
|
||||
[dashboardId, onCreateFileClick, loading]
|
||||
[dashboardId, onCreateFileClick, loading, isEditor]
|
||||
);
|
||||
};
|
||||
|
|
|
@ -26,9 +26,11 @@ import { useStartChatFromAsset } from '@/context/BusterAssets/useStartChatFromAs
|
|||
import { useBusterNotifications } from '@/context/BusterNotifications';
|
||||
import { ensureElementExists } from '@/lib/element';
|
||||
import { downloadElementToImage, exportJSONToCSV } from '@/lib/exportUtils';
|
||||
import { canEdit } from '../../../lib/share';
|
||||
import { FollowUpWithAssetContent } from '../assets/FollowUpWithAsset';
|
||||
import { useFavoriteStar } from '../favorites';
|
||||
import { ASSET_ICONS } from '../icons/assetIcons';
|
||||
import { getShareAssetConfig } from '../ShareMenu/helpers';
|
||||
import { useListMetricVersionDropdownItems } from '../versionHistory/useListMetricVersionDropdownItems';
|
||||
import { METRIC_CHART_CONTAINER_ID } from './MetricChartCard/config';
|
||||
import { METRIC_CHART_TITLE_INPUT_ID } from './MetricChartCard/MetricViewChartHeader';
|
||||
|
@ -375,6 +377,12 @@ export const useNavigateToDashboardMetricItem = ({
|
|||
};
|
||||
|
||||
export const useEditMetricWithAI = ({ metricId }: { metricId: string }): IDropdownItem => {
|
||||
const { data: shareAssetConfig } = useGetMetric(
|
||||
{ id: metricId },
|
||||
{ select: getShareAssetConfig }
|
||||
);
|
||||
const isEditor = canEdit(shareAssetConfig?.permission);
|
||||
|
||||
const { onCreateFileClick, loading } = useStartChatFromAsset({
|
||||
assetId: metricId,
|
||||
assetType: 'metric',
|
||||
|
@ -387,8 +395,9 @@ export const useEditMetricWithAI = ({ metricId }: { metricId: string }): IDropdo
|
|||
value: 'edit-with-ai',
|
||||
icon: <PenSparkle />,
|
||||
onClick: onCreateFileClick,
|
||||
disabled: !isEditor,
|
||||
loading,
|
||||
}),
|
||||
[metricId, onCreateFileClick, loading]
|
||||
[metricId, onCreateFileClick, loading, isEditor]
|
||||
);
|
||||
};
|
||||
|
|
|
@ -121,6 +121,12 @@ export const ReportThreeDotMenu = React.memo(
|
|||
ReportThreeDotMenu.displayName = 'ReportThreeDotMenu';
|
||||
|
||||
const useEditWithAI = ({ reportId }: { reportId: string }): IDropdownItem => {
|
||||
const { data: shareAssetConfig } = useGetReport(
|
||||
{ id: reportId },
|
||||
{ select: getShareAssetConfig }
|
||||
);
|
||||
const isEditor = canEdit(shareAssetConfig?.permission);
|
||||
|
||||
const { onCreateFileClick, loading } = useStartChatFromAsset({
|
||||
assetId: reportId,
|
||||
assetType: 'report',
|
||||
|
@ -133,9 +139,10 @@ const useEditWithAI = ({ reportId }: { reportId: string }): IDropdownItem => {
|
|||
value: 'edit-with-ai',
|
||||
icon: <PenSparkle />,
|
||||
onClick: onCreateFileClick,
|
||||
disabled: !isEditor,
|
||||
loading,
|
||||
}),
|
||||
[reportId, onCreateFileClick, loading]
|
||||
[reportId, onCreateFileClick, loading, isEditor]
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import { ClosePageButton } from '@/components/features/chat/ClosePageButton';
|
|||
import { DashboardThreeDotMenu } from '@/components/features/dashboard/DashboardThreeDotMenu';
|
||||
import { useIsChatMode, useIsFileMode } from '@/context/Chats/useMode';
|
||||
import { useIsDashboardReadOnly } from '@/context/Dashboards/useIsDashboardReadOnly';
|
||||
import { getIsEffectiveOwner } from '@/lib/share';
|
||||
import { canEdit, getIsEffectiveOwner } from '@/lib/share';
|
||||
import { FileButtonContainer } from '../FileButtonContainer';
|
||||
import { HideButtonContainer } from '../HideButtonContainer';
|
||||
|
||||
|
@ -26,6 +26,7 @@ export const DashboardContainerHeaderButtons: React.FC<{
|
|||
);
|
||||
|
||||
const isEffectiveOwner = getIsEffectiveOwner(permission);
|
||||
const isEditor = canEdit(permission);
|
||||
|
||||
return (
|
||||
<FileButtonContainer>
|
||||
|
@ -37,7 +38,7 @@ export const DashboardContainerHeaderButtons: React.FC<{
|
|||
isViewingOldVersion={isViewingOldVersion}
|
||||
dashboardVersionNumber={dashboardVersionNumber}
|
||||
/>
|
||||
<HideButtonContainer show={isFileMode}>
|
||||
<HideButtonContainer show={isFileMode && isEditor}>
|
||||
<CreateChatButton assetId={dashboardId} assetType="dashboard" />
|
||||
</HideButtonContainer>
|
||||
{isChatMode && <ClosePageButton />}
|
||||
|
|
|
@ -45,7 +45,7 @@ export const MetricContainerHeaderButtons: React.FC<{
|
|||
isViewingOldVersion={isViewingOldVersion}
|
||||
versionNumber={metricVersionNumber}
|
||||
/>
|
||||
<HideButtonContainer show={isFileMode}>
|
||||
<HideButtonContainer show={isFileMode && isEditor}>
|
||||
<CreateChatButton assetId={metricId} assetType="metric" />
|
||||
</HideButtonContainer>
|
||||
{isChatMode && <ClosePageButton />}
|
||||
|
|
|
@ -8,7 +8,7 @@ import { ClosePageButton } from '@/components/features/chat/ClosePageButton';
|
|||
import { ReportThreeDotMenu } from '@/components/features/reports/ReportThreeDotMenu';
|
||||
import { useIsChatMode, useIsFileMode } from '@/context/Chats/useMode';
|
||||
import { useIsReportReadOnly } from '@/context/Reports/useIsReportReadOnly';
|
||||
import { getIsEffectiveOwner } from '@/lib/share';
|
||||
import { canEdit, getIsEffectiveOwner } from '@/lib/share';
|
||||
import { FileButtonContainer } from '../FileButtonContainer';
|
||||
import { HideButtonContainer } from '../HideButtonContainer';
|
||||
|
||||
|
@ -32,6 +32,7 @@ export const ReportContainerHeaderButtons: React.FC<ReportContainerHeaderButtons
|
|||
);
|
||||
|
||||
const isEffectiveOwner = getIsEffectiveOwner(permission);
|
||||
const isEditor = canEdit(permission);
|
||||
|
||||
return (
|
||||
<FileButtonContainer>
|
||||
|
@ -43,7 +44,7 @@ export const ReportContainerHeaderButtons: React.FC<ReportContainerHeaderButtons
|
|||
isViewingOldVersion={isViewingOldVersion}
|
||||
/>
|
||||
|
||||
<HideButtonContainer show={isFileMode}>
|
||||
<HideButtonContainer show={isFileMode && isEditor}>
|
||||
<CreateChatButton assetId={reportId} assetType="report" />
|
||||
</HideButtonContainer>
|
||||
{isChatMode && <ClosePageButton />}
|
||||
|
|
Loading…
Reference in New Issue