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

(BEDS-481) API: dashboards notifications struct adjustments #873

Merged

Conversation

remoterami
Copy link
Contributor

No description provided.

Copy link

cloudflare-workers-and-pages bot commented Sep 19, 2024

Deploying beaconchain with  Cloudflare Pages  Cloudflare Pages

Latest commit: 46ff8a2
Status: ✅  Deploy successful!
Preview URL: https://4963b06c.beaconchain.pages.dev
Branch Preview URL: https://beds-481-api-dashboards-noti.beaconchain.pages.dev

View logs

@LuccaBitfly LuccaBitfly force-pushed the BEDS-481/api-dashboards-notifications-struct-changes branch from 31ab2ee to b38dbbb Compare October 2, 2024 09:31
- Modified `wrapWithIdentifier` function to accept multiple keys instead of a single `getIdFromRow` function.
- The unique identifier `wrapped_identifier` is now generated by joining the values of the specified keys with a dash (`-`).
- Adapted all usages of `wrapWithIdentifier`

See: BEDS-481
Comment on lines 2 to 19
/**
* This function wraps each element in an `ApiPagingResponse` interface with a unique id field `wrapped_identifier`.
* @param response The api response to wrap
* @param getIdFromRow A function that takes a row and builds a unique identifier
* @returns The wrapped response
*/
export function wrapWithIdentifier<T>(response: ApiPagingResponse<T> | undefined, ...keys: (keyof T)[]) {
if (!response) {
return
}
return {
data: response.data.map(row => ({
...row,
wrapped_identifier: keys.map(key => row[key]).join('-'),
})),
paging: response.paging,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

np: something like that would be kewl

Suggested change
/**
* This function wraps each element in an `ApiPagingResponse` interface with a unique id field `wrapped_identifier`.
* @param response The api response to wrap
* @param getIdFromRow A function that takes a row and builds a unique identifier
* @returns The wrapped response
*/
export function wrapWithIdentifier<T>(response: ApiPagingResponse<T> | undefined, ...keys: (keyof T)[]) {
if (!response) {
return
}
return {
data: response.data.map(row => ({
...row,
wrapped_identifier: keys.map(key => row[key]).join('-'),
})),
paging: response.paging,
}
}
/**
* Sometimes the api does not provide a `unique id` for objects in an array.
* But in `frontend` there are `components` that need to differentiate between the items.
* So an identifier for each item is constructed out of a combination of the `object`.
*/
export function addIdentifier<T>(response: ApiPagingResponse<T> | undefined, ...keys: (keyof T)[]) {
if (!response) {
return
}
return {
data: response.data.map(row => ({
...row,
identifier: keys.map(key => row[key]).join('-'),
})),
paging: response.paging,
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe think about generalize this function (is it important for the function that there has to be a row?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Pushed the changes, ptal.
As for the generalization, since this func takes ApiPagingResponses, which only concern tables, the function can expect there to be rows. If we want to add identifiers so something other than ApiPagingResponses, we can think about generalizing more.

Comment on lines 63 to 65
<BcTable
:data="notificationsDashboards"
data-key="notification_id"
:data="wrapWithIdentifier(notificationsDashboards, 'is_account_dashboard', 'dashboard_id', 'group_id', 'epoch')"
data-key="wrapped_identifier"
Copy link
Contributor

Choose a reason for hiding this comment

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

when using <BcTable> and using wrapedWithIdentifier function, which has the consequence that data-key would be always the wrapped_identifier key...

It would be nice if BcTable would be refactored that data-key is not needed anymore

Copy link
Contributor

@LuccaBitfly LuccaBitfly Oct 2, 2024

Choose a reason for hiding this comment

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

Do we want to refactor BcTable to do that though? As far as the prime vue component goes, data-key is optional and only optimizes performance, which may be lost if we wrap every time when using BcTable. I would suggest investigating whether BcTable truly needs a unique ID first (at a later time) and keeping this for now.

@LuccaBitfly LuccaBitfly force-pushed the BEDS-481/api-dashboards-notifications-struct-changes branch from becd3d3 to 46ff8a2 Compare October 3, 2024 06:02
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.

👍

Comment on lines +7 to +18
export function addIdentifier<T>(response: ApiPagingResponse<T> | undefined, ...keys: (keyof T)[]) {
if (!response) {
return
}
return {
data: response.data.map(row => ({
...row,
identifier: keys.map(key => row[key]).join('-'),
})),
paging: response.paging,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

np: this should work too and is a bit cleaner imo

Suggested change
export function addIdentifier<T>(response: ApiPagingResponse<T> | undefined, ...keys: (keyof T)[]) {
if (!response) {
return
}
return {
data: response.data.map(row => ({
...row,
identifier: keys.map(key => row[key]).join('-'),
})),
paging: response.paging,
}
}
export function addIdentifier<T>(
pagingResponse: ApiPagingResponse<T> | undefined,
keys: (keyof T)[],
) {
if (!pagingResponse) {
return
}
return {
...pagingResponse,
data: pagingResponse.data
.map(item => ({
...item,
identifier: keys.map(key => item[key]).join('-'),
})),
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

But again, imo this is a code smell and could potentially introduce performance issues in large data sets.
As this will be done for every row in a table.

I still think data manipulation should happen in backend.

@remoterami remoterami merged commit 87c3e67 into staging Oct 7, 2024
4 checks passed
@LuccaBitfly LuccaBitfly deleted the BEDS-481/api-dashboards-notifications-struct-changes branch December 17, 2024 09:41
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.

3 participants