Skip to content

Commit

Permalink
Fix aggregated wave status. Reflect all states in Jira instance
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <ibolton@redhat.com>
  • Loading branch information
ibolton336 committed Jul 12, 2023
1 parent d17502f commit 1a58075
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
type={isPasswordHidden ? "password" : "text"}
formGroupProps={{
labelIcon: !isPasswordEncrypted ? (
// TODO: add info icon for auth text explanation
<KeyDisplayToggle
keyName="password"
isKeyHidden={isPasswordHidden}
Expand All @@ -707,12 +708,13 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
<HookFormPFTextInput
control={control}
name="key"
label={"key"}
label={"Token"}
fieldId="key"
isRequired={true}
type={isKeyHidden ? "password" : "text"}
formGroupProps={{
labelIcon: !isKeyEncrypted ? (
// TODO: add info icon for auth text explanation
<KeyDisplayToggle
keyName="key"
isKeyHidden={isKeyHidden}
Expand Down
16 changes: 0 additions & 16 deletions client/src/app/pages/identities/identities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,6 @@ export const Identities: React.FC = () => {
return item.kind || "";
},
},
{
key: "createdBy",
title: "Created By",
type: FilterType.search,
placeholderText: "Filter by created by User...",
getItemValue: (item) => {
return item.createUser || "";
},
},
];

const { filterValues, setFilterValues, filteredItems } = useLegacyFilterState(
Expand All @@ -148,7 +139,6 @@ export const Identities: React.FC = () => {
identity?.name || "",
"", // description column
identity?.kind || "",
identity?.createUser || "",
"", // Action column
];
const { sortBy, onSort, sortedItems } = useLegacySortState(
Expand All @@ -167,7 +157,6 @@ export const Identities: React.FC = () => {
},
{ title: "Description", transforms: [cellWidth(25)] },
{ title: "Type", transforms: [sortable, cellWidth(20)] },
{ title: "Created by", transforms: [sortable, cellWidth(10)] },
{
title: "",
props: {
Expand Down Expand Up @@ -203,11 +192,6 @@ export const Identities: React.FC = () => {
</TableText>
),
},
{
title: (
<TableText wrapModifier="truncate">{item.createUser}</TableText>
),
},
{
title: (
<AppTableActionButtons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export const WaveForm: React.FC<WaveFormProps> = ({
}) => {
const { t } = useTranslation();

const { migrationWaves } = useFetchMigrationWaves();
const { pushNotification } = React.useContext(NotificationsContext);

const { stakeholders } = useFetchStakeholders();
Expand Down
4 changes: 1 addition & 3 deletions client/src/app/pages/migration-waves/migration-waves.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ export const MigrationWaves: React.FC = () => {
const { t } = useTranslation();
const { pushNotification } = React.useContext(NotificationsContext);

const { migrationWaves, isFetching, fetchError, refetch } =
useFetchMigrationWaves();

const { migrationWaves, isFetching, fetchError } = useFetchMigrationWaves();
const { trackers: trackers } = useFetchTrackers();
const { data: applications } = useFetchApplications();

Expand Down
14 changes: 11 additions & 3 deletions client/src/app/queries/migration-waves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
deleteAllMigrationWaves,
} from "@app/api/rest";
import { getWavesWithStatus } from "@app/utils/waves-selector";
import { TicketsQueryKey } from "./tickets";
import { useFetchTickets } from "./tickets";
import { TrackersQueryKey } from "./trackers";
import { useFetchApplications } from "./applications";
import { useFetchStakeholders } from "./stakeholders";

export const MigrationWavesQueryKey = "migration-waves";

Expand All @@ -29,14 +32,19 @@ export const useCreateMigrationWaveMutation = (
};

export const useFetchMigrationWaves = () => {
const { tickets } = useFetchTickets();
const { stakeholders } = useFetchStakeholders();
const { data: applications } = useFetchApplications();

const queryClient = useQueryClient();
const { isLoading, error, refetch, data } = useQuery({
queryKey: [MigrationWavesQueryKey],
queryFn: getMigrationWaves,
refetchInterval: 5000,
onError: (error) => console.log("error, ", error),
onSuccess: () => queryClient.invalidateQueries([TicketsQueryKey]),
select: (waves) => getWavesWithStatus(queryClient, waves),
onSuccess: () => queryClient.invalidateQueries([TrackersQueryKey]),
select: (waves) =>
getWavesWithStatus(waves, tickets, stakeholders, applications),
});
return {
migrationWaves: data || [],
Expand Down
42 changes: 19 additions & 23 deletions client/src/app/utils/waves-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,14 @@ import {
TicketStatus,
WaveWithStatus,
} from "@app/api/models";
import { ApplicationsQueryKey } from "@app/queries/applications";
import { StakeholdersQueryKey } from "@app/queries/stakeholders";
import { TicketsQueryKey } from "@app/queries/tickets";
import { QueryClient, useQueryClient } from "@tanstack/react-query";
import dayjs from "dayjs";

export const getWavesWithStatus = (
queryClient: QueryClient,
waves: MigrationWave[]
waves: MigrationWave[],
tickets: Ticket[],
stakeholders: StakeholderWithRole[],
applications: Application[]
) => {
const tickets = queryClient.getQueryData<Ticket[]>([TicketsQueryKey]) || [];

const stakeholders =
queryClient.getQueryData<StakeholderWithRole[]>([StakeholdersQueryKey]) ||
[];

const applications =
queryClient.getQueryData<Application[]>([ApplicationsQueryKey]) || [];

const aggregatedTicketStatus = (
wave: MigrationWave,
tickets: Ticket[]
Expand All @@ -45,6 +34,10 @@ export const getWavesWithStatus = (
}
} else if (statuses.includes("New")) {
return "Issues Created";
} else if (statuses.includes("In Progress")) {
return "In Progress";
} else if (statuses.every((status) => status === "Done")) {
return "Completed";
} else {
return "Not Started";
}
Expand All @@ -56,14 +49,16 @@ export const getWavesWithStatus = (
wave: MigrationWave,
tickets: Ticket[]
): TicketStatus[] =>
wave.applications.map((application): TicketStatus => {
const matchingTicket = getTicketByApplication(tickets, application.id);
if (matchingTicket?.error) {
return "Error";
} else if (matchingTicket?.status) {
return matchingTicket.status;
} else return "";
});
wave.applications
.map((application): TicketStatus => {
const matchingTicket = getTicketByApplication(tickets, application.id);
if (matchingTicket?.error) {
return "Error";
} else if (matchingTicket?.status) {
return matchingTicket.status;
} else return "";
})
.filter((ticketStatus) => ticketStatus !== "");

const getApplicationsOwners = (id: number) => {
const applicationOwnerIds = applications
Expand Down Expand Up @@ -143,6 +138,7 @@ export const getWavesWithStatus = (
};
const wavesWithStatus: WaveWithStatus[] = waves.map(
(wave): WaveWithStatus => {
console.log({ ticketStatus: aggregatedTicketStatus(wave, tickets) });
return {
...wave,
ticketStatus: getTicketStatus(wave, tickets),
Expand Down

0 comments on commit 1a58075

Please sign in to comment.