Skip to content

Update edit and create validators with workspace IDs to disallow duplicates #1838

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

Merged
merged 5 commits into from
May 28, 2025

Conversation

apinkert
Copy link
Contributor

@apinkert apinkert commented May 21, 2025

For RHCLOUD-39757. On edit, the workspace name validator would always come up as a duplicate because its name already existed in the allWorkspaces array which would prevent being able to submit on description change only.

Summary by Sourcery

Enhance workspace name validation to ignore the current workspace’s ID and prevent false duplicate errors on create and edit forms

Bug Fixes:

  • Fix false duplicate name error on edit by allowing the same name for the workspace being edited

Enhancements:

  • Add ID-aware duplicate-name validator to workspace creation schema
  • Update edit workspace validator to exclude the current workspace’s ID when checking for name conflicts
  • Introduce new i18n message key for workspace name taken error

@apinkert apinkert requested a review from a team as a code owner May 21, 2025 21:58
Copy link
Contributor

sourcery-ai bot commented May 21, 2025

Reviewer's Guide

Validators for creating and editing workspaces are updated to pull the current list of workspaces from Redux and refine the duplicate-name check to exclude the workspace being edited, and a new localized error message is added.

File-Level Changes

Change Details Files
Inject allWorkspaces from Redux into create-workspace schema
  • Imported useSelector and RBACStore
  • Declared allWorkspaces via useSelector in schemaBuilder
src/smart-components/workspaces/create-workspace/schema.tsx
Refine duplicate-name validators to ignore the current workspace’s ID
  • Enhanced create-workspace validator to compare incoming id and skip matches
  • Modified edit modal validator to accept id param and exclude that workspace from duplicates
src/smart-components/workspaces/create-workspace/schema.tsx
src/smart-components/workspaces/EditWorkspaceModal.tsx
Add a new localized error message for taken workspace names
  • Defined workspaceNameTaken message in Messages.js
src/Messages.js

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard 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

@codecov-commenter
Copy link

codecov-commenter commented May 21, 2025

Codecov Report

Attention: Patch coverage is 5.55556% with 17 lines in your changes missing coverage. Please review.

Project coverage is 35.62%. Comparing base (c7f50d7) to head (44075e9).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...smart-components/workspaces/EditWorkspaceModal.tsx 0.00% 6 Missing and 2 partials ⚠️
...-components/workspaces/create-workspace/schema.tsx 0.00% 7 Missing and 1 partial ⚠️
src/redux/reducers/workspaces-reducer.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1838      +/-   ##
==========================================
- Coverage   35.68%   35.62%   -0.06%     
==========================================
  Files         216      216              
  Lines        6389     6402      +13     
  Branches     1692     1699       +7     
==========================================
+ Hits         2280     2281       +1     
- Misses       3849     3859      +10     
- Partials      260      262       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @apinkert - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -44,6 +44,10 @@ const setWorkspace = (state: WorkspacesStore, { payload }: { payload: { data: Wo
isLoading: false,
});

export const isWorkspace = (data: unknown | Workspace): data is Workspace => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Hyperkid123 Great suggestion. This is definitely cleaner and allowed me to delete the casting in each validator for id

@apinkert apinkert requested a review from Hyperkid123 May 27, 2025 19:46
@karelhala karelhala merged commit 671e13f into master May 28, 2025
10 of 11 checks passed
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.

4 participants