fix the dashboard header buttons

This commit is contained in:
Nate Kelley 2025-04-01 11:36:57 -06:00
parent 75a804860a
commit 9cc126978f
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 58 additions and 15 deletions

View File

@ -1,10 +1,11 @@
'use client';
import React from 'react'; import React from 'react';
import { FileContainerButtonsProps } from '../interfaces'; import { FileContainerButtonsProps } from '../interfaces';
import { FileButtonContainer } from '../FileButtonContainer'; import { FileButtonContainer } from '../FileButtonContainer';
import { useChatIndividualContextSelector } from '../../../ChatContext'; import { useChatIndividualContextSelector } from '../../../ChatContext';
import { SaveDashboardToCollectionButton } from '@/components/features/buttons/SaveDashboardToCollectionButton'; import { SaveDashboardToCollectionButton } from '@/components/features/buttons/SaveDashboardToCollectionButton';
import { HideButtonContainer } from '../HideButtonContainer'; import { HideButtonContainer } from '../HideButtonContainer';
import { useChatLayoutContextSelector } from '../../../ChatLayoutContext';
import { CreateChatButton } from '../CreateChatButtont'; import { CreateChatButton } from '../CreateChatButtont';
import { ShareDashboardButton } from '@/components/features/buttons/ShareDashboardButton'; import { ShareDashboardButton } from '@/components/features/buttons/ShareDashboardButton';
import { Button } from '@/components/ui/buttons'; import { Button } from '@/components/ui/buttons';
@ -16,9 +17,8 @@ import { canEdit, getIsEffectiveOwner } from '@/lib/share';
import { useDashboardContentStore } from '@/context/Dashboards'; import { useDashboardContentStore } from '@/context/Dashboards';
export const DashboardContainerHeaderButtons: React.FC<FileContainerButtonsProps> = React.memo( export const DashboardContainerHeaderButtons: React.FC<FileContainerButtonsProps> = React.memo(
({ selectedFileView }) => { ({ selectedFileId }) => {
const selectedFileId = useChatIndividualContextSelector((x) => x.selectedFileId)!; const dashboardId = selectedFileId || '';
const dashboardId = selectedFileId;
const { data: permission, error: dashboardError } = useGetDashboard( const { data: permission, error: dashboardError } = useGetDashboard(
{ id: dashboardId }, { id: dashboardId },
@ -33,10 +33,10 @@ export const DashboardContainerHeaderButtons: React.FC<FileContainerButtonsProps
return ( return (
<FileButtonContainer> <FileButtonContainer>
<SaveToCollectionButton /> <SaveToCollectionButton />
{isEffectiveOwner && <ShareDashboardButton dashboardId={selectedFileId} />} {isEffectiveOwner && <ShareDashboardButton dashboardId={dashboardId} />}
{isEditor && <AddContentToDashboardButton />} {isEditor && <AddContentToDashboardButton />}
<DashboardThreeDotMenu dashboardId={selectedFileId} /> <DashboardThreeDotMenu dashboardId={dashboardId} />
<HideButtonContainer show={selectedFileView === 'file'}> <HideButtonContainer show>
<CreateChatButton /> <CreateChatButton />
</HideButtonContainer> </HideButtonContainer>
</FileButtonContainer> </FileButtonContainer>

View File

@ -1,24 +1,64 @@
import React from 'react'; import React, { useMemo } from 'react';
import type { FileContainerSegmentProps } from './interfaces'; import type { FileContainerSegmentProps } from './interfaces';
import type { FileView } from '../../ChatLayoutContext/useLayoutConfig'; import type { FileView } from '../../ChatLayoutContext/useLayoutConfig';
import { AppSegmented } from '@/components/ui/segmented'; import { AppSegmented } from '@/components/ui/segmented';
import { useChatLayoutContextSelector } from '../../ChatLayoutContext'; import { useChatLayoutContextSelector } from '../../ChatLayoutContext';
import { useMemoizedFn } from '@/hooks'; import { useMemoizedFn } from '@/hooks';
import { type SegmentedItem } from '@/components/ui/segmented'; import { type SegmentedItem } from '@/components/ui/segmented';
import { BusterRoutes, createBusterRoute } from '@/routes';
const segmentOptions: SegmentedItem<FileView>[] = [
{ label: 'Dashboard', value: 'dashboard' },
{ label: 'File', value: 'file' }
];
export const DashboardContainerHeaderSegment: React.FC<FileContainerSegmentProps> = React.memo( export const DashboardContainerHeaderSegment: React.FC<FileContainerSegmentProps> = React.memo(
({ selectedFileView }) => { ({ selectedFileView, chatId, selectedFileId }) => {
const onSetFileView = useChatLayoutContextSelector((x) => x.onSetFileView); const onSetFileView = useChatLayoutContextSelector((x) => x.onSetFileView);
const onChange = useMemoizedFn((fileView: SegmentedItem<FileView>) => { const onChange = useMemoizedFn((fileView: SegmentedItem<FileView>) => {
onSetFileView({ fileView: fileView.value }); onSetFileView({ fileView: fileView.value });
}); });
const segmentOptions: SegmentedItem<FileView>[] = useMemo(() => {
if (chatId) {
return [
{
label: 'Dashboard',
value: 'dashboard',
link: createBusterRoute({
route: BusterRoutes.APP_CHAT_ID_DASHBOARD_ID,
dashboardId: selectedFileId || '',
chatId
})
},
{
label: 'File',
value: 'file',
link: createBusterRoute({
route: BusterRoutes.APP_CHAT_ID_DASHBOARD_ID,
dashboardId: selectedFileId || '',
chatId
})
}
];
}
return [
{
label: 'Dashboard',
value: 'dashboard',
link: createBusterRoute({
route: BusterRoutes.APP_DASHBOARD_ID,
dashboardId: selectedFileId || ''
})
},
{
label: 'File',
value: 'file',
link: createBusterRoute({
route: BusterRoutes.APP_DASHBOARD_ID_FILE,
dashboardId: selectedFileId || ''
})
}
];
}, [chatId, selectedFileId]);
return ( return (
<AppSegmented <AppSegmented
type="button" type="button"

View File

@ -62,7 +62,9 @@ export const FileContainerHeader: React.FC = React.memo(() => {
)} )}
</div> </div>
{hasAccess && <SelectedFileButtons selectedFileView={selectedFileView} />} {hasAccess && (
<SelectedFileButtons selectedFileView={selectedFileView} selectedFileId={selectedFileId} />
)}
</> </>
); );
}); });

View File

@ -8,4 +8,5 @@ export type FileContainerSegmentProps = {
export type FileContainerButtonsProps = { export type FileContainerButtonsProps = {
selectedFileView: FileView | undefined; selectedFileView: FileView | undefined;
selectedFileId: string | undefined;
}; };