Skip to content

add support for filtering jobs in workload list#74

Open
Panaetius wants to merge 2 commits intomainfrom
job-filter
Open

add support for filtering jobs in workload list#74
Panaetius wants to merge 2 commits intomainfrom
job-filter

Conversation

@Panaetius
Copy link
Member

@Panaetius Panaetius commented Mar 23, 2026

closes #20

@Panaetius Panaetius requested a review from a team as a code owner March 23, 2026 14:56
@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix index calculation for job status selection

The code assumes that all values in self.values are valid indices into
JobStatus::VARIANTS, but this may not be true when 'All' is selected. The index
calculation should account for the offset caused by inserting "All" at index 0.

coman/src/components/job_status_filter_popup.rs [87-91]

 let selected_statuses = self
     .values
     .iter()
-    .map(|v| <JobStatus as VariantArray>::VARIANTS[*v - 1].clone())
+    .filter(|&&v| v != 0) // Skip 'All' selection
+    .map(|&v| <JobStatus as VariantArray>::VARIANTS[v - 1].clone())
     .collect();
Suggestion importance[1-10]: 8

__

Why: The suggestion identifies a potential bug in the index calculation when mapping selected values back to JobStatus variants. The code assumes all indices are valid, but when 'All' is selected, the indexing needs adjustment. This could lead to incorrect job status filtering, making it a medium-high impact issue.

Medium
Prevent potential panic during job status conversion

The conversion from string to JobStatus uses unwrap() which can cause a panic if the
input string is malformed. A safer approach would be to return an error or default
value instead.

coman/src/cscs/api_client/types.rs [196-201]

 impl From<String> for JobStatus {
     fn from(value: String) -> Self {
-        match value.split_whitespace().next().unwrap().to_uppercase().as_str() {
+        match value.split_whitespace().next().unwrap_or("").to_uppercase().as_str() {
             "RUNNING" => JobStatus::Running,
             "FAILED" => JobStatus::Failed,
             "COMPLETED" => JobStatus::Finished,
             "CANCELLED" => JobStatus::Cancelled,
 ...
Suggestion importance[1-10]: 7

__

Why: While the suggestion correctly identifies a potential panic risk with unwrap(), the fix suggested (unwrap_or("")) doesn't fully resolve the issue since the code still relies on .split_whitespace().next() which could return None. However, this is a reasonable improvement for robustness, though not critical.

Medium
General
Simplify job listing with optional filtering

The filtering logic does not properly handle the case where status is None. It
should still return all jobs when no filter is applied, which is currently handled
correctly, but the function signature suggests it could be simplified.

coman/src/cscs/api_client/client.rs [113-130]

+pub async fn list_jobs(
+    &self,
+    status: Option<Vec<JobStatus>>,
+    system_name: &str,
+    all_users: Option<bool>,
+) -> Result<Vec<Job>> {
+    let result = get_compute_system_jobs(&self.client, system_name, all_users)
+        .await
+        .wrap_err("couldn't fetch cscs jobs")?;
+    let mut result: Vec<Job> = result
+        .jobs
+        .map(|jobs| jobs.into_iter().map(|j| j.into()).collect())
+        .unwrap_or(vec![]);
+    if let Some(filter) = status {
+        result.retain(|j| filter.contains(&j.status));
+    }
+    Ok(result)
+}
 
-
Suggestion importance[1-10]: 3

__

Why: The suggestion proposes simplifying the function, but the existing implementation already correctly handles the None case. The function signature and logic are already appropriate, so this suggestion offers minimal improvement and doesn't address any real issue.

Low

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow filtering jobs by current project and status

1 participant