catalog-react: support string=number comparisons for entity predicates

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-03-06 00:30:49 +01:00
parent 6d85ae8321
commit 91e4fef6a3
2 changed files with 9 additions and 0 deletions
@@ -109,6 +109,8 @@ describe('entityPredicateToFilterFunction', () => {
owner: 'g',
definition: 'mock',
nothing: null,
oneNum: 1,
oneStr: '1',
},
relations: [
{
@@ -219,6 +221,10 @@ describe('entityPredicateToFilterFunction', () => {
['', { 'spec.nothing': null }],
['w,g,a', { $not: { 'spec.type': 'service' } }],
['', { 'spec.type': null }],
['a', { 'spec.oneNum': 1 }],
['a', { 'spec.oneStr': 1 }],
['a', { 'spec.oneNum': '1' }],
['a', { 'spec.oneStr': '1' }],
[
's,w',
{
@@ -117,6 +117,9 @@ function valuesAreEqual(
if (typeof a === 'string' && typeof b === 'string') {
return a.toLocaleUpperCase('en-US') === b.toLocaleUpperCase('en-US');
}
if (typeof a === 'number' || typeof b === 'number') {
return String(a) === String(b);
}
if (Array.isArray(a) && Array.isArray(b)) {
return a.length === b.length && a.every((v, i) => valuesAreEqual(v, b[i]));
}