feat(core): add text filtering to dep-graph visualization

This commit is contained in:
Philip Fulcher 2020-06-25 14:25:01 -06:00 committed by Victor Savkin
parent d74ab4e9d6
commit 840b7deb84
3 changed files with 77 additions and 1 deletions

View File

@ -253,3 +253,12 @@ g.affected ellipse {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
#textFilterInput {
flex: 1;
margin-right: 1.5em;
}
#textFilterButton {
flex: none;
}

View File

@ -45,6 +45,21 @@
group by folder group by folder
</label> </label>
</div> </div>
<div class="sidebar-section">
<div class="flex">
<input id="textFilterInput" type="text" name="filter" />
<button id="textFilterButton">Filter</button>
</div>
<label>
<input
type="checkbox"
name="textFilterCheckbox"
value="includeInPath"
/>
include projects in path
</label>
</div>
<div id="project-lists"></div> <div id="project-lists"></div>
</div> </div>
</div> </div>
@ -136,7 +151,7 @@
window.graph = null; window.graph = null;
window.affected = null; window.affected = null;
window.focusedProject = null; window.focusedProject = null;
window.filteredProjects = null; window.filteredProjects = [];
window.groupByFolder = null; window.groupByFolder = null;
window.exclude = null; window.exclude = null;
</script> </script>

View File

@ -496,6 +496,56 @@ window.filterProjects = () => {
render(); render();
}; };
function listenForTextFilterChanges() {
const textFilterInput = document.getElementById('textFilterInput');
const textFilterButton = document.getElementById('textFilterButton');
textFilterButton.addEventListener('click', () => {
filterProjectsByText(textFilterInput.value.toLowerCase());
});
textFilterInput.addEventListener('keyup', (event) => {
if (event.key === 'Enter') {
filterProjectsByText(textFilterInput.value.toLowerCase());
}
});
}
function filterProjectsByText(text) {
const checkboxes = Array.from(
document.querySelectorAll('input[name=projectName]')
);
checkboxes.forEach((checkbox) => (checkbox.checked = false));
const split = text.split(',').map((splitItem) => splitItem.trim());
const matchedProjects = checkboxes
.map((checkbox) => checkbox.value)
.filter(
(project) =>
split.findIndex((splitItem) => project.includes(splitItem)) > -1
);
const includeInPath = document.querySelector('input[name=textFilterCheckbox]')
.checked;
matchedProjects.forEach((project) => {
checkboxes.forEach((checkbox) => {
if (
checkbox.value === project ||
(includeInPath &&
(hasPath(project, checkbox.value, []) ||
hasPath(checkbox.value, project, [])))
) {
checkbox.checked = true;
}
});
});
window.filterProjects();
}
setTimeout(() => { setTimeout(() => {
addProjectCheckboxes(); addProjectCheckboxes();
checkForAffected(); checkForAffected();
@ -520,5 +570,7 @@ setTimeout(() => {
window.exclude.forEach((project) => excludeProject(project, false)); window.exclude.forEach((project) => excludeProject(project, false));
} }
listenForTextFilterChanges();
filterProjects(); filterProjects();
}); });