Skip to content

new functions, undo redo reload#1807

Merged
toddtarsi merged 1 commit into
trunkfrom
undo-redo-reload
Apr 4, 2024
Merged

new functions, undo redo reload#1807
toddtarsi merged 1 commit into
trunkfrom
undo-redo-reload

Conversation

@toddtarsi

@toddtarsi toddtarsi commented Apr 4, 2024

Copy link
Copy Markdown
Contributor

User description

all have hotkeys, reload needs an icon button

Thanks for contributing to the Selenium IDE!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Type

enhancement, bug_fix


Description

  • Implemented Undo and Redo functionality with hotkeys and enabled states.
  • Added a new menu item with a hotkey for refreshing the playback window, including recording a reload command during recording sessions.
  • Implemented state mutation handling to update project and state upon API calls.
  • Adjusted window loading to support development mode with Hot Module Replacement (HMR).
  • Centralized API logging and cleaned up unused imports and debug logs.
  • Configured Webpack for Hot Module Replacement, including setting up development server ports for different components.
  • Bumped version to 4.0.1-beta.5.

Changes walkthrough

Relevant files
Enhancement
editBasics.ts
Implement Undo and Redo Functionality with Hotkeys             

packages/selenium-ide/src/main/session/controllers/Menu/menus/editBasics.ts

  • Added hotkeys and enabled states for Undo and Redo menu items.
+14/-4   
projectView.ts
Add Refresh Playback Window Menu Item with Hotkey               

packages/selenium-ide/src/main/session/controllers/Menu/menus/projectView.ts

  • Added a new menu item with a hotkey for refreshing the playback
    window.
  • Records a reload command when the page is refreshed during recording.
  • +21/-0   
    index.ts
    Implement Undo and Redo Functionality and State Mutation Handling

    packages/selenium-ide/src/main/session/controllers/State/index.ts

  • Implemented undo and redo functionality by managing history states.
  • Added mutation handling to update project and state upon API calls.
  • +52/-2   
    index.ts
    Support Hot Module Replacement in Development Mode             

    packages/selenium-ide/src/main/session/controllers/Windows/index.ts

  • Adjusted window loading to support development mode with HMR.
  • Added preload script loading adjustment for development mode.
  • +13/-2   
    *.ts
    Centralize API Logging and Clean Up                                           

    packages/selenium-ide/src/main/api/classes/*.ts

  • Refactored API logging to use a centralized logger.
  • Removed unused imports and debug logs.
  • Configuration changes
    webpack.config.ts
    Configure Webpack for Hot Module Replacement                         

    packages/selenium-ide/webpack.config.ts

  • Adjusted Webpack configuration to support Hot Module Replacement.
  • Configured development server ports for different components.
  • +14/-28 
    Miscellaneous
    package.json
    Bump Version to 4.0.1-beta.5                                                         

    packages/selenium-ide/package.json

    • Bumped version to 4.0.1-beta.5.
    +1/-1     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    all have hotkeys, reload needs an icon button
    @qodo-code-review

    Copy link
    Copy Markdown

    PR Description updated to latest commit (c74581e)

    @qodo-code-review

    Copy link
    Copy Markdown

    PR Review

    ⏱️ Estimated effort to review [1-5]

    4, because the PR introduces a significant amount of changes across multiple files, including both feature additions and refactoring. The changes involve complex logic for undo/redo functionality, reloading, and logging adjustments, which require careful review to ensure correctness and maintainability.

    🧪 Relevant tests

    No

    🔍 Possible issues

    Possible Bug: The undo/redo functionality's impact on the application's state management needs thorough testing to ensure it does not introduce inconsistencies in the project's state.

    Performance Concern: The history management for undo/redo operations could potentially grow large, impacting the application's performance. Consider implementing a limit on the history size.

    Code Clarity: The removal of certain debug logs and changes in logging could make future debugging more challenging. Ensure that the new logging mechanism provides enough detail for effective debugging.

    🔒 Security concerns

    No


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    @qodo-code-review

    Copy link
    Copy Markdown

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Use a more explicit check for the SIDE_DEV environment variable.

    Consider using a more explicit check for the SIDE_DEV environment variable to ensure that
    the useHMR constant behaves as expected even if the environment variable is set to a value
    other than '1' or undefined. This can help avoid potential bugs related to environment
    variable misconfiguration.

    packages/selenium-ide/webpack.config.ts [21]

    -const useHMR = process.env.SIDE_DEV === '1' && isDevelopment
    +const useHMR = Boolean(process.env.SIDE_DEV) && isDevelopment
     
    Throw an error for unimplemented handler methods.

    Instead of using a noop function for missing methods, consider throwing an error or
    logging a warning. This change can help identify configuration issues or missing
    implementations during development.

    packages/selenium-ide/src/main/api/classes/Handler.ts [33]

    -return noop as unknown as AsyncHandler<HANDLER>
    +throw new Error(`Handler for path ${path} is not implemented`)
     
    Improve error handling in the shutdown method.

    For better error handling, consider adding specific error logging for the catch blocks in
    the shutdown method. This can help with debugging issues related to stopping the driver
    process or removing log listeners.

    packages/selenium-ide/src/main/session/controllers/System/index.ts [149-159]

    -console.warn('Failed to stop driver process', e)
    -console.warn('Failed to remove log listener', e)
    +this.session.system.loggers.api.warn('Failed to stop driver process', e)
    +this.session.system.loggers.api.warn('Failed to remove log listener', e)
     
    Use a ternary operator for URL selection to simplify code.

    Consider using a ternary operator for cleaner and more concise code when deciding the URL
    to load in the BrowserWindow.

    packages/selenium-ide/src/main/session/controllers/Windows/index.ts [69-72]

    -if (session.system.isDev) {
    -  win.loadURL(`http://localhost:8083/${filename}.html`)
    -} else {
    -  win.loadFile(join(__dirname, `${filename}.html`))
    -}
    +const url = session.system.isDev ? `http://localhost:8083/${filename}.html` : join(__dirname, `${filename}.html`);
    +win.loadURL(url);
     
    Adjust redo shortcut for Windows users.

    Use CommandOrControl+Y for redo operation on Windows to align with common shortcuts,
    enhancing user experience.

    packages/selenium-ide/src/main/session/controllers/Menu/menus/editBasics.ts [13]

    -accelerator: 'CommandOrControl+Shift+Z',
    +accelerator: process.platform === 'darwin' ? 'CommandOrControl+Shift+Z' : 'CommandOrControl+Y',
     
    Disable menu item when no playback window is active.

    Ensure that the 'Refresh Playback Window' menu item is only enabled when a playback window
    is active to prevent errors.

    packages/selenium-ide/src/main/session/controllers/Menu/menus/projectView.ts [29]

     accelerator: 'CommandOrControl+R',
    +enabled: !!await session.windows.getActivePlaybackWindow(),
     
    Bug
    Deep clone the state before pushing into history for undo/redo.

    To ensure the undo and redo functionality works correctly without accidentally mutating
    the current state, consider deep cloning the state before pushing it into the history
    arrays. This can prevent shared reference issues.

    packages/selenium-ide/src/main/session/controllers/State/index.ts [32-40]

    -this.prevHistory.push(this.get())
    -this.nextHistory.push(this.get())
    +this.prevHistory.push(cloneDeep(this.get()))
    +this.nextHistory.push(cloneDeep(this.get()))
     
    Maintainability
    Refactor API request handling to reduce code duplication.

    To improve the readability and maintainability of the API request handling, consider
    refactoring the repeated logic for handling API requests into a separate function. This
    can reduce code duplication and make future changes easier.

    packages/selenium-ide/src/main/api/classes/DriverRawHandler.ts [55-60]

    -ipcMain.handle(path, async (...args) => {
    -  session.system.loggers.api('Received API Request', path, args.slice(1))
    -  const result = await doAPI(...(args as Parameters<HANDLER>))
    -  session.system.loggers.api('Resolved API Request', path, result)
    -  return result
    -})
    +function handleAPIRequest(path, doAPI) {
    +  ipcMain.handle(path, async (...args) => {
    +    session.system.loggers.api('Received API Request', path, args.slice(1))
    +    const result = await doAPI(...(args as Parameters<HANDLER>))
    +    session.system.loggers.api('Resolved API Request', path, result)
    +    return result
    +  })
    +}
    +handleAPIRequest(path, doAPI)
     
    Security
    Remove console.log statement to enhance security.

    Remove the console.log statement to avoid exposing window count information in production
    environments.

    packages/selenium-ide/src/main/session/controllers/Windows/index.ts [258]

    -console.log('Window count:', windowCount)
    +// console.log('Window count:', windowCount)
     
    Remove debug logging to enhance security.

    Avoid using console.debug for logging in production code to prevent potential leakage of
    sensitive information.

    packages/selenium-ide/src/main/session/controllers/Playback/index.ts [347-348]

    -console.debug(
    -  `Playing state changed ${e.state} for test ${testName}, doink?`
    -)
    +// console.debug(`Playing state changed ${e.state} for test ${testName}, doink?`)
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @toddtarsi toddtarsi merged commit ae1f9ad into trunk Apr 4, 2024
    @toddtarsi toddtarsi deleted the undo-redo-reload branch April 4, 2024 14:06
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant