cozy-ui 117.1.0 → 117.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "117.1.0",
3
+ "version": "117.2.1",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -1,13 +1,14 @@
1
1
  import cx from 'classnames'
2
+ import debounce from 'lodash/debounce'
2
3
  import omit from 'lodash/omit'
3
4
  import PropTypes from 'prop-types'
4
- import React, { useState, useRef } from 'react'
5
+ import React, { useState, useRef, useMemo } from 'react'
5
6
 
6
7
  import ItemRow from './ItemRow'
7
8
  import { makeHistory } from './helpers'
8
9
  import styles from './styles.styl'
9
- import Input from '../Input'
10
10
  import List from '../List'
11
+ import SearchBar from '../SearchBar'
11
12
  import Typography from '../Typography'
12
13
 
13
14
  export { ItemRow }
@@ -35,9 +36,13 @@ const NestedSelect = ({
35
36
  const innerRef = useRef()
36
37
  const [state, setState] = useState({
37
38
  history: makeHistory(options, canSelectParent),
38
- searchValue: '',
39
- searchResult: []
39
+ searchValue: ''
40
40
  })
41
+ const [searchResult, setSearchResult] = useState(null)
42
+ const delayedSetSearchResult = useMemo(
43
+ () => debounce(setSearchResult, 250),
44
+ [setSearchResult]
45
+ )
41
46
 
42
47
  const handleBack = () => {
43
48
  const [item, ...newHistory] = state.history
@@ -70,16 +75,21 @@ const NestedSelect = ({
70
75
  if (onSearch) {
71
76
  const searchValue = ev.target.value
72
77
  const searchResult = onSearch(searchValue)
73
- setState(state => ({ ...state, searchValue, searchResult }))
78
+ setState(state => ({ ...state, searchValue }))
79
+ delayedSetSearchResult(searchResult)
74
80
  }
75
81
  }
76
82
 
83
+ const onClear = () => {
84
+ setState(state => ({ ...state, searchValue: '' }))
85
+ delayedSetSearchResult(null)
86
+ }
87
+
77
88
  const current = state.history[0]
78
89
  const children = current.children || []
79
90
  const level = state.history.length - 1
80
91
  const parentItem = transformParentItem(omit(current, 'children'))
81
92
 
82
- const hasSearchResult = state.searchValue?.length > 0
83
93
  const isSelectedWithLevel = item => isSelected(item, level)
84
94
  const currentTitle = current.title || title
85
95
 
@@ -117,16 +127,17 @@ const NestedSelect = ({
117
127
  [styles['search-container--without-title']]: !currentTitle
118
128
  })}
119
129
  >
120
- <Input
130
+ <SearchBar
121
131
  placeholder={searchOptions.placeholderSearch}
122
- onChange={onChange}
123
132
  value={state.searchValue}
133
+ onChange={onChange}
134
+ onClear={onClear}
124
135
  />
125
136
  </div>
126
137
  )}
127
138
 
128
- {hasSearchResult ? (
129
- state.searchResult.length === 0 ? (
139
+ {searchResult ? (
140
+ searchResult.length === 0 ? (
130
141
  <Typography
131
142
  variant="body1"
132
143
  className="u-flex u-flex-justify-center u-mb-1 "
@@ -134,14 +145,14 @@ const NestedSelect = ({
134
145
  {searchOptions.noDataLabel}
135
146
  </Typography>
136
147
  ) : (
137
- state.searchResult.map((item, index) => (
148
+ searchResult.map((item, index) => (
138
149
  <ItemRow
139
150
  radioPosition={radioPosition}
140
151
  key={item.key || item.title}
141
152
  item={item}
142
153
  onClick={handleClickItem}
143
154
  isSelected={isSelectedWithLevel(item)}
144
- isLast={index === state.searchResult.length - 1}
155
+ isLast={index === searchResult.length - 1}
145
156
  ellipsis={ellipsis}
146
157
  noDivider={noDivider}
147
158
  />
@@ -155,14 +155,7 @@ const InteractiveExample = () => {
155
155
  onSearch: (value) => {
156
156
  const options = makeOptions({ withHeaders })
157
157
  return options.children.filter(o => o.description && o.description.toLowerCase().includes(value.toLowerCase()))
158
- },
159
- displaySearchResultItem: item =>
160
- <ListItem key={item.id} dense button divider>
161
- <ListItemText
162
- primary={item.description}
163
- ellipsis
164
- />
165
- </ListItem>
158
+ }
166
159
  })
167
160
 
168
161
  const handleSelect = item => {
@@ -1,9 +1,9 @@
1
1
  import React from 'react'
2
2
  import '@testing-library/jest-dom'
3
- import { render, fireEvent } from '@testing-library/react'
3
+ import { render, fireEvent, waitFor } from '@testing-library/react'
4
4
 
5
5
  import NestedSelect from './NestedSelect'
6
- import { BreakpointsProvider } from '../providers/Breakpoints'
6
+ import DemoProvider from '../providers/DemoProvider'
7
7
 
8
8
  describe('NestedSelect', () => {
9
9
  const makeOption = text => ({
@@ -40,7 +40,7 @@ describe('NestedSelect', () => {
40
40
  const options = makeOptions(itemSelected)
41
41
 
42
42
  return render(
43
- <BreakpointsProvider>
43
+ <DemoProvider>
44
44
  <NestedSelect
45
45
  canSelectParent={canSelectParent}
46
46
  options={options}
@@ -49,7 +49,7 @@ describe('NestedSelect', () => {
49
49
  onCancel={onCancel}
50
50
  searchOptions={searchOptions}
51
51
  />
52
- </BreakpointsProvider>
52
+ </DemoProvider>
53
53
  )
54
54
  }
55
55
 
@@ -159,9 +159,11 @@ describe('NestedSelect', () => {
159
159
  const searchInput = getByPlaceholderText('Placeholder Search')
160
160
  expect(searchInput).toBeTruthy()
161
161
 
162
- fireEvent.change(searchInput, { target: { value: 'cozy' } })
163
- const noData = getByText('No Data Found')
164
- expect(noData).toBeTruthy()
162
+ waitFor(() => {
163
+ fireEvent.change(searchInput, { target: { value: 'cozy' } })
164
+ const noData = getByText('No Data Found')
165
+ expect(noData).toBeTruthy()
166
+ })
165
167
  })
166
168
 
167
169
  it('should show search results', () => {
@@ -186,11 +188,12 @@ describe('NestedSelect', () => {
186
188
  const searchInput = getByPlaceholderText('Placeholder Search')
187
189
  expect(searchInput).toBeTruthy()
188
190
 
189
- fireEvent.change(searchInput, { target: { value: 'cozy' } })
190
-
191
- expect(queryByText('cozy 1')).toBeTruthy()
192
- expect(queryByText('cozy 1')).toBeTruthy()
193
- expect(queryByText('anything')).toBeFalsy()
191
+ waitFor(() => {
192
+ fireEvent.change(searchInput, { target: { value: 'cozy' } })
193
+ expect(queryByText('cozy 1')).toBeTruthy()
194
+ expect(queryByText('cozy 1')).toBeTruthy()
195
+ expect(queryByText('anything')).toBeFalsy()
196
+ })
194
197
  })
195
198
  })
196
199
  })
@@ -13,5 +13,5 @@
13
13
  top -0.5rem
14
14
 
15
15
  .search-container--without-title
16
- margin-right 5rem
16
+ margin-right 1rem
17
17
  margin-top 0.5rem
@@ -0,0 +1,61 @@
1
+ import React from 'react'
2
+
3
+ import { themesList } from 'cozy-client/dist/models/document/documentTypeData'
4
+ import { isQualificationNote } from 'cozy-client/dist/models/document/documentTypeDataHelpers'
5
+ import { getBoundT } from 'cozy-client/dist/models/document/locales'
6
+
7
+ import Icon from '../Icon'
8
+ import FileTypeNoteIcon from '../Icons/FileTypeNote'
9
+ import QualificationIconStack from '../QualificationIconStack'
10
+
11
+ export const makeOptions = lang => {
12
+ const qualifT = getBoundT(lang)
13
+
14
+ return {
15
+ children: [
16
+ {
17
+ id: 'none',
18
+ title: qualifT('Scan.themes.none'),
19
+ icon: <QualificationIconStack />
20
+ },
21
+ ...themesList.map(theme => ({
22
+ id: theme.id,
23
+ title: qualifT(`Scan.themes.${theme.label}`),
24
+ icon: <QualificationIconStack theme={theme.label} />,
25
+ children: theme.items.map(item => ({
26
+ id: item.label,
27
+ item,
28
+ title: qualifT(`Scan.items.${item.label}`),
29
+ icon: isQualificationNote(item) ? (
30
+ <Icon icon={FileTypeNoteIcon} size={64} />
31
+ ) : (
32
+ <QualificationIconStack qualification={item.label} />
33
+ )
34
+ }))
35
+ }))
36
+ ]
37
+ }
38
+ }
39
+
40
+ export const searchOptionsFn = (options, value) => {
41
+ const deepOptions = options.children
42
+ .flatMap(child => child.children)
43
+ .reduce((acc, curr) => {
44
+ if (!!curr && !acc.some(el => el.id === curr.id)) {
45
+ acc.push(curr)
46
+ }
47
+ return acc
48
+ }, [])
49
+
50
+ return deepOptions.filter(deepOption =>
51
+ deepOption.title.toLowerCase().includes(value.toLowerCase())
52
+ )
53
+ }
54
+
55
+ export const makeSearchOptions = ({ options, title, noDataLabel, t }) => {
56
+ return {
57
+ placeholderSearch: title || t('QualificationModal.title'),
58
+ noDataLabel: noDataLabel || t('QualificationModal.noDataLabel'),
59
+ onSearch: value => searchOptionsFn(options, value)
60
+ }
61
+ }
@@ -0,0 +1,32 @@
1
+ import { searchOptionsFn } from './helpers'
2
+
3
+ describe('searchOptionsFn', () => {
4
+ it('should return only the uniq good result', () => {
5
+ const options = {
6
+ children: [
7
+ { id: 'none', title: 'None' },
8
+ {
9
+ id: 'theme1',
10
+ title: 'Identity',
11
+ children: [
12
+ { id: '01', title: 'Identity Photo' },
13
+ { id: '02', title: 'ID card' }
14
+ ]
15
+ },
16
+ {
17
+ id: 'theme2',
18
+ title: 'Family',
19
+ children: [
20
+ { id: '03', title: 'Family record book' },
21
+ { id: '04', title: 'Birth certificate' },
22
+ { id: '01', title: 'Identity Photo' }
23
+ ]
24
+ }
25
+ ]
26
+ }
27
+
28
+ const res = searchOptionsFn(options, 'photo')
29
+
30
+ expect(res).toStrictEqual([{ id: '01', title: 'Identity Photo' }])
31
+ })
32
+ })
@@ -2,54 +2,30 @@ import PropTypes from 'prop-types'
2
2
  import React, { useMemo } from 'react'
3
3
 
4
4
  import { useClient } from 'cozy-client'
5
- import { themesList } from 'cozy-client/dist/models/document/documentTypeData'
6
- import { isQualificationNote } from 'cozy-client/dist/models/document/documentTypeDataHelpers'
7
- import { getBoundT } from 'cozy-client/dist/models/document/locales'
8
5
  import { isSupportedQualification } from 'cozy-client/dist/models/document/qualification'
9
6
 
7
+ import { makeOptions, makeSearchOptions } from './helpers'
10
8
  import { locales } from './locales'
11
- import Icon from '../Icon'
12
- import FileTypeNoteIcon from '../Icons/FileTypeNote'
13
9
  import NestedSelectResponsive from '../NestedSelect/NestedSelectResponsive'
14
- import QualificationIconStack from '../QualificationIconStack'
15
10
  import { useI18n, useExtendI18n } from '../providers/I18n'
16
11
 
17
- const makeOptions = lang => {
18
- const qualifT = getBoundT(lang)
19
-
20
- return {
21
- children: [
22
- {
23
- id: 'none',
24
- title: qualifT('Scan.themes.none'),
25
- icon: <QualificationIconStack />
26
- },
27
- ...themesList.map(theme => ({
28
- id: theme.id,
29
- title: qualifT(`Scan.themes.${theme.label}`),
30
- icon: <QualificationIconStack theme={theme.label} />,
31
- children: theme.items.map(item => ({
32
- id: item.label,
33
- item,
34
- title: qualifT(`Scan.items.${item.label}`),
35
- icon: isQualificationNote(item) ? (
36
- <Icon icon={FileTypeNoteIcon} size={64} />
37
- ) : (
38
- <QualificationIconStack qualification={item.label} />
39
- )
40
- }))
41
- }))
42
- ]
43
- }
44
- }
45
-
46
- const QualificationModal = ({ file, title, onClose }) => {
12
+ const QualificationModal = ({ file, title, noDataLabel, onClose }) => {
47
13
  useExtendI18n(locales)
48
14
  const client = useClient()
49
15
  const { t, lang } = useI18n()
50
16
 
51
17
  const qualificationLabel = file.metadata?.qualification?.label
52
18
  const options = useMemo(() => makeOptions(lang), [lang])
19
+ const searchOptions = useMemo(
20
+ () =>
21
+ makeSearchOptions({
22
+ options,
23
+ title,
24
+ noDataLabel,
25
+ t
26
+ }),
27
+ [options, title, noDataLabel, t]
28
+ )
53
29
 
54
30
  const isSelected = ({ id, item }) => {
55
31
  return isSupportedQualification(qualificationLabel)
@@ -74,11 +50,11 @@ const QualificationModal = ({ file, title, onClose }) => {
74
50
 
75
51
  return (
76
52
  <NestedSelectResponsive
77
- title={title || t('QualificationModal.title')}
78
53
  options={options}
79
54
  noDivider
80
55
  document={file}
81
56
  isSelected={isSelected}
57
+ searchOptions={searchOptions}
82
58
  onSelect={handleClick}
83
59
  onClose={onClose}
84
60
  />
@@ -88,6 +64,7 @@ const QualificationModal = ({ file, title, onClose }) => {
88
64
  QualificationModal.propTypes = {
89
65
  file: PropTypes.object,
90
66
  title: PropTypes.string,
67
+ noDataLabel: PropTypes.string,
91
68
  onClose: PropTypes.func
92
69
  }
93
70
 
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "QualificationModal": {
3
- "title": "Document type"
3
+ "title": "Document type",
4
+ "noDataLabel": "No result"
4
5
  }
5
6
  }
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "QualificationModal": {
3
- "title": "Type de document"
3
+ "title": "Type de document",
4
+ "noDataLabel": "Aucun résultat"
4
5
  }
5
6
  }
@@ -61,7 +61,7 @@ $table-row-head
61
61
  $table-row-selected
62
62
  &
63
63
  &:hover
64
- background-color var(--zircon)
64
+ background-color var(--actionColorSelected)
65
65
 
66
66
  $table-cell
67
67
  box-sizing border-box
@@ -8,17 +8,18 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
8
8
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
9
9
 
10
10
  import cx from 'classnames';
11
+ import debounce from 'lodash/debounce';
11
12
  import omit from 'lodash/omit';
12
13
  import PropTypes from 'prop-types';
13
- import React, { useState, useRef } from 'react';
14
+ import React, { useState, useRef, useMemo } from 'react';
14
15
  import ItemRow from "cozy-ui/transpiled/react/NestedSelect/ItemRow";
15
16
  import { makeHistory } from "cozy-ui/transpiled/react/NestedSelect/helpers";
16
17
  var styles = {
17
18
  "Modal__back": "styles__Modal__back___qxUn_",
18
19
  "search-container--without-title": "styles__search-container--without-title___3P2fe"
19
20
  };
20
- import Input from "cozy-ui/transpiled/react/Input";
21
21
  import List from "cozy-ui/transpiled/react/List";
22
+ import SearchBar from "cozy-ui/transpiled/react/SearchBar";
22
23
  import Typography from "cozy-ui/transpiled/react/Typography";
23
24
  export { ItemRow };
24
25
  /**
@@ -29,8 +30,6 @@ export { ItemRow };
29
30
  */
30
31
 
31
32
  var NestedSelect = function NestedSelect(_ref) {
32
- var _state$searchValue;
33
-
34
33
  var onSelect = _ref.onSelect,
35
34
  ContentComponent = _ref.ContentComponent,
36
35
  HeaderComponent = _ref.HeaderComponent,
@@ -47,13 +46,21 @@ var NestedSelect = function NestedSelect(_ref) {
47
46
 
48
47
  var _useState = useState({
49
48
  history: makeHistory(options, canSelectParent),
50
- searchValue: '',
51
- searchResult: []
49
+ searchValue: ''
52
50
  }),
53
51
  _useState2 = _slicedToArray(_useState, 2),
54
52
  state = _useState2[0],
55
53
  setState = _useState2[1];
56
54
 
55
+ var _useState3 = useState(null),
56
+ _useState4 = _slicedToArray(_useState3, 2),
57
+ searchResult = _useState4[0],
58
+ setSearchResult = _useState4[1];
59
+
60
+ var delayedSetSearchResult = useMemo(function () {
61
+ return debounce(setSearchResult, 250);
62
+ }, [setSearchResult]);
63
+
57
64
  var handleBack = function handleBack() {
58
65
  var _state$history = _toArray(state.history),
59
66
  item = _state$history[0],
@@ -93,21 +100,31 @@ var NestedSelect = function NestedSelect(_ref) {
93
100
 
94
101
  if (onSearch) {
95
102
  var searchValue = ev.target.value;
96
- var searchResult = onSearch(searchValue);
103
+
104
+ var _searchResult = onSearch(searchValue);
105
+
97
106
  setState(function (state) {
98
107
  return _objectSpread(_objectSpread({}, state), {}, {
99
- searchValue: searchValue,
100
- searchResult: searchResult
108
+ searchValue: searchValue
101
109
  });
102
110
  });
111
+ delayedSetSearchResult(_searchResult);
103
112
  }
104
113
  };
105
114
 
115
+ var onClear = function onClear() {
116
+ setState(function (state) {
117
+ return _objectSpread(_objectSpread({}, state), {}, {
118
+ searchValue: ''
119
+ });
120
+ });
121
+ delayedSetSearchResult(null);
122
+ };
123
+
106
124
  var current = state.history[0];
107
125
  var children = current.children || [];
108
126
  var level = state.history.length - 1;
109
127
  var parentItem = transformParentItem(omit(current, 'children'));
110
- var hasSearchResult = ((_state$searchValue = state.searchValue) === null || _state$searchValue === void 0 ? void 0 : _state$searchValue.length) > 0;
111
128
 
112
129
  var isSelectedWithLevel = function isSelectedWithLevel(item) {
113
130
  return isSelected(item, level);
@@ -131,21 +148,22 @@ var NestedSelect = function NestedSelect(_ref) {
131
148
  className: cx('u-ml-1 u-mb-half', _defineProperty({
132
149
  'u-mr-1': currentTitle
133
150
  }, styles['search-container--without-title'], !currentTitle))
134
- }, /*#__PURE__*/React.createElement(Input, {
151
+ }, /*#__PURE__*/React.createElement(SearchBar, {
135
152
  placeholder: searchOptions.placeholderSearch,
153
+ value: state.searchValue,
136
154
  onChange: onChange,
137
- value: state.searchValue
138
- })), hasSearchResult ? state.searchResult.length === 0 ? /*#__PURE__*/React.createElement(Typography, {
155
+ onClear: onClear
156
+ })), searchResult ? searchResult.length === 0 ? /*#__PURE__*/React.createElement(Typography, {
139
157
  variant: "body1",
140
158
  className: "u-flex u-flex-justify-center u-mb-1 "
141
- }, searchOptions.noDataLabel) : state.searchResult.map(function (item, index) {
159
+ }, searchOptions.noDataLabel) : searchResult.map(function (item, index) {
142
160
  return /*#__PURE__*/React.createElement(ItemRow, {
143
161
  radioPosition: radioPosition,
144
162
  key: item.key || item.title,
145
163
  item: item,
146
164
  onClick: handleClickItem,
147
165
  isSelected: isSelectedWithLevel(item),
148
- isLast: index === state.searchResult.length - 1,
166
+ isLast: index === searchResult.length - 1,
149
167
  ellipsis: ellipsis,
150
168
  noDivider: noDivider
151
169
  });
@@ -0,0 +1,68 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import React from 'react';
3
+ import { themesList } from 'cozy-client/dist/models/document/documentTypeData';
4
+ import { isQualificationNote } from 'cozy-client/dist/models/document/documentTypeDataHelpers';
5
+ import { getBoundT } from 'cozy-client/dist/models/document/locales';
6
+ import Icon from "cozy-ui/transpiled/react/Icon";
7
+ import FileTypeNoteIcon from "cozy-ui/transpiled/react/Icons/FileTypeNote";
8
+ import QualificationIconStack from "cozy-ui/transpiled/react/QualificationIconStack";
9
+ export var makeOptions = function makeOptions(lang) {
10
+ var qualifT = getBoundT(lang);
11
+ return {
12
+ children: [{
13
+ id: 'none',
14
+ title: qualifT('Scan.themes.none'),
15
+ icon: /*#__PURE__*/React.createElement(QualificationIconStack, null)
16
+ }].concat(_toConsumableArray(themesList.map(function (theme) {
17
+ return {
18
+ id: theme.id,
19
+ title: qualifT("Scan.themes.".concat(theme.label)),
20
+ icon: /*#__PURE__*/React.createElement(QualificationIconStack, {
21
+ theme: theme.label
22
+ }),
23
+ children: theme.items.map(function (item) {
24
+ return {
25
+ id: item.label,
26
+ item: item,
27
+ title: qualifT("Scan.items.".concat(item.label)),
28
+ icon: isQualificationNote(item) ? /*#__PURE__*/React.createElement(Icon, {
29
+ icon: FileTypeNoteIcon,
30
+ size: 64
31
+ }) : /*#__PURE__*/React.createElement(QualificationIconStack, {
32
+ qualification: item.label
33
+ })
34
+ };
35
+ })
36
+ };
37
+ })))
38
+ };
39
+ };
40
+ export var searchOptionsFn = function searchOptionsFn(options, value) {
41
+ var deepOptions = options.children.flatMap(function (child) {
42
+ return child.children;
43
+ }).reduce(function (acc, curr) {
44
+ if (!!curr && !acc.some(function (el) {
45
+ return el.id === curr.id;
46
+ })) {
47
+ acc.push(curr);
48
+ }
49
+
50
+ return acc;
51
+ }, []);
52
+ return deepOptions.filter(function (deepOption) {
53
+ return deepOption.title.toLowerCase().includes(value.toLowerCase());
54
+ });
55
+ };
56
+ export var makeSearchOptions = function makeSearchOptions(_ref) {
57
+ var options = _ref.options,
58
+ title = _ref.title,
59
+ noDataLabel = _ref.noDataLabel,
60
+ t = _ref.t;
61
+ return {
62
+ placeholderSearch: title || t('QualificationModal.title'),
63
+ noDataLabel: noDataLabel || t('QualificationModal.noDataLabel'),
64
+ onSearch: function onSearch(value) {
65
+ return searchOptionsFn(options, value);
66
+ }
67
+ };
68
+ };
@@ -1,57 +1,20 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
3
  import PropTypes from 'prop-types';
5
4
  import React, { useMemo } from 'react';
6
5
  import { useClient } from 'cozy-client';
7
- import { themesList } from 'cozy-client/dist/models/document/documentTypeData';
8
- import { isQualificationNote } from 'cozy-client/dist/models/document/documentTypeDataHelpers';
9
- import { getBoundT } from 'cozy-client/dist/models/document/locales';
10
6
  import { isSupportedQualification } from 'cozy-client/dist/models/document/qualification';
7
+ import { makeOptions, makeSearchOptions } from "cozy-ui/transpiled/react/QualificationModal/helpers";
11
8
  import { locales } from "cozy-ui/transpiled/react/QualificationModal/locales";
12
- import Icon from "cozy-ui/transpiled/react/Icon";
13
- import FileTypeNoteIcon from "cozy-ui/transpiled/react/Icons/FileTypeNote";
14
9
  import NestedSelectResponsive from "cozy-ui/transpiled/react/NestedSelect/NestedSelectResponsive";
15
- import QualificationIconStack from "cozy-ui/transpiled/react/QualificationIconStack";
16
10
  import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
17
11
 
18
- var makeOptions = function makeOptions(lang) {
19
- var qualifT = getBoundT(lang);
20
- return {
21
- children: [{
22
- id: 'none',
23
- title: qualifT('Scan.themes.none'),
24
- icon: /*#__PURE__*/React.createElement(QualificationIconStack, null)
25
- }].concat(_toConsumableArray(themesList.map(function (theme) {
26
- return {
27
- id: theme.id,
28
- title: qualifT("Scan.themes.".concat(theme.label)),
29
- icon: /*#__PURE__*/React.createElement(QualificationIconStack, {
30
- theme: theme.label
31
- }),
32
- children: theme.items.map(function (item) {
33
- return {
34
- id: item.label,
35
- item: item,
36
- title: qualifT("Scan.items.".concat(item.label)),
37
- icon: isQualificationNote(item) ? /*#__PURE__*/React.createElement(Icon, {
38
- icon: FileTypeNoteIcon,
39
- size: 64
40
- }) : /*#__PURE__*/React.createElement(QualificationIconStack, {
41
- qualification: item.label
42
- })
43
- };
44
- })
45
- };
46
- })))
47
- };
48
- };
49
-
50
12
  var QualificationModal = function QualificationModal(_ref) {
51
13
  var _file$metadata, _file$metadata$qualif;
52
14
 
53
15
  var file = _ref.file,
54
16
  title = _ref.title,
17
+ noDataLabel = _ref.noDataLabel,
55
18
  onClose = _ref.onClose;
56
19
  useExtendI18n(locales);
57
20
  var client = useClient();
@@ -64,6 +27,14 @@ var QualificationModal = function QualificationModal(_ref) {
64
27
  var options = useMemo(function () {
65
28
  return makeOptions(lang);
66
29
  }, [lang]);
30
+ var searchOptions = useMemo(function () {
31
+ return makeSearchOptions({
32
+ options: options,
33
+ title: title,
34
+ noDataLabel: noDataLabel,
35
+ t: t
36
+ });
37
+ }, [options, title, noDataLabel, t]);
67
38
 
68
39
  var isSelected = function isSelected(_ref2) {
69
40
  var id = _ref2.id,
@@ -108,11 +79,11 @@ var QualificationModal = function QualificationModal(_ref) {
108
79
  }();
109
80
 
110
81
  return /*#__PURE__*/React.createElement(NestedSelectResponsive, {
111
- title: title || t('QualificationModal.title'),
112
82
  options: options,
113
83
  noDivider: true,
114
84
  document: file,
115
85
  isSelected: isSelected,
86
+ searchOptions: searchOptions,
116
87
  onSelect: handleClick,
117
88
  onClose: onClose
118
89
  });
@@ -121,6 +92,7 @@ var QualificationModal = function QualificationModal(_ref) {
121
92
  QualificationModal.propTypes = {
122
93
  file: PropTypes.object,
123
94
  title: PropTypes.string,
95
+ noDataLabel: PropTypes.string,
124
96
  onClose: PropTypes.func
125
97
  };
126
98
  export default QualificationModal;