Skip to content

feat: registry metaservice#584

Merged
chilingling merged 1 commit intoopentiny:refactor/developfrom
hexqi:feat/registry-service
Jun 18, 2024
Merged

feat: registry metaservice#584
chilingling merged 1 commit intoopentiny:refactor/developfrom
hexqi:feat/registry-service

Conversation

@hexqi
Copy link
Collaborator

@hexqi hexqi 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

    • Introduced multiple new services such as EditorInfoService, HelpService, AppService, and others, which enhance the app functionality and provide more utilities.
    • Added new path mappings for specific modules under the @opentiny namespace for improved module organization.
  • Refactor

    • Updated various hooks to remove unnecessary imports and initialization functions, streamlining the code and improving maintainability.
    • Modified hook functionality to simplify logic and improve performance.
  • Documentation

    • Updated registry.md to include new interfaces and fields, providing clearer guidance and structure for developers.
  • Style

    • Moved the docsUrl constant declaration within setup() in Main.vue to clean the global scope.
  • Chores

    • Refactored imports and initialized state variables within multiple files for consistency and better code organization.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 15, 2024

Warning

Rate limit exceeded

@hexqi has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 51 minutes and 37 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 4fd457f and 82ca5fe.

Walkthrough

The recent changes primarily involve expanding and refining various services and hook functionalities across multiple files, particularly within the designer-demo, controller, and layout packages. New service hooks provide granular functions, and the removal of certain initializations streamlines operations. Additionally, path mappings in jsconfig.json and modular imports have been optimized for easier development and maintenance.

Changes

File(s) Change Summary
designer-demo/registry.js Added multiple services to the root object within the export.
jsconfig.json Introduced new path mappings for @opentiny namespace modules.
packages/canvas/container/index.js Added import statement for HOOK_NAME and new property composable in the exported object.
packages/controller/src/index.js Changed export to include all from hooks/, imported useMessage and useData, exported metaData.
packages/controller/src/hooks/index.js Created new file to export a variety of service hooks.
packages/.../useApp.js, packages/.../useBlock.js, packages/.../useBreadcrumb.js, ... Removed imports and initialization of hooks using HOOK_NAME and initHook.
packages/design-core/index.js Exported additional services and controllers from @opentiny/tiny-engine-controller.
packages/entry/docs/registry.md Added new Overwrite, MetaApp, and MetaService interfaces.
packages/entry/src/common.js Modified handleRegistryProp function to initialize hook based on composable.name.
packages/layout/index.js Updated import statement and modified exported object to include layout properties.
packages/layout/src/hooks/useLayout.js Removed HOOK_NAME and initHook imports and initialization.
packages/plugins/block/src/Main.vue Moved docsUrl constant declaration to within the setup() function.
packages/plugins/bridge/src/js/resource.js Changed id in state object initialization to an empty string.
packages/plugins/robot/src/js/robotSetting.js Refactored imports, removed useBlock, initialized blockList as empty array, updated http.
packages/settings/styles/src/js/useStyle.js Modified logic in getClassNameAndIdList, updateGlobalStyleStr, updateStyle for schema and API.

Sequence Diagrams

High-Level Service Integration

sequenceDiagram
    participant App as Application
    participant Controller as Controller
    participant Service as Service Hook
    App->>Controller: Request Service
    Controller->>Service: Initialize Service Hook
    Service-->>Controller: Provide Functionality
    Controller-->>App: Return Service Functions
    App->>Service: Utilize Service APIs
Loading

Poem

In lines of code, we found a cheer,
With hooks and services drawing near.
A dance of logic, clear and bright,
Paths mapped out in the morning light.
With HOOK_NAME now a whispered past,
Each function's call is built to last.
A rabbit hops through fields of change,
In this code garden, wide and strange.

🐇✨


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.

@hexqi hexqi force-pushed the feat/registry-service branch 2 times, most recently from ef9bead to 4fd457f Compare June 15, 2024 13:31
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: 5

Outside diff range and nitpick comments (12)
packages/controller/src/hooks/useApp.js (1)

Line range hint 1-59: Ensure comprehensive testing and error handling for the new hook useApp.

Would you like me to help by generating unit tests or setting up error handling for this hook?

packages/layout/src/hooks/useLayout.js (1)

Line range hint 1-1: Consider adding unit tests for the functions defined in this file to ensure they behave as expected.

Would you like me to help generate unit tests for these functions?

packages/controller/src/hooks/index.js (1)

17-24: Consider adding documentation for each service export to explain their purpose and usage within the project.

Adding detailed comments will enhance maintainability and understandability for other developers.

Also applies to: 26-33, 35-42, 44-51, 53-60, 62-69, 71-78, 80-87, 89-96, 98-105, 107-114, 116-123, 125-132

packages/canvas/container/src/api/useCanvas.js (1)

Line range hint 110-110: Fix the order of default parameters to follow the last required parameter.

- const resetPageCanvasState = (state = {}) => {
+ const resetPageCanvasState = (currentPage, state = {}) => {
  state.isBlock = false
  resetCanvasState(state)
  useHistory().addHistory(state.pageSchema)
}
packages/controller/src/hooks/usePage.js (1)

Line range hint 70-94: Consider simplifying the condition checks to enhance readability.

- Object.keys(dataCopy).some((item) => {
-   if (['children', 'label', 'createdBy', 'assets', 'occupier'].includes(item)) {
-     return false
-   } else if (item === 'page_content') {
-     const obj = {
-       inputs: dataCopy[item].inputs,
-       outputs: dataCopy[item].outputs,
-       lifeCycles: dataCopy[item].lifeCycles
-     }
-     const objCopy = {
-       inputs: data[item].inputs,
-       outputs: data[item].outputs,
-       lifeCycles: data[item].lifeCycles
-     }
-     if (JSON.stringify(obj) !== JSON.stringify(objCopy)) {
-       isEqual = false
-     }
-   } else {
-     if (dataCopy[item] !== data[item]) {
-       isEqual = false
-     }
-   }
-   return !isEqual
- })
+ Object.keys(dataCopy).some((item) => {
+   if (['children', 'label', 'createdBy', 'assets', 'occupier'].includes(item)) {
+     return false
+   } 
+   if (item === 'page_content') {
+     const obj = {
+       inputs: dataCopy[item].inputs,
+       outputs: dataCopy[item].outputs,
+       lifeCycles: dataCopy[item].lifeCycles
+     }
+     const objCopy = {
+       inputs: data[item].inputs,
+       outputs: data[item].outputs,
+       lifeCycles: data[item].lifeCycles
+     }
+     if (JSON.stringify(obj) !== JSON.stringify(objCopy)) {
+       isEqual = false
+     }
+   }
+   return dataCopy[item] !== data[item] && !isEqual
+ })

The refactoring simplifies the condition checks by removing unnecessary else clauses and directly returning the comparison result.

packages/controller/src/hooks/useTranslate.js (1)

Line range hint 145-147: Consider removing the unnecessary else clause to simplify the condition checks.

- if (send) {
-   const exist = langs[key]
-   // existing code
- } else {
-   // existing code
- }
+ if (send) {
+   const exist = langs[key]
+   // existing code
+ }

Removing the else clause simplifies the logic since the if block contains a return statement, making the else unnecessary.

packages/settings/styles/src/js/useStyle.js (1)

Line range hint 81-92: Optimize the method chain by using .flatMap() instead of .map().flat().

- res = expressRes
-   .map((item) => {
-     if (typeof item === 'string') {
-       return item
-     }
-     if (typeof item === 'object') {
-       return Object.keys(item)
-     }
-     return null
-   })
-   .flat()
-   .filter(Boolean)
+ res = expressRes.flatMap((item) => {
+   if (typeof item === 'string') {
+     return item
+   }
+   if (typeof item === 'object') {
+     return Object.keys(item)
+   }
+   return []
+ }).filter(Boolean)

The .flatMap() method can be used to achieve the same result as .map().flat() in a single operation, improving code clarity and potentially enhancing performance.

packages/controller/src/hooks/useResource.js (4)

Line range hint 62-63: Avoid assignments in expressions for clarity.

- block.assets = history?.assets || block.assets
+ const assets = history?.assets || block.assets;
+ block.assets = assets;

Line range hint 145-168: Remove unnecessary else clause to simplify code.

- if (notFetchResouce) {
-   return block
- } else {
-   if (!blockResource.get(label)) {
-     const { addScript, addStyle } = useCanvas().canvasApi.value
-     const promises = scripts
-       .filter((item) => item.includes('umd.js'))
-       .map(addScript)
-       .concat(styles.map(addStyle))
-     // 此处删除await,提前放行区块数据,在区块渲染前找到区块数据源映射关系
-     Promise.allSettled(promises)
-     blockResource.set(label, block.content)
-   }
- }
+ if (!notFetchResouce && !blockResource.get(label)) {
+   const { addScript, addStyle } = useCanvas().canvasApi.value
+   const promises = scripts
+     .filter((item) => item.includes('umd.js'))
+     .map(addScript)
+     .concat(styles.map(addStyle))
+   // 此处删除await,提前放行区块数据,在区块渲染前找到区块数据源映射关系
+   Promise.allSettled(promises)
+   blockResource.set(label, block.content)
+ }
+ return block;

Line range hint 251-251: Remove unnecessary else clause to simplify code.

- if (isInit) {
-   await initPageOrBlock()
- }
- await useTranslate().initI18n({ host: id, hostType: type, init: true })
+ if (isInit) {
+   await initPageOrBlock()
+ }
+ await useTranslate().initI18n({ host: id, hostType: type, init: true })

Line range hint 470-471: Avoid assignments in expressions for clarity.

- npmInfo.components = { ...components, ...npm.components }
+ const updatedComponents = { ...components, ...npm.components };
+ npmInfo.components = updatedComponents;
packages/controller/src/hooks/useBlock.js (1)

Line range hint 281-281: Ensure default parameters follow the last required parameter.

- const initBlock = async (block = {}, _langs = {}, isEdit) => {
+ const initBlock = async (block = {}, isEdit, _langs = {}) => {
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

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

Files selected for processing (28)
  • designer-demo/registry.js (1 hunks)
  • jsconfig.json (1 hunks)
  • packages/canvas/container/index.js (1 hunks)
  • packages/canvas/container/src/api/useCanvas.js (2 hunks)
  • packages/controller/src/hooks/index.js (1 hunks)
  • packages/controller/src/hooks/useApp.js (2 hunks)
  • packages/controller/src/hooks/useBlock.js (2 hunks)
  • packages/controller/src/hooks/useBreadcrumb.js (2 hunks)
  • packages/controller/src/hooks/useDataSource.js (2 hunks)
  • packages/controller/src/hooks/useEditorInfo.js (2 hunks)
  • packages/controller/src/hooks/useHelp.js (2 hunks)
  • packages/controller/src/hooks/useHistory.js (2 hunks)
  • packages/controller/src/hooks/usePage.js (2 hunks)
  • packages/controller/src/hooks/useProperties.js (2 hunks)
  • packages/controller/src/hooks/useProperty.js (2 hunks)
  • packages/controller/src/hooks/useResource.js (2 hunks)
  • packages/controller/src/hooks/useSaveLocal.js (2 hunks)
  • packages/controller/src/hooks/useTranslate.js (2 hunks)
  • packages/controller/src/index.js (1 hunks)
  • packages/design-core/index.js (1 hunks)
  • packages/entry/docs/registry.md (1 hunks)
  • packages/entry/src/common.js (3 hunks)
  • packages/layout/index.js (1 hunks)
  • packages/layout/src/hooks/useLayout.js (2 hunks)
  • packages/plugins/block/src/Main.vue (2 hunks)
  • packages/plugins/bridge/src/js/resource.js (1 hunks)
  • packages/plugins/robot/src/js/robotSetting.js (2 hunks)
  • packages/settings/styles/src/js/useStyle.js (4 hunks)
Files skipped from review due to trivial changes (10)
  • jsconfig.json
  • packages/controller/src/hooks/useBreadcrumb.js
  • packages/controller/src/hooks/useDataSource.js
  • packages/controller/src/hooks/useEditorInfo.js
  • packages/controller/src/hooks/useHelp.js
  • packages/controller/src/hooks/useSaveLocal.js
  • packages/controller/src/index.js
  • packages/design-core/index.js
  • packages/plugins/block/src/Main.vue
  • packages/plugins/bridge/src/js/resource.js
Additional context used
Biome
packages/canvas/container/src/api/useCanvas.js

[error] 110-110: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.

packages/controller/src/hooks/usePage.js

[error] 70-94: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.

packages/controller/src/hooks/useProperties.js

[error] 219-222: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

packages/controller/src/hooks/useTranslate.js

[error] 145-147: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.

packages/settings/styles/src/js/useStyle.js

[error] 81-92: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

Safe fix: Replace the chain with .flatMap().

packages/controller/src/hooks/useResource.js

[error] 62-63: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 145-168: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 251-251: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 470-471: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 430-431: 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.

packages/controller/src/hooks/useBlock.js

[error] 281-281: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.


[error] 281-281: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.

Additional comments not posted (14)
packages/layout/index.js (4)

3-3: Ensure that useLayout is correctly implemented and integrates well with other components.

Verification successful

The useLayout hook is correctly implemented and integrated across various components and files in the codebase. The verification steps confirm the presence of the import statement, the detailed implementation of useLayout, and its extensive usage throughout the project.

  • The import statement for useLayout was found in packages/layout/index.js.
  • The implementation of useLayout in the hooks directory is comprehensive and includes various functionalities.
  • The usage of useLayout is widespread across multiple files, indicating it is well-integrated within the project.

This confirms that useLayout is correctly implemented and integrated with other components.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of `useLayout` and its integration.
ast-grep --lang javascript --pattern $'import useLayout from "./src/hooks/useLayout" { $$$ }'

Length of output: 570



Script:

#!/bin/bash
# Step 1: Find the import statement for `useLayout`.
rg 'import useLayout from' 

# Step 2: Locate the implementation of `useLayout` in the hooks directory.
fd 'useLayout' --exec cat

# Step 3: Check for any references or usage of `useLayout` in the codebase to ensure it is integrated well.
rg 'useLayout' 

Length of output: 17465


4-4: Ensure HOOK_NAME is properly defined and utilized across the project.

Verification successful

The verification confirms that HOOK_NAME is properly defined in packages/entry/src/hooks.js and is utilized across various files in the project. The import statement in packages/layout/index.js is consistent with its usage and definition.

  • HOOK_NAME is defined as an object with various hooks in packages/entry/src/hooks.js.
  • It is imported and used in multiple files, including packages/layout/index.js, designer-demo/src/preview.js, designer-demo/src/main.js, and others.

This indicates that HOOK_NAME is correctly defined and utilized as expected.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the definition and usage of `HOOK_NAME` across the project.
ast-grep --lang javascript --pattern $'import { HOOK_NAME } from "@opentiny/tiny-engine-entry" { $$$ }'

Length of output: 590



Script:

#!/bin/bash
# Description: Verify the import of `HOOK_NAME` from "@opentiny/tiny-engine-entry"
ast-grep --lang javascript --pattern 'import { HOOK_NAME } from "@opentiny/tiny-engine-entry"'

# Description: Verify the definition of `HOOK_NAME` in the project
ast-grep --lang javascript --pattern 'const HOOK_NAME = $_'

# Description: Verify the usage of `HOOK_NAME` across the project
rg 'HOOK_NAME'

Length of output: 6265


10-12: Check the usage of HOOK_NAME.useLayout to ensure it aligns with the project's standards.

Verification successful

The usage of HOOK_NAME.useLayout appears in three places within the codebase:

  • ./packages/layout/index.js:11:

    composable: {
      name: HOOK_NAME.useLayout
    }
  • ./packages/entry/src/hooks.js:23:

    const hooksState = {
      [HOOK_NAME.useLayout]: {},
      ...
    }
  • ./packages/entry/src/hooks.js:43:

    export const useLayout = () => hooksState[HOOK_NAME.useLayout]

These usages seem consistent with defining and exporting a hook, which aligns with typical project standards for managing and using hooks.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `HOOK_NAME.useLayout`.
ast-grep --lang javascript --pattern $'composable: { name: HOOK_NAME.useLayout }'

Length of output: 173



Script:

#!/bin/bash
# Check the encoding of the problematic file
file -i ./packages/controller/js/constants.js

# If the file has encoding issues, convert it to UTF-8
iconv -f $(file -i ./packages/controller/js/constants.js | awk -F'=' '{print $2}') -t utf-8 ./packages/controller/js/constants.js -o ./packages/controller/js/constants.js

# Verify the usage of `HOOK_NAME.useLayout` after ensuring the file is in proper UTF-8 format
ast-grep --lang javascript --pattern $'HOOK_NAME.useLayout'

Length of output: 804



Script:

#!/bin/bash
# Extract and display the relevant lines around the found occurrences for detailed inspection
rg -A 5 -B 5 'HOOK_NAME.useLayout' ./packages/layout/index.js ./packages/entry/src/hooks.js

Length of output: 1809


9-9: Confirm that useLayout() returns the expected API objects.

Verification successful

The useLayout function is defined in packages/entry/src/hooks.js and returns the hooksState[HOOK_NAME.useLayout] object, which is part of a predefined state object. This confirms that useLayout() returns the expected API objects.

  • packages/entry/src/hooks.js: export const useLayout = () => hooksState[HOOK_NAME.useLayout]
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the return value of `useLayout()`.
ast-grep --lang javascript --pattern $'function useLayout() { return $$$ }'

Length of output: 167



Script:

#!/bin/bash
# Description: Find the definition of `useLayout` and inspect its return value.

# Locate the file containing the `useLayout` function definition
useLayoutFile=$(rg --files-with-matches --fixed-strings 'function useLayout' | head -n 1)

# If the file is found, print the function definition and its return statement
if [ -n "$useLayoutFile" ]; then
  echo "Found useLayout in: $useLayoutFile"
  rg --context 10 --fixed-strings 'function useLayout' "$useLayoutFile"
else
  echo "useLayout function not found."
fi

Length of output: 178



Script:

#!/bin/bash
# Description: Broadly search for `useLayout` definition and its return value.

# Search for `useLayout` as a variable assignment or import
rg --context 10 --fixed-strings 'useLayout' 

Length of output: 156374

packages/canvas/container/index.js (2)

9-12: Verify that api() returns the expected objects and HOOK_NAME.useCanvas is used appropriately.


4-4: Ensure HOOK_NAME is consistently used and defined as expected in the project.

Verification successful

The investigation confirms that HOOK_NAME is defined in packages/entry/src/hooks.js and is consistently used across multiple files in the codebase, including the file under review (packages/canvas/container/index.js). The import statement is valid and aligns with the project's structure.

  • packages/entry/src/hooks.js: Definition of HOOK_NAME.
  • packages/canvas/container/index.js: Uses HOOK_NAME.useCanvas.

No issues were found with the import or usage of HOOK_NAME.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the consistent use and definition of `HOOK_NAME`.
ast-grep --lang javascript --pattern $'import { HOOK_NAME } from "@opentiny/tiny-engine-entry" { $$$ }'

Length of output: 590



Script:

#!/bin/bash
# Description: Verify the consistent use and definition of `HOOK_NAME`.
ast-grep --lang javascript --pattern 'import { HOOK_NAME } from "@opentiny/tiny-engine-entry"'

Length of output: 187



Script:

#!/bin/bash
# Description: Verify the consistent use and definition of `HOOK_NAME` excluding the problematic file.
fd -t f -e js | grep -v './packages/controller/js/constants.js' | xargs ast-grep --lang javascript --pattern 'import { HOOK_NAME } from "@opentiny/tiny-engine-entry"'

Length of output: 255



Script:

#!/bin/bash
# Description: Verify the consistent use and definition of `HOOK_NAME` excluding the problematic file.
fd -t f -e js --exclude packages/controller/js/constants.js | xargs ast-grep --lang javascript --pattern 'import { HOOK_NAME } from "@opentiny/tiny-engine-entry"'

Length of output: 164



Script:

#!/bin/bash
# Description: Verify the definition and usage of `HOOK_NAME` in the codebase.
fd -t f -e js --exclude packages/controller/js/constants.js | xargs rg 'HOOK_NAME'

Length of output: 4871

packages/plugins/robot/src/js/robotSetting.js (1)

14-24: Validate the integration and functionality of the new imports and reactive state management in robotSetting.js.

Verification successful

The verification of the useApp and useHttp imports and their usage in the codebase has been successfully completed. The imports are present and used correctly in robotSetting.js.

  • useApp is imported and used in robotSetting.js:

    • Import: Line 14
    • Usage: Line 62
  • useHttp is imported and used in robotSetting.js:

    • Import: Line 15
    • Usage: Line 64
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `useApp` and `useHttp` in `robotSetting.js`.
ast-grep --lang javascript --pattern $'import { useApp, useHttp } from "@opentiny/tiny-engine-controller" { $$$ }'

Length of output: 612



Script:

#!/bin/bash
# Check the presence of `useApp` and `useHttp` imports in `robotSetting.js`
ast-grep --lang javascript --pattern 'import { useApp } from "@opentiny/tiny-engine-controller"' --json
ast-grep --lang javascript --pattern 'import { useHttp } from "@opentiny/tiny-engine-http"' --json

# Check the usage of `useApp` in the codebase
rg 'useApp' --json

# Check the usage of `useHttp` in the codebase
rg 'useHttp' --json

Length of output: 57532

designer-demo/registry.js (1)

44-57: Validate the integration of new services in the root object.

Also applies to: 61-77

packages/controller/src/hooks/useHistory.js (1)

14-14: Validate the integration of useCanvas in the history management logic.

Verification successful

The search results confirm that useCanvas is integrated and used extensively within the codebase, including the file packages/controller/src/hooks/useHistory.js where it is used multiple times.

  • packages/controller/src/hooks/useHistory.js
    • Line 14: import { useCanvas } from '@opentiny/tiny-engine-entry'
    • Various lines: useCanvas().canvasApi.value?.setSchema(string2Schema(list[historyState.index])), useCanvas().setSaved(false), push(useCanvas().canvasApi.value?.getSchema()), etc.

The integration appears to be consistent and appropriate within the context of the file.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `useCanvas` in the history management logic.

# Test: Search for usages of `useCanvas` in the history management logic. Expect: Proper integration and no errors.
rg --type javascript $'useCanvas'

Length of output: 67



Script:

#!/bin/bash
# Description: Verify the integration of `useCanvas` in the history management logic.

# Test: Search for usages of `useCanvas` in the history management logic. Expect: Proper integration and no errors.
rg --type js 'useCanvas'

Length of output: 22645

packages/controller/src/hooks/useProperty.js (1)

16-16: Validate the integration of useBlock in the property management logic.

Verification successful

The useBlock hook is indeed imported and used in the useProperty.js file as well as in various other files across the codebase. The integration appears to be consistent and appropriate within these contexts.

  • packages/controller/src/hooks/useProperty.js: useBlock is imported and used to access getCurrentBlock and getBlockProperties.

Given this, the integration of useBlock in the property management logic seems to be correctly implemented and consistent with its usage in other parts of the project.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `useBlock` in the property management logic.

# Test: Search for usages of `useBlock` in the property management logic. Expect: Proper integration and no errors.
rg --type javascript $'useBlock'

Length of output: 66



Script:

#!/bin/bash
# Description: Verify the integration of `useBlock` in the property management logic.

# Test: Search for usages of `useBlock` in JavaScript files. Expect: Proper integration and no errors.
rg --type js 'useBlock'

Length of output: 7287

packages/layout/src/hooks/useLayout.js (1)

Line range hint 1-1: Ensure all necessary imports are included for the functionality used in this file.

Verification successful

The verification script did not produce any output, indicating that there are no undeclared functions or variables in the useLayout.js file. This suggests that all necessary imports are included.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all necessary imports are included in `useLayout.js`.
# Expect: All imports used in the file should be declared.

# Check for undeclared variables/functions
ast-grep --lang javascript --pattern $'$_($_) {
  $$$
}' packages/layout/src/hooks/useLayout.js | grep -v 'import'

Length of output: 552



Script:

#!/bin/bash
# Description: Verify all necessary imports are included in `useLayout.js`.
# Expect: All imports used in the file should be declared.

# Correct pattern to find function declarations and expressions
ast-grep --lang javascript --pattern $'(function $_($_) { $$$ })' packages/layout/src/hooks/useLayout.js | grep -v 'import'
ast-grep --lang javascript --pattern $'(const $_ = ($_ => { $$$ }))' packages/layout/src/hooks/useLayout.js | grep -v 'import'

Length of output: 248

packages/controller/src/hooks/index.js (1)

17-24: Ensure that the services exported from this file are correctly used elsewhere in the project, especially since they seem to be newly introduced.

Also applies to: 26-33, 35-42, 44-51, 53-60, 62-69, 71-78, 80-87, 89-96, 98-105, 107-114, 116-123, 125-132

Verification successful

The services exported from packages/controller/src/hooks/index.js are being correctly used in multiple places within the codebase, including designer-demo/registry.js, packages/design-core/index.js, and mockServer/src/services. This confirms that the newly introduced services are integrated and utilized as expected.

  • designer-demo/registry.js
  • packages/design-core/index.js
  • mockServer/src/services/mockService.js
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct usage of services exported from `packages/controller/src/hooks/index.js`.

# Search for usage of exported services
rg --type javascript $'AppService|ResourceService|HistoryService|PropertiesService|SaveLocalService|EditorInfoService|BlockService|TranslateService|PageService|DataSourceService|BreadcrumbService|PropertyService|HelpService'

Length of output: 260



Script:

#!/bin/bash
# Description: Verify the correct usage of services exported from `packages/controller/src/hooks/index.js`.

# Search for usage of exported services
rg --type js $'AppService|ResourceService|HistoryService|PropertiesService|SaveLocalService|EditorInfoService|BlockService|TranslateService|PageService|DataSourceService|BreadcrumbService|PropertyService|HelpService'

Length of output: 3853

packages/entry/src/common.js (1)

13-13: Ensure initHook is used correctly throughout the project, especially since it's imported here for potentially significant functionality.

Verification successful

The initHook function is used in multiple files across the project, confirming its integration and usage in various contexts. The search results indicate that initHook is imported and utilized correctly, including in the file under review (packages/entry/src/common.js).

  • designer-demo/src/preview.js
  • designer-demo/src/main.js
  • packages/entry/src/common.js
  • packages/engine-cli/template/designer/src/main.js
  • packages/http/src/index.js

These usages suggest that initHook is consistently utilized for initializing hooks, and there are no apparent issues with its usage.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct usage of `initHook` across the project.

# Search for usage of `initHook`
rg --type javascript 'initHook'

Length of output: 66



Script:

#!/bin/bash
# Description: Verify the correct usage of `initHook` across the project.

# Search for usage of `initHook` with the correct file type
rg --type js 'initHook'

Length of output: 978

packages/controller/src/hooks/useResource.js (1)

Line range hint 430-431: Avoid using spread syntax on accumulators in reduce.
[PERFORMANCE]

- resState.componentsMap = appData.componentsMap?.reduce((componentsMap, component) => {
-   if (component.dependencies) {
-     getBlockDeps(component.dependencies)
-   }
-   return { ...componentsMap, [component.componentName]: component }
- }, {})
+ const componentsMap = {};
+ appData.componentsMap?.forEach(component => {
+   if (component.dependencies) {
+     getBlockDeps(component.dependencies);
+   }
+   componentsMap[component.componentName] = component;
+ });
+ resState.componentsMap = componentsMap;

@hexqi hexqi force-pushed the feat/registry-service branch from 4fd457f to 82ca5fe Compare June 15, 2024 13:37
@chilingling chilingling merged commit 4ddb159 into opentiny:refactor/develop Jun 18, 2024
yy-wow pushed a commit to yy-wow/tiny-engine that referenced this pull request Oct 10, 2024
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