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

✨ adding filter& sort by analysis to Application-inventory table #2100

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import { useLocalTableControls } from "@app/hooks/table-controls";

// Queries
import { getArchetypeById, getAssessmentsByItemId } from "@app/api/rest";
import { Assessment, Ref } from "@app/api/models";
import { Assessment, Ref, TaskState } from "@app/api/models";
import {
useBulkDeleteApplicationMutation,
useFetchApplications,
Expand All @@ -88,7 +88,10 @@ import { useFetchTagsWithTagItems } from "@app/queries/tags";

// Relative components
import { AnalysisWizard } from "../analysis-wizard/analysis-wizard";
import { ApplicationAnalysisStatus } from "../components/application-analysis-status";
import {
ApplicationAnalysisStatus,
taskStateToAnalyze,
} from "../components/application-analysis-status";
import { ApplicationAssessmentStatus } from "../components/application-assessment-status";
import { ApplicationBusinessService } from "../components/application-business-service";
import { ApplicationDependenciesForm } from "@app/components/ApplicationDependenciesFormContainer/ApplicationDependenciesForm";
Expand Down Expand Up @@ -334,7 +337,7 @@ export const ApplicationsTable: React.FC = () => {
sort: "sessionStorage",
},
isLoading: isFetchingApplications,
sortableColumns: ["name", "businessService", "tags", "effort"],
sortableColumns: ["name", "businessService", "tags", "effort", "analysis"],
initialSort: { columnKey: "name", direction: "asc" },
initialColumns: {
name: { isIdentity: true },
Expand All @@ -344,6 +347,7 @@ export const ApplicationsTable: React.FC = () => {
businessService: app.businessService?.name || "",
tags: app.tags?.length || 0,
effort: app.effort || 0,
analysis: app.tasks.currentAnalyzer?.state || "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should sort on labels visible on the screen - see the propsed mapAnalysisStateToLabel below

}),
filterCategories: [
{
Expand Down Expand Up @@ -498,7 +502,38 @@ export const ApplicationsTable: React.FC = () => {
],
getItemValue: (item) => normalizeRisk(item.risk) ?? "",
},

{
categoryKey: "analysis",
title: t("terms.analysis"),
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", {
what: t("terms.analysis").toLowerCase(),
}) + "...",

selectOptions: Object.values(applications)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applications is already an array - no need to use Object.values

.map((a) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to re-use the same mapper for sorting so let's create a named function for that.
The steps remain the same i.e. (pseudo-code)

const mapAnalysisStateToLabel = (value: TaskState) => {
   // for consistency let's use the same wa of converting as the rest of the code
   const presetKey: IconedStatusPreset = getTaskStatus(value);
  // as for now the presets are created inside the  IconedStatus
  // we need refactor this code and extract this functionality to a function i.e.buildPresets() 
  // this is best to do under a different PR 
   const presets = buildPresets(t);
   // IMHO fallback to "Unknown" makes most sense
   const label = presets[presetKey]?.label ?? t("terms.unknown");
   return label;
}

Links:
getTaskStatus(value)

Copy link

@TalyaNaima TalyaNaima Nov 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the functions mentioned here are pushed in #2152

let value = a?.tasks.currentAnalyzer?.state || "No Task";

if (value === "No Task") {
value = "No task";
}

let label = taskStateToAnalyze.get(value as TaskState) || value;

if (label === "NotStarted") {
label = "Not started";
}
return { value, label };
})
.filter((v, i, a) => a.findIndex((v2) => v2.label === v.label) === i)
.sort((a, b) => a.value.localeCompare(b.value)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should sort on label - note also that universalComparator helper adds some extra power to localeCompare ("natural sorting")


getItemValue: (item) => item?.tasks.currentAnalyzer?.state || "No Task",
rszwajko marked this conversation as resolved.
Show resolved Hide resolved
},
],

initialItemsPerPage: 10,
hasActionsColumn: true,
isSelectionEnabled: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface ApplicationAnalysisStatusProps {
state: TaskState;
}

const taskStateToAnalyze: Map<TaskState, IconedStatusPreset> = new Map([
export const taskStateToAnalyze: Map<TaskState, IconedStatusPreset> = new Map([
["not supported", "Canceled"],
["Canceled", "Canceled"],
["Created", "Scheduled"],
Expand Down
Loading