fix: use correct keys in dashboard list (#7283)

* fix: use correct keys in dashboard list

* fix: use correct keys in dashboard list
This commit is contained in:
Nityananda Gohain 2025-03-12 19:37:54 +05:30 committed by GitHub
parent a9618886b9
commit 5dba1f3dbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 35 deletions

View File

@ -186,16 +186,14 @@ function DashboardsList(): JSX.Element {
const sortDashboardsByCreatedAt = (dashboards: Dashboard[]): void => { const sortDashboardsByCreatedAt = (dashboards: Dashboard[]): void => {
const sortedDashboards = dashboards.sort( const sortedDashboards = dashboards.sort(
(a, b) => (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
new Date(b.created_at).getTime() - new Date(a.created_at).getTime(),
); );
setDashboards(sortedDashboards); setDashboards(sortedDashboards);
}; };
const sortDashboardsByUpdatedAt = (dashboards: Dashboard[]): void => { const sortDashboardsByUpdatedAt = (dashboards: Dashboard[]): void => {
const sortedDashboards = dashboards.sort( const sortedDashboards = dashboards.sort(
(a, b) => (a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(),
new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime(),
); );
setDashboards(sortedDashboards); setDashboards(sortedDashboards);
}; };
@ -260,16 +258,16 @@ function DashboardsList(): JSX.Element {
const data: Data[] = const data: Data[] =
dashboards?.map((e) => ({ dashboards?.map((e) => ({
createdAt: e.created_at, createdAt: e.createdAt,
description: e.data.description || '', description: e.data.description || '',
id: e.uuid, id: e.uuid,
lastUpdatedTime: e.updated_at, lastUpdatedTime: e.updatedAt,
name: e.data.title, name: e.data.title,
tags: e.data.tags || [], tags: e.data.tags || [],
key: e.uuid, key: e.uuid,
createdBy: e.created_by, createdBy: e.createdBy,
isLocked: !!e.isLocked || false, isLocked: !!e.isLocked || false,
lastUpdatedBy: e.updated_by, lastUpdatedBy: e.updatedBy,
image: e.data.image || Base64Icons[0], image: e.data.image || Base64Icons[0],
variables: e.data.variables, variables: e.data.variables,
widgets: e.data.widgets, widgets: e.data.widgets,
@ -978,10 +976,10 @@ function DashboardsList(): JSX.Element {
{visibleColumns.createdBy && ( {visibleColumns.createdBy && (
<div className="user"> <div className="user">
<Typography.Text className="user-tag"> <Typography.Text className="user-tag">
{dashboards?.[0]?.created_by?.substring(0, 1).toUpperCase()} {dashboards?.[0]?.createdBy?.substring(0, 1).toUpperCase()}
</Typography.Text> </Typography.Text>
<Typography.Text className="dashboard-created-by"> <Typography.Text className="dashboard-created-by">
{dashboards?.[0]?.created_by} {dashboards?.[0]?.createdBy}
</Typography.Text> </Typography.Text>
</div> </div>
)} )}
@ -990,16 +988,16 @@ function DashboardsList(): JSX.Element {
{visibleColumns.updatedAt && ( {visibleColumns.updatedAt && (
<Typography.Text className="formatted-time"> <Typography.Text className="formatted-time">
<CalendarClock size={14} /> <CalendarClock size={14} />
{onLastUpdated(dashboards?.[0]?.updated_at || '')} {onLastUpdated(dashboards?.[0]?.updatedAt || '')}
</Typography.Text> </Typography.Text>
)} )}
{visibleColumns.updatedBy && ( {visibleColumns.updatedBy && (
<div className="user"> <div className="user">
<Typography.Text className="user-tag"> <Typography.Text className="user-tag">
{dashboards?.[0]?.updated_by?.substring(0, 1).toUpperCase()} {dashboards?.[0]?.updatedBy?.substring(0, 1).toUpperCase()}
</Typography.Text> </Typography.Text>
<Typography.Text className="dashboard-created-by"> <Typography.Text className="dashboard-created-by">
{dashboards?.[0]?.updated_by} {dashboards?.[0]?.updatedBy}
</Typography.Text> </Typography.Text>
</div> </div>
)} )}

View File

@ -140,7 +140,7 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
let isAuthor = false; let isAuthor = false;
if (selectedDashboard && user && user.email) { if (selectedDashboard && user && user.email) {
isAuthor = selectedDashboard?.created_by === user?.email; isAuthor = selectedDashboard?.createdBy === user?.email;
} }
let permissions: ComponentTypes[] = ['add_panel']; let permissions: ComponentTypes[] = ['add_panel'];
@ -152,7 +152,7 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
const { notifications } = useNotifications(); const { notifications } = useNotifications();
const userRole: ROLES | null = const userRole: ROLES | null =
selectedDashboard?.created_by === user?.email selectedDashboard?.createdBy === user?.email
? (USER_ROLES.AUTHOR as ROLES) ? (USER_ROLES.AUTHOR as ROLES)
: user.role; : user.role;
@ -364,14 +364,14 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
{(isAuthor || user.role === USER_ROLES.ADMIN) && ( {(isAuthor || user.role === USER_ROLES.ADMIN) && (
<Tooltip <Tooltip
title={ title={
selectedDashboard?.created_by === 'integration' && selectedDashboard?.createdBy === 'integration' &&
'Dashboards created by integrations cannot be unlocked' 'Dashboards created by integrations cannot be unlocked'
} }
> >
<Button <Button
type="text" type="text"
icon={<LockKeyhole size={14} />} icon={<LockKeyhole size={14} />}
disabled={selectedDashboard?.created_by === 'integration'} disabled={selectedDashboard?.createdBy === 'integration'}
onClick={handleLockDashboardToggle} onClick={handleLockDashboardToggle}
data-testid="lock-unlock-dashboard" data-testid="lock-unlock-dashboard"
> >
@ -443,7 +443,7 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
</section> </section>
<section className="delete-dashboard"> <section className="delete-dashboard">
<DeleteButton <DeleteButton
createdBy={selectedDashboard?.created_by || ''} createdBy={selectedDashboard?.createdBy || ''}
name={selectedDashboard?.data.title || ''} name={selectedDashboard?.data.title || ''}
id={String(selectedDashboard?.uuid) || ''} id={String(selectedDashboard?.uuid) || ''}
isLocked={isDashboardLocked} isLocked={isDashboardLocked}

View File

@ -11,7 +11,7 @@ export const useUpdateDashboard = (): UseUpdateDashboard => {
return useMutation(update, { return useMutation(update, {
onSuccess: (data) => { onSuccess: (data) => {
if (data.payload) { if (data.payload) {
updatedTimeRef.current = dayjs(data.payload.updated_at); updatedTimeRef.current = dayjs(data.payload.updatedAt);
} }
}, },
}); });

View File

@ -5,10 +5,10 @@ export const dashboardSuccessResponse = {
{ {
id: 1, id: 1,
uuid: '1', uuid: '1',
created_at: '2022-11-16T13:29:47.064874419Z', createdAt: '2022-11-16T13:29:47.064874419Z',
created_by: null, createdBy: null,
updated_at: '2024-05-21T06:41:30.546630961Z', updatedAt: '2024-05-21T06:41:30.546630961Z',
updated_by: 'thor@avengers.io', updatedBy: 'thor@avengers.io',
isLocked: 0, isLocked: 0,
data: { data: {
collapsableRowsMigrated: true, collapsableRowsMigrated: true,
@ -25,10 +25,10 @@ export const dashboardSuccessResponse = {
{ {
id: 2, id: 2,
uuid: '2', uuid: '2',
created_at: '2022-11-16T13:20:47.064874419Z', createdAt: '2022-11-16T13:20:47.064874419Z',
created_by: null, createdBy: null,
updated_at: '2024-05-21T06:42:30.546630961Z', updatedAt: '2024-05-21T06:42:30.546630961Z',
updated_by: 'captain-america@avengers.io', updatedBy: 'captain-america@avengers.io',
isLocked: 0, isLocked: 0,
data: { data: {
collapsableRowsMigrated: true, collapsableRowsMigrated: true,
@ -55,10 +55,10 @@ export const getDashboardById = {
data: { data: {
id: 1, id: 1,
uuid: '1', uuid: '1',
created_at: '2022-11-16T13:29:47.064874419Z', createdAt: '2022-11-16T13:29:47.064874419Z',
created_by: 'integration', createdBy: 'integration',
updated_at: '2024-05-21T06:41:30.546630961Z', updatedAt: '2024-05-21T06:41:30.546630961Z',
updated_by: 'thor@avengers.io', updatedBy: 'thor@avengers.io',
isLocked: true, isLocked: true,
data: { data: {
collapsableRowsMigrated: true, collapsableRowsMigrated: true,
@ -80,10 +80,10 @@ export const getNonIntegrationDashboardById = {
data: { data: {
id: 1, id: 1,
uuid: '1', uuid: '1',
created_at: '2022-11-16T13:29:47.064874419Z', createdAt: '2022-11-16T13:29:47.064874419Z',
created_by: 'thor', createdBy: 'thor',
updated_at: '2024-05-21T06:41:30.546630961Z', updatedAt: '2024-05-21T06:41:30.546630961Z',
updated_by: 'thor@avengers.io', updatedBy: 'thor@avengers.io',
isLocked: true, isLocked: true,
data: { data: {
collapsableRowsMigrated: true, collapsableRowsMigrated: true,