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

refactor: settings dialog #4265

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open

refactor: settings dialog #4265

wants to merge 60 commits into from

Conversation

Schwehn42
Copy link
Collaborator

Description

Refactors the settings dialog. The reason for this is the fact the settings will be required at other locations (like templates/sessions, #4254), and while the current state was great, it had some issues:

  1. hardcoded menu items
  2. state that wouldn't be available on other pages (like board state)
  3. hardcoded navigation

The new solution provides solutions for all of these:

  1. dynamically render menu items
    1. all sections are kept in a configurable file
    2. each section can be enabled/disabled using props
  2. remove or outsource unnessecary state
  3. dynamic navigation
    1. returning to previous route instead of navigatin to hardcoded routes
    2. when navigating to /settings, automatically redirect to the first allowed option

Changelog

  • add file constants/settings.ts incuding nessecary types and list of all menu items
  • SettingsDialog
    • add render function
    • adjust logic
  • add tests

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • The application was tested in the most commonly used browsers (e.g. Chrome, Firefox, Safari)

@Schwehn42 Schwehn42 added the Review Needed This pull request is ready for review label Jun 26, 2024

This comment has been minimized.

This comment has been minimized.

@Schwehn42 Schwehn42 added Review Needed This pull request is ready for review and removed Review Needed This pull request is ready for review labels Jul 19, 2024
Copy link

octomind-dev bot commented Jul 24, 2024

🐙 Octomind

Test Report: 14/14 successful.

description status details
About Section Visibility Test Passed ✅ click
change avatar Passed ✅ click
check Privacy Policy Passed ✅ click
check terms & conditions Passed ✅ click
close cookie banner - front page Passed ✅ click
close cookie banner - sign-in Passed ✅ click
create and delete board columns Passed ✅ click
create_and_delete_notes_and_actions_v2 Passed ✅ click
create lean coffee board Passed ✅ click
edit_notes_and_actions_v5 Passed ✅ click
get started Passed ✅ click
share_session Passed ✅ click
sign-in Passed ✅ click
test all ways to open the setup flow Passed ✅ click

commit sha: 0e85826

.eslintrc.json Outdated
@@ -57,7 +57,8 @@
"jsx-a11y/no-noninteractive-element-interactions": "off",
"no-plusplus": "off",
"no-param-reassign": "off",
"jsx-a11y/anchor-is-valid": "off"
"jsx-a11y/anchor-is-valid": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you're right, this was required for something but not anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm having an issue wrapping my head around that component right now, but not necessarily because of your changes.

You've made the seed property optional. When the component gets rendered with an undefined seed, you return null. That signals to me that the seed property is necessary in any case to render the component. But there's one case where the seed isn't necessary, isn't it? If the avatar property is defined, we don't need to have the seed to render an avatar. So as I understand it, null should only be returned if the seed and the avatar are undefined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The change stems from the fact that the seed which is used is the user's id, which can be undefined.
So you could either do a non-null assertion or allow undefined values. I know it's not optimal, maybe it would be a good change overall to change ParticipantsState.me to always be defined?

export const BoardOptionButton: FC<PropsWithChildren<BoardOptionButtonProps>> = ({label, icon, onClick, isExpandable = false, className, children, ...other}) => {
export const BoardOptionButton: FC<PropsWithChildren<BoardOptionButtonProps>> = ({label, icon, onClick, isExpandable = false, children, ...other}) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess you've removed the className here because it wasn't used anyways. But having className within the {...other} props make it unusable. If in the future, someone would add a classname to the <BoardOptionButton /> component, it wouldn't be applied.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah true, I've readded the prop and also apply it to the div now, which wasn't the case before.

Comment on lines -15 to +19
<div className={classNames("settings-dialog__container", "accent-color__lean-lilac")}>
<div className={classNames("settings-dialog__container", getColorClassName(activeMenuItem?.color))}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't the accent color of the appearance tab the same, no matter if it's used within a board or for the template page?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question for all of the other tabs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well, since the color of the menu items is determined by the menu item config, it makes sense for the actual settings dialogs to use the same color instead of using hard-coded values.

<Route path="feedback" element={<Feedback />} />
<Route path="profile" element={<ProfileSettings />} />
const Router = () => {
const feedbackEnabled = useAppSelector((state) => state.view.feedbackEnabled);
Copy link
Collaborator

@brandstetterm brandstetterm Aug 28, 2024

Choose a reason for hiding this comment

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

Doesn't seem like something that belongs in the state (since it won't change), but rather as an imported const with the value of an environment variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the value comes from the backend, that's why it's in the store.

import {GeneralSettings, Participants, SettingsAppearance, SettingsFeedback, Share, FileDefault} from "components/Icon";
import {Color} from "./colors";

export const MOBILE_BREAKPOINT = 920;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where is the magic value coming from?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that magic value has been in the code since the very first version of the setting component added in 2022 (1f88c5e), I just decided to outsource it and clarify its use in the code.

Comment on lines 7 to 17
export type MenuKey = "board" | "participants" | "appearance" | "share" | "export" | "feedback" | "profile";

type LocalizationKey = "BoardSettings" | "Participants" | "Appearance" | "ShareSession" | "ExportBoard" | "Feedback" | "Profile";

export type MenuItem = {
localizationKey: LocalizationKey;
location: string;
isModeratorOnly: boolean;
color: Color;
icon: ComponentType<SVGProps<SVGSVGElement>> | "profile"; // profile: special case
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'd prefer the following naming: MenuItemKey, MenuItemConfig

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

renamed 👍

Comment on lines 76 to 84
export const ENABLE_ALL: Record<MenuKey, boolean> = {
board: true,
participants: true,
appearance: true,
share: true,
export: true,
feedback: true,
profile: true,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: Add a feedbackEnabled const in this file, get the value from an environment variable and use the value of it inside the ENABLE_ALL record.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, maybe a different name like enabledFeedbackItems would fit better

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The feedbackEnabled comes from the store which in turn retrieves it from the ServerInfo.

The idea of the const ENABLE_ALL was to be able to use it as a shorthand to avoid having to enable all menu items manually, while still retaining the option to overwrite it.

<SettingsDialog enabledMenuItems={{...ENABLE_ALL, feedback: feedbackEnabled}} />

Remember, the reason this refactor was required in the first place is to be able to dynamically change which menu items are available, and which aren't.

@brandstetterm brandstetterm removed the Review Needed This pull request is ready for review label Aug 28, 2024
@Schwehn42 Schwehn42 added the Changes Requested Changes requested by the reviewer label Aug 29, 2024
`MenuKey` -> `MenuItemKey`
`MenuItem` -> `MenuItemConfig`
`MENU_ENTRY_CONFIG` -> `MENU_ITEM_CONFIG`
Copy link

The deployment to the dev cluster was successful. You can find the deployment here: https://4265.development.scrumlr.fra.ics.inovex.io
This deployment is only for testing purposes and will be deleted after 1 week.
To redeploy rerun the workflow.
DO NOT STORE IMPORTANT DATA ON THIS DEPLOYMENT

Deployed Images
  • ghcr.io/inovex/scrumlr.io/scrumlr-frontend:sha-7771ce4

  • ghcr.io/inovex/scrumlr.io/scrumlr-server:sha-7771ce4

@Schwehn42 Schwehn42 added Review Needed This pull request is ready for review and removed Changes Requested Changes requested by the reviewer labels Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Review Needed This pull request is ready for review
Projects
Status: Review
Development

Successfully merging this pull request may close these issues.

2 participants