Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing the pending pipelines on top #1488

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/src/store/pipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { computed, reactive, Ref, ref } from 'vue';
import useApiClient from '~/compositions/useApiClient';
import { Pipeline, PipelineFeed, PipelineWorkflow } from '~/lib/api/types';
import { useRepoStore } from '~/store/repos';
import { comparePipelines, isPipelineActive } from '~/utils/helpers';
import { comparePipelines, comparePipelinesWithStatus, isPipelineActive } from '~/utils/helpers';

export const usePipelineStore = defineStore('pipelines', () => {
const apiClient = useApiClient();
Expand Down Expand Up @@ -71,7 +71,7 @@ export const usePipelineStore = defineStore('pipelines', () => {
);
return [...acc, ...repoPipelinesArray];
}, [])
.sort(comparePipelines)
.sort(comparePipelinesWithStatus)
.filter((pipeline) => repoStore.ownedRepoIds.includes(pipeline.repo_id)),
);

Expand Down
13 changes: 13 additions & 0 deletions web/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ export function comparePipelines(a: Pipeline, b: Pipeline): number {
return (b.created_at || -1) - (a.created_at || -1);
}

/**
* Compare two pipelines by the status.
* Giving pending, running, or started higher priority than other status
* @param {Object} a - A pipeline.
* @param {Object} b - A pipeline.
* @returns {number}
*/
export function comparePipelinesWithStatus(a: Pipeline, b: Pipeline): number {
6543 marked this conversation as resolved.
Show resolved Hide resolved
const bPriority = ['pending', 'running', 'started'].includes(b.status) ? 1 : 0;
const aPriority = ['pending', 'running', 'started'].includes(a.status) ? 1 : 0;
return bPriority - aPriority;
}

export function isPipelineActive(pipeline: Pipeline): boolean {
return ['pending', 'running', 'started'].includes(pipeline.status);
}
Expand Down