Skip to content

Fix/prevent re-render reports menu - #1252

Closed
jorgeart81 wants to merge 15 commits into
traccar:masterfrom
jorgeart81:fix/re-render-reports-menu
Closed

jorgeart81 wants to merge 15 commits into
traccar:masterfrom
jorgeart81:fix/re-render-reports-menu

Conversation

@jorgeart81

Copy link
Copy Markdown
Contributor

Create a ReportLayout so that the ReportsMenu is not affected by the status update.
Ref -> PR/1251

Video

2024-06-28.18-54-18.mp4

const ReportsLayout = () => (
<PageLayout
menu={<ReportsMenu />}
breadcrumbs={['reportTitle', 'reportCombined']}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The breadcrumbs is different per report.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's true, I hadn't noticed it.
I made these changes to fix it.

Comment thread src/Navigation.jsx
</Route>

<Route path="reports">
<Route path="reports" element={<ReportsLayout />}>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we do the same thing for settings?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It seems to me that yes, in the components that have the same design.
It would be necessary to analyze it because I do not see that the state update generated by the socket is rendering the settings menu.

I apologize for any translation errors, my language is Spanish and I am using a translator.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please update settings as well, so we have consistent codebase.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Of course, let me see what I can do.

@tananaev

Copy link
Copy Markdown
Member

Can you please clarify how this fixes the problem.

@jorgeart81

jorgeart81 commented Jun 29, 2024 •

Copy link
Copy Markdown
Contributor Author

Response to comment #1252 (comment)

Child components are affected by the rendering of the parent or container component.
In this case, when converting <PageLayout menu={<ReportsMenu />} Breadcrumbs={['reportTitle', 'reportCombined']}> to the parent container, the change of state of the children only affects their content, therefore the component main (Layout) is not affected.

Comment on lines +7 to +16
'/reports/combined': ['reportTitle', 'reportCombined'],
'/reports/route': ['reportTitle', 'reportRoute'],
'/reports/event': ['reportTitle', 'reportEvents'],
'/reports/trip': ['reportTitle', 'reportTrips'],
'/reports/stop': ['reportTitle', 'reportStops'],
'/reports/summary': ['reportTitle', 'reportSummary'],
'/reports/chart': ['reportTitle', 'reportChart'],
'/reports/logs': ['reportTitle', 'statisticsTitle'],
'/reports/scheduled': ['settingsTitle', 'reportScheduled'],
'/reports/statistics': ['reportTitle', 'statisticsTitle'],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You probably don't need to duplicate 'reportTitle' everywhere. Just the second part is different.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made this change, what do you think? 395ada3

@jorgeart81 jorgeart81 Jun 29, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I found that being part was different-> '/reports/scheduled': ['settingsTitle', 'reportScheduled'],

<PageLayout menu={<ReportsMenu />} breadcrumbs={['settingsTitle', 'reportScheduled']}>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably a mistake. All of them should be under reports.

import ReportsMenu from './ReportsMenu';

const routes = {
reports: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need a nested JSON here. I think reports property should be removed. This is only reports anyway.

const commondBreadcrumb = 'settingsTitle';

const routes = {
settings: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here

},
};

const compoundRoutes = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks really complicated. Why do we need all of these? I think you should be able to split it by path segements.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like it's still overcomplicated. Why can't we just append to an array? Something like:

let breadcrumbs = ['settingsTitle'];
if (length >= 2) {
  breadcrumbs.add(routes[pathSegmets[1]);
}
if (length >= 3) {
  switch ...
}

@jorgeart81 jorgeart81 Jul 2, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I understand your points of view. I think that although it works for the current context, using push would not be correct because push is used to add elements to an array, every time it is called.

I propose another solution so as not to affect the structure of your code too much. PR -> #1253

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The other PR looks promising, if it works as expected. Commented there.

@jorgeart81 jorgeart81 mentioned this pull request Jul 2, 2024
@tananaev

Copy link
Copy Markdown
Member

We already have a solution for this. We only re-render when id or name changes.

@tananaev tananaev closed this Jun 23, 2026
@jorgeart81
jorgeart81 deleted the fix/re-render-reports-menu branch June 23, 2026 02:51
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