Skip to content

Commit

Permalink
ENG-48510 - dd support for single selection per category in the al-ca…
Browse files Browse the repository at this point in the history
…rdstack 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
  • Loading branch information
dev4ndy authored Mar 30, 2023
1 parent fa2fc9a commit f65dc5b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,6 @@ dist
.pnp.*

.idea

#history
.history
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.196",
"version": "1.0.197",
"description": "Node Enterprise Packages for Alert Logic (NEPAL) Core Library",
"main": "./dist/index.cjs.js",
"types": "./dist/index.d.ts",
Expand Down
18 changes: 8 additions & 10 deletions ps_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ stages:
- pull_request
- pull_request:
trigger_phrase: test it
image: node:13
image: public.ecr.aws/codebuild/amazonlinux2-x86_64-standard:4.0
compute_size: small
commands:
- npm install
- echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- apt-get update && apt-get -y install google-chrome-stable jq
- export CHROME_BIN='/usr/bin/google-chrome'
- curl https://intoli.com/install-google-chrome.sh | bash
- mv /usr/bin/google-chrome-stable /usr/bin/google-chrome
- google-chrome --version && which google-chrome
- npm run test
- npm run lint
- npm run build
Expand Down Expand Up @@ -60,13 +59,12 @@ stages:
name: Master Push - Publish
when:
- push: ['master']
image: node:13
image: public.ecr.aws/codebuild/amazonlinux2-x86_64-standard:4.0
compute_size: small
commands:
- echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- apt-get update && apt-get -y install google-chrome-stable
- export CHROME_BIN='/usr/bin/google-chrome'
- curl https://intoli.com/install-google-chrome.sh | bash
- mv /usr/bin/google-chrome-stable /usr/bin/google-chrome
- google-chrome --version && which google-chrome
- |
set -ex
Expand Down
26 changes: 21 additions & 5 deletions src/common/cardstack/al-cardstack-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ export abstract class AlCardstackView< EntityType=any,
/**
* Applies a filter to the current view, optionally specifying a custom filter callback.
*/
public applyFilterBy( vDescriptor:AlCardstackValueDescriptor,
public applyFilterBy( vDescriptor:AlCardstackValueDescriptor, resetActiveFilters: boolean = false,
callback?:{(entity:EntityType,properties:PropertyType,filter:AlCardstackActiveFilter<EntityType,PropertyType>):boolean} ) {

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

vDescriptors.forEach(vDescriptor => {
this.updateActiveFilters(vDescriptor, callback);
this.updateActiveFilters(vDescriptor, resetActiveFilters, callback);
});
}

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

protected updateActiveFilters(vDescriptor:AlCardstackValueDescriptor,
/**
* Updates the list of active filters based on the provided value descriptor.
*
* @param {AlCardstackValueDescriptor} vDescriptor - The value descriptor to apply as a filter.
* @param {boolean} [resetActiveFilters=false] - If true, clears all filters in the same category as the one being applied, leaving only the new filter active.
* @param {function} [callback] - An optional callback function to be called when the filter is applied.
* @returns {void}
*/
protected updateActiveFilters(vDescriptor:AlCardstackValueDescriptor, resetActiveFilters: boolean = false,
callback?:{(entity:EntityType,properties:PropertyType,filter:AlCardstackActiveFilter<EntityType,PropertyType>):boolean}) {
const pDescriptor = this.getProperty( vDescriptor.property );
const existing = this.activeFilters.find( filter => filter.property === pDescriptor );
if ( existing ) {
if ( existing.values.includes( vDescriptor ) ) {
return; // no change
}
if ( resetActiveFilters ) {
existing.values = [];
pDescriptor.values.forEach(value => {
if ( vDescriptor.value !== value.value ) {
value.activeFilter = false;
}
});
}
existing.values.push( vDescriptor );
existing.rawValues = existing.values.map( vDescr => vDescr.value );
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/common/al-cardstack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ describe( 'AlCardstackView', () => {
it( 'should show/hide items based on a custom filter', () => {
let firstCard = stack.cards[0];
let color = stack.getValue( "color", firstCard.properties.color );
stack.applyFilterBy( color, ( e, p, f ) => false );
stack.applyFilterBy( color, false, ( e, p, f ) => false );
for ( let i = 0; i < stack.cards.length; i++ ) {
let card = stack.cards[i];
expect( card.visible ).to.equal( false );
Expand Down

0 comments on commit f65dc5b

Please sign in to comment.