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

Fix/enable edit menu server web #3387

Merged
merged 2 commits into from
Dec 4, 2024
Merged

Conversation

syns2191
Copy link
Collaborator

@syns2191 syns2191 commented Dec 1, 2024

Description

Please include a summary of the changes and the related issue.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Previous screenshots

Please add here videos or images of previous status

Current screenshots

Please add here videos or images of previous status

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a dynamic application menu that adapts based on the application state and includes an "Edit" submenu with common editing options.
    • Added a ThemeToggler component to the landing page for enhanced user interface customization.
  • Bug Fixes

    • Improved error handling for server operations, ensuring clearer logging for unexpected stops.
  • Style

    • Updated the visual presentation of the Select component for improved readability.
  • Refactor

    • Renamed functions and interfaces for clarity and consistency, including the renaming of onSelectPeriode to onSelectPeriod.

Copy link
Contributor

coderabbitai bot commented Dec 1, 2024

Walkthrough

The pull request introduces significant modifications to the Electron application's menu handling and window management. Key changes include the restructuring of the application menu to ensure consistency across different window types, enhancements to event handling for language and theme changes, and refined error handling in server operations. Additionally, updates to the SelectComponent and UpdaterComponent improve clarity and maintainability. The interface naming convention is also standardized, aligning with TypeScript best practices.

Changes

File Path Change Summary
apps/server-web/src/main/main.ts Updated menu handling in setupWindow, modified onInitApplication for dynamic menu updates, refined error handling in runServer, and adjusted interval management.
apps/server-web/src/main/menu.ts Renamed defaultMenu to initialMenu, added "Edit" submenu, and introduced buildInitialTemplate method.
apps/server-web/src/renderer/components/Select.tsx Changed className property in Select.Trigger from text-[violet11] to text-black.
apps/server-web/src/renderer/components/Updater.tsx Renamed function onSelectPeriode to onSelectPeriod for clarity.
apps/server-web/src/renderer/pages/setup/Landing.tsx Added ThemeToggler component and modified layout to include it alongside LanguageSelector.
apps/web/app/interfaces/IRuntimeServerConfig.ts Renamed interface from ServerRuntimeConfig to IServerRuntimeConfig for naming consistency.
apps/web/app/services/server/requests/desktop-source.ts Updated return type of getDesktopConfig from Partial<ServerRuntimeConfig> to Partial<IServerRuntimeConfig>.

Possibly related PRs

Suggested labels

WEB, Bug fix, Ever Teams

Suggested reviewers

  • evereq
  • Cedric921

🐰 In the code we hop and play,
Menus change, and themes display.
With toggles bright and colors bold,
Our app's new look is pure gold!
So let us code and dance with glee,
For every change brings joy, you see! 🎉

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/server-web/src/main/main.ts

Oops! Something went wrong! :(

ESLint: 8.46.0

ESLint couldn't find the config "erb" to extend from. Please check that the name of the config is correct.

The config "erb" was referenced from the config file in "/apps/server-web/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (4)
apps/server-web/src/renderer/components/Updater.tsx (2)

Line range hint 70-79: Consider extracting update settings logic

The onSelectPeriod function is calling two similar prop methods with identical parameters. Consider extracting this pattern to reduce duplication and improve maintainability.

  const onSelectPeriod = (value: string) => {
-   props.changeAutoUpdate({
-     autoUpdate: props.data.autoUpdate,
-     updateCheckPeriod: value,
-   });
-   props.saveSettingUpdate({
-     autoUpdate: props.data.autoUpdate,
-     updateCheckPeriod: value,
-   });
+   const settings = {
+     autoUpdate: props.data.autoUpdate,
+     updateCheckPeriod: value,
+   };
+   props.changeAutoUpdate(settings);
+   props.saveSettingUpdate(settings);
  };

Line range hint 1-234: Consider component architecture improvements

A few architectural suggestions to improve the component:

  1. The component handles multiple responsibilities (settings, updates, logs). Consider splitting it into smaller, focused components.
  2. The update logs state could be lifted to a parent component or managed through a state management solution to persist across renders.
  3. The toast state management could be extracted into a custom hook for reusability.

Would you like me to provide a detailed refactoring proposal for any of these suggestions?

apps/web/app/services/server/requests/desktop-source.ts (1)

Line range hint 5-15: Improve error handling and type safety

While the type update is correct, there are several areas for improvement:

  1. Error logging should be more descriptive
  2. Consider validating the runtime config structure
  3. Document which fields are required vs optional

Consider applying these improvements:

 export function getDesktopConfig(): Partial<IServerRuntimeConfig> {
     try {
         const { serverRuntimeConfig } = getConfig();
+        // Validate required fields
+        if (!serverRuntimeConfig?.GAUZY_API_SERVER_URL) {
+            throw new Error('Missing required GAUZY_API_SERVER_URL in server config');
+        }
         return serverRuntimeConfig;
     } catch (error) {
-        console.log('skip get server runtime config');
+        console.error('Failed to load server runtime config:', error instanceof Error ? error.message : 'Unknown error');
         return {
             GAUZY_API_SERVER_URL,
             NEXT_PUBLIC_GAUZY_API_SERVER_URL: GAUZY_API_BASE_SERVER_URL.value
         };
     }
 }
apps/server-web/src/main/menu.ts (1)

Line range hint 19-58: LGTM! Consider extracting menu templates

The implementation correctly handles platform-specific accelerators and follows standard Electron menu practices. However, consider extracting the menu templates into separate constants to improve maintainability.

+const EDIT_MENU_TEMPLATE = [
+  { label: 'MENU_APP.APP_SUBMENU.APP_UNDO', accelerator: "CmdOrCtrl+Z", role: "undo" },
+  { label: "MENU_APP.APP_SUBMENU.APP_REDO", accelerator: "Shift+CmdOrCtrl+Z", role: "redo" },
+  { type: "separator" },
+  { label: "MENU_APP.APP_SUBMENU.APP_CUT", accelerator: "CmdOrCtrl+X", role: "cut" },
+  { label: "MENU_APP.APP_SUBMENU.APP_COPY", accelerator: "CmdOrCtrl+C", role: "copy" },
+  { label: "MENU_APP.APP_SUBMENU.APP_PASTE", accelerator: "CmdOrCtrl+V", role: "paste" },
+  { label: "MENU_APP.APP_SUBMENU.APP_SELECT_ALL", accelerator: "CmdOrCtrl+A", role: "selectAll" }
+];
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1965f0b and ebe2aee.

📒 Files selected for processing (7)
  • apps/server-web/src/main/main.ts (3 hunks)
  • apps/server-web/src/main/menu.ts (3 hunks)
  • apps/server-web/src/renderer/components/Select.tsx (1 hunks)
  • apps/server-web/src/renderer/components/Updater.tsx (2 hunks)
  • apps/server-web/src/renderer/pages/setup/Landing.tsx (2 hunks)
  • apps/web/app/interfaces/IRuntimeServerConfig.ts (1 hunks)
  • apps/web/app/services/server/requests/desktop-source.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • apps/server-web/src/renderer/components/Select.tsx
  • apps/web/app/interfaces/IRuntimeServerConfig.ts
🔇 Additional comments (7)
apps/server-web/src/renderer/components/Updater.tsx (1)

Line range hint 70-79: LGTM! Spelling correction from onSelectPeriode to onSelectPeriod

The spelling correction improves code clarity while maintaining the same functionality.

Also applies to: 155-155

apps/server-web/src/renderer/pages/setup/Landing.tsx (2)

6-6: LGTM: Clean import statement

The ThemeToggler import follows the project's import conventions.


29-39: Verify integration with Electron menu system

Since this PR involves menu handling, ensure that theme changes through the ThemeToggler component properly sync with the application menu state.

apps/server-web/src/main/menu.ts (1)

Line range hint 60-127: Consider conditionally showing the dev menu

The dev menu provides access to development windows and settings. Consider showing this menu only in development mode to prevent accidental access in production.

apps/server-web/src/main/main.ts (3)

200-200: LGTM! Consistent menu handling

The change correctly uses the new initialMenu method for the setup window, ensuring a consistent menu structure.


269-270: LGTM! Appropriate menu context handling

The implementation correctly switches between initial and default menus based on the application's setup state.


379-379: LGTM! Consistent theme handling

The change ensures that the setup window receives theme updates, maintaining visual consistency across all windows.

@@ -1,8 +1,8 @@
import getConfig from 'next/config';
import { ServerRuntimeConfig } from '@app/interfaces/IRuntimeServerConfig';
import { IServerRuntimeConfig } from '@app/interfaces/IRuntimeServerConfig';
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Interface renaming needs to be completed across the codebase

The verification reveals inconsistent interface naming:

  • The interface has been renamed to IServerRuntimeConfig in IRuntimeServerConfig.ts
  • However, getServerRuntimeConfig() function in env.ts and its usage in constants.ts still use the old naming convention
  • This creates a mix of old and new naming patterns that should be standardized

Locations needing updates:

  • apps/web/app/env.ts: Function name should be updated to getIServerRuntimeConfig()
  • apps/web/app/constants.ts: Variable name should be updated to match the new interface naming
🔗 Analysis chain

Verify consistent interface renaming across the codebase

The interface renaming from ServerRuntimeConfig to IServerRuntimeConfig follows TypeScript naming conventions. Let's ensure this change is consistent throughout the codebase.


Let me analyze the results further by checking the implementation details of these files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining occurrences of the old interface name
# and verify the new interface is used consistently

# Search for any remaining instances of the old interface name
echo "Checking for remaining instances of ServerRuntimeConfig..."
rg "ServerRuntimeConfig" --type ts

# Verify the new interface usage
echo "Verifying IServerRuntimeConfig usage..."
rg "IServerRuntimeConfig" --type ts

Length of output: 1213


Script:

#!/bin/bash
# Check the implementation of getServerRuntimeConfig and its usage
echo "Checking env.ts implementation..."
cat apps/web/app/env.ts

echo -e "\nChecking constants.ts implementation..."
cat apps/web/app/constants.ts

echo -e "\nChecking IRuntimeServerConfig interface..."
cat apps/web/app/interfaces/IRuntimeServerConfig.ts

Length of output: 12996

Comment on lines +29 to +39
<div className="flex w-full mb-6 ml-10">
<div className="flex flex-col w-6/12">
<div>
<LanguageSelector lang={defaultLang} />
</div>
</div>
<div className="flex w-6/12 flex-row-reverse mr-10">
<div className="flex flex-col w-2/8">
<ThemeToggler />
</div>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve layout structure and accessibility

The current implementation has several issues that should be addressed:

  1. The width class w-2/8 is invalid in Tailwind CSS
  2. The nested structure could be simplified
  3. Missing accessibility attributes for language and theme controls

Consider applying these improvements:

-      <div className="flex w-full mb-6 ml-10">
-        <div className="flex flex-col w-6/12">
-          <div>
-            <LanguageSelector lang={defaultLang} />
-          </div>
-        </div>
-        <div className="flex w-6/12 flex-row-reverse mr-10">
-          <div className="flex flex-col w-2/8">
-            <ThemeToggler />
-          </div>
-        </div>
+      <nav className="flex justify-between items-center w-full px-10 mb-6" aria-label="Site settings">
+        <div className="flex-shrink-0" role="region" aria-label="Language selection">
+          <LanguageSelector lang={defaultLang} />
+        </div>
+        <div className="flex-shrink-0" role="region" aria-label="Theme selection">
+          <ThemeToggler />
+        </div>
+      </nav>

Changes made:

  • Replaced invalid w-2/8 with a more flexible layout using flex-shrink-0
  • Simplified the nested structure
  • Added semantic nav element and ARIA labels
  • Used consistent padding with px-10 instead of ml-10 and mr-10
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div className="flex w-full mb-6 ml-10">
<div className="flex flex-col w-6/12">
<div>
<LanguageSelector lang={defaultLang} />
</div>
</div>
<div className="flex w-6/12 flex-row-reverse mr-10">
<div className="flex flex-col w-2/8">
<ThemeToggler />
</div>
</div>
<nav className="flex justify-between items-center w-full px-10 mb-6" aria-label="Site settings">
<div className="flex-shrink-0" role="region" aria-label="Language selection">
<LanguageSelector lang={defaultLang} />
</div>
<div className="flex-shrink-0" role="region" aria-label="Theme selection">
<ThemeToggler />
</div>
</nav>

Comment on lines +132 to +134
buildInitialTemplate(menuItems: any, i18nextMainBackend: typeof i18n) {
return Menu.buildFromTemplate(this.translateAppMenu(i18nextMainBackend, menuItems));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove duplicate method implementation

buildInitialTemplate appears to be identical to buildDefaultTemplate. Consider removing this duplication and reusing buildDefaultTemplate instead.

-buildInitialTemplate(menuItems: any, i18nextMainBackend: typeof i18n) {
-  return Menu.buildFromTemplate(this.translateAppMenu(i18nextMainBackend, menuItems));
-}

Committable suggestion skipped: line range outside the PR's diff.

@evereq
Copy link
Member

evereq commented Dec 4, 2024

@syns2191 I am merging this PR, but please go over suggestions above by Coderabbit and fix those! Somehow you keep missing them...

@evereq evereq merged commit 8db23c8 into develop Dec 4, 2024
13 checks passed
@evereq evereq deleted the fix/enable-edit-menu-server-web branch December 4, 2024 18:27
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