@griddo/ax 10.1.73 → 10.1.74

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/ax",
3
3
  "description": "Griddo Author Experience",
4
- "version": "10.1.73",
4
+ "version": "10.1.74",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -233,5 +233,5 @@
233
233
  "publishConfig": {
234
234
  "access": "public"
235
235
  },
236
- "gitHead": "b6055975421e2aec8714822b77b0392b6a9290e9"
236
+ "gitHead": "67ea3b4084fb731daaef0fef90fedf0a6a8e0892"
237
237
  }
@@ -337,7 +337,7 @@ describe("search field events", () => {
337
337
  const fieldWrapper = screen.getByTestId("field-wrapper");
338
338
  const input = screen.getByTestId("search-input");
339
339
  expect(fieldWrapper).toBeTruthy();
340
- fireEvent.keyDown(input, { key: "A", code: "KeyA" });
340
+ fireEvent.change(input, { target: { value: "a" } });
341
341
  expect(onChangeMock).toBeCalledTimes(1);
342
342
  });
343
343
 
@@ -3,7 +3,7 @@ import React, { useState } from "react";
3
3
  import { structuredData } from "@ax/api";
4
4
  import { isReqOk } from "@ax/helpers";
5
5
  import { IGetStructuredDataParams, IDataSource, ISite, IStructuredData } from "@ax/types";
6
- import { Button, CheckField, FieldsBehavior, FloatingMenu, Icon, IconAction, Tag } from "@ax/components";
6
+ import { Button, CheckField, FieldsBehavior, FloatingMenu, Icon, IconAction, SearchField, Tag } from "@ax/components";
7
7
 
8
8
  import * as S from "./style";
9
9
 
@@ -15,6 +15,7 @@ const AutoItem = (props: IProps) => {
15
15
  options: [],
16
16
  filter,
17
17
  isOpen: false,
18
+ filteredOptions: [],
18
19
  };
19
20
 
20
21
  const [state, setState] = useState(initState);
@@ -79,7 +80,7 @@ const AutoItem = (props: IProps) => {
79
80
  try {
80
81
  const result = await structuredData.getDataContents(params, siteID);
81
82
  if (isReqOk(result.status)) {
82
- setState({ ...state, selected: newValue, options: result.data.items });
83
+ setState({ ...state, selected: newValue, options: result.data.items, filteredOptions: result.data.items });
83
84
  }
84
85
  } catch (e) {
85
86
  console.log(e);
@@ -88,10 +89,10 @@ const AutoItem = (props: IProps) => {
88
89
  };
89
90
 
90
91
  const handleSelectOnChange = (newValue: string | null) => {
91
- if(newValue){
92
+ if (newValue) {
92
93
  getCategoryContent(newValue);
93
94
  } else {
94
- setState({ ...state, selected: "", options: [] });
95
+ setState({ ...state, selected: "", options: [], filteredOptions: [] });
95
96
  }
96
97
  };
97
98
 
@@ -128,6 +129,13 @@ const AutoItem = (props: IProps) => {
128
129
  addFilter(newFilters, source.id);
129
130
  };
130
131
 
132
+ const handleSearchChange = (query: string) => {
133
+ const filteredOptions = state.options.filter(
134
+ (option) => option.content.title.toLowerCase().indexOf(query.toLowerCase()) !== -1
135
+ );
136
+ setState({ ...state, filteredOptions });
137
+ };
138
+
131
139
  return (
132
140
  <S.TypeContainer key={source.id}>
133
141
  <S.TypeWrapper>
@@ -158,9 +166,14 @@ const AutoItem = (props: IProps) => {
158
166
  entityId={source.id}
159
167
  site={site}
160
168
  />
169
+ {state.options.length > 0 && (
170
+ <S.SearchWrapper>
171
+ <SearchField onChange={handleSearchChange} searchOnEnter={false} size="XS" />
172
+ </S.SearchWrapper>
173
+ )}
161
174
  <S.ChecksWrapper>
162
- {state.options &&
163
- state.options.map((option: any) => (
175
+ {state.filteredOptions &&
176
+ state.filteredOptions.map((option: any) => (
164
177
  <CheckField
165
178
  key={option.content.title}
166
179
  title={option.content.title}
@@ -188,6 +201,7 @@ interface IState {
188
201
  options: any[];
189
202
  filter: any[];
190
203
  isOpen: boolean;
204
+ filteredOptions: any[];
191
205
  }
192
206
 
193
207
  interface IProps {
@@ -121,6 +121,11 @@ const ChecksWrapper = styled.div`
121
121
  overflow: auto;
122
122
  `;
123
123
 
124
+ const SearchWrapper = styled.div`
125
+ margin-top: ${(p) => `-${p.theme.spacing.s}`};
126
+ margin-bottom: ${(p) => p.theme.spacing.xs};
127
+ `;
128
+
124
129
  export {
125
130
  IconActionWrapper,
126
131
  IconWrapper,
@@ -135,4 +140,5 @@ export {
135
140
  FiltersWrapper,
136
141
  ButtonWrapper,
137
142
  ChecksWrapper,
143
+ SearchWrapper,
138
144
  };
@@ -14,6 +14,7 @@ const SearchField = (props: ISearchFieldProps): JSX.Element => {
14
14
  searchFilters,
15
15
  onFilterChange,
16
16
  small,
17
+ size = "M",
17
18
  } = props;
18
19
 
19
20
  const [isOpen, setIsOpen] = useState(false);
@@ -26,6 +27,9 @@ const SearchField = (props: ISearchFieldProps): JSX.Element => {
26
27
  const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
27
28
  const newValue = e.target.value;
28
29
  setInputValue(newValue);
30
+ if (!searchOnEnter) {
31
+ onChange(newValue);
32
+ }
29
33
  };
30
34
 
31
35
  const handleClear = () => {
@@ -44,7 +48,7 @@ const SearchField = (props: ISearchFieldProps): JSX.Element => {
44
48
  };
45
49
 
46
50
  const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
47
- if (!searchOnEnter || e.key === "Enter") {
51
+ if (searchOnEnter && e.key === "Enter") {
48
52
  onChange(inputValue);
49
53
  }
50
54
  };
@@ -93,6 +97,7 @@ const SearchField = (props: ISearchFieldProps): JSX.Element => {
93
97
  disabled={disabled}
94
98
  data-testid="search-input"
95
99
  small={small}
100
+ inputSize={size}
96
101
  />
97
102
  {inputValue.trim() !== "" && searchOnEnter && <S.HelpText>Press ENTER</S.HelpText>}
98
103
  {closeOnInactive || inputValue.length > 0 ? (
@@ -123,6 +128,7 @@ export interface ISearchFieldProps {
123
128
  searchFilters?: any;
124
129
  onFilterChange?(filter: string): void;
125
130
  small?: boolean;
131
+ size?: "M" | "S" | "XS";
126
132
  }
127
133
 
128
134
  export default SearchField;
@@ -19,15 +19,21 @@ const FieldWrapper = styled.div<{ closeOnInactive: boolean; disabled: boolean }>
19
19
  border-radius: ${(p) => (p.closeOnInactive ? 0 : p.theme.radii.s)};
20
20
  `;
21
21
 
22
- const Input = styled.input<{ closeOnInactive: boolean; disabled: boolean; small?: boolean }>`
22
+ const Input = styled.input<{
23
+ closeOnInactive: boolean;
24
+ disabled: boolean;
25
+ small?: boolean;
26
+ inputSize: "M" | "S" | "XS";
27
+ }>`
23
28
  ${(p) => p.theme.textStyle.fieldContent};
24
29
  color: ${(p) => p.theme.color.textHighEmphasis};
25
30
  background-color: ${(p) => p.theme.color.interactiveBackground};
26
31
  flex: 1 1 auto;
27
- height: ${(p) => p.theme.spacing.l};
32
+ height: ${(p) => (p.inputSize === "XS" ? "40px" : p.theme.spacing.l)};
28
33
  padding-left: ${(p) => p.theme.spacing.xs};
29
34
  border: none;
30
- width: ${(p) => (p.small ? `calc(${p.theme.spacing.xl} * 2)` : `calc(${p.theme.spacing.xl} * 4)`)};
35
+ width: ${(p) =>
36
+ p.small || p.inputSize !== "M" ? `calc(${p.theme.spacing.xl} * 2)` : `calc(${p.theme.spacing.xl} * 4)`};
31
37
 
32
38
  &:active,
33
39
  &:focus {