Skip to content
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

frontend: overhaul validator dashboard fetching logic #1166

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from

Conversation

LuccaBitfly
Copy link
Contributor

@LuccaBitfly LuccaBitfly commented Nov 26, 2024

In the current validator dashboard fetching flow, components will either fetch their own data by reacting to changes in other unrelated components or manually trigger refreshes in unrelated components, making tracing bugs a hassle.
This PR aims to bring back order by making sure that most data fetching happens in the dashboards root component and that these are only triggered through emits. As a consequence of removing sibling component data dependencies, most of the dashboards Pinia stores won't be necessary anymore.

Copy link

cloudflare-workers-and-pages bot commented Nov 26, 2024

Deploying beaconchain with  Cloudflare Pages  Cloudflare Pages

Latest commit: 60fe37d
Status: ✅  Deploy successful!
Preview URL: https://2d4474df.beaconchain.pages.dev
Branch Preview URL: https://beds-914-better-dashboard-fe.beaconchain.pages.dev

View logs

@LuccaBitfly LuccaBitfly force-pushed the BEDS-914/better-dashboard-fetching branch from 3cbdf1c to cab1b5d Compare November 27, 2024 08:21
@LuccaBitfly LuccaBitfly changed the title refactor(dashboard): better overview and slotviz data fetching frontend: overhaul validator dashboard fetching logic Nov 27, 2024
@LuccaBitfly LuccaBitfly force-pushed the BEDS-914/better-dashboard-fetching branch 4 times, most recently from 190d26c to ce80077 Compare November 27, 2024 14:45
Copy link
Contributor

@marcel-bitfly marcel-bitfly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice work so far 💪

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np:
🤔 if this composable would ever only be used inside one component this might be the wrong abstraction or this might not be pulled out of the component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to at least put the fetching logic outside of the component (e.g. a service file), as to not clutter the index component with too much code. I.e. inside the component, the only concern should be what you fetch and not how you fetch it. As we have no pattern for services right now, I'm opting to extract them into composables. Is that an antipattern?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not an anti-pattern per se, but what you tell the world is:

  • here is a composable plz feel free to implement me wherever you want
  • I would come in handy in other contexts as well

frontend/composables/useValidatorSlotViz.ts Outdated Show resolved Hide resolved
headers: {},
query,
},
{ dashboardKey: dashboardKey || 'MQ' }, // If guest dashboard has no validators yet (= empty dashboardKey), load small guest dashboard with 1 validator (MQ)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is nice 👌
As it gives more context and explains the why

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this what should happen though? (loading validator index 1 if empty?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the goal is to load a very small slot viz and remove the validator information. This is hacky, but the only way to achieve an empty guest dashboard slot viz currently.

frontend/pages/dashboard/[[id]]/index.vue Outdated Show resolved Hide resolved
// Helper: Handle errors
function handleError(e: any) {
if (e?.statusCode === 404) {
// TODO: redirect to 404 page
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 404 page exists?

// Helper: fetches all data for the dashboard (overview, slot viz, active table)
function fetchAllData() {
if (dashboardKey.value) { // valid dashboard key -> fetch all data
return Promise.all([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz think about Promise.allSettled instead: https://dev.to/viclafouch/promise-allsettled-vs-promise-all-in-javascript-4mle

proper error handling would be nice (but I guess is still wip)

frontend/components/dashboard/DashboardControls.vue Outdated Show resolved Hide resolved
@@ -116,7 +116,7 @@ const addGroup = async () => {
},
{ dashboardKey: dashboardKey.value },
)
await refreshOverview(dashboardKey.value)
emit('updateAll')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the DashboardGroupManagementModal component emitting a update-all event?
How does this component know about things like all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like modified-dashboard would prob be better naming, will change.

'validator_dashboard_store',
() => {
const { t: $t } = useTranslation()
// TODO: bring ID in here and remove the provider composable!!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ love this -> #promotioncantidate

@LuccaBitfly LuccaBitfly force-pushed the BEDS-914/better-dashboard-fetching branch 2 times, most recently from 3acad26 to 45e540d Compare November 28, 2024 15:21
- Overview and SlotViz data is now fetched in `index.vue` and propped down
- SlotViz updates are handled through update emits
- Introduces proper SSR fetching
- removes all direct sibling dependencies on the overview (including the dashboard group composable)
- introduces new validator dashboard store
- dashboard modyfing actions now emit an `updateAll` event instead of directly calling `refreshOverview`

See: BEDS-914
@LuccaBitfly LuccaBitfly force-pushed the BEDS-914/better-dashboard-fetching branch from 45e540d to 60fe37d Compare November 29, 2024 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants