Skip to content
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

feat(bulletin-board): [bulletin-board] Add click events #2143 #2601

Merged
merged 4 commits into from
Dec 3, 2024

Conversation

wuyiping0628
Copy link
Collaborator

@wuyiping0628 wuyiping0628 commented Dec 3, 2024

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #2143

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new interactive bulletin board component with enhanced data structure and user click events.
    • Added support for click events that trigger modals displaying item details.
    • Expanded API with new props for better customization of the bulletin board component.
    • Added a new demo for click event functionality.
  • Bug Fixes

    • Improved type safety for data properties in the bulletin board component.
  • Documentation

    • Localized descriptions for the new demo added.
  • Style

    • Enhanced UI feedback with cursor changes for interactive elements.
  • Tests

    • Added new test cases to ensure click event functionality works as expected.

@wuyiping0628 wuyiping0628 added the enhancement New feature or request label Dec 3, 2024
Copy link

coderabbitai bot commented Dec 3, 2024

Walkthrough

The changes in this pull request involve significant updates to the bulletin-board component's API, including a more specific data type and the introduction of a new click event. New Vue components utilizing the Composition API have been created to display bulletin entries and handle user interactions. Additionally, tests have been added to ensure functionality, and the overall structure of related files has been refined for clarity and usability.

Changes

File Path Change Summary
examples/sites/demos/apis/bulletin-board.js Updated data property type from Array to BulletinBoardData[], added typeAnchorName, introduced contentClick event, and defined BulletinBoardData interface.
examples/sites/demos/pc/app/bulletin-board/events-composition-api.vue Added new <tiny-bulletin-board> component with props and contentClick function to manage click events.
examples/sites/demos/pc/app/bulletin-board/events.spec.ts Introduced a test case for click event functionality in the bulletin board application using Playwright.
examples/sites/demos/pc/app/bulletin-board/events.vue Added new tiny-bulletin-board component, defined tabTitle and data properties, and implemented contentClick method for user interaction.
examples/sites/demos/pc/app/bulletin-board/webdoc/bulletin-board.js Added new demo entry with demoId: 'events', localized names and descriptions, and associated it with events.vue.
packages/renderless/src/bulletin-board/index.ts Introduced handleBulletinBoardClick function for handling click events on bulletin board items.
packages/renderless/src/bulletin-board/vue.ts Updated to include handleBulletinBoardClick in the public API and modified function signature for event emission.
packages/theme/src/bulletin-board/index.less Added cursor: pointer; to .bulletin-board__item .bulletin-board__textTitle for improved UI interaction feedback.
packages/vue/src/bulletin-board/src/pc.vue Updated template to add click event handlers to both anchor and span elements and expanded component props to include new properties.

Possibly related PRs

Suggested reviewers

  • zzcr

Poem

In the garden of boards, we hop and play,
With clicks and events brightening the day.
A bulletin blooms, with data so neat,
Each click brings a message, oh, what a treat!
So gather 'round, friends, let’s share and explore,
The joy of our changes, forevermore! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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.

@wuyiping0628 wuyiping0628 changed the title feat(bulletin-board): [bulletin-board] Add click events feat(bulletin-board): [bulletin-board] Add click events #2143 Dec 3, 2024
Copy link

@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: 3

🧹 Outside diff range and nitpick comments (11)
examples/sites/demos/pc/app/bulletin-board/events.spec.ts (1)

3-11: Test coverage could be enhanced

While the basic click event test is good, consider adding:

  1. Multiple test cases with different bulletin items
  2. Negative test cases (e.g., disabled items)
  3. Modal dismissal verification
 test('测试点击事件', async ({ page }) => {
   page.on('pageerror', (exception) => expect(exception).toBeNull())
   await page.goto('bulletin-board#events')
   const demo = page.locator('#events')
   const modal = page.locator('.tiny-modal')

   await demo.getByRole('link', { name: 'TINY v2.1.3 版本' }).click()
   await expect(modal.getByText('click 事件:内容为TINY v2.1.3 版本')).toBeVisible()
+  
+  // Test multiple items
+  await demo.getByRole('link', { name: 'Another Item' }).click()
+  await expect(modal.getByText('click 事件:内容为Another Item')).toBeVisible()
+  
+  // Verify modal can be dismissed
+  await page.keyboard.press('Escape')
+  await expect(modal).not.toBeVisible()
 })
packages/renderless/src/bulletin-board/index.ts (1)

38-42: Add TypeScript types for better type safety

The click handler would benefit from explicit TypeScript types for better maintainability and type checking.

+interface BulletinBoardItem {
+  url?: string;
+  content: string;
+  [key: string]: any;
+}

 export const handleBulletinBoardClick =
-  ({ emit }) =>
-  (item) => {
+  ({ emit }: { emit: (event: string, item: BulletinBoardItem) => void }) =>
+  (item: BulletinBoardItem) => {
     emit('handleClick', item)
   }
packages/renderless/src/bulletin-board/vue.ts (2)

13-15: Add JSDoc documentation for the new API

The new handleBulletinBoardClick API should be documented for better developer experience.

+/**
+ * @typedef {Object} BulletinBoardItem
+ * @property {string} [url] - Optional URL for the bulletin item
+ * @property {string} content - Content of the bulletin item
+ */

+/**
+ * @type {string[]} api - List of exposed API methods
+ * @property {string} handleBulletinBoardClick - Event handler for bulletin item clicks
+ */
 export const api = ['state', 'getRoute', 'handleBulletinBoardClick']

17-17: Document the emit event contract

Add documentation for the event emission contract to help consumers understand the expected payload.

+/**
+ * @typedef {Object} RenderlessProps
+ * @property {string} activeName - Currently active bulletin name
+ * @property {Array<BulletinBoardItem[]>} data - Bulletin board data
+ */

+/**
+ * Renderless function for bulletin board component
+ * @param {RenderlessProps} props - Component props
+ * @param {Object} context - Vue composition API context
+ * @param {Object} hooks - Component hooks
+ * @param {Function} hooks.emit - Event emitter that triggers 'handleClick' with BulletinBoardItem
+ */
 export const renderless = (props, { reactive, computed, watch }, { emit }) => {

Also applies to: 37-38

examples/sites/demos/pc/app/bulletin-board/events-composition-api.vue (1)

89-94: Enhance click handler with type safety

The click handler should include type information for better maintainability and IDE support.

-function handleClick(item) {
+interface BulletinItem {
+  text: string;
+  date?: string;
+  url?: string;
+  target?: string;
+  route?: string;
+}
+
+function handleClick(item: BulletinItem) {
   TinyModal.message({
     message: 'click 事件:内容为' + item.text,
     status: 'info'
   })
 }
examples/sites/demos/pc/app/bulletin-board/events.vue (1)

97-102: Consider extracting message text to constants

The message text is hardcoded in both components. Consider extracting it to a shared constant or i18n key.

+const CLICK_MESSAGE_PREFIX = 'click 事件:内容为';
+
 methods: {
   handleClick(item) {
     TinyModal.message({
-      message: 'click 事件:内容为' + item.text,
+      message: CLICK_MESSAGE_PREFIX + item.text,
       status: 'info'
     })
   }
 }
packages/vue/src/bulletin-board/src/pc.vue (2)

Line range hint 35-41: Enhance accessibility for non-link clickable elements

The span element that acts as a clickable item should have proper accessibility attributes.

- <span v-else class="tiny-bulletin-board__textTitle" @click.native="handleBulletinBoardClick(subItem)">
+ <span
+   v-else
+   class="tiny-bulletin-board__textTitle"
+   @click="handleBulletinBoardClick(subItem)"
+   role="button"
+   tabindex="0"
+   @keydown.enter="handleBulletinBoardClick(subItem)"
+ >

Line range hint 28-41: Consider keyboard navigation for bulletin items

The bulletin board should support keyboard navigation between items for better accessibility.

Consider implementing:

  1. Arrow key navigation between items
  2. Focus management
  3. ARIA attributes for the current item
    Would you like me to help create an issue for tracking these accessibility improvements?
examples/sites/demos/apis/bulletin-board.js (1)

109-120: Consider enhancing the BulletinBoardData interface documentation

While the interface is well-structured, the comments could be improved for better clarity.

Consider updating the interface documentation:

 interface BulletinBoardData {
-  text: string // 显示文本
-  date: string // 日期
-  url: string // 需要跳转的地址
-  target: string // <a> 标签的一个属性,该属性指定在何处显示链接的资源
+  text: string   // Display text for the bulletin item
+  date: string   // Publication date of the bulletin
+  url?: string   // Optional URL for redirection when clicked
+  target?: string // Optional target attribute for URL opening behavior (_blank, _self, etc.)
 }
examples/sites/demos/pc/app/bulletin-board/webdoc/bulletin-board.js (2)

109-118: Consider improving English translation

While the demo entry is well-structured, the English translation could be more natural.

Consider updating the English text:

 name: {
   'zh-CN': 'click事件',
-  'en-US': 'Fold panel click event'
+  'en-US': 'Click Event'
 },
 desc: {
   'zh-CN': '<p>当点击后会触发触发 <code>click</code> 事件。</p>',
-  'en-US': '<p>When clicked, it will trigger<code>click</code>. </p>'
+  'en-US': '<p>Triggers the <code>click</code> event when a bulletin item is clicked.</p>'
 }

115-115: Fix typo in Chinese description

There's a duplicate word "触发" in the Chinese description.

-'zh-CN': '<p>当点击后会触发触发 <code>click</code> 事件。</p>',
+'zh-CN': '<p>当点击后会触发 <code>click</code> 事件。</p>',
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between da4f7fa and 494c225.

📒 Files selected for processing (9)
  • examples/sites/demos/apis/bulletin-board.js (2 hunks)
  • examples/sites/demos/pc/app/bulletin-board/events-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/bulletin-board/events.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/bulletin-board/events.vue (1 hunks)
  • examples/sites/demos/pc/app/bulletin-board/webdoc/bulletin-board.js (1 hunks)
  • packages/renderless/src/bulletin-board/index.ts (1 hunks)
  • packages/renderless/src/bulletin-board/vue.ts (2 hunks)
  • packages/theme/src/bulletin-board/index.less (1 hunks)
  • packages/vue/src/bulletin-board/src/pc.vue (1 hunks)
🔇 Additional comments (5)
packages/renderless/src/bulletin-board/vue.ts (1)

Line range hint 17-42: Verify event handling in component usage

Let's verify that the click event is properly handled in component implementations.

✅ Verification successful

Event handling implementation is properly integrated

The verification shows that event handling is correctly implemented:

  • The component properly emits click events via handleBulletinBoardClick for both URL and non-URL items
  • Event handling is consistently implemented across different usage patterns (basic, composition API)
  • The click handler is properly bound with .native modifier where needed
  • Example implementations demonstrate correct event binding with @handleClick
  • The component supports both URL navigation and route-based navigation with proper click handling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check component implementations for proper event handling

# Find all Vue files using the bulletin-board component
echo "Checking component usage patterns..."
rg -l "tiny-bulletin-board" --type vue

# Check for proper event handling
echo "\nChecking event handler implementation..."
rg "@handleClick" --type vue -A 2

Length of output: 306


Script:

#!/bin/bash
# Let's try a different approach to find component usage and event handling

# Find files containing bulletin-board references
echo "Searching for bulletin-board component usage..."
rg -l "bulletin-board"

# After finding files, let's check their content for event handling
echo "\nChecking event handler implementations..."
rg -p "bulletin-board.*@" -A 3

Length of output: 8018


Script:

#!/bin/bash
# Let's examine the event handling implementation in more detail

# Check the test files for event handling verification
echo "Checking test implementations..."
rg -p "handleClick" examples/sites/demos/pc/app/bulletin-board/events.spec.ts -A 5

# Check the actual component implementation
echo "\nChecking component implementation..."
cat packages/vue/src/bulletin-board/src/pc.vue

# Check for any additional event handling in the base demo
echo "\nChecking base implementation..."
cat examples/sites/demos/pc/app/bulletin-board/base.vue

Length of output: 6091

examples/sites/demos/pc/app/bulletin-board/events.vue (1)

1-2: Event handler naming inconsistency

Same issue as in the Composition API version - event handler name should be @click instead of @handleClick.

examples/sites/demos/apis/bulletin-board.js (2)

21-26: LGTM! Type safety improvement

The change from generic Array to strongly-typed BulletinBoardData[] improves type safety and developer experience.


91-102: LGTM! Well-defined click event

The click event is well-defined with proper typing and clear documentation in both languages.

packages/theme/src/bulletin-board/index.less (1)

34-34: LGTM! Improved user interaction feedback

The addition of cursor: pointer provides appropriate visual feedback for the new click functionality.

Copy link

@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: 1

🧹 Outside diff range and nitpick comments (1)
examples/sites/demos/apis/bulletin-board.js (1)

21-26: Enhance the data property descriptions

While the type specification is now more precise with BulletinBoardData[], the descriptions could be more informative by including:

  • The purpose of the data
  • Required/optional fields
  • Example usage

Consider updating the descriptions to:

-  'zh-CN': 'tab-item 数据;',
-  'en-US': 'tab-item data;'
+  'zh-CN': '公告栏数据列表,每项包含文本内容(text)、日期(date)、链接(url)和打开方式(target)',
+  'en-US': 'Bulletin board data list. Each item contains text content, date, URL, and target attribute for link behavior'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 494c225 and acf1191.

📒 Files selected for processing (2)
  • examples/sites/demos/apis/bulletin-board.js (2 hunks)
  • packages/vue/src/bulletin-board/src/pc.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/vue/src/bulletin-board/src/pc.vue
🔇 Additional comments (2)
examples/sites/demos/apis/bulletin-board.js (2)

91-103: LGTM! Well-structured event definition

The handleClick event is well-defined with:

  • Clear type signature using BulletinBoardData
  • Descriptive documentation in both languages
  • Proper demo reference

Line range hint 1-122: Verify API changes against PR objectives

The changes align with the PR objective of adding click events to the bulletin board. However, let's verify the integration with existing code to ensure backward compatibility.

✅ Verification successful

API changes are consistent and backward compatible

The verification shows that:

  • The handleClick event is already implemented and used in existing demo files (events.vue and events-composition-api.vue)
  • The API documentation in bulletin-board.js correctly reflects the existing implementation
  • The event handler follows the same pattern across both traditional and composition API usage
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for existing usage of bulletin-board component to ensure changes don't break existing code

# Search for bulletin-board component usage
echo "Checking bulletin-board component usage patterns..."
rg -l "tiny-bulletin-board" --type vue

# Search for any existing click handlers
echo "Checking existing click handler patterns..."
rg "(@click|v-on:click|handleClick).*bulletin" --type vue

Length of output: 364


Script:

#!/bin/bash
# Description: Check for existing usage of bulletin-board component and click handlers with broader search

# Search for bulletin-board component usage in all files
echo "Checking bulletin-board component usage patterns..."
rg -l "bulletin-board"

# Search for demo files related to bulletin board
echo "Checking demo files..."
fd "bulletin.*\.(vue|jsx?|tsx?)"

# Search for any existing click handlers related to bulletin
echo "Checking existing click handler patterns..."
rg "(@click|v-on:click|handleClick).*bulletin"

Length of output: 6537

examples/sites/demos/apis/bulletin-board.js Show resolved Hide resolved
Copy link

@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

🧹 Outside diff range and nitpick comments (3)
examples/sites/demos/pc/app/bulletin-board/events-composition-api.vue (2)

10-88: Consider adding type annotations for reactive refs

While the code works, adding type annotations would improve maintainability and provide better IDE support.

-const tabTitle = ref(['TINY 更新日志', '他们都在用', 'TINY 特性'])
+const tabTitle = ref<string[]>(['TINY 更新日志', '他们都在用', 'TINY 特性'])
-const data = ref([
+const data = ref<BulletinBoardData[][]>([

89-94: Add error handling to contentClick function

Consider adding error handling to manage cases where item properties might be undefined.

 function contentClick(item) {
+  if (!item?.text) {
+    console.warn('Invalid item clicked')
+    return
+  }
   TinyModal.message({
     message: '触发 contentClick 事件:内容为' + item.text,
     status: 'info'
   })
 }
examples/sites/demos/apis/bulletin-board.js (1)

21-26: Enhance data property documentation

The current description is too brief. Consider adding more details about the data structure and usage.

   desc: {
-    'zh-CN': 'tab-item 数据;',
-    'en-US': 'tab-item data;'
+    'zh-CN': 'tab-item 数据,每个数组项代表一个标签页的内容列表,内容项需符合 BulletinBoardData 接口定义',
+    'en-US': 'tab-item data, each array item represents a content list for a tab, content items should conform to BulletinBoardData interface'
   },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between acf1191 and e57af4d.

📒 Files selected for processing (5)
  • examples/sites/demos/apis/bulletin-board.js (2 hunks)
  • examples/sites/demos/pc/app/bulletin-board/events-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/bulletin-board/events.vue (1 hunks)
  • examples/sites/demos/pc/app/bulletin-board/webdoc/bulletin-board.js (1 hunks)
  • packages/renderless/src/bulletin-board/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/renderless/src/bulletin-board/index.ts
  • examples/sites/demos/pc/app/bulletin-board/events.vue
  • examples/sites/demos/pc/app/bulletin-board/webdoc/bulletin-board.js
🔇 Additional comments (4)
examples/sites/demos/pc/app/bulletin-board/events-composition-api.vue (2)

1-3: LGTM! Template structure and event binding are correct.

The component usage follows Vue.js best practices with proper prop binding and event handling.


15-15: Security: URLs should use HTTPS

Several URLs in the data are using either HTTP or localhost. For production examples, use HTTPS URLs to demonstrate secure practices.

Also applies to: 20-20, 25-25, 33-33, 38-38, 44-44, 49-49, 55-55, 61-61

examples/sites/demos/apis/bulletin-board.js (2)

91-105: LGTM! Event definition is well documented

The contentClick event is properly defined with:

  • Clear type definition
  • Bilingual descriptions
  • Version metadata

111-123: Improve the interface definition

The BulletinBoardData interface needs the following improvements:

  1. Add bilingual comments
  2. Specify types for all fields
  3. Fix code formatting

@zzcr zzcr merged commit 070997f into opentiny:dev Dec 3, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants