Skip to content

Commit f65dc5b

Browse files
authored
ENG-48510 - dd support for single selection per category in the al-cardstack component (#256)
* ENG-48510 - dd support for single selection per category in the al-cardstack component * fix unit test * adding spaces in the if * fix pipeline * fix pipeline #2
1 parent fa2fc9a commit f65dc5b

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,6 @@ dist
190190
.pnp.*
191191

192192
.idea
193+
194+
#history
195+
.history

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@al/core",
3-
"version": "1.0.196",
3+
"version": "1.0.197",
44
"description": "Node Enterprise Packages for Alert Logic (NEPAL) Core Library",
55
"main": "./dist/index.cjs.js",
66
"types": "./dist/index.d.ts",

ps_spec.yml

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ stages:
88
- pull_request
99
- pull_request:
1010
trigger_phrase: test it
11-
image: node:13
11+
image: public.ecr.aws/codebuild/amazonlinux2-x86_64-standard:4.0
1212
compute_size: small
1313
commands:
1414
- npm install
15-
- echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
16-
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
17-
- apt-get update && apt-get -y install google-chrome-stable jq
18-
- export CHROME_BIN='/usr/bin/google-chrome'
15+
- curl https://intoli.com/install-google-chrome.sh | bash
16+
- mv /usr/bin/google-chrome-stable /usr/bin/google-chrome
17+
- google-chrome --version && which google-chrome
1918
- npm run test
2019
- npm run lint
2120
- npm run build
@@ -60,13 +59,12 @@ stages:
6059
name: Master Push - Publish
6160
when:
6261
- push: ['master']
63-
image: node:13
62+
image: public.ecr.aws/codebuild/amazonlinux2-x86_64-standard:4.0
6463
compute_size: small
6564
commands:
66-
- echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
67-
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
68-
- apt-get update && apt-get -y install google-chrome-stable
69-
- export CHROME_BIN='/usr/bin/google-chrome'
65+
- curl https://intoli.com/install-google-chrome.sh | bash
66+
- mv /usr/bin/google-chrome-stable /usr/bin/google-chrome
67+
- google-chrome --version && which google-chrome
7068
- |
7169
set -ex
7270

src/common/cardstack/al-cardstack-view.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@ export abstract class AlCardstackView< EntityType=any,
299299
/**
300300
* Applies a filter to the current view, optionally specifying a custom filter callback.
301301
*/
302-
public applyFilterBy( vDescriptor:AlCardstackValueDescriptor,
302+
public applyFilterBy( vDescriptor:AlCardstackValueDescriptor, resetActiveFilters: boolean = false,
303303
callback?:{(entity:EntityType,properties:PropertyType,filter:AlCardstackActiveFilter<EntityType,PropertyType>):boolean} ) {
304304

305-
this.updateActiveFilters(vDescriptor, callback);
305+
this.updateActiveFilters(vDescriptor, resetActiveFilters, callback);
306306
const pDescriptor = this.getProperty( vDescriptor.property );
307307
if ( pDescriptor.remote ) {
308308
this.start(); // restart view
@@ -315,11 +315,11 @@ export abstract class AlCardstackView< EntityType=any,
315315
/**
316316
* Applies multiple filter to the current view, optionally specifying a custom filter callback.
317317
*/
318-
public applyMultipleFilterBy( vDescriptors:AlCardstackValueDescriptor[],
318+
public applyMultipleFilterBy( vDescriptors:AlCardstackValueDescriptor[], resetActiveFilters: boolean = false,
319319
callback?:{(entity:EntityType,properties:PropertyType,filter:AlCardstackActiveFilter<EntityType,PropertyType>):boolean} ) {
320320

321321
vDescriptors.forEach(vDescriptor => {
322-
this.updateActiveFilters(vDescriptor, callback);
322+
this.updateActiveFilters(vDescriptor, resetActiveFilters, callback);
323323
});
324324
}
325325

@@ -708,14 +708,30 @@ export abstract class AlCardstackView< EntityType=any,
708708
return this.activeFilters.filter( filter => filter.property.remote );
709709
}
710710

711-
protected updateActiveFilters(vDescriptor:AlCardstackValueDescriptor,
711+
/**
712+
* Updates the list of active filters based on the provided value descriptor.
713+
*
714+
* @param {AlCardstackValueDescriptor} vDescriptor - The value descriptor to apply as a filter.
715+
* @param {boolean} [resetActiveFilters=false] - If true, clears all filters in the same category as the one being applied, leaving only the new filter active.
716+
* @param {function} [callback] - An optional callback function to be called when the filter is applied.
717+
* @returns {void}
718+
*/
719+
protected updateActiveFilters(vDescriptor:AlCardstackValueDescriptor, resetActiveFilters: boolean = false,
712720
callback?:{(entity:EntityType,properties:PropertyType,filter:AlCardstackActiveFilter<EntityType,PropertyType>):boolean}) {
713721
const pDescriptor = this.getProperty( vDescriptor.property );
714722
const existing = this.activeFilters.find( filter => filter.property === pDescriptor );
715723
if ( existing ) {
716724
if ( existing.values.includes( vDescriptor ) ) {
717725
return; // no change
718726
}
727+
if ( resetActiveFilters ) {
728+
existing.values = [];
729+
pDescriptor.values.forEach(value => {
730+
if ( vDescriptor.value !== value.value ) {
731+
value.activeFilter = false;
732+
}
733+
});
734+
}
719735
existing.values.push( vDescriptor );
720736
existing.rawValues = existing.values.map( vDescr => vDescr.value );
721737
} else {

test/common/al-cardstack.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ describe( 'AlCardstackView', () => {
359359
it( 'should show/hide items based on a custom filter', () => {
360360
let firstCard = stack.cards[0];
361361
let color = stack.getValue( "color", firstCard.properties.color );
362-
stack.applyFilterBy( color, ( e, p, f ) => false );
362+
stack.applyFilterBy( color, false, ( e, p, f ) => false );
363363
for ( let i = 0; i < stack.cards.length; i++ ) {
364364
let card = stack.cards[i];
365365
expect( card.visible ).to.equal( false );

0 commit comments

Comments
 (0)