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

Chore/user config handling and performance fixes #2856

Open
wants to merge 18 commits into
base: feat/make-classification-and-criticality-optional
Choose a base branch
from

Conversation

Hellgartner
Copy link
Contributor

Summary of changes

Exchange the current setup for using electron settings in the frontend with

  • Make sure all of the configuration are always set, this reduces the need for defaults
  • Do not use the variables section but create a dedicated redux store for user config
  • Sync this store directly at frontend startup -- before any rendering happens
  • Register one central handler which forwards any user settings changes to the store
  • Using user settings is then only a normal use on the store
  • Note that writing user settings from the frontend still requires and IPC call to the backend.

Context and reason for change

The current setup for the user configuration does not scale to the higher number of uses.
Using useUserSetting leads to a lot of

useIpcRenderer(
    AllowedFrontendChannels.UserSettingsChanged, ...

handlers being registered. This has a few unpleasant consequences:

  • On any change of any user setting all these handlers fire.
  • All these handlers cause a write to the redux store and thus re-renders.
  • Hooks for these variables are used in the App.tsx causing re-renders of the entire app on change

This makes even handling small files hard to work with and makes the app crash on larger, more realistic, files.

How can the changes be tested

Full regression test

Note: Please review the guidelines for contributing to this repository.

Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
@Hellgartner Hellgartner linked an issue Mar 14, 2025 that may be closed by this pull request
Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
@Hellgartner Hellgartner force-pushed the chore/user-config-handling-and-performance-fixes branch from 0a59632 to 0f3855f Compare March 19, 2025 08:00
tests showed: electron-settings do not reliably update if multiple updates are pending at the same time

Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
@Hellgartner Hellgartner marked this pull request as ready for review March 19, 2025 12:40
@mstykow mstykow self-assigned this Mar 19, 2025
UserSettings,
} from '../../shared/shared-types';

export class UserSettingsProvider {
Copy link
Member

@mstykow mstykow Mar 19, 2025

Choose a reason for hiding this comment

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

  1. git does not recognize that this file has been renamed from the old one. could you please fix this to keep the git history intact?
  2. i'm not sure the name is great. in React, a "provider" usually refers to context provider but what you have here is a service/util. what's wrong with keeping the old name of "UserSettings"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Concerning 1)
It does for me, both in IntelliJ as well as in GitHub
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Take UserSettingsService

Copy link
Member

@mstykow mstykow Mar 19, 2025

Choose a reason for hiding this comment

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

does it really make things easier to have one selector per setting? this way, i have to know exactly the name of what i'm looking for. it seems to me it would be easier to have a single selector for the user settings and then just do settings.MY_SETTING which comes with autocomplete.

import { useAppDispatch } from '../hooks';

// should only be called once
export function useInitialSyncUserSettings() {
Copy link
Member

Choose a reason for hiding this comment

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

hook name no longer matches file name. but as mentioned in my other comment: perhaps we still want a single useUserSettings hook.

};
}

export function toggleAreHiddenSignalsVisible(
Copy link
Member

Choose a reason for hiding this comment

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

you are breaking naming convention. i would have expected "updateAreHiddenSignalsVisible". also, why do only some user settings have a dedicated action while others do not?
suggestion: create only a single action that can be used to update any user setting. then use this action in the single hook for updating any user setting.

@@ -58,14 +58,14 @@ export function useAuditingOptions({
}) {
const dispatch = useAppDispatch();
const store = useAppStore();
const [qaMode] = useUserSetting({ key: 'qaMode' });
const qaMode = useAppSelector(getQaMode);
Copy link
Member

Choose a reason for hiding this comment

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

it's strange to me that for some user settings we have dedicated hooks for getting and setting but other user settings we call useAppSelector. suggestion: have a single hook for getting and setting all user settings such as useUserSettings.

Copy link
Member

Choose a reason for hiding this comment

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

not a great fan of redux action tests. better to write integration or e2e tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ToDo: Delete

Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
Note: Now the old signal for fetching a single backend information should be unused

Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
only allow one channel to get the full user-settings information from the backend

Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
… chore/user-config-handling-and-performance-fixes

 Conflicts:
	src/ElectronBackend/main/main.ts
	src/ElectronBackend/main/menu/viewMenu.ts
	src/shared/shared-types.ts
in order to avoid clashes with react naming where a provider
has a fixed meaning

Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
…unction

Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
…e functions

Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
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.

Make display of classification and criticality optional
2 participants