-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: Application list search criteria support querying by status #3803
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,11 @@ def get_query_set(self, instance: Dict, workspace_manage: bool, is_x_pack_ee: bo | |
| 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') | ||
| if publish_status is not None: | ||
| is_publish = True if publish_status == "published" else False | ||
| 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) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code looks mostly correct, but there are some improvements and optimizations that can be made: Improvements:
Optimizations:
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:
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ | |
| <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> | ||
| <el-input | ||
| v-if="search_type === 'name'" | ||
|
|
@@ -47,6 +49,17 @@ | |
| > | ||
| <el-option v-for="u in user_options" :key="u.id" :value="u.id" :label="u.nick_name" /> | ||
| </el-select> | ||
| <el-select | ||
| v-else-if="search_type === 'publish_status'" | ||
| v-model="search_form.publish_status" | ||
| @change="searchHandle" | ||
| filterable | ||
| clearable | ||
| style="width: 220px" | ||
| > | ||
| <el-option :label="$t('common.published')" value="published" /> | ||
| <el-option :label="$t('common.unpublished')" value="unpublished" /> | ||
| </el-select> | ||
| </div> | ||
| <el-dropdown trigger="click" v-if="permissionPrecise.create()"> | ||
| <el-button type="primary" class="ml-8"> | ||
|
|
@@ -333,6 +346,7 @@ const search_type = ref('name') | |
| const search_form = ref<any>({ | ||
| name: '', | ||
| create_user: '', | ||
| publish_status: undefined, | ||
| }) | ||
|
|
||
| const user_options = ref<any[]>([]) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet appears to be for an Vue.js application with Element UI components. Here are some observations and suggestions:
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:
These changes will improve readability, performance, and maintainability of your code. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.