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: merge preview entry with index entry #581

Draft
wants to merge 2 commits into
base: refactor/develop
Choose a base branch
from

Conversation

chilingling
Copy link
Member

@chilingling chilingling commented Jun 15, 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

  • New Features

    • Updated favicon and webpage title for a refreshed look.
  • Bug Fixes

    • Simplified URL construction in preview mode for consistent behavior.
  • Refactor

    • Cleaned HTML inclusion configuration, focusing only on index.html.
    • Updated component imports in Toolbar.vue for more efficient usage.

Copy link
Contributor

coderabbitai bot commented Jun 15, 2024

Walkthrough

The recent update encompasses modifications to various packages, notably centered around simplifying the preview logic, altering HTML inclusions in the build config, and refining component imports within the Toolbar.vue. These changes enhance code maintainability by streamlining configurations, updating imports, and adjusting the logic to remove unnecessary preview functionality across different files.

Changes

File Change Summary
designer-demo/index.html Updated favicon link and webpage title
packages/.../src/default-config.js Removed preview.html from the input and updated includeHtmls array to include only index.html
packages/controller/js/preview.js Commented out isDevelopEnv import and simplified openUrl construction to always use ${href}/preview?tenant=${tenant}#${hashString}
packages/design-core/index.js Removed export of initPreview
packages/design-core/src/init.js Added import for initPreview and adjusted export functions to conditionally call based on URL path
packages/.../preview/src/Toolbar.vue Restructured component imports to use entry properties instead of component

Sequence Diagrams

sequenceDiagram
    participant User
    participant App
    participant PreviewComponent

    User->>App: Request URL
    alt URL is "/preview"
        App->>PreviewComponent: Call initPreview
        PreviewComponent-->>App: Initialized Preview
    else URL is not "/preview"
        App->>PreviewComponent: Call initMain
        PreviewComponent-->>App: Initialized Main
    end
Loading

Poem

🐰✨
In code we weave the magic bright,
Removing clutter, setting things right.
With previews streamlined, simpler with glee,
Enhanced our tools for you and me.
Refined and tidy, swift as a hare,
Celebrate updates with care. 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
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: 3

Outside diff range and nitpick comments (1)
packages/controller/js/preview.js (1)

Line range hint 31-31: Optimize the use of spread syntax in .reduce to improve performance.

- params.scripts = scripts
-   .filter((item) => item.script)
-   .reduce((pre, cur) => ({ ...pre, [cur.package]: cur.script }), {})
+ const scriptEntries = scripts.filter(item => item.script).map(item => [item.package, item.script]);
+ params.scripts = Object.fromEntries(scriptEntries);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d5eaa6d and e480b33.

Files selected for processing (6)
  • designer-demo/index.html (1 hunks)
  • packages/build/vite-config/src/default-config.js (2 hunks)
  • packages/controller/js/preview.js (2 hunks)
  • packages/design-core/index.js (1 hunks)
  • packages/design-core/src/init.js (3 hunks)
  • packages/design-core/src/preview/src/Toolbar.vue (1 hunks)
Files skipped from review due to trivial changes (2)
  • designer-demo/index.html
  • packages/design-core/index.js
Additional context used
Biome
packages/controller/js/preview.js

[error] 31-31: Avoid the use of spread (...) syntax on accumulators. (lint/performance/noAccumulatingSpread)

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

Additional comments not posted (2)
packages/controller/js/preview.js (1)

39-43: Simplified URL construction logic enhances maintainability. Ensure that this change is tested across environments as the removed condition might affect behavior.

packages/design-core/src/init.js (1)

25-25: Ensure the imported initPreview is used correctly and does not introduce side effects.

Verification successful

The initPreview function is correctly imported and used in both packages/design-core/src/init.js and packages/engine-cli/template/designer/src/preview.js. The parameters passed to initPreview align with its definition, ensuring proper usage without introducing side effects.

  • initPreview is called with params in packages/design-core/src/init.js.
  • initPreview is called with a specific object in packages/engine-cli/template/designer/src/preview.js.
  • The function definition in packages/design-core/src/preview/src/main.js correctly handles the parameters.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `initPreview` across the application.

# Test: Search for all usages of `initPreview` to ensure it's being called appropriately.
rg --type js $'initPreview'

Length of output: 515



Script:

#!/bin/bash
# Description: Extract the relevant lines where `initPreview` is called to review the parameters passed to it.

# Extract the lines where `initPreview` is called in `packages/design-core/src/init.js`
rg --type js --context 5 'initPreview' packages/design-core/src/init.js

# Extract the lines where `initPreview` is called in `packages/engine-cli/template/designer/src/preview.js`
rg --type js --context 5 'initPreview' packages/engine-cli/template/designer/src/preview.js

# Extract the definition of `initPreview` in `packages/design-core/src/preview/src/main.js`
rg --type js --context 10 'export const initPreview' packages/design-core/src/preview/src/main.js

Length of output: 1908

@@ -11,7 +11,7 @@
*/

import { constants } from '@opentiny/tiny-engine-utils'
import { isDevelopEnv } from './environments'
// import { isDevelopEnv } from './environments'
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider removing the commented-out import if isDevelopEnv is no longer needed.

- // import { isDevelopEnv } from './environments'
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// import { isDevelopEnv } from './environments'

Comment on lines +77 to +87
export const init = (params) => {
const path = window.location.pathname

// 预览页面
if (path.endsWith('/preview')) {
initPreview(params)
} else {
// 主设计器
initMain(params)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The previous commands did not yield any results indicating that there are no direct or indirect tests for the init function, initPreview, or initMain in the identified test files. This suggests that the new conditional initialization logic in the init function is not covered by existing tests.

To ensure comprehensive test coverage, tests should be added for the init function covering both conditions (/preview and the main path).

  • Please add unit tests for the init function in the appropriate test files.
  • Ensure the tests cover both scenarios: when the path ends with /preview and when it doesn't.
Analysis chain

The new conditional initialization logic in init function is a good approach to handle different page types. Ensure comprehensive tests cover all conditions.


The previous commands successfully listed numerous test files but failed to find any mentions of the init function within those files. This suggests that there might be a lack of direct tests for the init function or the tests might be located in a different context.

To ensure comprehensive verification, let's broaden our search to include any test cases that might indirectly test the init function by looking for related terms such as initPreview and initMain.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check the test coverage for the new conditional initialization logic.

# Test: Search for test files related to the `init` function.
rg --type js $'test.*init'

Length of output: 27



Script:

#!/bin/bash
# Description: Broaden the search to find any test files and then look for specific test cases related to the `init` function.

# Step 1: Search for all test files in the repository.
fd --type f --name '*test*.js'

# Step 2: Within those test files, search for any mentions of the `init` function.
fd --type f --name '*test*.js' --exec rg 'init'

Length of output: 582



Script:

#!/bin/bash
# Description: Correct the search command to find test files and then look for specific test cases related to the `init` function.

# Step 1: Search for all test files in the repository using the correct syntax.
fd 'test' --type f --extension js

# Step 2: Within those test files, search for any mentions of the `init` function.
fd 'test' --type f --extension js --exec rg 'init' {}

Length of output: 2752



Script:

#!/bin/bash
# Description: Search for test cases that might indirectly test the `init` function by looking for related terms.

# Step 1: Search for all test files in the repository using the correct syntax.
fd 'test' --type f --extension js

# Step 2: Within those test files, search for any mentions of the `initPreview` or `initMain` functions.
fd 'test' --type f --extension js --exec rg 'initPreview|initMain' {}

Length of output: 2770

@@ -150,7 +149,7 @@ export default defineConfig(({ command = 'serve', mode = 'serve' }, extOptions)
})
const htmlPlugin = (mode) => {
const upgradeHttpsMetaTags = []
const includeHtmls = ['index.html', 'preview.html', 'previewApp.html']
const includeHtmls = ['index.html']
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The output indicates that canvas.html and previewApp.html are actively referenced in the codebase, suggesting they might be important for the build process. On the other hand, tmp/report.html appears to be a temporary file and might not need inclusion in the includeHtmls array.

To ensure the build process includes all necessary HTML files, it's advisable to add canvas.html and previewApp.html to the includeHtmls array.

  • packages/build/vite-config/src/default-config.js:
    • Add canvas.html and previewApp.html to includeHtmls.
Analysis chain

The simplification of the includeHtmls array aligns with the PR's objective to consolidate entry points. Confirm that all necessary HTML files are included.


The includeHtmls array currently only includes index.html. However, the search results show other HTML files like canvas.html, previewApp.html, and tmp/report.html. It is important to verify if these files need to be included in the includeHtmls array for the build process.

  • tmp/report.html: This might be a temporary file and may not need inclusion.
  • canvas.html: This is referenced in DesignCanvas.vue.
  • previewApp.html: This is referenced in Main.vue.

To make a final decision, it's necessary to understand the role of these files in the build process.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all necessary HTML files are correctly included in builds.

# Test: Search for configurations that specify included HTML files.
rg --type js $'includeHtmls'

Length of output: 258



Script:

#!/bin/bash
# Description: Search for references to HTML files in the project to ensure no necessary files are omitted.

# Search for references to HTML files in the project.
rg --type js '\.html'

Length of output: 898



Script:

#!/bin/bash
# Description: Gather more context about the usage of the identified HTML files.

# Search for references to `canvas.html`.
rg --type js 'canvas.html'

# Search for references to `previewApp.html`.
rg --type js 'previewApp.html'

# Search for references to `tmp/report.html`.
rg --type js 'tmp/report.html'

Length of output: 467

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 (1)
packages/controller/js/preview.js (1)

Line range hint 30-30: Optimize the accumulation in reduce to improve performance.

- params.scripts = scripts
-   .filter((item) => item.script)
-   .reduce((pre, cur) => ({ ...pre, [cur.package]: cur.script }), {})
+ params.scripts = scripts
+   .filter((item) => item.script)
+   .reduce((pre, cur) => {
+     pre[cur.package] = cur.script;
+     return pre;
+   }, {})
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e480b33 and 94b0473.

Files selected for processing (1)
  • packages/controller/js/preview.js (2 hunks)
Additional context used
Biome
packages/controller/js/preview.js

[error] 30-30: Avoid the use of spread (...) syntax on accumulators. (lint/performance/noAccumulatingSpread)

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

Additional comments not posted (3)
packages/controller/js/preview.js (3)

38-38: Simplified URL construction logic looks good and aligns with PR objectives.


Line range hint 55-57: Function previewPage correctly sets the component type and uses the open function efficiently.


Line range hint 59-61: Function previewBlock is implemented correctly, setting the component type and delegating to the open function.

@rhlin
Copy link
Collaborator

rhlin commented Jun 17, 2024

这个是有点反方向操作了感觉, preview应该是元应用 ,只是被单独渲染, 不应该和main启动器耦合, 应该往元应用(第一个单独被渲染的元应用)+ 提供一个元应用单独渲染器发展

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


This feels a bit like operating in the opposite direction. The preview should be a meta-application, which is only rendered separately. It should not be coupled with the main launcher. It should go to the meta-application (the first meta-application that is rendered independently) + provide a meta-application for independent rendering. device development

@chilingling chilingling marked this pull request as draft June 19, 2024 02:49
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