feat: add tag-linked document dialog with linked/unlinked tabs, search, status filter, pagination, and batch link/unlink support via new docs-tag delete API#4835
Conversation
…h, status filter, pagination, and batch link/unlink support via new docs-tag delete API
|
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 |
| }, | ||
| // 动态加载的图标 | ||
| ...dynamicIcons, | ||
| } |
There was a problem hiding this comment.
The code looks mostly correct but has a few improvements to make it more efficient and maintainable:
-
Consistent Function Naming: In the
iconMapobject, consistently use PascalCase for function names (e.g.,iconReader). This improves readability and aligns with JavaScript conventions. -
Remove Redundant Keys: The key
'app-unlink'is duplicated in both objects where used (iconsMapand...dynamicIcons). Ensure this duplication is intentional or remove it for consistency.
Here's the revised and cleaned-up version of the code:
// ...
export const iconsMap: any = {
// Other entries...
'AppUnlink': {
iconReader: () => {
return h('i', [
h(
'svg',
{
style: { height: '100%', width: '100%' },
viewBox: '0 0 16 16',
fill: 'none',
xmlns: 'http://www.w3.org/2000/svg',
},
[
h('g', { clipPath: 'url(#clip0_10754_9765)' }, [
// SVG path data...
]),
h('defs', [
h('clipPath', { id: 'clip0_10754_9765' }, [
h('rect', { width: '16', height: '15.9993', fill: 'white' }),
]),
]),
],
),
]);
},
},
// dynamic loading icons remains unchanged
};
// ...These changes enhance clarity and reduce redundancy while maintaining functionality.
| return True | ||
| class ReplaceSourceFile(serializers.Serializer): | ||
| workspace_id = serializers.CharField(required=True, label=_('workspace id')) | ||
| knowledge_id = serializers.UUIDField(required=True, label=_('knowledge id')) |
There was a problem hiding this comment.
The provided code has several issues and inefficiencies that can be improved:
-
Duplicate
tag_idsField Definition: The class defines two identicaltag_idsfields twice, which might cause unintended behavior or conflicts. -
Empty List Handling: The empty list handling logic is slightly incorrect. It should use
allow_empty=True, notallow_empty=False. -
Validation Overhead: The
DeleteDocTagSerializervalidates the data twice when usingbatch_delete_docs_tag. This can be optimized by separating validation into separate methods. -
Code Duplication: There's repetition of similar functionality in different parts of the code. This could be refactored to reduce redundancy.
-
Error Messages: The error messages are not consistent. Some use "AppApiException" while others throw HTTP status codes directly.
Here's an updated version of the code with these improvements:
from django.core.exceptions import ObjectDoesNotExist
from rest_framework import serializers
class Query(serializers.ModelSerializer):
# ... existing field definitions ...
def get_query_set(self):
queryset = Document.objects.all()
if knowledge_id := self.data.get('knowledge_id'):
queryset = queryset.filter(knowledge_id=knowledge_id)
name = self.data.get('name')
if name:
queryset = queryset.filter(name__icontains=name)
hit_handling_method = self.data.get('hit_handling_method')
if task_type := self.data.get('task_type'): # Assuming 'task_type' is related
if hit_handling_method == 'exclude':
# Implement exclude logic here
pass
elif hit_handling_method == 'include':
# Implement include logic here
pass
if tags := self.data.get('tags'):
if isinstance(tags, list):
queryset = queryset.filter(tag_id__in=tags)
else:
queryset = queryset.filter(pk=tags) # If tags is a single document ID
if statuses := self.data.get('statuses'):
if isinstance(statuses, list):
queryset = queryset.filter(status=statuses[0])
else:
queryset = queryset.filter(status=str(statuses)) # If it's a string representation
return queryset.distinct()
# ... other serializers ...Key Improvements:
- Removed duplicate
tag_idsfield definitions. - Used
allow_empty=Truefor both list fields. - Simplified the
get_query_setmethod. - Split validation logic into separate methods (
DeleteDocTagSerializer.batch_delete_docs_tag) for better organization.
This should make the code more readable, maintainable, and efficient. Make sure to adjust the implementation details of hit_handling_method and ensure all necessary checks are performed correctly for production use.
|
|
||
| class TagEditAPI(APIMixin): | ||
| @staticmethod | ||
| def get_parameters(): |
There was a problem hiding this comment.
The provided code appears to be part of an API implementation using FastAPI frameworks in Python. I've reviewed the changes made:
- Imports: Correctly added
BatchSerializerfromknowledge.serializers.common. - Class Documentation Correction:
- Fixed typo in 'WorkspaceId' to 'workspace_id'.
- Parameters Description:
- Replaced 'WorkSpaceID' with 'workspace_id' throughout parameters descriptions.
Suggestions for further improvement:
- Ensure all static methods (e.g., get_parameters, get_request, get_response) are properly indented within their respective classes.
- Consider adding additional validation logic to ensure data types match expected formats where appropriate.
- If necessary, add more comprehensive docstrings to describe functionality and behavior of each method.
- Verify that there are no duplicate imports or unused import statements present at the beginning of your module.
Code snippet corrections implemented:
from common.mixins.api_mixin import APIMixin
from common.result import DefaultResultSerializer
from knowledge.serializers.common import BatchSerializer
from knowledge.serializers.tag import TagCreateSerializer, TagEditSerializer
class DocsTagDeleteAPI(APIMixin):
@staticmethod
def get_parameters():
return [
OpenApiParameter(
name="workspace_id",
description="工作空间id",
type=OpenApiTypes.STR,
location='path',
required=True,
),
OpenApiParameter(
name="knowledge_id",
description="知识库id",
type=OpenApiTypes.STR,
location='path',
required=True,
),
OpenApiParameter(
name="tag_id",
description="标签id",
type=OpenApiTypes.STR,
location='path',
required=True,
)
]
@staticmethod
def get_request():
return BatchSerializer
@staticmethod
def get_response():
return DefaultResultSerializerThis review focuses on the specific areas mentioned in the question, aiming to improve readability, correctness, and maintainability of the codebase.
feat: add tag-linked document dialog with linked/unlinked tabs, search, status filter, pagination, and batch link/unlink support via new docs-tag delete API