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(headless SSR): support both search and listing solution types #4249

Merged
merged 69 commits into from
Aug 19, 2024

Conversation

y-lakhdar
Copy link
Contributor

@y-lakhdar y-lakhdar commented Aug 2, 2024

TL;DR

Enhance the commerce engine to support both search and listing solution types, implementing type inference and conditional types to ensure the correct controllers are instantiated based on the solution type.

Key Changes

Solution Type Support:

The commerce engine now supports both search and listing solution types. This is particularly important when building sub-controllers (e.g., summary, facets, sort, etc.). Since, in SSR, users do not manually build their controllers because it is done under the hood (in the SSR utils), the SSR utils need to know which function to call (e.g., buildProductListing() or buildSearch()).

Conditional Controller Instantiation:

Based on the specified solution type, the engine now conditionally instantiates controllers. This mechanism ensures that only relevant controllers are active for a given solution type, optimizing the engine’s performance and resource usage by avoiding the creation of unnecessary controllers.

Example

For instance, if you create an engine definition containing a Query Summary but want the QuerySummary controller to not be created on listing pages, you can opt out for this solution type. Otherwise, it will be built like other controllers.

const engineDefinition = defineCommerceEngine({
  configuration: configuration,
  controllers: {
    searchbox: defineStandaloneSearchBox({
      options: {redirectionUrl: '/search'},
    }),
    summary: defineQuerySummary({listing: false}), // opting out for listing context
    // ... other controllers
  },
});

Type Inference Enhancements:

Since Conditional Controller Instantiation is a runtime logic, I had to update the typing to reflect that change so that the same logic could also be available statically with TypeScript. This means that if you opt out from a solution type during the engine definition (like in the previous example), you should not have the controller available when using code completion.

These enhancements facilitate the accurate determination of controller types based on the solution type, streamlining the setup process for developers.

Example

Using the same engine definition from the previous example, and since we have opted out from query summary in the listing context, you will notice that you get an error if you try to get that controller in the listing context.
image

Duplicate Types and Methods:

Due to compatibility issues with existing types used by the non-commerce SSR package, some types and methods have been duplicated and adapted to fit the solution type strategy.

https://coveord.atlassian.net/browse/KIT-3394

@y-lakhdar y-lakhdar added this pull request to the merge queue Aug 19, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 19, 2024
@alexprudhomme alexprudhomme added this pull request to the merge queue Aug 19, 2024
@alexprudhomme alexprudhomme self-assigned this Aug 19, 2024
@alexprudhomme alexprudhomme removed this pull request from the merge queue due to a manual request Aug 19, 2024
@alexprudhomme alexprudhomme added this pull request to the merge queue Aug 19, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 19, 2024
@alexprudhomme alexprudhomme added this pull request to the merge queue Aug 19, 2024
Merged via the queue into master with commit dcd35d8 Aug 19, 2024
116 checks passed
@alexprudhomme alexprudhomme deleted the KIT-3394 branch August 19, 2024 20:42
fpbrault pushed a commit that referenced this pull request Aug 23, 2024
…4249)

## TL;DR

Enhance the commerce engine to support both search and listing solution
types, implementing type inference and conditional types to ensure the
correct controllers are instantiated based on the solution type.

## Key Changes
### **Solution Type Support**:
The commerce engine now supports both search and listing solution types.
This is particularly important when building sub-controllers (e.g.,
summary, facets, sort, etc.). Since, in SSR, users do not manually build
their controllers because it is done under the hood (in the SSR utils),
the SSR utils need to know which function to call (e.g.,
`buildProductListing()` or `buildSearch()`).

### **Conditional Controller Instantiation**: 
Based on the specified solution type, the engine now conditionally
instantiates controllers. This mechanism ensures that only relevant
controllers are active for a given solution type, optimizing the
engine’s performance and resource usage by avoiding the creation of
unnecessary controllers.

#### Example
For instance, if you create an engine definition containing a Query
Summary but want the QuerySummary controller to not be created on
listing pages, you can opt out for this solution type. Otherwise, it
will be built like other controllers.

```ts
const engineDefinition = defineCommerceEngine({
  configuration: configuration,
  controllers: {
    searchbox: defineStandaloneSearchBox({
      options: {redirectionUrl: '/search'},
    }),
    summary: defineQuerySummary({listing: false}), // opting out for listing context
    // ... other controllers
  },
});
```

### **Type Inference Enhancements**:
Since Conditional Controller Instantiation is a runtime logic, I had to
update the typing to reflect that change so that the same logic could
also be available statically with TypeScript. This means that if you opt
out from a solution type during the engine definition (like in the
previous example), you should not have the controller available when
using code completion.

These enhancements facilitate the accurate determination of controller
types based on the solution type, streamlining the setup process for
developers.

#### Example
Using the same engine definition from the previous example, and since we
have opted out from query summary in the listing context, you will
notice that you get an error if you try to get that controller in the
listing context.

![image](https://github.com/user-attachments/assets/6724fd40-4a37-4a0f-9b20-15a9d93e1a3b)

### **Duplicate Types and Methods**: 
Due to compatibility issues with existing types used by the non-commerce
SSR package, some types and methods have been duplicated and adapted to
fit the solution type strategy.

https://coveord.atlassian.net/browse/KIT-3394

---------

Co-authored-by: Alex Prudhomme <[email protected]>
Co-authored-by: Frederic Beaudoin <[email protected]>
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.

4 participants