feat(ui): add environment filter toggle buttons
This commit is contained in:
+28
-1
@@ -13,6 +13,7 @@ const closeStatus = document.getElementById('close-status');
|
||||
const refreshBranchesBtn = document.getElementById('refresh-branches');
|
||||
const applyChangesBtn = document.getElementById('apply-changes');
|
||||
const branchFilter = document.getElementById('branch-filter');
|
||||
const envFilterToggles = document.getElementById('env-filter-toggles');
|
||||
const appVersion = document.getElementById('app-version');
|
||||
|
||||
// Branches list (flattened) for UI rendering: [{ envId, envName, branch, commits: [] }]
|
||||
@@ -21,6 +22,7 @@ let filteredBranches = [];
|
||||
|
||||
// Toggle state: show all branches or filtered
|
||||
let showAllBranches = false;
|
||||
const activeEnvFilters = new Set();
|
||||
|
||||
// Environment runtime state storage:
|
||||
// environmentsRaw: array as received from backend: [ [envObj, jobsArr], ... ]
|
||||
@@ -68,6 +70,7 @@ function checkForPendingChanges() {
|
||||
function filterBranches() {
|
||||
const filterText = branchFilter.value.toLowerCase().trim();
|
||||
filteredBranches = branches.filter(({envId, branch, commits}) => {
|
||||
if (activeEnvFilters.size > 0 && !activeEnvFilters.has(envId)) return false;
|
||||
const selList = selectedBranchesByEnv[envId] || [];
|
||||
const isSelected = selList.some(([b]) => b === branch);
|
||||
// Always show branches that appear in any column (e.g. deployed branches from GitUnmerge)
|
||||
@@ -86,6 +89,29 @@ function filterBranches() {
|
||||
renderBranches();
|
||||
}
|
||||
|
||||
function renderEnvironmentFilters() {
|
||||
const environments = environmentsRaw
|
||||
.filter(envObj => envObj && (envObj.id || envObj.name))
|
||||
.map(envObj => ({id: envObj.id || envObj.name, name: envObj.name || envObj.id}))
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
const environmentIds = new Set(environments.map(env => env.id));
|
||||
[...activeEnvFilters].forEach(envId => {
|
||||
if (!environmentIds.has(envId)) activeEnvFilters.delete(envId);
|
||||
});
|
||||
envFilterToggles.innerHTML = environments.map(({id, name}) => `
|
||||
<button type="button" class="env-filter-toggle${activeEnvFilters.has(id) ? ' active' : ''}" data-env="${escapeHtml(id)}" aria-pressed="${activeEnvFilters.has(id)}">${escapeHtml(name)}</button>
|
||||
`).join('');
|
||||
envFilterToggles.querySelectorAll('.env-filter-toggle').forEach(button => {
|
||||
button.onclick = () => {
|
||||
const envId = button.dataset.env;
|
||||
if (activeEnvFilters.has(envId)) activeEnvFilters.delete(envId);
|
||||
else activeEnvFilters.add(envId);
|
||||
renderEnvironmentFilters();
|
||||
filterBranches();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function getCommitDropdownOptions(envId, branchName, desiredCommit) {
|
||||
const branchObj = branches.find(b => b.envId === envId && b.branch === branchName);
|
||||
let options = '';
|
||||
@@ -156,7 +182,7 @@ function renderBranches() {
|
||||
}
|
||||
checkForPendingChanges();
|
||||
|
||||
const branchesToShow = filteredBranches.length > 0 || branchFilter.value.trim() ? filteredBranches : branches;
|
||||
const branchesToShow = filteredBranches.length > 0 || branchFilter.value.trim() || activeEnvFilters.size > 0 ? filteredBranches : branches;
|
||||
if (!branchesToShow.length) {
|
||||
branchesList.innerHTML = '<p class="loading">No branches found.</p>';
|
||||
return;
|
||||
@@ -426,6 +452,7 @@ function setupWebSockets() {
|
||||
const data = message.environments;
|
||||
payload = data || {};
|
||||
environmentsRaw = Object.values(payload);
|
||||
renderEnvironmentFilters();
|
||||
|
||||
// Sync selections and column data per environment
|
||||
environmentsRaw.forEach((envObj) => {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<input type="text" id="branch-filter"
|
||||
placeholder="Filter branches by name, commit ID, or commit message..." class="filter-input">
|
||||
</div>
|
||||
<div id="env-filter-toggles" class="env-filter-toggles" aria-label="Environment filters"></div>
|
||||
<div class="control-bar" style="float: left;">
|
||||
<button id="toggle-show-all" class="toggle-button">Show All</button>
|
||||
</div>
|
||||
|
||||
@@ -136,6 +136,31 @@ body {
|
||||
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
|
||||
}
|
||||
|
||||
.env-filter-toggles {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
clear: both;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.env-filter-toggle {
|
||||
background: #fff;
|
||||
color: #495057;
|
||||
border: 1px solid #adb5bd;
|
||||
border-radius: 4px;
|
||||
padding: 8px 14px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.env-filter-toggle:hover,
|
||||
.env-filter-toggle.active {
|
||||
background: #007bff;
|
||||
color: #fff;
|
||||
border-color: #007bff;
|
||||
}
|
||||
|
||||
/* Branches table styling */
|
||||
.branches-table {
|
||||
width: 100%;
|
||||
|
||||
Reference in New Issue
Block a user