fix: Application list search criteria support querying by status#3803
fix: Application list search criteria support querying by status#3803shaohuzhang1 merged 1 commit intov2from
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| publish_status: undefined, | ||
| }) | ||
|
|
||
| const user_options = ref<any[]>([]) |
There was a problem hiding this comment.
The provided code snippet appears to be for an Vue.js application with Element UI components. Here are some observations and suggestions:
-
Duplicate Code: The
el-selectfor selecting users and publications have similar logic, except the options labels. Consider creating a reusable component or using computed properties to avoid duplication. -
Empty Search Form Value: In the second
if (search_type === 'name'), you're settingsearch_form.namewithout initializing it first. It should be initialized as an empty string if needed. -
Nullish Coalescing Operator: Using nullish coalescing (
??) would make the code more concise when checking ifsearch_form.publish_statusisundefined. -
Dynamic Options Binding: Ensure that the data source for the publication select list (
publishersOptions) is properly set up and populated before the dropdown initializes. -
Accessibility: Make sure all input fields are accessible within the context of the page. Use appropriate ARIA roles where necessary.
-
Consistency in Event Handling: Ensure that event handlers like
@change="searchHandle"work correctly across different conditions.
Here's an optimized version of the relevant part of the code:
<div>
<!-- ... existing code for selection filters ... -->
<div class="flex items-center justify-between mt-2">
<el-select
v-model="search_form.searchType"
@change="handleSearchTypeChange"
style="min-width: 150px;"
>
<el-option :label="$t('common.type')" value="type" />
<el-option :label="$t('common.tag')" value="tag" />
<el Option :label="$t('common.creator')" value="create_user" />
<el-option :label="$t('common.name')" value="name" />
<el-option :label="$t('common.publishStatus')" value="publish_status" />
</el-select>
<input
v-if="searchForm.searchType === 'name' && !this.user_options.length"
v-model="searchForm.name"
@keyup.enter="searchHandle($event)"
/>
<select
v-else-if= searchForm.searchType === 'creator'
>
<option selected disabled>Loading...</option>
<!-- Replace this placeholder with actual options loading mechanism -->
</select>
<select
v-else-if="searchForm.searchType === 'tag'"
>
<option selected disabled>Loading...</option>
<!-- Replace this placeholder with actual options loading mechanism -->
</select>
<select
v-else-if="searchForm.searchType === 'name'"
>
<option v-for="u in user_options" :key="u.id" :value="u.id">{{ u.nick_name }}</option>
</select>
<select
v-else-if="searchForm.searchType === 'publish_status'"
>
<option :value="null">All</option>
<option>{{ $t('common.published') }}</option>
<option>{{ $t('common.unpublished') }}</option>
</select>
</div>
<!-- ... remaining code ... -->
</div>Key Changes:
- Moved the dynamic options into their respective sections based on
search_type. - Removed unnecessary conditional checks and directly bind values where possible.
- Used template literals for cleaner HTML construction.
- Ensured that all dropdowns maintain consistent functionality, handling both static and interactive content types.
These changes will improve readability, performance, and maintainability of your code.
| required=False, | ||
| ) | ||
| ] | ||
|
|
There was a problem hiding this comment.
There don't appear to be any specific errors in this code snippet. However, here's a few comments and suggestions:
-
Parameter Naming: The parameter
publish_statusis described with descriptions that include both "published" and "unpublished". It might be clearer if one of these was clarified or removed since it doesn't seem to have different meanings. -
Description Formatting: Ensure that any underscores in the descriptions are properly escaped. For example, consider using
'Published'instead of'Published|unpublished'. -
Consistency: Maintain consistency in the use of punctuation and spacing in the field labels (like
location='query',) for better readability. -
Comments: If you want to further document this method and its parameters, adding more comments would be helpful.
-
General Optimization: Make sure there aren't other parts of the function that could be optimized or simplified based on your overall design goals and constraints.
Overall, the provided code looks well-structured for handling query parameters related to publish statuses.
| application_query_set = application_query_set.filter(is_publish=is_publish) | ||
| if workspace_id is not None: | ||
| folder_query_set = folder_query_set.filter(workspace_id=workspace_id) | ||
| application_query_set = application_query_set.filter(workspace_id=workspace_id) |
There was a problem hiding this comment.
The code looks mostly correct, but there are some improvements and optimizations that can be made:
Improvements:
- Consistent Field Names: Ensure all field labels are consistently formatted (e.g., use
lower_case_with_underscores). - Optional Arguments: Simplify the way optional arguments are handled.
Optimizations:
- Conditional Logic: Move conditional logic outside the filtering to optimize performance.
Here's an updated version of your code with these improvements and optimizations:
@@ -284,6 +284,9 @@ class ApplicationQueryRequest(serializers.Serializer):
folder_id = serializers.CharField(required=False, label="folder_id")
name = serializers.CharField(required=False, label="application_name")
desc = serializers.CharField(required=False, label="application_description")
+ publish_status = serializers.ChoiceField(
+ required=False,
+ label="publish_status",
+ choices=[("published", "Published"), ("unpublished", "Unpublished")]
+ )
user_id = serializers.UUIDField(required=False, label="user_id")
@@ -311,7 +314,12 @@ def get_query_set(self, instance: Dict, workspace_manage: bool, is_x_pack_ee: bool
user_id = self.data.get('user_id')
desc = instance.get('desc')
name = instance.get('name')
+ publish_status = instance.get("publish_status")
create_user = instance.get('create_user')
+ # Apply publishing status filter if provided
+ if publish_status in ["published", "unpublished"]:
+ application_query_set = application_query_set.filter(is_published=publish_status == 'published')
if workspace_id is not None:
folder_query_set = folder_query_set.filter(workspace_id=workspace_id)
application_query_set = application_query_set.filter(workspace_id=workspace_id)Key Changes:
- Formatting: Consistently uses underscores in field names.
- Optimized Filter Condition: Moved the condition for checking publishing status outside the loop, which can improve readability and performance.
- ChoiceField Label Formatting: Ensures consistent formatting across the choice field.
fix: Application list search criteria support querying by status