Skip to content

Commit

Permalink
feat: add lint check to CI. (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrisbey authored Nov 28, 2023
1 parent 696160f commit 70068e8
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 46 deletions.
11 changes: 11 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Please always provide the [JIRA issue(s)]([../issues](https://jira.corp.adobe.com/)) your PR is for, as well as a description of your changes:

JIRA: ASSETS-00000

Test URLs:
<!--- For now you shouldn't add a path other than /sample-public-site. We can start changing -->
<!--- the URL after we've figured out how to run the CI on pages that require authentication. -->
<!--- /sample-public-site doesn't require authentication, so this is a way for us to ensure -->
<!--- that Franklin's CI (which we can't configure directly) will pass-->
- Before: https://main--assets-distribution-portal--adobe.hlx.page/sample-public-site
- After: https://<branch>--assets-distribution-portal--adobe.hlx.page/sample-public-site
17 changes: 17 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Linting

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16' #required for npm 8 or later.
- run: npm install
- run: npm run lint:js
env:
CI: true
2 changes: 1 addition & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["stylelint-config-standard", "stylelint-config-prettier"]
"extends": ["stylelint-config-standard"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export function hasAllAssetsSelected() {
return infiniteResultsContainer.hasAllItemsSelected();
}

export function selectedAssetsCount(){
export function selectedAssetsCount() {
return infiniteResultsContainer.getSelectedItemsCount();
}

export function allAssetsCount(){
export function allAssetsCount() {
return infiniteResultsContainer.getAllItemsCount();
}
}
26 changes: 14 additions & 12 deletions blocks/adp-selection-items/adp-selection-items.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { EventNames, addEventListener } from '../../scripts/events.js';
import { selectAllAssets, deselectAllAssets, hasAllAssetsSelected, selectedAssetsCount, allAssetsCount } from '../adp-infinite-results-instantsearch/adp-infinite-results-instantsearch.js';
import {
selectAllAssets, deselectAllAssets, hasAllAssetsSelected, selectedAssetsCount, allAssetsCount,
} from '../adp-infinite-results-instantsearch/adp-infinite-results-instantsearch.js';

export default function decorate(block) {
block.innerHTML = '';
Expand All @@ -15,7 +17,7 @@ export default function decorate(block) {
textLabel.classList.add('selection-text-label');
textLabel.innerText = 'Select All';
textLabel.title = 'Deselect all';
textLabel.setAttribute('for', 'select-all')
textLabel.setAttribute('for', 'select-all');
block.appendChild(textLabel);

const counterContainer = document.createElement('div');
Expand All @@ -36,7 +38,7 @@ export default function decorate(block) {
});

addEventListener(EventNames.ADD_ITEM_MULTISELECT, () => {
if (selectedAssetsCount()){
if (selectedAssetsCount()) {
checkbox.style.display = 'inline-block';
textLabel.style.display = 'inline-flex';
counterContainer.style.display = 'inline-flex';
Expand All @@ -46,9 +48,9 @@ export default function decorate(block) {
});
addEventListener(EventNames.REMOVE_ITEM_MULTISELECT, () => {
updateCheckbox(checkbox);
if(selectedAssetsCount()) {
if (selectedAssetsCount()) {
renderCounterText(counterContainer);
} else { //once no assets are selected
} else { // once no assets are selected
hideSelectionItems(checkbox, textLabel, counterContainer);
}
});
Expand All @@ -62,29 +64,29 @@ export default function decorate(block) {
});
addEventListener(EventNames.FACET, () => {
hideSelectionItems(checkbox, textLabel, counterContainer);
})
});
}

function updateCheckbox(checkbox) {
if (hasAllAssetsSelected()) {
checkbox.checked = true;
checkbox.indeterminate = false;
} else if (!hasAllAssetsSelected() && selectedAssetsCount()){ //if some assets are selected
} else if (!hasAllAssetsSelected() && selectedAssetsCount()) { // if some assets are selected
checkbox.checked = false;
checkbox.indeterminate = true;
} else { //if no assets are selected
} else { // if no assets are selected
checkbox.checked = false;
checkbox.indeterminate = false;
}
}

function hideSelectionItems(checkbox, textLabel, counterContainer){
function hideSelectionItems(checkbox, textLabel, counterContainer) {
checkbox.style.display = 'none';
textLabel.style.display = 'none';
counterContainer.style.display = 'none';
counterContainer.innerText = '';
counterContainer.innerText = '';
}

function renderCounterText(counterContainer){
function renderCounterText(counterContainer) {
counterContainer.innerText = `Selected ${selectedAssetsCount().toString()} out of ${allAssetsCount().toString()} assets`;
}
}
25 changes: 0 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"fs": "^0.0.1-security",
"sinon": "15.0.1",
"stylelint": "15.2.0",
"stylelint-config-prettier": "9.0.4",
"stylelint-config-standard": "30.0.1",
"webpack-cli": "^5.1.4"
},
Expand Down
6 changes: 3 additions & 3 deletions scripts/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const EventNames = {
/**
* Sent whenever a user selects all assets in the infinite results container
* via the "Select All" checkbox
*
*
* The event's detail will contain the following properties:
* * selections: Array of the selected ids.
*/
Expand All @@ -11,12 +11,12 @@ export const EventNames = {
/**
* Sent whenever a user deselects all assets in the infinite results container
* via the "Select All" checkbox
*
*
* The event's detail will contain the following properties:
* * selections: Array of the selected ids.
*/
DESELECT_ALL_ITEMS: 'deselect-all-items',

/**
* Sent whenever a user selects an asset in the infinite results panel.
*
Expand Down
2 changes: 1 addition & 1 deletion scripts/infinite-results/InfiniteResultsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default class InfiniteResultsContainer {
* Checks if all assets in the infininte results container have been selected via card checkbox
*/
hasAllItemsSelected() {
if (this.#selectedItems.length) return this.#itemCount === this.#selectedItems.length;
return this.#selectedItems.length && this.#itemCount === this.#selectedItems.length;
}

/**
Expand Down

0 comments on commit 70068e8

Please sign in to comment.