@magento/peregrine 12.2.0-alpha.1 → 12.2.0

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.
@@ -104,6 +104,35 @@ export const getFiltersFromSearch = initialValue => {
104
104
  return filters;
105
105
  };
106
106
 
107
+ /**
108
+ * Sort filters array
109
+ * @param {Array} initialArray an array containing filters data
110
+ */
111
+ export const sortFiltersArray = initialArray => {
112
+ return initialArray.sort((a, b) => {
113
+ // Place Category filter first
114
+ if (a['attribute_code'] === 'category_id') {
115
+ return -1;
116
+ }
117
+ if (b['attribute_code'] === 'category_id') {
118
+ return 1;
119
+ }
120
+
121
+ // Sort alphabetically if same position
122
+ if (a['position'] === b['position']) {
123
+ if (a['label'] < b['label']) {
124
+ return -1;
125
+ }
126
+ if (a['label'] > b['label']) {
127
+ return 1;
128
+ }
129
+ }
130
+
131
+ // Sort by position
132
+ return a['position'] - b['position'];
133
+ });
134
+ };
135
+
107
136
  export const stripHtml = html => html.replace(/(<([^>]+)>)/gi, '');
108
137
 
109
138
  /** GetFilterInput helpers below. */
@@ -6,7 +6,12 @@ import { useAppContext } from '@magento/peregrine/lib/context/app';
6
6
 
7
7
  import mergeOperations from '../../util/shallowMerge';
8
8
  import { useFilterState } from './useFilterState';
9
- import { getSearchFromState, getStateFromSearch, stripHtml } from './helpers';
9
+ import {
10
+ getSearchFromState,
11
+ getStateFromSearch,
12
+ sortFiltersArray,
13
+ stripHtml
14
+ } from './helpers';
10
15
 
11
16
  import DEFAULT_OPERATIONS from './filterModal.gql';
12
17
 
@@ -83,7 +88,9 @@ export const useFilterModal = props => {
83
88
  const keys = new Set();
84
89
  const itemsByGroup = new Map();
85
90
 
86
- for (const filter of filters) {
91
+ const sortedFilters = sortFiltersArray([...filters]);
92
+
93
+ for (const filter of sortedFilters) {
87
94
  const { options, label: name, attribute_code: group } = filter;
88
95
 
89
96
  // If this aggregation is not a possible filter, just back out.
@@ -9,6 +9,7 @@ import { useFilterState } from '../FilterModal';
9
9
  import {
10
10
  getSearchFromState,
11
11
  getStateFromSearch,
12
+ sortFiltersArray,
12
13
  stripHtml
13
14
  } from '../FilterModal/helpers';
14
15
 
@@ -77,7 +78,9 @@ export const useFilterSidebar = props => {
77
78
  const keys = new Set();
78
79
  const itemsByGroup = new Map();
79
80
 
80
- for (const filter of filters) {
81
+ const sortedFilters = sortFiltersArray([...filters]);
82
+
83
+ for (const filter of sortedFilters) {
81
84
  const { options, label: name, attribute_code: group } = filter;
82
85
 
83
86
  // If this aggregation is not a possible filter, just back out.
@@ -13,6 +13,7 @@ export const GET_PRODUCT_FILTERS_BY_CATEGORY = gql`
13
13
  label
14
14
  value
15
15
  }
16
+ position
16
17
  }
17
18
  }
18
19
  }
@@ -60,12 +60,14 @@ export const ProductDetailsFragment = gql`
60
60
  }
61
61
  data_type
62
62
  is_system
63
- is_visible_on_front
64
63
  entity_type
65
64
  ui_input {
66
65
  ui_input_type
67
66
  is_html_allowed
68
67
  }
68
+ ... on ProductAttributeMetadata {
69
+ used_in_components
70
+ }
69
71
  }
70
72
  }
71
73
  ... on ConfigurableProduct {
@@ -138,12 +140,14 @@ export const ProductDetailsFragment = gql`
138
140
  }
139
141
  data_type
140
142
  is_system
141
- is_visible_on_front
142
143
  entity_type
143
144
  ui_input {
144
145
  ui_input_type
145
146
  is_html_allowed
146
147
  }
148
+ ... on ProductAttributeMetadata {
149
+ used_in_components
150
+ }
147
151
  }
148
152
  }
149
153
  }
@@ -21,6 +21,7 @@ export const GET_PRODUCT_FILTERS_BY_SEARCH = gql`
21
21
  label
22
22
  value
23
23
  }
24
+ position
24
25
  }
25
26
  }
26
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magento/peregrine",
3
- "version": "12.2.0-alpha.1",
3
+ "version": "12.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },