gatsby-core-theme 44.30.6 → 44.30.7
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/CHANGELOG.md +10 -0
- package/package.json +1 -1
- package/src/helpers/search.js +17 -0
- package/src/helpers/search.test.js +72 -1
- package/src/helpers/server-data.js +6 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## [44.30.7](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v44.30.6...v44.30.7) (2026-07-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* filter nonactive opertors ([9b9e7ee](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/9b9e7eed246697404be814022f09b9cc430de7d1))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
* Merge branch 'en=580-nonactive-operators' into 'master' ([4896cdd](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/4896cdd5304f25c51c0b85cc342cb37419604292))
|
|
10
|
+
|
|
1
11
|
## [44.30.6](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v44.30.5...v44.30.6) (2026-06-29)
|
|
2
12
|
|
|
3
13
|
|
package/package.json
CHANGED
package/src/helpers/search.js
CHANGED
|
@@ -50,3 +50,20 @@ export function sortIntOn(key) {
|
|
|
50
50
|
export function normalizeForSearch(str) {
|
|
51
51
|
return str.toLowerCase().replace(/\s+/g, "");
|
|
52
52
|
}
|
|
53
|
+
|
|
54
|
+
const isInactiveOperator = (item) =>
|
|
55
|
+
item.type === "operator" && item?.relation?.status !== "active";
|
|
56
|
+
export function filterSearchResults(results = [], searchTerm) {
|
|
57
|
+
const term = (searchTerm || "").toLowerCase();
|
|
58
|
+
const matched = results.filter((item) =>
|
|
59
|
+
item.title.toLowerCase().includes(term)
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (!searchTerm) {
|
|
63
|
+
return matched.filter((item) => !isInactiveOperator(item));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return [...matched].sort(
|
|
67
|
+
(a, b) => Number(isInactiveOperator(a)) - Number(isInactiveOperator(b))
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
filterByKey,
|
|
3
|
+
sortStringOn,
|
|
4
|
+
sortIntOn,
|
|
5
|
+
sortDateOn,
|
|
6
|
+
filterSearchResults,
|
|
7
|
+
} from './search';
|
|
2
8
|
import loadSource from './search-source';
|
|
9
|
+
import searchIndex from '../../tests/factories/search/data.json';
|
|
3
10
|
|
|
4
11
|
describe('Scroll test', () => {
|
|
5
12
|
test('loadSource()', () => {
|
|
@@ -62,3 +69,67 @@ describe('Scroll test', () => {
|
|
|
62
69
|
expect(arr.sort(sortDateOn('created_at'))).toEqual(sorted);
|
|
63
70
|
});
|
|
64
71
|
});
|
|
72
|
+
|
|
73
|
+
describe('filterSearchResults', () => {
|
|
74
|
+
const results = [
|
|
75
|
+
{ title: 'Ladbrokes Casino', type: 'operator', relation: { status: 'inactive' } },
|
|
76
|
+
{ title: 'Betfair Casino', type: 'operator', relation: { status: 'blacklisted' } },
|
|
77
|
+
{ title: 'Upcoming Casino', type: 'operator', relation: { status: 'coming_soon' } },
|
|
78
|
+
{ title: 'NotRec Casino', type: 'operator', relation: { status: 'not_recommended' } },
|
|
79
|
+
{ title: 'Active Casino', type: 'operator', relation: { status: 'active' } },
|
|
80
|
+
{ title: 'Another Active Casino', type: 'operator', relation: { status: 'active' } },
|
|
81
|
+
{ title: 'Casino News Article', type: 'article' },
|
|
82
|
+
{ title: 'Blackjack Game', type: 'game' },
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
test('empty search shows active casinos only (hides inactive/upcoming/blacklisted/not_recommended)', () => {
|
|
86
|
+
const titles = filterSearchResults(results, '').map((i) => i.title);
|
|
87
|
+
expect(titles).toContain('Active Casino');
|
|
88
|
+
expect(titles).toContain('Another Active Casino');
|
|
89
|
+
expect(titles).not.toContain('Ladbrokes Casino');
|
|
90
|
+
expect(titles).not.toContain('Betfair Casino');
|
|
91
|
+
expect(titles).not.toContain('Upcoming Casino');
|
|
92
|
+
expect(titles).not.toContain('NotRec Casino');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('empty search keeps non-operator content (articles, games)', () => {
|
|
96
|
+
const titles = filterSearchResults(results, '').map((i) => i.title);
|
|
97
|
+
expect(titles).toContain('Casino News Article');
|
|
98
|
+
expect(titles).toContain('Blackjack Game');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('active search keeps inactive casinos so they remain findable', () => {
|
|
102
|
+
const titles = filterSearchResults(results, 'ladbrokes').map((i) => i.title);
|
|
103
|
+
expect(titles).toContain('Ladbrokes Casino');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('active search orders active casinos before inactive ones', () => {
|
|
107
|
+
const operators = filterSearchResults(results, 'casino').filter(
|
|
108
|
+
(i) => i.type === 'operator'
|
|
109
|
+
);
|
|
110
|
+
let seenInactive = false;
|
|
111
|
+
const activeAfterInactive = operators.some((op) => {
|
|
112
|
+
const active = op.relation?.status === 'active';
|
|
113
|
+
if (!active) {
|
|
114
|
+
seenInactive = true;
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return seenInactive;
|
|
118
|
+
});
|
|
119
|
+
expect(activeAfterInactive).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('does not mutate the input array', () => {
|
|
123
|
+
const snapshot = [...results];
|
|
124
|
+
filterSearchResults(results, 'casino');
|
|
125
|
+
expect(results).toEqual(snapshot);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('empty search on the generated index keeps only active operators', () => {
|
|
129
|
+
const operatorStatuses = filterSearchResults(searchIndex.arab_en, '')
|
|
130
|
+
.filter((i) => i.type === 'operator')
|
|
131
|
+
.map((i) => i.relation?.status);
|
|
132
|
+
expect(operatorStatuses.length).toBeGreaterThan(0);
|
|
133
|
+
expect(operatorStatuses.every((status) => status === 'active')).toBe(true);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -8,6 +8,7 @@ import { deparam } from "~helpers/strings";
|
|
|
8
8
|
import { groupBy } from "~helpers/getters";
|
|
9
9
|
import processor from "../resolver/index.mjs";
|
|
10
10
|
import { fetchSiteSettings } from "../services/fetch.mjs";
|
|
11
|
+
import { filterSearchResults } from "~helpers/search";
|
|
11
12
|
|
|
12
13
|
export async function getAPIData(page, url, headers, preview) {
|
|
13
14
|
if (preview) {
|
|
@@ -91,22 +92,16 @@ export async function getAPIData(page, url, headers, preview) {
|
|
|
91
92
|
urlParams = deparam(`${url.split("?")[1]}`);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
const
|
|
95
|
-
? urlParams.hasOwnProperty("s")
|
|
96
|
-
? groupBy(
|
|
97
|
-
results.filter((item) =>
|
|
98
|
-
item.title.toLowerCase().includes(urlParams.s.toLowerCase())
|
|
99
|
-
),
|
|
100
|
-
"pageType"
|
|
101
|
-
)
|
|
102
|
-
: null
|
|
103
|
-
: null;
|
|
95
|
+
const hasSearchParam = Boolean(urlParams && urlParams.hasOwnProperty("s"));
|
|
104
96
|
|
|
97
|
+
const searchData = hasSearchParam
|
|
98
|
+
? groupBy(filterSearchResults(results, urlParams.s), "pageType")
|
|
99
|
+
: null;
|
|
105
100
|
|
|
106
101
|
return {
|
|
107
102
|
props: {
|
|
108
103
|
data: searchData,
|
|
109
|
-
searchParam:
|
|
104
|
+
searchParam: hasSearchParam ? urlParams.s : null,
|
|
110
105
|
},
|
|
111
106
|
};
|
|
112
107
|
}
|