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(pro:search): mutiple search filed validation error #1475

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/pro/search/src/composables/useSearchStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,22 @@ export function useSearchStates(
return false
}

const searchField = props.searchFields?.find(field => field.key === searchState.fieldKey)
// all valid segmentValue are not allowd to be undefined or null
// when current value isn't valid, return immediatly
if (!searchState.segmentValues.every(segmentValue => !isNil(segmentValue.value))) {
return false
}

const count = dataKeyCountMap.get(searchState.fieldKey)

// if there are more than one searchState of the same field key
// check whether mutiple searchState is allowed from the field config
if (count && count > (existed ? 1 : 0)) {
return !!searchField?.multiple
return !!props.searchFields?.find(field => field.key === searchState.fieldKey)?.multiple
}

return searchState.segmentValues.every(segmentValue => !isNil(segmentValue.value))
// all validations are passed
return true
}

const validateSearchState = (key: VKey) => {
Copy link

Choose a reason for hiding this comment

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

the code review:

  1. In the first part of the code, it is important to check that the segmentValues are not undefined or null. This is a good way to prevent bugs from happening and make sure that the code runs smoothly.
  2. The second part of the code checks whether there are more than one searchState of the same field key and if multiple searchStates are allowed from the field config. This allows the code to be able to handle cases with multiple searchStates of the same field key.
  3. The last part of the code validates the searchState by checking that all segmentValues are not nil. This ensures that all validations are passed before the code is executed.

Overall, the code looks good and should be able to handle different cases without any issues. However, there might be some edge cases that are not addressed and should be considered in the future.

Expand Down