Skip to content

Commit b426bff

Browse files
committed
global: update documentation and fix Toggle cmp
* fix Toggle cmp overridable name * make Overridable params explicit and well defined * update documentation
1 parent c74cb5e commit b426bff

47 files changed

Lines changed: 609 additions & 445 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/docs/components/active_filters.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,32 @@ Each label has a `close` icon which can be clicked to remove the selected filter
1515

1616
## Props
1717

18-
* **renderElement** `function` *optional*
18+
* **overridableId** `String` *optional*
1919

20-
An optional function to override the default rendered component.
20+
An optional string to define a specific overridable id.
2121

22-
## Usage when overriding template
22+
## Usage when overriding
2323

2424
```jsx
25-
<ActiveFilters renderElement={renderActiveFilters}/>
26-
```
27-
28-
The function `renderElement` is called every time `results` or `filters` in query state change.
29-
30-
```jsx
31-
renderActiveFilters = (filters, removeActiveFilter) => {
32-
return filters.map(filter => {
33-
const aggName = filter[0];
34-
const value = filter[1];
35-
const label = `${aggName}:${value}`;
36-
return <div onClick={removeActiveFilter([aggName, value])}>{label}</div>
37-
};
25+
const MyActiveFilters = ({ filters, removeActiveFilter, getLabel }) => {
26+
...
3827
}
28+
29+
const overriddenComponents = {
30+
"ActiveFilters.element": MyActiveFilters
31+
};
3932
```
4033

4134
### Parameters
4235

43-
* **filters** `array`
36+
* **filters** `Array`
4437

4538
The `filters` `query` state. It contains the list of active filters selected by the user. Each element is a list `[ "<agg name>", "<value>" ]`.
4639

47-
* **removeActiveFilter** `function`
40+
* **removeActiveFilter** `Function`
41+
42+
Function to be called with the active filter list as parameter if you want to remove one of the active filters `removeActiveFilter(<active filter>)`.
43+
44+
* **getLabel** `Function`
4845

49-
A function to be called with the active filter list as parameter if you want to remove one of the active filters.
46+
Function to be called to get a display label for the given active filter `getLabel(filter)`.

docs/docs/components/bucket_aggregation.md

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ By default it supports child aggregations. The user can select aggregations to f
1313
<BucketAggregation
1414
title="Employee Types"
1515
agg={{
16-
field: 'employee_type.type',
17-
aggName: 'type_agg',
16+
field: "employee_type.type",
17+
aggName: "type_agg",
1818
childAgg: {
19-
field: 'employee_type.subtype',
20-
aggName: 'subtype_agg',
19+
field: "employee_type.subtype",
20+
aggName: "subtype_agg",
2121
},
2222
}}
2323
/>
@@ -29,91 +29,97 @@ By default it supports child aggregations. The user can select aggregations to f
2929

3030
The title to display for the aggregation.
3131

32-
* **agg** `object`
32+
* **agg** `Object`
3333

3434
An object that describes the aggregation to look for in the `results`:
3535

3636
* **field** `String`: the field name
3737

3838
* **aggName** `String`: the aggregation name to look for in `results`
3939

40-
* **childAgg** `object`: a child aggregation with the same format as the `agg` prop
40+
* **childAgg** `Object`: a child aggregation with the same format as the `agg` prop
4141

42-
* **renderValuesContainerElement** `function` *optional*
42+
* **overridableId** `String` *optional*
4343

44-
An optional function to override the default rendered container component that wraps each value.
44+
An optional string to define a specific overridable id.
4545

46-
* **renderValueElement** `function` *optional*
47-
48-
An optional function to override the default rendered component for each of the value.
49-
50-
## Usage when overriding template
51-
52-
```jsx
53-
<BucketAggregation
54-
renderValuesContainerElement={customAggValuesContainerCmp}
55-
renderValueElement={customAggValueCmp}
56-
/>
57-
```
58-
59-
Each `render*` function is called every time `results` `aggregations` value changes.
46+
## Usage when overriding
6047

6148
```jsx
62-
const customAggComp = (title, containerCmp) => {
63-
return containerCmp ? (
49+
const MyBucketAggregation = ({title, containerCmp}) => {
50+
return (
6451
<Menu vertical>
6552
<Menu.Item>
6653
<Menu.Header>{title}</Menu.Header>
6754
{containerCmp}
6855
</Menu.Item>
6956
</Menu>
70-
) : null;
57+
);
58+
}
59+
60+
const BucketAggregationContainer = ({ valuesCmp }) => {
61+
...
62+
}
63+
64+
const MyBucketAggregationValues = ({ bucket, label, onFilterClicked, isSelected, childAggCmps }) => {
65+
...
66+
}
67+
68+
const overriddenComponents = {
69+
"BucketAggregation.element": MyBucketAggregation,
70+
"BucketAggregationContainer.element": MyBucketAggregationContainer,
71+
"BucketAggregationValues.element": MyBucketAggregationValues,
7172
};
7273
```
7374

74-
### renderValuesContainerElement parameters
75+
### BucketAggregation parameters
76+
77+
Component that wraps the bucket aggregations and renders a title and the container of aggregations.
78+
79+
* **title** `String`
80+
81+
The title to render.
82+
83+
* **containerCmp** `React component`
84+
85+
The `BucketAggregationContainer` to render.
86+
87+
* **agg** `Object`
88+
89+
Same object as in the props.
90+
91+
* **updateQueryFilters** `Function`
92+
93+
A function to call to update the current selected filters.
94+
95+
### BucketAggregationContainer parameters
96+
97+
Component that wraps the list of aggregations.
7598

7699
* **valuesCmp** `React component`
77100

78-
Component to render each of the aggregation values.
101+
List of components of each aggregation value.
79102

80-
```jsx
81-
const customAggValueCmp = (
82-
bucket,
83-
isSelected,
84-
onFilterClicked,
85-
getChildAggCmps
86-
) => {
87-
const childAggCmps = getChildAggCmps(bucket);
88-
return (
89-
<Menu.Item
90-
key={bucket.key}
91-
name={bucket.key}
92-
active={isSelected}
93-
onClick={() => onFilterClicked(bucket.key)}
94-
>
95-
<Label>{bucket.doc_count}</Label>
96-
{bucket.key}
97-
{childAggCmps}
98-
</Menu.Item>
99-
);
100-
};
101-
```
103+
### BucketAggregationValues parameters
102104

103-
### renderValueElement parameters
105+
Component that renders each of the aggregation.
104106

105-
* **bucket** `array`
107+
* **bucket** `Array`
106108

107109
The bucket to display, which by default contains the `key` field with the value and the `doc_count` number.
108110

109-
* **isSelected** `boolean`
111+
* **label** `String`
112+
113+
The label to display.
114+
115+
* **isSelected** `Boolean`
110116

111117
`true` if this value is active/selected, `false` otherwise.
112118

113-
* **onFilterClicked** `function`
119+
* **onFilterClicked** `Function`
114120

115121
The function to be called when the user click on this value to activate the filter. It should be called with the `bucket.key` parameter.
116122

117-
* **getChildAggCmps** `function`
123+
* **getChildAggCmps** `Function`
118124

119125
A function to be called to render child component. It accepts the current `bucket` as parameter and it will render recursively this component. It returns a list of child components.

docs/docs/components/count.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,25 @@ The component is **not** displayed while executing the search query or if there
1717

1818
## Props
1919

20-
* **renderElement** `function` *optional*
21-
22-
An optional function to override the default rendered component.
23-
24-
- **label** `function` _optional_
20+
- **label** `Function` _optional_
2521

2622
An optional function to wrap the component with a prefix and suffix string. <br />
2723
E.g. `label={(cmp) => <> Found {cmp} results</>} />`
2824

29-
## Usage when overriding template
25+
* **overridableId** `String` *optional*
3026

31-
```jsx
32-
<Count renderElement={renderCount} />
33-
```
27+
An optional string to define a specific overridable id.
3428

35-
The function `renderElement` is called every time the number of results changes.
29+
## Usage when overriding
3630

3731
```jsx
38-
renderCount = totalResults => {
32+
const MyCount = ({ totalResults }) => {
3933
return <div>Found {totalResults} results.</div>;
4034
}
35+
36+
const overriddenComponents = {
37+
"Count.element": MyCount
38+
};
4139
```
4240

4341
### Parameters

docs/docs/components/empty_results.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,20 @@ results is greater than 0.
1616

1717
## Props
1818

19-
* **renderElement** `function` *optional*
19+
* **overridableId** `String` *optional*
2020

21-
An optional function to override the default rendered component.
21+
An optional string to define a specific overridable id.
2222

23-
## Usage when overriding template
23+
## Usage when overriding
2424

2525
```jsx
26-
<EmptyResults renderElement={renderEmptyResults} />
27-
```
28-
29-
The function `renderElement` is called every time the number of results changes.
30-
31-
```jsx
32-
renderEmptyResults = (queryString, resetQuery) => {
33-
return (<div>
34-
<em>No results found with query "{queryString}"</em>
35-
<div><button onClick={() => resetQuery()}>Clear query</button></div>
36-
</div>);
26+
const MyEmptyResults = ({ queryString, resetQuery, extraContent }) => {
27+
...
3728
}
29+
30+
const overriddenComponents = {
31+
"EmptyResults.element": MyEmptyResults
32+
};
3833
```
3934

4035
### Parameters
@@ -43,6 +38,14 @@ renderEmptyResults = (queryString, resetQuery) => {
4338

4439
The current value of the `queryString` `query` state.
4540

46-
* **resetQuery** `function`
41+
* **resetQuery** `Function`
4742

4843
A function to call to reset the current search query.
44+
45+
* **extraContent** `React component`
46+
47+
Any extra React component to be rendered.
48+
49+
* **userSelectionFilters** `Array`
50+
51+
List of the currently selected filters.

docs/docs/components/error.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,20 @@ The component is **not** displayed while executing the search query or if there
1313
<Error />
1414
```
1515

16-
## Props
17-
18-
* **renderElement** `function` *optional*
19-
20-
An optional function to override the default rendered component.
21-
22-
## Usage when overriding template
23-
24-
```jsx
25-
<Error renderElement={renderError} />
26-
```
27-
28-
The function `renderElement` is called every time the results error object is not empty.
16+
## Usage when overriding
2917

3018
```jsx
31-
renderError = error => {
32-
return <div>Error while performing the search. Message: {error.message}</div>;
19+
const MyError = ({ error }) => {
20+
...
3321
}
22+
23+
const overriddenComponents = {
24+
"Error.element": MyError
25+
};
3426
```
3527

3628
### Parameters
3729

38-
* **error** `object`
30+
* **error** `Object`
3931

4032
The current value of the `error` `results` state, containing the error returned by the search API connector.

docs/docs/components/layout_switcher.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,20 @@ there are no results.
2222

2323
The default layout, one of `list` or `grid`. Default value: `list`.
2424

25-
* **renderElement** `function` *optional*
25+
* **overridableId** `String` *optional*
2626

27-
An optional function to override the default rendered component.
27+
An optional string to define a specific overridable id.
2828

29-
## Usage when overriding template
29+
## Usage when overriding
3030

3131
```jsx
32-
<LayoutSwitcher renderElement={renderLayoutSwitcher} />
33-
```
34-
35-
The function `renderElement` is called every time the number of results changes.
36-
37-
```jsx
38-
renderLayoutSwitcher = (currentLayout, onLayoutChange) => {
39-
return <a onClick={() => onLayoutChange('list')}>LIST</a>/<a onClick={() => onLayoutChange('grid')}>GRID</a>;
32+
const MyLayoutSwitcher = ({ currentLayout, onLayoutChange }) => {
33+
...
4034
}
35+
36+
const overriddenComponents = {
37+
"LayoutSwitcher.element": MyLayoutSwitcher
38+
};
4139
```
4240

4341
### Parameters

0 commit comments

Comments
 (0)