@rh-support/cases 2.1.84 → 2.1.85

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.
@@ -1 +1 @@
1
- {"version":3,"file":"VersionsFilter.d.ts","sourceRoot":"","sources":["../../../../../src/components/case-list/case-list-filters/VersionsFilter.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA+B,MAAM,OAAO,CAAC;AAIpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAgB,MAAM,0BAA0B,CAAC;AAMxE,UAAU,MAAM;IACZ,WAAW,EAAE,cAAc,CAAC;IAC5B,mBAAmB,EAAE,uBAAuB,EAAE,CAAC;CAClD;AAED,wBAAgB,cAAc,CAAC,EAAE,WAAW,EAAE,mBAAmB,EAAE,EAAE,MAAM,qBA4D1E"}
1
+ {"version":3,"file":"VersionsFilter.d.ts","sourceRoot":"","sources":["../../../../../src/components/case-list/case-list-filters/VersionsFilter.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAI7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAgB,MAAM,0BAA0B,CAAC;AAoCxE,UAAU,MAAM;IACZ,WAAW,EAAE,cAAc,CAAC;IAC5B,mBAAmB,EAAE,uBAAuB,EAAE,CAAC;CAClD;AAED,wBAAgB,cAAc,CAAC,EAAE,WAAW,EAAE,mBAAmB,EAAE,EAAE,MAAM,qBA+D1E"}
@@ -1,6 +1,6 @@
1
1
  import { Select, SelectOption, SelectVariant } from '@patternfly/react-core/deprecated';
2
2
  import isEmpty from 'lodash/isEmpty';
3
- import React, { useContext, useState } from 'react';
3
+ import React, { useContext, useMemo, useState } from 'react';
4
4
  import { useTranslation } from 'react-i18next';
5
5
  import { SolrKeys, SolrPivotKeys } from '../../../enums/filters';
6
6
  import { CaseListFilterDispatchContext, CaseListFilterStateContext } from '../CaseListFilterContext';
@@ -8,6 +8,34 @@ import { updateFilter } from '../CaseListFilterReducer';
8
8
  function getVersionValuesForProduct(productPivot = [], productName) {
9
9
  return (productPivot.find((item) => item.value === productName) || {}).case_version;
10
10
  }
11
+ //split version into parts
12
+ function parseVersionIntoParts(version) {
13
+ //keep unknown version at last
14
+ if (version === 'Unknown')
15
+ return [Infinity];
16
+ //split dots and spaces
17
+ return version.split(/[.\s]/).map((p) => (isNaN(Number(p)) ? p : Number(p)));
18
+ }
19
+ function compareVersions(versionA, versionB) {
20
+ var _a, _b;
21
+ const pA = parseVersionIntoParts(versionA), pB = parseVersionIntoParts(versionB);
22
+ //compare each part
23
+ for (let i = 0; i < Math.max(pA.length, pB.length); i++) {
24
+ const a = (_a = pA[i]) !== null && _a !== void 0 ? _a : 0, b = (_b = pB[i]) !== null && _b !== void 0 ? _b : 0; //undefined as 0
25
+ if (a == b)
26
+ continue;
27
+ if (typeof a === 'number' && typeof b === 'number')
28
+ return a - b;
29
+ if (typeof a === 'string' && typeof b === 'string')
30
+ return a.localeCompare(b);
31
+ //one is string and other is number => string takes precendence
32
+ if (typeof a === 'string')
33
+ return -1;
34
+ if (typeof b == 'string')
35
+ return 1;
36
+ }
37
+ return 0;
38
+ }
11
39
  export function VersionsFilter({ productInfo, productVersionPivot }) {
12
40
  const { t } = useTranslation();
13
41
  const { filterInfo } = useContext(CaseListFilterStateContext);
@@ -29,7 +57,10 @@ export function VersionsFilter({ productInfo, productVersionPivot }) {
29
57
  };
30
58
  updateFilter(dispatch, { filterKey: SolrPivotKeys.product_version, values: productNewState });
31
59
  };
32
- const versions = getVersionValuesForProduct(productVersionPivot, productInfo.value);
60
+ const versions = useMemo(() => {
61
+ const versionValues = getVersionValuesForProduct(productVersionPivot, productInfo.value);
62
+ return versionValues === null || versionValues === void 0 ? void 0 : versionValues.sort((a, b) => compareVersions(a.value, b.value));
63
+ }, [productVersionPivot, productInfo.value]);
33
64
  const titleId = 'case-list-versions-filter';
34
65
  return (React.createElement(React.Fragment, null, !isEmpty(versions) && (React.createElement(React.Fragment, null,
35
66
  React.createElement("label", { hidden: true, htmlFor: titleId }, t('Open versions dropdown')),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rh-support/cases",
3
- "version": "2.1.84",
3
+ "version": "2.1.85",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -96,5 +96,5 @@
96
96
  "defaults and supports es6-module",
97
97
  "maintained node versions"
98
98
  ],
99
- "gitHead": "099d42e24ad273e72ecd1066dc081abe1b2e09f1"
99
+ "gitHead": "667a07388538d5e8a6e406b8bedfeabfef4b8cf4"
100
100
  }