-
Notifications
You must be signed in to change notification settings - Fork 4
🐞 Admin Portal: Dashboard doesn't automatically update when tab is clicked #2534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| // | ||
| // SPDX-License-Identifier: AGPL-3.0-only | ||
|
|
||
| import React, {Suspense, useContext, useEffect, useMemo, useState} from "react" | ||
| import React, {Suspense, useContext, useEffect, useMemo, useRef, useState} from "react" | ||
| import {useTranslation} from "react-i18next" | ||
| import {useRecordContext, useSidebarState, RecordContextProvider} from "react-admin" | ||
| import {v4 as uuidv4} from "uuid" | ||
|
|
@@ -27,9 +27,11 @@ import {useAliasRenderer} from "@/hooks/useAliasRenderer" | |
| // Stable Tab Components | ||
| // --------------------------------------------------------------------- | ||
|
|
||
| const DashboardTab: React.FC = () => ( | ||
| const DashboardTab: React.FC<{refreshRef: React.RefObject<HTMLButtonElement | null>}> = ({ | ||
| refreshRef, | ||
| }) => ( | ||
| <Suspense fallback={<div>Loading Dashboard...</div>}> | ||
| <DashboardElection /> | ||
| <DashboardElection refreshRef={refreshRef} /> | ||
| </Suspense> | ||
| ) | ||
|
|
||
|
|
@@ -85,6 +87,7 @@ export const ElectionTabs: React.FC = () => { | |
| const [hasPermissionToViewElection, setHasPermissionToViewElection] = useState<boolean>(true) | ||
| const [open] = useSidebarState() | ||
| const aliasRenderer = useAliasRenderer() | ||
| const refreshRef = useRef<HTMLButtonElement | null>(null) | ||
|
|
||
| const isElectionEventLocked = | ||
| record?.presentation?.locked_down === EElectionEventLockedDown.LOCKED_DOWN | ||
|
|
@@ -135,14 +138,17 @@ export const ElectionTabs: React.FC = () => { | |
| const tabs = useMemo(() => { | ||
| const result: Array<{ | ||
| label: string | ||
| component: React.FC | ||
| component: React.FC<any> | ||
| props?: any | ||
| action?: (index: number) => void | ||
| }> = [] | ||
|
|
||
| if (showDashboard) { | ||
| result.push({ | ||
| label: t("electionScreen.tabs.dashboard"), | ||
| component: DashboardTab, | ||
| props: {refreshRef}, | ||
| action: () => refreshRef.current?.click(), | ||
| }) | ||
|
Comment on lines
146
to
152
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,6 +323,7 @@ export const ElectionEventTabs: React.FC = () => { | |
| label: t("electionEventScreen.tabs.dashboard"), | ||
| component: DashboardTab, | ||
| props: {refreshRef, handleChildMount}, | ||
| action: () => refreshRef.current?.click(), | ||
|
Comment on lines
323
to
+326
|
||
| }) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hidden refresh
<button>should settype="button"to avoid inadvertently submitting a surrounding form, and the handler should guard against missing query variables (e.g.,canQueryStatsfalse) before callingdoRefetch(). Also consider handling the returned promise (e.g.,void doRefetch()/ catch) to avoid unhandled rejections if the refetch errors.