Merge pull request #222 from buster-so/evals

Evals
This commit is contained in:
Nate Kelley 2025-04-22 17:22:54 -06:00 committed by GitHub
commit c9ccc191df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 49 additions and 22 deletions

View File

@ -33,12 +33,13 @@ export default async function Layout({
const userInfo = queryClient.getQueryData(queryKeys.userGetUserMyself.queryKey); const userInfo = queryClient.getQueryData(queryKeys.userGetUserMyself.queryKey);
const newUserRoute = createBusterRoute({ route: BusterRoutes.NEW_USER }); const newUserRoute = createBusterRoute({ route: BusterRoutes.NEW_USER });
const loginRoute = createBusterRoute({ route: BusterRoutes.AUTH_LOGIN });
if ( if (supabaseContext.user?.is_anonymous && pathname !== loginRoute) {
(!userInfo?.organizations?.[0]?.id || !userInfo?.user?.name) && return <ClientRedirect to={loginRoute} />;
!supabaseContext.user?.is_anonymous && }
pathname !== newUserRoute
) { if ((!userInfo?.organizations?.[0]?.id || !userInfo?.user?.name) && pathname !== newUserRoute) {
return <ClientRedirect to={newUserRoute} />; return <ClientRedirect to={newUserRoute} />;
} }

View File

@ -35,7 +35,10 @@ export const assetTypeToRoute = (assetType: ShareAssetType, assetId: string) =>
return createBusterRoute({ route: BusterRoutes.APP_DASHBOARD_ID, dashboardId: assetId }); return createBusterRoute({ route: BusterRoutes.APP_DASHBOARD_ID, dashboardId: assetId });
case ShareAssetType.COLLECTION: case ShareAssetType.COLLECTION:
return createBusterRoute({ route: BusterRoutes.APP_COLLECTIONS_ID, collectionId: assetId }); return createBusterRoute({ route: BusterRoutes.APP_COLLECTIONS_ID, collectionId: assetId });
case ShareAssetType.CHAT:
return createBusterRoute({ route: BusterRoutes.APP_CHAT_ID, chatId: assetId });
default: default:
console.warn('Asset type to route not found', assetType, assetId);
return ''; return '';
} }
}; };

View File

@ -3,7 +3,8 @@ import { AvatarUserButton } from './AvatarUserButton';
const defaultUser = { const defaultUser = {
username: 'John Doe', username: 'John Doe',
avatarUrl: 'https://i.pravatar.cc/200', avatarUrl:
'https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=200&h=200&q=80',
email: 'john.doe@example.com' email: 'john.doe@example.com'
}; };

View File

@ -9016,8 +9016,6 @@ export const scatterDataProblematic1 = {
} }
}; };
console.log(scatterDataProblematic1);
export const scatterConfig_problematic1 = { export const scatterConfig_problematic1 = {
selectedChartType: ChartType.Scatter, selectedChartType: ChartType.Scatter,
columnLabelFormats: { columnLabelFormats: {

View File

@ -7,6 +7,8 @@ import { dashboardQueryKeys } from '@/api/query_keys/dashboard';
import { compareObjectsByKeys } from '@/lib/objects'; import { compareObjectsByKeys } from '@/lib/objects';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { create } from 'mutative'; import { create } from 'mutative';
import { canEdit } from '@/lib/share';
import last from 'lodash/last';
export const useIsDashboardChanged = ({ dashboardId }: { dashboardId: string | undefined }) => { export const useIsDashboardChanged = ({ dashboardId }: { dashboardId: string | undefined }) => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
@ -19,11 +21,18 @@ export const useIsDashboardChanged = ({ dashboardId }: { dashboardId: string | u
name: x.dashboard.name, name: x.dashboard.name,
description: x.dashboard.description, description: x.dashboard.description,
config: x.dashboard.config, config: x.dashboard.config,
file: x.dashboard.file file: x.dashboard.file,
permission: x.permission,
versions: x.versions,
version_number: x.dashboard.version_number
}) })
} }
); );
const isLatestVersion = useMemo(() => {
return currentDashboard?.version_number === last(currentDashboard?.versions)?.version_number;
}, [currentDashboard]);
const onResetDashboardToOriginal = useMemoizedFn(() => { const onResetDashboardToOriginal = useMemoizedFn(() => {
const options = dashboardQueryKeys.dashboardGetDashboard( const options = dashboardQueryKeys.dashboardGetDashboard(
dashboardId || '', dashboardId || '',
@ -39,7 +48,10 @@ export const useIsDashboardChanged = ({ dashboardId }: { dashboardId: string | u
refetchCurrentDashboard(); refetchCurrentDashboard();
}); });
const isEditor = canEdit(currentDashboard?.permission);
const isDashboardChanged = useMemo(() => { const isDashboardChanged = useMemo(() => {
if (!isEditor || !isLatestVersion || !currentDashboard || !originalDashboard) return false;
return ( return (
!originalDashboard || !originalDashboard ||
!currentDashboard || !currentDashboard ||
@ -50,7 +62,7 @@ export const useIsDashboardChanged = ({ dashboardId }: { dashboardId: string | u
'file' 'file'
]) ])
); );
}, [originalDashboard, currentDashboard]); }, [originalDashboard, isEditor, currentDashboard, isLatestVersion]);
return { return {
onResetDashboardToOriginal, onResetDashboardToOriginal,

View File

@ -1,5 +1,5 @@
import { useGetDashboard } from '@/api/buster_rest/dashboards'; import { useGetDashboard } from '@/api/buster_rest/dashboards';
import { canEdit } from '@/lib/share'; import { canEdit, getIsOwner } from '@/lib/share';
import { useMemo } from 'react'; import { useMemo } from 'react';
import last from 'lodash/last'; import last from 'lodash/last';
import { useChatLayoutContextSelector } from '@/layouts/ChatLayout'; import { useChatLayoutContextSelector } from '@/layouts/ChatLayout';
@ -44,11 +44,14 @@ export const useIsDashboardReadOnly = ({
return false; return false;
}, [isError, isFetched, dashboardData, isVersionHistoryMode, isViewingOldVersion]); }, [isError, isFetched, dashboardData, isVersionHistoryMode, isViewingOldVersion]);
const isEditor = canEdit(dashboardData?.permission);
return { return {
isVersionHistoryMode, isVersionHistoryMode,
isReadOnly, isReadOnly,
isViewingOldVersion, isViewingOldVersion,
isFetched, isFetched,
isError isError,
isEditor
}; };
}; };

View File

@ -6,6 +6,7 @@ import { useGetMetric } from '@/api/buster_rest/metrics';
import { compareObjectsByKeys } from '@/lib/objects'; import { compareObjectsByKeys } from '@/lib/objects';
import { useMemo } from 'react'; import { useMemo } from 'react';
import last from 'lodash/last'; import last from 'lodash/last';
import { canEdit } from '@/lib/share';
export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined }) => { export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined }) => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
@ -25,7 +26,8 @@ export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined
chart_config: x.chart_config, chart_config: x.chart_config,
file: x.file, file: x.file,
version_number: x.version_number, version_number: x.version_number,
versions: x.versions versions: x.versions,
permission: x.permission
}) })
} }
); );
@ -44,8 +46,10 @@ export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined
refetchCurrentMetric(); refetchCurrentMetric();
}); });
const isEditor = canEdit(currentMetric?.permission);
const isMetricChanged = useMemo(() => { const isMetricChanged = useMemo(() => {
if (!originalMetric || !isLatestVersion) return false; if (!isEditor || !originalMetric || !isLatestVersion || !currentMetric) return false;
return ( return (
!currentMetric || !currentMetric ||
@ -57,7 +61,7 @@ export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined
'version_number' 'version_number'
]) ])
); );
}, [originalMetric, currentMetric, isLatestVersion]); }, [originalMetric, currentMetric, isLatestVersion, isEditor]);
return { return {
onResetMetricToOriginal, onResetMetricToOriginal,

View File

@ -51,11 +51,14 @@ export const useIsMetricReadOnly = ({
isViewingOldVersion isViewingOldVersion
]); ]);
const isEditor = canEdit(metricData?.permission);
return { return {
isFetched, isFetched,
isError, isError,
isVersionHistoryMode, isVersionHistoryMode,
isReadOnly, isReadOnly,
isViewingOldVersion isViewingOldVersion,
isEditor
}; };
}; };

View File

@ -63,7 +63,7 @@ export const DashboardViewDashboardController: React.FC<{
readOnly={isReadOnly} readOnly={isReadOnly}
/> />
{!isVersionHistoryMode && !isViewingOldVersion && ( {!isReadOnly && !isVersionHistoryMode && !isViewingOldVersion && (
<DashboardSaveFilePopup dashboardId={dashboardId} /> <DashboardSaveFilePopup dashboardId={dashboardId} />
)} )}
</div> </div>

View File

@ -57,10 +57,12 @@ export const MetricViewChart: React.FC<{
const { name, description, time_frame, evaluation_score, evaluation_summary } = metric || {}; const { name, description, time_frame, evaluation_score, evaluation_summary } = metric || {};
const isTable = metric?.chart_config.selectedChartType === ChartType.Table; const isTable = metric?.chart_config.selectedChartType === ChartType.Table;
const { isReadOnly, isVersionHistoryMode, isViewingOldVersion } = useIsMetricReadOnly({ const { isReadOnly, isEditor, isVersionHistoryMode, isViewingOldVersion } = useIsMetricReadOnly(
metricId, {
readOnly: readOnlyProp metricId,
}); readOnly: readOnlyProp
}
);
const loadingData = !isFetchedMetricData; const loadingData = !isFetchedMetricData;
const errorData = !!metricDataError; const errorData = !!metricDataError;
const showEvaluation = !!evaluation_score && !!evaluation_summary; const showEvaluation = !!evaluation_score && !!evaluation_summary;
@ -109,7 +111,7 @@ export const MetricViewChart: React.FC<{
/> />
</AnimatePresenceWrapper> </AnimatePresenceWrapper>
{!isVersionHistoryMode && !isViewingOldVersion && ( {!isReadOnly && !isVersionHistoryMode && !isViewingOldVersion && (
<MetricSaveFilePopup metricId={metricId} /> <MetricSaveFilePopup metricId={metricId} />
)} )}
</div> </div>