Skip to content

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

Merged
zhanweizhang7 merged 1 commit intov2from
pr@v2@feat_add_tag_link
Mar 3, 2026
Merged

Conversation

@shaohuzhang1
Copy link
Contributor

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

…h, status filter, pagination, and batch link/unlink support via new docs-tag delete API
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Mar 3, 2026

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.

Details

Instructions 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.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Mar 3, 2026

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

},
// 动态加载的图标
...dynamicIcons,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code looks mostly correct but has a few improvements to make it more efficient and maintainable:

  1. Consistent Function Naming: In the iconMap object, consistently use PascalCase for function names (e.g., iconReader). This improves readability and aligns with JavaScript conventions.

  2. Remove Redundant Keys: The key 'app-unlink' is duplicated in both objects where used (iconsMap and ...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'))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code has several issues and inefficiencies that can be improved:

  1. Duplicate tag_ids Field Definition: The class defines two identical tag_ids fields twice, which might cause unintended behavior or conflicts.

  2. Empty List Handling: The empty list handling logic is slightly incorrect. It should use allow_empty=True, not allow_empty=False.

  3. Validation Overhead: The DeleteDocTagSerializer validates the data twice when using batch_delete_docs_tag. This can be optimized by separating validation into separate methods.

  4. Code Duplication: There's repetition of similar functionality in different parts of the code. This could be refactored to reduce redundancy.

  5. 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_ids field definitions.
  • Used allow_empty=True for both list fields.
  • Simplified the get_query_set method.
  • 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():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code appears to be part of an API implementation using FastAPI frameworks in Python. I've reviewed the changes made:

  1. Imports: Correctly added BatchSerializer from knowledge.serializers.common.
  2. Class Documentation Correction:
    • Fixed typo in 'WorkspaceId' to 'workspace_id'.
  3. 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 DefaultResultSerializer

This review focuses on the specific areas mentioned in the question, aiming to improve readability, correctness, and maintainability of the codebase.

@zhanweizhang7 zhanweizhang7 merged commit dedec02 into v2 Mar 3, 2026
3 of 4 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@feat_add_tag_link branch March 3, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants