Skip to content

Commit

Permalink
Merge pull request #2282 from spryker/feature/cc-31652-fe-new-service…
Browse files Browse the repository at this point in the history
…s-documentation

CC-31652 Introduced `datasource.dependable` and `datasource.trigger` services.
  • Loading branch information
andriitserkovnyi authored Jan 16, 2024
2 parents 0c1b785 + 9cd3a48 commit 46205b6
Show file tree
Hide file tree
Showing 19 changed files with 988 additions and 109 deletions.
15 changes: 15 additions & 0 deletions _data/sidebars/scos_dev_sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,21 @@ entries:
- title: "Datasources"
url: /docs/scos/dev/front-end-development/marketplace/ui-components-library/datasources/datasources.html
nested:
- title: "Trigger"
url: /docs/scos/dev/front-end-development/marketplace/ui-components-library/datasources/datasource-trigger/datasource-trigger.html
include_versions:
- "202307.0"
- "202311.0"
nested:
- title: "Change"
url: /docs/scos/dev/front-end-development/marketplace/ui-components-library/datasources/datasource-trigger/datasource-trigger-change.html
- title: "Input"
url: /docs/scos/dev/front-end-development/marketplace/ui-components-library/datasources/datasource-trigger/datasource-trigger-input.html
- title: "Dependable"
url: /docs/scos/dev/front-end-development/marketplace/ui-components-library/datasources/datasource-dependable.html
include_versions:
- "202307.0"
- "202311.0"
- title: "HTTP"
url: /docs/scos/dev/front-end-development/marketplace/ui-components-library/datasources/datasource-http.html
- title: "Inline"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
title: Datasource Dependable
description: Details about the Datasource Dependable service in the components library.
template: concept-topic-template
related:
- title: Datasource Trigger
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-trigger/datasource-trigger.html
- title: Datasource Http
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-http.html
- title: Datasource Inline Table
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-inline-table.html
- title: Datasource Inline
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-inline.html
---


Datasource Dependable is an Angular service in the components library that resolves datasources for a component based on the value of a specific element.

## Usage

Service configuration:

| ATTRIBUTE | DESCRIPTION |
| - | - |
| type | A datasource type. |
| id | An ID of the dependent element. |
| datasource | The next datasource that runs based on the depended element value, like [http](/docs/scos/dev/front-end-development/{{page.version}}/marketplace/ui-components-library/datasources/datasource-http.html). |

Usage example:

```html
<spy-datasource-dependable id="dependable-select">
<spy-select
[options]="{ ... }"
>
</spy-select>
</spy-datasource-dependable>

<spy-select
[datasource]="{
type: 'dependable-element',
id: 'dependable-select',
datasource: {
type: 'http',
url: '/request-url',
},
}"
>
</spy-select>
```

The dependent element, being `SelectComponent` in the example, must implement a `DatasourceDependableElement` abstract class (token) and return a component value using the `getValueChanges()` abstract method:

```ts
@Component({
...,
providers: [
{
provide: DatasourceDependableElement,
useExisting: SelectComponent,
},
],
})
export class SelectComponent implements DatasourceDependableElement {
...
getValueChanges(): Observable<SelectValueSelected> {
// This method must return an Observable of the component value.
}
...
}
```

## Service registration

Register the service:

```ts
declare module '@spryker/datasource' {
interface DatasourceRegistry {
'dependable-element': DatasourceDependableService;
}
}

@NgModule({
imports: [
DatasourceModule.withDatasources({
'dependable-element': DatasourceDependableService,
}),
],
})
export class RootModule {}
```

## Datasource Dependable interfaces

Datasource Dependable interfaces:

```ts
import { DatasourceConfig } from '@spryker/datasource';
import { Observable } from 'rxjs';

export interface DatasourceDependableConfig extends DatasourceConfig {
id: string;
datasource: DatasourceConfig;
}

export interface DatasourceDependableElementsConfig {
[id: string]: DatasourceDependableElement;
}

export abstract class DatasourceDependableElement {
abstract getValueChanges(): Observable<unknown>;
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@ template: concept-topic-template
redirect_from:
- /docs/marketplace/dev/front-end/202212.0/ui-components-library/datasources/datasource-http.html
related:
- title: Datasources
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasources.html
- title: Datasource Dependable
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-dependable.html
- title: Datasource Trigger
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-trigger/datasource-trigger.html
- title: Datasource Inline Table
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-inline-table.html
- title: Datasource Inline
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-inline.html
---

This document explains the Datasource Http service in the Components Library.
Datasource Http is an Angular service in the components library that fetches data from URLs via HTTP as configured in the Datasource configuration.
Datasource Http supports the [caching strategy](/docs/scos/dev/front-end-development/{{page.version}}/marketplace/ui-components-library/cache/ui-components-library-cache-service.html) that can be configured via config and used before the request is made.

## Overview

Datasource Http is an Angular Service that fetches data from URLs via HTTP as configured in the Datasource configuration.
Datasource Http supports caching strategy (see [Cache](/docs/scos/dev/front-end-development/{{page.version}}/marketplace/ui-components-library/cache/ui-components-library-cache-service.html)) that can be configured via config and used before the request is made, when applicable.
## Usage

Check out an example usage of the Datasource Http.

Service configuration:

- `type`—a datasource type.
- `url`—a datasource request URL.
- `method`—a datasource request method (`GET` by default).
| ATTRIBUTE | DESCRIPTION |
| - | - |
|`type` | A datasource type. |
|`url` | A datasource request URL. |
|`method` | A datasource request method; `GET` by default. |

Usage example:

```html
<spy-select
Expand Down Expand Up @@ -62,7 +66,7 @@ export class RootModule {}

## Interfaces

Below you can find interfaces for the Datasource Http:
Datasource Http interfaces:

```ts
export interface DatasourceHttpConfig extends DatasourceConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@ template: concept-topic-template
redirect_from:
- /docs/marketplace/dev/front-end/202212.0/ui-components-library/datasources/datasource-inline-table.html
related:
- title: Datasources
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasources.html
- title: Datasource Dependable
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-dependable.html
- title: Datasource Trigger
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-trigger/datasource-trigger.html
- title: Datasource Http
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-http.html
- title: Datasource Inline
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-inline.html
---

This document explains the Datasource Inline Table service in the Components Library.
Datasource Inline Table is an Angular service in the components library that allows for passing the data transformed for the table format along with the configuration of the Datasource.

Datasource Inline Table is an Angular Service that allows passing transformed for the table format data along with the configuration of the Datasource.

Check out an example usage of the Datasource Inline Table.
## Usage

Service configuration:

- `type`-a datasource type.
- `data`-a datasource table data (usually coming from backend).
- `filter`-an array of filters that passes transformed for the table format data.
| ATTRIBUTE | DESCRIPTION |
| - | - |
| `type` | A datasource type. |
| `data` | Datasource table data, which usually comes from the backend. |
| `filter` | An array of filters that passes the data transformed for the table format. |

Usage example:

```html
<spy-table
Expand Down Expand Up @@ -93,7 +97,7 @@ export class RootModule {}

## Interfaces

Below you can find interfaces for the Datasource Inline Table:
Datasource Inline Table interfaces:

```ts
export interface TableDatasourceInlineConfig extends DatasourceConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ template: concept-topic-template
redirect_from:
- /docs/marketplace/dev/front-end/202212.0/ui-components-library/datasources/datasource-inline.html
related:
- title: Datasources
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasources.html
- title: Datasource Dependable
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-dependable.html
- title: Datasource Trigger
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-trigger/datasource-trigger.html
- title: Datasource Http
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-http.html
- title: Datasource Inline Table
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-inline-table.html
---

This document explains the Datasource Inline service in the Components Library.

## Overview
Datasource Inline is an Angular service in the components library that allows for passing data along with the configuration of the Datasource.

Datasource Inline is an Angular Service that allows passing data along with the configuration of the Datasource.

Check out an example usage of the Datasource Inline.
## Usage

Service configuration:

- `type`—a datasource type.
- `data`—a datasource data.
| ATTRIBUTE | DESCRIPTION |
| - | - |
| `type` | A datasource type. |
| `data` | Datasource data. |

Usage example:

```html
<spy-select
Expand Down Expand Up @@ -59,7 +62,7 @@ export class RootModule {}

## Interfaces

Below you can find interfaces for the Datasource Inline:
Datasource Inline interfaces:

```ts
export interface DatasourceInlineConfig extends DatasourceConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
title: Datasource Trigger Change
description: This document provides details about the Datasource Trigger Change service in the Components Library.
template: concept-topic-template
related:
- title: Datasource Dependable
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-dependable.html
- title: Datasource Http
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-http.html
- title: Datasource Inline Table
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-inline-table.html
- title: Datasource Inline
link: docs/scos/dev/front-end-development/page.version/marketplace/ui-components-library/datasources/datasource-inline.html
---

Datasource Trigger Change is an Angular service in the components library that extracts the value from an event trigger element and checks if it meets a certain criteria. If the value is valid, it emits an object containing the value.

## Usage

Service configuration:

| ATTRIBUTE | DESCRIPTION |
| - | - |
|type | A datasource type. |
|event | An event type triggered by element. |
|debounce | Delays the emission of values of the next datasource; by default, delays by `300ms`. |
|minCharacters | Emits the trigger element value if the length is greater than or equal to the `minCharacters` property. The default value is `2`. |
|datasource | the next datasource that runs based on the dependent element value, like [http](/docs/scos/dev/front-end-development/{{page.version}}/marketplace/ui-components-library/datasources/datasource-http.html). |


Usage example:


```html
<spy-select
[datasource]="{
type: 'trigger',
event: 'change',
debounce: 400,
minCharacters: 3,
datasource: {
type: 'http',
url: '/request-url',
},
}"
>
</spy-select>
```

## Service registration

Register the service

```ts
declare module '@spryker/datasource' {
interface DatasourceRegistry {
trigger: DatasourceTriggerService;
}
}

@NgModule({
imports: [
DatasourceModule.withDatasources({
trigger: DatasourceTriggerService,
}),
DatasourceTriggerModule.withEvents({
change: ChangeDatasourceTriggerService,
}),
],
})
export class RootModule {}
```

## Interfaces

Datasource Trigger Change interfaces:

```ts
import { DatasourceTriggerConfig } from '@spryker/datasource.trigger';

export interface ChangeDatasourceTriggerConfig extends DatasourceTriggerConfig {
minCharacters?: number;
}

export type ChangeDatasourceTriggerHTMLElement = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
```
Loading

0 comments on commit 46205b6

Please sign in to comment.