Skip to content

Commit

Permalink
Us116156 - case insensitive search (#5)
Browse files Browse the repository at this point in the history
* US116156 - case insensitive search

* US116156 - case insensitive search
  • Loading branch information
scottarver authored Apr 20, 2020
1 parent a5eb76b commit 08d9f7c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@al/core",
"version": "1.0.3",
"version": "1.0.4",
"description": "Nepal Core",
"main": "./dist/index.cjs.js",
"types": "./dist/index.d.ts",
Expand Down
27 changes: 16 additions & 11 deletions src/common/cardstack/al-cardstack-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export abstract class AlCardstackView< EntityType=any,
public async continue() {
this.loading = true;
try {
let entities = [];
let cardsSection = [];
let entities :EntityType[] = [];
let cardsSection:AlCardstackItem<EntityType>[];

if (this.localPagination) {
cardsSection = this.filteredCards.slice(this.cards.length, this.cards.length + this.itemsPerPage);
Expand Down Expand Up @@ -369,16 +369,15 @@ export abstract class AlCardstackView< EntityType=any,
id: string;
caption: string;
}[]{
let newData = entities.map( entity => {
let properties = this.deriveEntityProperties( entity );
return entities.map(entity => {
const properties = this.deriveEntityProperties(entity);
return {
properties,
entity,
id: properties.id,
caption: properties.caption
};
} );
return newData;
});
}

/**
Expand Down Expand Up @@ -450,25 +449,31 @@ export abstract class AlCardstackView< EntityType=any,
if (!card.properties.hasOwnProperty(property) || !(card.properties as any)[property]) {
return false;
}
const cardPropValue = (card.properties as any)[property];
const cardPropValue: unknown[]|unknown = (card.properties as any)[property];
if (Array.isArray(cardPropValue)) {
const matches = cardPropValue.find((value) => {
const matches = cardPropValue.some((value:unknown) => {
if(typeof value !== 'string'){
console.error('cardPropValue must be a string');
return false;
}
if (search instanceof RegExp) {
return search.test(value);
}
if (typeof search === "string") {
return value.includes(search);
return value.toLowerCase().includes(search.toLowerCase());
}
console.error("Search should be a string or regex.");
return false;
});
if (matches) {
return true;
}
} else if ( search instanceof RegExp && search.test(cardPropValue)) {
} else if ( search instanceof RegExp && typeof cardPropValue === 'string' && search.test(cardPropValue)) {
return true;
} else if ( typeof search === "string" && cardPropValue.includes(search)) {
} else if ( typeof search === "string" && (typeof cardPropValue === 'string' || Array.isArray(cardPropValue)) && cardPropValue.includes(search)) {
return true;
}else{
console.error('Unknown search type for ',cardPropValue);
}
return false;
});
Expand Down

0 comments on commit 08d9f7c

Please sign in to comment.