Skip to content

docs(conversations): add editable demo #91

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wzc520pyfm
Copy link
Owner

@wzc520pyfm wzc520pyfm commented Feb 26, 2025

About #84 .

Summary by CodeRabbit

  • New Features
    • Introduced an interactive editing capability for conversation names, allowing users to toggle between view and edit modes with intuitive controls.
    • Added a new Vue component for managing editable conversation items.
  • Documentation
    • Updated the documentation to include a new section with a demo that showcases the editable conversation feature.

Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

Walkthrough

The pull request introduces a new editable conversation feature. It adds a "可编辑" section in the conversations component documentation, which includes a demo reference (conversations/editable). Additionally, a corresponding Vue component, AXConversationsEditable, is introduced in the examples directory. This component employs the Composition API with TypeScript and integrates Ant Design Vue components to manage the editing state of conversation items through user interactions such as clicking, blurring, or pressing Enter.

Changes

File(s) Change Summary
docs/component/conversations.md Added a new "可编辑" section with a demo labeled "可编辑对话名" and integrated a new demo path (conversations/editable).
docs/examples/conversations/editable.vue Introduced the AXConversationsEditable Vue component using the Composition API and Ant Design Vue; manages editable conversation items with interactive state toggling.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant V as AXConversationsEditable
  participant E as EditableItem

  U->>V: Clicks edit button on a conversation item
  V->>E: Activates editing mode
  E->>U: Displays input field for editing
  U->>E: Updates the conversation name (on blur/Enter)
  E-->>V: Sends updated name and exits editing mode
Loading

Poem

I hop through code in the moonlit night,
New editable features gleam so bright.
With clicks and keys, the changes sing,
Like carrots in fields, new ideas spring.
Code and whimsy, a joyous flight –
Rabbit cheers for updates done right!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

docs/examples/conversations/editable.vue

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser 'vue-eslint-parser' declared in '.eslintrc.js': Cannot find module 'vue-eslint-parser'
Require stack:

  • /.eslintrc.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Feb 26, 2025

Deploy Preview for antd-design-x-vue ready!

Name Link
🔨 Latest commit 804d1d5
🔍 Latest deploy log https://app.netlify.com/sites/antd-design-x-vue/deploys/67bf2364620e3b0008344456
😎 Deploy Preview https://deploy-preview-91--antd-design-x-vue.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
docs/examples/conversations/editable.vue (4)

10-34: Enhance accessibility and user experience of the EditableItem component

The EditableItem component implements a good editing pattern, but could benefit from several UX and accessibility improvements:

  1. The edit button lacks an accessible label
  2. The input field doesn't automatically receive focus when edit mode is activated
  3. There's no visual indication that an item is being edited beyond the input field itself

Consider applying these improvements:

const EditableItem = (props: { index: number }) => {
  const editing = ref(false);
  const label = ref(`Conversation Item ${props.index + 1}`)
+ const inputRef = ref<HTMLInputElement | null>(null);
+
+ const enableEditing = () => {
+   editing.value = true;
+   // Allow DOM to update before focusing
+   setTimeout(() => inputRef.value?.focus(), 0);
+ };

  return (
    <Flex justify="space-between" align="center" style={{ width: '100%' }}>
      {
        editing.value
        ? <Input
            v-model:value={label.value}
+           ref={inputRef}
            onBlur={() => editing.value = false}
            onPressEnter={() => editing.value = false}
+           placeholder="Enter conversation name"
          />
        : <>
            <span>{label.value}</span>
            <Button
              type="text"
              icon={<EditOutlined />}
-             onClick={() => editing.value = true}
+             onClick={enableEditing}
+             aria-label="Edit conversation name"
+             title="Edit conversation name"
            />
          </>
      }
    </Flex>
  )
}

36-40: Add visual indicator for disabled items

Currently, there's no visual cue to indicate that the 4th item is disabled.

Consider adding a visual indicator to show the disabled state:

const items: ConversationsProps['items'] = Array.from({ length: 4 }).map((_, index) => {
  const isDisabled = index === 3;
  return {
    key: `item${index + 1}`,
-   label: <EditableItem index={index} />,
+   label: isDisabled 
+     ? <Flex justify="space-between" align="center" style={{ width: '100%', opacity: '0.5' }}>
+         <span>{`Conversation Item ${index + 1}`}</span>
+         <Button type="text" icon={<EditOutlined />} disabled />
+       </Flex>
+     : <EditableItem index={index} />,
    disabled: isDisabled,
  }
});

45-49: Consider providing a shadow or border for better visual separation

The container styling could benefit from a border or shadow to provide better visual separation from the background.

const style = computed(() => ({
  width: '256px',
  background: token.value.colorBgContainer,
  borderRadius: token.value.borderRadius,
+ boxShadow: token.value.boxShadowTertiary,
+ border: `1px solid ${token.value.colorBorderSecondary}`,
}));

51-55: Implement error handling for user input

The current implementation doesn't provide feedback for empty or invalid conversation names.

Consider implementing validation to prevent empty conversation names or provide proper error handling:

<script setup lang="tsx">
import { EditOutlined } from '@ant-design/icons-vue';
- import { Button, Flex, Input, theme } from 'ant-design-vue';
+ import { Button, Flex, Input, theme, message } from 'ant-design-vue';
import { Conversations } from 'ant-design-x-vue';
import type { ConversationsProps } from 'ant-design-x-vue';
import { computed, ref } from 'vue';

// ... existing code ...

const EditableItem = (props: { index: number }) => {
  const editing = ref(false);
  const label = ref(`Conversation Item ${props.index + 1}`)
  const previousLabel = ref(label.value);
  
  const saveLabel = () => {
    if (!label.value.trim()) {
      message.error('Conversation name cannot be empty');
      label.value = previousLabel.value;
    }
    editing.value = false;
  };
  
  const startEditing = () => {
    previousLabel.value = label.value;
    editing.value = true;
  };

  return (
    <Flex justify="space-between" align="center" style={{ width: '100%' }}>
      {
        editing.value
        ? <Input
            v-model:value={label.value}
            onBlur={saveLabel}
            onPressEnter={saveLabel}
          />
        : <>
            <span>{label.value}</span>
            <Button
              type="text"
              icon={<EditOutlined />}
              onClick={startEditing}
            />
          </>
      }
    </Flex>
  )
}

// ... rest of the code ...
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9573747 and 4d0b275.

📒 Files selected for processing (2)
  • docs/component/conversations.md (1 hunks)
  • docs/examples/conversations/editable.vue (1 hunks)
🔇 Additional comments (1)
docs/component/conversations.md (1)

29-36: Documentation addition looks good!

The new "可编辑" (Editable) section follows the established pattern of the documentation, providing a clear reference to the new editable conversations demo.

@wzc520pyfm wzc520pyfm force-pushed the docs/conversation-add-editable-demo branch from 4d0b275 to 804d1d5 Compare February 26, 2025 14:21
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
docs/examples/conversations/editable.vue (4)

10-13: Add semicolon for consistency.

Missing semicolon at the end of line 12.

-  const label = ref(`Conversation Item ${props.index + 1}`)
+  const label = ref(`Conversation Item ${props.index + 1}`);

14-34: Consider accessibility improvements for the edit functionality.

The edit button lacks accessibility attributes, which makes it difficult for screen reader users to understand its purpose.

  <Button
    type="text"
    icon={<EditOutlined />}
    onClick={() => editing.value = true}
+   aria-label="Edit conversation name"
  />

Also, consider providing some visual feedback when the input is focused for better UX.


51-56: Consider adding validation before exiting edit mode.

Currently, the editing state changes immediately on blur or Enter key press without validating input. Consider adding validation to prevent empty values or applying other business rules.

const EditableItem = (props: { index: number }) => {
  const editing = ref(false);
  const label = ref(`Conversation Item ${props.index + 1}`);
+ const validateAndSave = () => {
+   if (label.value.trim()) {
+     editing.value = false;
+   }
+ };

  return (
    <Flex justify="space-between" align="center" style={{ width: '100%' }}>
      {
        editing.value
        ? <Input
            v-model:value={label.value}
-           onBlur={() => editing.value = false}
-           onPressEnter={() => editing.value = false}
+           onBlur={validateAndSave}
+           onPressEnter={validateAndSave}
          />
        : /* rest of the component */
      }
    </Flex>
  )
}

1-56: Consider extracting EditableItem to its own component for better reusability.

The EditableItem component is well-structured but would benefit from being extracted if it's intended to be reused elsewhere.

Also, if this component is part of a real application rather than just a demo, consider implementing:

  1. Error handling for edit operations
  2. State persistence between renders
  3. Event emitters to notify parent components of label changes
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d0b275 and 804d1d5.

📒 Files selected for processing (2)
  • docs/component/conversations.md (1 hunks)
  • docs/examples/conversations/editable.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/component/conversations.md
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - antd-design-x-vue
  • GitHub Check: Header rules - antd-design-x-vue
  • GitHub Check: Pages changed - antd-design-x-vue
🔇 Additional comments (4)
docs/examples/conversations/editable.vue (4)

1-7: Good choice of imports and setup structure.

The script is properly configured with TypeScript and TSX support. You've imported all necessary components from Ant Design Vue and your custom library.


8-8: Good use of defineOptions for component naming.

Explicitly naming the component helps with debugging and DevTools identification.


36-40: Good approach for item generation with appropriate disabled state handling.

Creating items with Array.from and map is clean and efficient. The disabled state for the last item demonstrates proper constraint handling.


42-49: Great use of theme tokens for consistent styling.

Using the theme token system ensures the component adapts to theme changes automatically.

@wzc520pyfm wzc520pyfm added the documentation Improvements or additions to documentation label Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant