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

BA-2387: activity log storybook #248

Merged
merged 2 commits into from
Apr 1, 2025
Merged

Conversation

rafaelhdr
Copy link
Contributor

@rafaelhdr rafaelhdr commented Mar 27, 2025

Storybook for Activity Log components

Loom: https://www.loom.com/share/8596c6e240e7483787ba5ffa07fd208b?sid=07586109-e865-433a-8df8-cf28f89fdfd3

Summary by CodeRabbit

  • Documentation

    • Added comprehensive guides for the LogGroups, LogItem, and ActivityLogComponent, detailing usage, props, and examples.
  • New Features

    • Introduced demonstration stories for LogGroups, LogItem, and ActivityLog, showcasing their functionalities and interactions.
    • Added a new component ActivityLogWithQuery for fetching and displaying activity log data dynamically.

Copy link

changeset-bot bot commented Mar 27, 2025

⚠️ No Changeset found

Latest commit: deb6e31

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

coderabbitai bot commented Mar 27, 2025

Walkthrough

This pull request introduces new Storybook documentation and story files for the activity log components. Detailed documentation for the LogGroups, LogItem, and ActivityLogComponent is now available in MDX format, alongside corresponding Storybook stories. Additionally, a new component ActivityLogWithQuery has been added for fetching data via a GraphQL query, complemented by a mock data resolver file for testing purposes.

Changes

File(s) Change Summary
packages/.../LogGroups/__storybook__/LogGroups.mdx
packages/.../LogGroups/__storybook__/stories.tsx
Added Storybook documentation and story for the LogGroups component with prop details and usage examples.
packages/.../LogItem/__storybook__/LogItem.mdx
packages/.../LogItem/__storybook__/stories.tsx
Introduced Storybook documentation and story for the LogItem component, outlining props and functionalities such as editing and reactions.
packages/.../ActivityLogComponent/__storybook__/ActivityLog.mdx
packages/.../ActivityLogComponent/__storybook__/ActivityLogWithQuery.tsx
packages/.../ActivityLogComponent/__storybook__/mockResolvers.ts
packages/.../ActivityLogComponent/__storybook__/stories.tsx
Added documentation for the ActivityLogComponent, a new query-enabled component (ActivityLogWithQuery) utilizing GraphQL via Relay, and a mock resolvers file to simulate API data in Storybook.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant ALQ as ActivityLogWithQuery
  participant API as GraphQL API
  participant AL as ActivityLog

  U->>ALQ: Render Activity Log view
  ALQ->>API: Execute GraphQL query (useLazyLoadQuery)
  API-->>ALQ: Return activity logs data
  ALQ->>AL: Pass queryRef with data
  AL->>U: Display grouped activity logs
Loading

Suggested reviewers

  • anicioalexandre
  • deboracosilveira
  • ficast
  • mathieubouhelier

Poem

Oh, what a joy to hop along,
In a world of logs and queries strong!
Carrots of code and trails anew,
A Storybook tale in every view.
With hops of change and bytes in glee,
This rabbit cheers—let's code and be free!
🐰🥕

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.

packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/mockResolvers.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /packages/components/.eslintrc.js
Error: Cannot find module '@baseapp-frontend/config/.eslintrc-with-restricted-paths.js'
Require stack:

  • /packages/components/.eslintrc.js
  • /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/packages/components/.eslintrc.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c68db9b and deb6e31.

📒 Files selected for processing (1)
  • packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/mockResolvers.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/components/modules/activity-log/web/ActivityLogComponent/storybook/mockResolvers.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Component Test Packages

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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

@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

🧹 Nitpick comments (11)
packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/ActivityLogWithQuery.tsx (1)

8-12: Consider adding more information to the Relay test operation

The GraphQL query is correctly marked with @relay_test_operation, but you might want to add a descriptive name or comment to clarify its purpose in test environments.

packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/stories.tsx (2)

7-10: Story component and declared type don't match

The meta object declares ActivityLog as the component type, but sets ActivityLogWithQuery as the actual component to render. While this works functionally (since ActivityLogWithQuery renders ActivityLog), it's better to align the type declaration with the actual component being rendered.

-const meta: Meta<typeof ActivityLog> = {
+const meta: Meta<typeof ActivityLogWithQuery> = {
  title: '@baseapp-frontend | components/ActivityLog/ActivityLog',
  component: ActivityLogWithQuery,
}

16-21: Story name inconsistent with component

The story is named DefaultLogItem but it's actually for the ActivityLog component. This could be confusing since there's also a LogItem component in the system. Consider renaming it to DefaultActivityLog for clarity.

export const DefaultLogItem: Story = {
-  name: 'Default ActivityLog',
+  name: 'Default ActivityLog',
  parameters: {
    mockData,
  },
}

And rename the export as well:

-export const DefaultLogItem: Story = {
+export const DefaultActivityLog: Story = {
  name: 'Default ActivityLog',
  parameters: {
    mockData,
  },
}
packages/components/modules/activity-log/web/ActivityLogComponent/LogItem/__storybook__/stories.tsx (1)

36-38: Consider making avatar URLs consistent across mock data

The avatar URL uses a generic placeholder service. For consistency with the mock data in other stories and resolvers, consider using the same URL pattern or service across all mock data files.

packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/mockResolvers.ts (1)

1-308: Consider organizing mock data into smaller, focused sets

The mock data file is quite large with many repetitive entries. Consider organizing it into smaller, reusable datasets or extracting helper functions to generate mock entries. This would make the file more maintainable.

// Example approach
const createMockUser = (id: string, name: string, email: string, avatarUrl?: string) => ({
  id,
  fullName: name,
  email,
  avatar: avatarUrl ? { url: avatarUrl } : null,
});

const createMockLogEntry = (id: string, verb: string, createdAt: string, user: any, cursor: string) => ({
  node: {
    id,
    createdAt,
    verb,
    url: '/graphql',
    user,
    __typename: 'ActivityLog',
  },
  cursor,
});

// Then use these helpers to create your mock data
export const mockData = {
  data: {
    activityLogs: {
      edges: [
        createMockLogEntry(
          'QWN0aXZpdHlMb2c6NWQ1NDA4M2UtZjRkOS00MzQ4LWJmM2ItN2YwMzBiZjgwYThl',
          'baseapp_reactions.add_reaction',
          '2025-03-09T10:11:00.395806+00:00',
          createMockUser('VXNlcjozOQ==', 'Activity Lok', 'll+act2@tsl.io', 'https://nyc3.digitaloceanspaces.com/baseapp-db-staging/media/profile_images/2162b9f5-3c50-4b45-8d33-9fdb28f5dee4.JPG.48x48_q85.jpg'),
          'YXJyYXljb25uZWN0aW9uOjc0'
        ),
        // Additional entries...
      ],
      pageInfo: {
        endCursor: 'YXJyYXljb25uZWN0aW9uOjkz',
        hasNextPage: false,
      },
    },
  },
};
packages/components/modules/activity-log/web/ActivityLogComponent/LogGroups/__storybook__/stories.tsx (1)

14-16: Story name mismatch with component

The story is named DefaultLogItem but it's demonstrating the LogGroups component. This naming mismatch can be confusing for developers browsing the Storybook.

-export const DefaultLogItem: Story = {
-  name: 'Default LogGroups',
+export const DefaultLogGroups: Story = {
+  name: 'Default LogGroups',
packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/ActivityLog.mdx (1)

9-9: Add a comma for improved readability

There should be a comma after "activity log groups" to properly separate the clauses in this sentence.

-A component that renders the activity log groups allowing the user to search by user and filter by periods.
+A component that renders the activity log groups, allowing the user to search by user and filter by periods.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~9-~9: Possible missing comma found.
Context: ...component that renders the activity log groups allowing the user to search by user and...

(AI_HYDRA_LEO_MISSING_COMMA)

packages/components/modules/activity-log/web/ActivityLogComponent/LogItem/__storybook__/LogItem.mdx (1)

10-11: Redundant "Expected Behavior" entries

There are two separate entries for "Expected Behavior" which is redundant. Consider combining them or using bullet points to differentiate between the behaviors.

-Expected Behavior**: Displays comment content with the author's avatar and name, allows editing and deleting (if permitted), supports reactions and replies, and can expand/collapse nested replies.
-- **Expected Behavior**: Displays single log based on the verb passed to it.
+Expected Behavior**: 
+  - Displays comment content with the author's avatar and name, allows editing and deleting (if permitted), supports reactions and replies, and can expand/collapse nested replies.
+  - Displays single log based on the verb passed to it.
packages/components/modules/activity-log/web/ActivityLogComponent/LogGroups/__storybook__/LogGroups.mdx (3)

10-10: Improve grammatical structure

The sentence has a few grammatical issues that should be corrected for clarity.

-Displays array of log groups. A group is intended to group activities happening in close times, instead of just display each one (similar to how Slack does it).
+Displays array of log groups. A group is intended to group activities happening at close times, instead of just displaying each one (similar to how Slack does it).
🧰 Tools
🪛 LanguageTool

[uncategorized] ~10-~10: The preposition “at” seems more likely in this position than the preposition “in”.
Context: ... intended to group activities happening in close times, instead of just display ea...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_IN_AT)


[uncategorized] ~10-~10: This verb may not be in the correct form. Consider using a different form for this context.
Context: ...ppening in close times, instead of just display each one (similar to how Slack does it)...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)


18-18: Correct pluralization in prop description

Since you're describing a list of items, "reference" should be plural.

-**logGroups** (LogGroup[]): List of relay fragment reference for log items.
+**logGroups** (LogGroup[]): List of relay fragment references for log items.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~18-~18: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...** (LogGroup[]): List of relay fragment reference for log items. - LoadingState (FC):...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)


52-52: Component name mismatch in example

The example defines a component named MyComponent but exports ActivityLogComponent. This mismatch could cause confusion.

-export default ActivityLogComponent
+export default MyComponent
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 39bf260 and c68db9b.

⛔ Files ignored due to path filters (1)
  • packages/components/__generated__/ActivityLogsFragment.graphql.ts is excluded by !**/__generated__/**
📒 Files selected for processing (8)
  • packages/components/modules/activity-log/web/ActivityLogComponent/LogGroups/__storybook__/LogGroups.mdx (1 hunks)
  • packages/components/modules/activity-log/web/ActivityLogComponent/LogGroups/__storybook__/stories.tsx (1 hunks)
  • packages/components/modules/activity-log/web/ActivityLogComponent/LogItem/__storybook__/LogItem.mdx (1 hunks)
  • packages/components/modules/activity-log/web/ActivityLogComponent/LogItem/__storybook__/stories.tsx (1 hunks)
  • packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/ActivityLog.mdx (1 hunks)
  • packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/ActivityLogWithQuery.tsx (1 hunks)
  • packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/mockResolvers.ts (1 hunks)
  • packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/stories.tsx (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
packages/components/modules/activity-log/web/ActivityLogComponent/LogItem/__storybook__/stories.tsx (2)
packages/components/modules/activity-log/web/ActivityLogComponent/LogGroups/__storybook__/stories.tsx (1)
  • DefaultLogItem (14-66)
packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/stories.tsx (1)
  • DefaultLogItem (16-21)
packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/stories.tsx (2)
packages/components/modules/activity-log/web/ActivityLogComponent/LogItem/__storybook__/stories.tsx (1)
  • DefaultLogItem (14-42)
packages/components/modules/activity-log/web/ActivityLogComponent/LogGroups/__storybook__/stories.tsx (1)
  • DefaultLogItem (14-66)
🪛 LanguageTool
packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/ActivityLog.mdx

[uncategorized] ~9-~9: Possible missing comma found.
Context: ...component that renders the activity log groups allowing the user to search by user and...

(AI_HYDRA_LEO_MISSING_COMMA)

packages/components/modules/activity-log/web/ActivityLogComponent/LogGroups/__storybook__/LogGroups.mdx

[uncategorized] ~10-~10: The preposition “at” seems more likely in this position than the preposition “in”.
Context: ... intended to group activities happening in close times, instead of just display ea...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_IN_AT)


[uncategorized] ~10-~10: This verb may not be in the correct form. Consider using a different form for this context.
Context: ...ppening in close times, instead of just display each one (similar to how Slack does it)...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)


[uncategorized] ~18-~18: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...** (LogGroup[]): List of relay fragment reference for log items. - LoadingState (FC):...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)

🔇 Additional comments (4)
packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/ActivityLogWithQuery.tsx (1)

7-16: Well-implemented wrapper component for activity logs!

This component correctly wraps the ActivityLog component with a GraphQL query using useLazyLoadQuery. The implementation follows React-Relay patterns by defining a GraphQL fragment query and passing the retrieved data to the underlying component.

packages/components/modules/activity-log/web/ActivityLogComponent/LogItem/__storybook__/stories.tsx (1)

14-42: Well-structured LogItem story with good mock data

The story provides a complete set of mock data that demonstrates all the important properties of a LogItem. The use of placeholder images and realistic data values makes this a good example for documentation.

packages/components/modules/activity-log/web/ActivityLogComponent/__storybook__/mockResolvers.ts (2)

1-308: Comprehensive mock data for activity logs

The mock data covers a good range of scenarios with different users, timestamps, and activity types. This will be useful for testing and demonstrating the component's capabilities.


301-305: Pagination mock is well-structured

The inclusion of pageInfo with endCursor and hasNextPage properties is excellent - it properly simulates GraphQL pagination which will be important for testing infinite scrolling or "load more" functionality.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
64.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@rafaelhdr rafaelhdr merged commit 6d2a87d into master Apr 1, 2025
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants