Create a Search Component
- What is a Component?
-
A Component is a reusable building block of the user interface in a UI Application. It encapsulates the structure, behavior, and presentation of a specific part of the UI, allowing developers to create modular and maintainable applications.
Components can represent anything from a simple button or form field to complex data-driven views. - Search Component and Entity/Resource
-
The Search Component is a specific type of component that provides a user interface for searching and displaying results based on a certain entity or resource.
The entity or resource represents the data model that the search component interacts with. Therefore, the resource is the base parameter for the generation of a search component.
Generate a Search Component
The current working directory must be the root of an existing OneCX UI Application.
When a resource name is specified with the --resource option, the generator will preset the API service name to <Resource>APIService used by the generated search component. This should correspond to the created schema in OpenAPI file, see step before.
nx generate <namespace>/nx-plugin:search <feature> --resource=<resource>
with:
| <namespace> |
The base namespace of the project where the application is part of. |
| <feature> |
The name of the generated feature module. |
| <resource> |
Optional. The name of the resource entity for which the feature module is generated. |
Next, you will be asked if you would like to adapt the names for the generation.
If you answer No, the generator will use the preset resource name (if specified) or derive the name from feature name. This is the fastest way.
If you answer Yes, you can specify a name for the resource/entity and the API components. This can be helpful if you want to customize an existing API.
The generator creates a new search component within the specified feature module and set up the necessary structure and configurations.
Post-Generation Steps
The next steps involve adapting the search component to your specific requirements and integrating it into other parts of the application. All parts that need to be adapted after the generation are described in the following sections.
ACTION S<NUMBER>: <Short Description>
Search in your IDE for the string ACTION S to quickly find all places that need to be adapted.
|
|
The generator uses the following Extension Marker in the search component spec file
This marker is used as a placeholder for future extensions by newly generated components. Do not remove the marker from the code, as doing so will prevent these future generated functions and tests from being added to the Search Page Spec File. |
Example
Create a search component for books inside the book feature module.
Execute the following command with the bookstore application as current working directory.
nx generate @onecx/nx-plugin:search book --resource=Book
This command will generate a new search component book-search within the specified feature module with the necessary structure and configurations. With the presetted resource/entity name Book, the generator will also preset the API service name to BookAPIService used by the generated search component. This should correspond to the created schema in OpenAPI file, see step before.
Integrate UI App into OneCX
After the generation, you need to integrate the generated App into the local running OneCX. This involves adding the search component to the routing configuration of the feature module and ensuring that it is properly linked to the rest of the application.
| It is recommended to use the mechanism of OneCX Local environment to integrate the generated UI App into the running OneCX environment. Follow the guide in Extend OneCX. |
-
Start the application with a dedicated port
-
Integrate the application into running OneCX environment with this port
-
Add necessary data to the backend to be able to call the search component (product, permissions, workspace registration, menu entry, etc.)
-
After making these changes, reload the OneCX UI and navigate to the search component route
Preview
In the following image, the search component is integrated into the application unchanged, exactly as it was generated.
After little adaptations to the search criteria and search results, the search component can look like this: