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

fix:adjust some styles #884

Merged
merged 69 commits into from
Nov 14, 2024
Merged

Conversation

lichunn
Copy link
Contributor

@lichunn lichunn commented Oct 29, 2024

English | 简体中文

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)
  • Built its own designer, fully self-validated

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:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new tiny-popover component for help interactions, replacing the previous help box.
  • Improvements

    • Enhanced styling for various components, including MonacoEditor, StateFullscreenHead, and toolbar components, to improve visual presentation and user experience.
    • Added error handling for store name validation in CreateStore.vue.
    • Updated icon handling in the toolbar components for better robustness.
  • Bug Fixes

    • Removed hover effects for button icons in MonacoEditor to streamline interactions.
  • Chores

    • Organized styles and structure in multiple components for better maintainability.
    • Updated default icon for collaboration toolbar from 'user' to 'team-collaboration'.
    • Consolidated language-specific icon mappings into a single default entry for improved clarity.

Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

Walkthrough

This pull request introduces modifications across several Vue components, primarily focusing on enhancing styling, structure, and functionality. Key changes include the addition of an id attribute to the buttons container in MonacoEditor.vue, restructuring the help box into a tiny-popover in HelpIcon.vue, and various style adjustments in components like CreateStore.vue, CreateVariable.vue, and StateFullscreenHead.vue. Overall, the changes aim to refine the user interface and improve the organization of component templates without altering core functionalities.

Changes

File Path Change Summary
packages/common/component/MonacoEditor.vue Added id attribute to buttons container; removed hover effect from .buttons class; introduced nested styles for #icon-buttons.
packages/layout/src/ToolbarCollapse.vue Added :visible-arrow="false" prop to tiny-popover component; introduced new styles for .collapse-content and .toolbar-list-button.
packages/plugins/help/src/HelpIcon.vue Replaced help box with tiny-popover component; removed helpBox state; adjusted tooltip placement; updated styling for new layout.
packages/plugins/state/src/CreateStore.vue Organized tiny-collapse-item components; updated @change event for monaco-editor; enhanced validateName function for error handling.
packages/plugins/state/src/CreateVariable.vue Adjusted padding for .var class; added nested style for .tiny-collapse-item__content; maintained existing logic and validation.
packages/plugins/state/src/StateFullscreenHead.vue Updated <span> element to include class title; added CSS rules for .title class to enhance styling.
packages/toolbars/save/src/Main.vue Updated padding and styles for .save-style, .save-setting, and .save-time classes; improved layout organization without logic changes.
packages/common/component/ToolbarBase.vue Introduced .toolbar-item-wrap class; updated default value for options prop to ensure unique object reference.
packages/theme/base/src/base.less Added new CSS variable --te-base-rgba-27 for RGBA color definitions.
packages/theme/base/src/component-common.less Updated styles for various components including .tiny-popover, .tiny-modal, and .tiny-button to enhance visual presentation.
packages/toolbars/collaboration/meta.js Updated default icon from 'user' to 'team-collaboration'.
packages/toolbars/lang/meta.js Modified options.icon to unify language-specific icons into a single default entry of 'cn-en'.
packages/toolbars/lang/src/Main.vue Enhanced icon handling in toolbar-base component's :icon prop for improved robustness.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • hexqi
  • chilingling

🐰 In the meadow where changes bloom,
A new popover dispels the gloom.
With buttons now styled and neat,
The editors dance to a new beat.
Hopping along, we refine and play,
In our code garden, bright as the day! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5f81847 and de057b5.

📒 Files selected for processing (1)
  • packages/common/component/MonacoEditor.vue (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/common/component/MonacoEditor.vue

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.

@github-actions github-actions bot added bug Something isn't working refactor-main refactor/develop branch feature labels Oct 29, 2024
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: 4

🧹 Outside diff range and nitpick comments (5)
packages/plugins/state/src/StateFullscreenHead.vue (1)

40-44: Consider adding line-height for better vertical alignment.

The styling uses design system variables appropriately, but could benefit from explicit line-height for better vertical alignment with the close icon.

Consider adding line-height:

 .title {
   font-size: var(--te-base-font-size-base);
   color: var(--te-common-text-primary);
   font-weight: var(--te-base-font-weight-7);
+  line-height: 30px; /* Match parent's height for vertical centering */
 }

Also, could you verify if font-weight-7 is the intended weight for this title? It seems unusually heavy.

packages/plugins/state/src/CreateStore.vue (3)

Line range hint 13-29: Improve Monaco editor event handling and validation.

Several issues with the current implementation:

  1. Both @editorDidMount and @change events call the same method, which is redundant.
  2. The method name editorDidMount is misleading as it performs content validation.
  3. The validation doesn't handle JSON parse errors.

Consider this improved implementation:

 <monaco-editor
   ref="variableEditor"
   class="store-editor"
   :value="editorCode"
   :showFormatBtn="true"
   :options="{
     language: 'json',
     overviewRulerBorder: false,
     renderLineHighlightOnlyWhenFocus: true
   }"
-  @editorDidMount="editorDidMount"
-  @change="editorDidMount"
+  @editorDidMount="handleEditorMount"
+  @change="validateStateContent"
 >

And update the methods:

const validateStateContent = () => {
  try {
    const content = variableEditor.value.getEditor().getValue();
    const parsed = JSON.parse(content);
    return typeof parsed === 'object' && parsed !== null;
  } catch (e) {
    return false;
  }
};

const handleEditorMount = (editor) => {
  // Handle editor initialization if needed
};

Line range hint 142-157: Enhance store name validation.

The current validation could be improved to handle more edge cases and provide clearer error messages.

Consider enhancing the validation:

 const validateName = (rule, name, callback) => {
   let errorMessage = ''
   let isSameState = Object.keys(props.dataSource).includes(name)
+  const reservedKeywords = ['break', 'case', 'catch', 'class', 'const', 'continue',
+    'debugger', 'default', 'delete', 'do', 'else', 'export', 'extends', 'finally',
+    'for', 'function', 'if', 'import', 'in', 'instanceof', 'new', 'return', 'super',
+    'switch', 'this', 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with', 'yield']

   if (!name) {
     errorMessage = 'store 属性名称未定义'
+  } else if (reservedKeywords.includes(name)) {
+    errorMessage = 'store 属性名称不能使用 JavaScript 保留关键字'
   } else if (!verifyJsVarName(name)) {
-    errorMessage = ' store 属性名称只能以字母或下划线开头且仅包含数字字母及下划线'
+    errorMessage = name.match(/^\d/) ? 
+      'store 属性名称不能以数字开头' :
+      'store 属性名称只能包含字母、数字和下划线,且必须以字母或下划线开头'
   } else if (isSameState && (props.flag !== 'update' || name !== props.updateKey)) {
     errorMessage = '已存在同名 store 属性'
   }

   errorMessage ? callback(new Error(errorMessage)) : callback()
   emit('nameInput', errorMessage)
 }

Line range hint 187-206: Optimize state management and AST operations.

The current implementation could benefit from improved error handling and performance optimizations.

Consider these improvements:

+ import { onBeforeUnmount } from 'vue'

 const saveMethods = (editor) => {
+  try {
     const storeEditor = editor === 'gettersEditor' ? gettersEditor : actionsEditor
     let gettersMap = {}
     const editorContent = storeEditor?.value?.getEditor()?.getValue()
     const ast = string2Ast(editorContent)

     ast.program.body.forEach((declaration) => {
       const name = declaration?.id?.name
       const content = ast2String(declaration).trim()
       Object.assign(gettersMap, saveMethod({ name, content }))
     })

     return gettersMap
+  } catch (error) {
+    console.error('Failed to parse methods:', error)
+    return {}
+  }
 }

+ // Cleanup editor instances
+ onBeforeUnmount(() => {
+   variableEditor.value?.getEditor()?.dispose()
+   gettersEditor.value?.getEditor()?.dispose()
+   actionsEditor.value?.getEditor()?.dispose()
+ })
packages/plugins/help/src/HelpIcon.vue (1)

Line range hint 109-124: Consider cleanup of timer in component unmount.

The toolTipTimer should be cleared when the component is unmounted to prevent memory leaks.

Add the following cleanup:

+import { reactive, onMounted, ref, onBeforeUnmount } from 'vue'

 export default {
   // ... existing code ...
   setup() {
     // ... existing code ...
+    onBeforeUnmount(() => {
+      clearTimeout(toolTipTimer)
+    })
     // ... existing code ...
   }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 48687e8 and ebc7305.

⛔ Files ignored due to path filters (2)
  • packages/design-core/assets/full-screen.svg is excluded by !**/*.svg
  • packages/design-core/assets/全屏.svg is excluded by !**/*.svg
📒 Files selected for processing (7)
  • packages/common/component/MonacoEditor.vue (2 hunks)
  • packages/layout/src/ToolbarCollapse.vue (1 hunks)
  • packages/plugins/help/src/HelpIcon.vue (4 hunks)
  • packages/plugins/state/src/CreateStore.vue (1 hunks)
  • packages/plugins/state/src/CreateVariable.vue (2 hunks)
  • packages/plugins/state/src/StateFullscreenHead.vue (2 hunks)
  • packages/toolbars/save/src/Main.vue (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/plugins/state/src/CreateVariable.vue
🔇 Additional comments (6)
packages/plugins/state/src/StateFullscreenHead.vue (1)

3-3: LGTM! Semantic class name addition.

The addition of the "title" class name is semantic and follows good CSS naming practices.

packages/layout/src/ToolbarCollapse.vue (1)

2-2: LGTM! Verify consistent popover styling across the application.

The addition of :visible-arrow="false" to hide the popover arrow is valid and aligns with the style adjustments objective.

Let's verify if this style is consistently applied across other popover instances:

✅ Verification successful

:visible-arrow="false" is consistently used across similar hover popovers

The search results show that hiding the popover arrow is a common pattern in the codebase, particularly for hover-triggered popovers in toolbar and menu components. Examples:

  • packages/toolbars/save/src/Main.vue: :visible-arrow="false" with hover trigger
  • packages/plugins/help/src/HelpIcon.vue: :visible-arrow="false" for menu popover
  • packages/plugins/state/src/EditorI18nTool.vue: :visible-arrow="false" for tool popover

The change aligns with the established pattern in the codebase for similar UI components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if other popovers in the codebase have consistent arrow visibility settings
# Expected: Find other popover instances to ensure consistent styling

# Search for tiny-popover usage in vue files
rg -t vue 'tiny-popover' -A 2 -B 2

# Search specifically for visible-arrow prop usage
rg -t vue 'visible-arrow' -A 2 -B 2

Length of output: 126


Script:

#!/bin/bash
# Let's try without file type filtering since rg doesn't recognize .vue
# Search for tiny-popover usage
rg 'tiny-popover' -A 2 -B 2

# Search specifically for visible-arrow prop usage
rg 'visible-arrow' -A 2 -B 2

Length of output: 52395

packages/toolbars/save/src/Main.vue (1)

203-212: LGTM! Clean and consistent styling structure.

The style changes improve the visual hierarchy and spacing in the save settings popover. The padding, font sizes, and margins create a well-balanced layout.

packages/plugins/state/src/CreateStore.vue (1)

257-259: LGTM: Style adjustment improves spacing.

The removal of padding from .tiny-collapse-item__content prevents double padding since the parent wrapper already has padding, resulting in cleaner spacing.

packages/plugins/help/src/HelpIcon.vue (2)

64-64: LGTM: Component registration is correct.

The Popover component is properly imported and registered.

Also applies to: 75-75


349-349: LGTM: Style changes maintain consistency.

The styling updates properly utilize CSS variables for theming and maintain consistent spacing through the help box items.

Also applies to: 355-371

packages/common/component/MonacoEditor.vue Outdated Show resolved Hide resolved
packages/common/component/MonacoEditor.vue Outdated Show resolved Hide resolved
packages/toolbars/save/src/Main.vue Show resolved Hide resolved
packages/plugins/help/src/HelpIcon.vue Show resolved Hide resolved
@lichunn lichunn changed the title fix:adjust some styles fix:adjust some styles Oct 30, 2024
@github-actions github-actions bot removed the bug Something isn't working label Oct 30, 2024
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

🧹 Outside diff range and nitpick comments (4)
packages/toolbars/lang/src/Main.vue (2)

3-3: Consider internationalizing the tooltip text.

The hardcoded Chinese tooltip "画布中英文切换" should be internationalized since this is a language switcher component.

-    content="画布中英文切换"
+    :content="t('canvas.languageSwitcher')"

Line range hint 39-49: Consider making language options configurable.

The language options are currently hardcoded in the component. Consider making them configurable through props or configuration to:

  1. Support additional languages in the future
  2. Allow customization of labels
  3. Maintain language configurations in a central location
+    langOptions: {
+      type: Array,
+      default: () => [
+        { value: 'zh_CN', label: '中文' },
+        { value: 'en_US', label: 'English' }
+      ]
+    },
     options: {
       type: Object,
       default: () => ({})
     }
   },
   setup(props) {
     const langVal = ref('zh_CN')
     const { post, data } = useBroadcastChannel({ name: props.langChannel })
 
     watch(data, () => {
       langVal.value = data.value
     })
 
-    const langOptions = [
-      {
-        value: 'zh_CN',
-        label: '中文'
-      },
-      {
-        value: 'en_US',
-        label: 'English'
-      }
-    ]
     const changeLang = () => {
-      langVal.value = langVal.value === langOptions[0].value ? langOptions[1].value : langOptions[0].value
+      const currentIndex = props.langOptions.findIndex(opt => opt.value === langVal.value)
+      const nextIndex = (currentIndex + 1) % props.langOptions.length
+      langVal.value = props.langOptions[nextIndex].value
       post(langVal.value)
     }
packages/common/component/ToolbarBase.vue (2)

Line range hint 39-42: Fix the options prop default value.

The current default value () => {} returns undefined instead of an empty object. This could cause runtime errors when accessing properties like options.renderType or options.collapsed.

Apply this fix:

    options: {
      type: Object,
-     default: () => {}
+     default: () => ({})
    }

Default options prop needs correction to prevent runtime errors

The options prop default value is incorrectly set to () => {} which returns undefined. This causes potential runtime errors in getRender() when accessing props.options.renderType. The default value should be an empty object () => ({}).

  • packages/common/component/ToolbarBase.vue:33: Change default value of options prop from () => {} to () => ({})
🔗 Analysis chain

Line range hint 8-8: Verify error handling in getRender function.

The getRender function assumes props.options is always an object when accessing props.options.renderType. With the current default value issue, this could lead to runtime errors.

Let's verify if there are any error cases in the codebase:

Also applies to: 41-56

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for ToolbarBase usage without options prop
# or with invalid renderType values

# Search for ToolbarBase component usage
rg -A 3 '<(?:ToolbarBase|toolbar-base)' 

# Search for any error handling related to ToolbarBase rendering
rg -A 3 'renderType.*(?:error|catch|try|handle)'

Length of output: 4255


Script:

#!/bin/bash
# Let's check the implementation of getRender function and its error handling
ast-grep --pattern 'getRender() {
  $$$
}'

# Also check for any default props or options initialization
ast-grep --pattern 'props: {
  $$$
}'

# And check for any renderType related code
rg -A 3 'renderType'

Length of output: 2904


Script:

#!/bin/bash
# Let's check the complete ToolbarBase.vue file to understand the props definition and default values
cat packages/common/component/ToolbarBase.vue

# Also check if there are any default options in the meta files
rg -l 'export default' packages/toolbars/*/meta.js | xargs cat

Length of output: 5150

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ebc7305 and 5f81847.

⛔ Files ignored due to path filters (3)
  • packages/design-core/assets/cn-en.svg is excluded by !**/*.svg
  • packages/design-core/assets/refresh.svg is excluded by !**/*.svg
  • packages/design-core/assets/team-collaboration.svg is excluded by !**/*.svg
📒 Files selected for processing (8)
  • packages/common/component/ToolbarBase.vue (1 hunks)
  • packages/layout/src/ToolbarCollapse.vue (2 hunks)
  • packages/theme/base/src/base.less (1 hunks)
  • packages/theme/base/src/component-common.less (1 hunks)
  • packages/toolbars/collaboration/meta.js (1 hunks)
  • packages/toolbars/lang/meta.js (1 hunks)
  • packages/toolbars/lang/src/Main.vue (1 hunks)
  • packages/toolbars/save/src/Main.vue (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/theme/base/src/base.less
  • packages/toolbars/collaboration/meta.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/layout/src/ToolbarCollapse.vue
  • packages/toolbars/save/src/Main.vue
🔇 Additional comments (4)
packages/toolbars/lang/meta.js (1)

7-7: LGTM! Verify the new icon asset exists.

The consolidation of language icons into a single combined icon is a good UI optimization.

Let's verify the existence of the new icon asset:

✅ Verification successful

Icon asset verified: cn-en.svg exists in design-core assets

The new combined language icon asset cn-en.svg is present at packages/design-core/assets/cn-en.svg, confirming that the icon configuration change is properly supported by the required asset.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the new combined language icon asset exists
# Expected: Find references to the 'cn-en' icon in asset files or style definitions

# Search for the icon in asset files
fd -e svg -e png -e jpg -e jpeg . | rg -i "cn-en"

# Search for the icon name in style files
rg -t css -t scss -t less "cn-en"

Length of output: 150

packages/toolbars/lang/src/Main.vue (1)

4-4: LGTM: Robust icon fallback implementation.

The fallback mechanism options.icon.default || options.icon ensures graceful handling of icon configuration.

packages/common/component/ToolbarBase.vue (1)

74-77: LGTM! Clean and semantic CSS implementation.

The new flexbox layout provides proper vertical alignment for toolbar items.

packages/theme/base/src/component-common.less (1)

463-465: LGTM! Clean popover styling update.

The removal of the border in favor of a box-shadow creates a more modern, floating appearance for the popover component. The use of CSS variables maintains consistency with the design system.

@hexqi hexqi merged commit ef582f8 into opentiny:refactor/develop Nov 14, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor-main refactor/develop branch feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants