kloudlite / web

Kloudlite Web
http://kloudlite.io
GNU Affero General Public License v3.0
2 stars 1 forks source link

WEB: Discard changes working fine when switching tab of app settings #312

Closed nxtCoder19 closed 1 month ago

nxtCoder19 commented 1 month ago

Summary by Sourcery

Implement a new hook to check account ownership and enhance the unsaved changes handling by introducing a callback mechanism and a standardized action management system.

New Features:

Enhancements:

sourcery-ai[bot] commented 1 month ago

Reviewer's Guide by Sourcery

This pull request implements changes to improve the functionality of discarding changes when switching tabs in app settings. It introduces a new hook for checking owner status, updates the UnsavedChangesProvider to handle discarding changes, and refactors the use of action constants across multiple components.

Class diagram for useIsOwner hook

classDiagram
    class useIsOwner {
        +boolean isOwner
        +boolean isLoading
        +useCallback()
    }
    useIsOwner --> useCustomSwr
    useIsOwner --> useConsoleApi
    useCustomSwr --> useConsoleApi

File-Level Changes

Change Details Files
Implement discard changes functionality in app settings
  • Add useEffect hook to handle discarding changes
  • Update useForm hook to include reset functionality
  • Modify initialValues to use getReadOnlyContainer().env
  • Add reset() call in useEffect for readOnlyApp changes
src/apps/console/routes/_main+/$account+/env+/$environment+/new-app/app-environment-variables.tsx
Refactor UnsavedChangesProvider and introduce DISCARD_ACTIONS constants
  • Add onProceed prop to UnsavedChangesProvider
  • Implement DISCARD_ACTIONS object with action constants
  • Update Popup.Button onClick to call onProceed
lib/client/hooks/use-unsaved-changes.tsx
Update app settings layout to use new DISCARD_ACTIONS constants
  • Replace string literals with DISCARD_ACTIONS constants
  • Add onProceed prop to UnsavedChangesProvider in Settings component
src/apps/console/routes/_main+/$account+/env+/$environment+/app+/$app+/settings+/_layout.tsx
Refactor other components to use DISCARD_ACTIONS constants
  • Update performAction checks to use DISCARD_ACTIONS constants
src/apps/console/page-components/app/general.tsx
src/apps/iot-console/routes/_main+/$account+/$project+/deviceblueprint+/$deviceblueprint+/app+/$app+/settings+/_layout.tsx
src/apps/console/page-components/app/compute.tsx
Implement useIsOwner hook for checking account ownership
  • Create useIsOwner hook to fetch team members and current user
  • Implement isOwner function to check if current user is account owner
src/apps/console/hooks/use-is-owner.tsx

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).