Skip to content

Commit

Permalink
feat(board): rework card selection
Browse files Browse the repository at this point in the history
* Standard click on links opens them on GitHub
* SHIFT + click adds to filter or removes it
* CTRL + click sets filter to selected element

Closes #35
  • Loading branch information
nikku committed Jul 30, 2019
1 parent 5ec83f5 commit 7c62a00
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
11 changes: 6 additions & 5 deletions packages/board/src/Card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
isOpenOrMerged,
isPull,
hasModifier,
hasShiftModifier,
noDuplicates
} from './util';
Expand Down Expand Up @@ -64,17 +65,17 @@
$: cardUrl = `https://github.com/${ repositoryName }/issues/${ number }`;
function handleSelection(qualifier, value) {
function handleSelection(qualifier, value, clickThrough=true) {
return function(event) {
if (hasModifier(event)) {
if (clickThrough && !hasModifier(event)) {
return;
}
event.preventDefault();
onSelect(qualifier, value);
onSelect(qualifier, value, hasShiftModifier(event));
};
}
</script>
Expand Down Expand Up @@ -209,7 +210,7 @@
<Tag
class="tag milestone"
name={ milestone.title }
onClick={ onSelect && handleSelection('milestone', milestone.title) }
onClick={ onSelect && handleSelection('milestone', milestone.title, false) }
/>
{/if}

Expand All @@ -218,7 +219,7 @@
class="tag label"
color="#{ color }"
name={ name }
onClick={ onSelect && handleSelection('label', name) }
onClick={ onSelect && handleSelection('label', name, false) }
/>
{/each}

Expand Down
7 changes: 4 additions & 3 deletions packages/board/src/CardLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import LinkIcon from './components/LinkIcon.svelte';
import {
hasModifier
hasModifier,
hasShiftModifier
} from './util';
export let item;
Expand Down Expand Up @@ -32,13 +33,13 @@
return function(event) {
if (hasModifier(event)) {
if (!hasModifier(event)) {
return;
}
event.preventDefault();
onSelect(qualifier, value);
onSelect(qualifier, value, hasShiftModifier(event));
};
}
</script>
Expand Down
26 changes: 23 additions & 3 deletions packages/board/src/Taskboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,35 @@
return () => teardownHooks.forEach(fn => fn && fn());
});
function applyFilter(qualifier, value) {
function applyFilter(qualifier, value, add) {
if (/[\s:]+/.test(value)) {
value = '"' + value + '"';
}
if (value) {
return filterChanged(`${qualifier}:${value}`);
const criteria = value && `${qualifier}:${value}`;
if (!criteria) {
return;
}
let newFilter;
const criteriaIndex = filter.indexOf(criteria);
if (criteriaIndex === 0) {
newFilter = filter.substring(criteria.length + 1);
} else if (criteriaIndex > 0) {
newFilter = filter.substring(0, criteriaIndex - 1) + filter.substring(criteriaIndex + criteria.length);
} else {
if (add && filter.trim()) {
newFilter = `${filter} ${qualifier}:${value}`;
} else {
newFilter = criteria;
}
}
return filterChanged(newFilter);
}
function filterChanged(value, pushHistory=true) {
Expand Down
4 changes: 4 additions & 0 deletions packages/board/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export function hasModifier(event) {
return event.ctrlKey || event.shiftKey || event.altKey || event.metaKey;
}

export function hasShiftModifier(event) {
return event.shiftKey;
}

export function noDuplicates(keyFn) {

const found = {};
Expand Down

0 comments on commit 7c62a00

Please sign in to comment.