Skip to content
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
@@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React, { useEffect, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useFormikContext } from "formik";

Expand All @@ -11,11 +11,19 @@ import {
TextContent,
} from "@patternfly/react-core";

import { useFetchStakeholderGroups, useFetchStakeholders } from "shared/hooks";
import { useFetch } from "shared/hooks";

import { DEFAULT_SELECT_MAX_HEIGHT } from "Constants";
import { getValidatedFromError } from "utils/utils";

import { StakeholderGroupPage, StakeholderPage } from "api/models";
import {
getAllStakeholderGroups,
getAllStakeholders,
stakeholderGroupPageMapper,
stakeholderPageMapper,
} from "api/apiUtils";

import { IFormValues } from "../../form-utils";

import { StakeholderSelect } from "./stakeholder-select";
Expand All @@ -27,23 +35,45 @@ export const StakeholdersForm: React.FC<StakeholdersFormProps> = () => {
const { t } = useTranslation();
const formik = useFormikContext<IFormValues>();

// Fetch stakeholders

const {
stakeholders,
data: stakeholdersPage,
isFetching: isFetchingStakeholders,
fetchError: fetchErrorStakeholders,
fetchAllStakeholders,
} = useFetchStakeholders();
requestFetch: fetchAllStakeholders,
} = useFetch<StakeholderPage>({
defaultIsFetching: true,
onFetch: getAllStakeholders,
});

const stakeholders = useMemo(() => {
return stakeholdersPage
? stakeholderPageMapper(stakeholdersPage)
: undefined;
}, [stakeholdersPage]);

useEffect(() => {
fetchAllStakeholders();
}, [fetchAllStakeholders]);

// Fetch stakeholder groups

const {
stakeholderGroups,
data: stakeholderGroupPage,
isFetching: isFetchingStakeholderGroups,
fetchError: fetchErrorStakeholderGroups,
fetchAllStakeholderGroups,
} = useFetchStakeholderGroups();
requestFetch: fetchAllStakeholderGroups,
} = useFetch<StakeholderGroupPage>({
defaultIsFetching: true,
onFetch: getAllStakeholderGroups,
});

const stakeholderGroups = useMemo(() => {
return stakeholderGroupPage
? stakeholderGroupPageMapper(stakeholderGroupPage)
: undefined;
}, [stakeholderGroupPage]);

useEffect(() => {
fetchAllStakeholderGroups();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { useContext, useEffect, useState } from "react";
import React, {
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from "react";
import { useTranslation } from "react-i18next";

import {
Expand All @@ -13,16 +19,25 @@ import {
} from "@patternfly/react-core";

import { OptionWithValue } from "shared/components";
import { useFetch } from "shared/hooks";

import {
useFetchApplicationDependencies,
useFetchApplications,
} from "shared/hooks";
Application,
ApplicationDependency,
ApplicationDependencyPage,
ApplicationPage,
} from "api/models";

import { Application, ApplicationDependency } from "api/models";
import {
applicationDependencyPageMapper,
applicationPageMapper,
getAllApplicationDependencies,
getAllApplications,
} from "api/apiUtils";
import { getAxiosErrorMessage } from "utils/utils";

import { FormContext } from "./form-context";
import { SelectDependency } from "./select-dependency";
import { getAxiosErrorMessage } from "utils/utils";

const northToStringFn = (value: ApplicationDependency) => value.from.name;
const southToStringFn = (value: ApplicationDependency) => value.to.name;
Expand Down Expand Up @@ -66,40 +81,75 @@ export const ApplicationDependenciesForm: React.FC<ApplicationDependenciesFormPr

// Dependencies

const getAllNorthApplicationDependencies = useCallback(() => {
return getAllApplicationDependencies({
to: [`${application.id}`],
});
}, [application]);

const getAllSouthApplicationDependencies = useCallback(() => {
return getAllApplicationDependencies({
from: [`${application.id}`],
});
}, [application]);

const {
applicationDependencies: northDependencies,
data: northDependenciesPage,
isFetching: isFetchingNorthDependencies,
fetchError: fetchErrorNorthDependencies,
fetchAllApplicationDependencies: fetchAllNorthDependencies,
} = useFetchApplicationDependencies();
requestFetch: fetchAllNorthDependencies,
} = useFetch<ApplicationDependencyPage>({
defaultIsFetching: true,
onFetch: getAllNorthApplicationDependencies,
});

const northDependencies = useMemo(() => {
return northDependenciesPage
? applicationDependencyPageMapper(northDependenciesPage)
: undefined;
}, [northDependenciesPage]);

const {
applicationDependencies: southDependencies,
data: southDependenciesPage,
isFetching: isFetchingSouthDependencies,
fetchError: fetchErrorSouthDependencies,
fetchAllApplicationDependencies: fetchAllSouthDependencies,
} = useFetchApplicationDependencies();
requestFetch: fetchAllSouthDependencies,
} = useFetch<ApplicationDependencyPage>({
defaultIsFetching: true,
onFetch: getAllSouthApplicationDependencies,
});

const southDependencies = useMemo(() => {
return southDependenciesPage
? applicationDependencyPageMapper(southDependenciesPage)
: undefined;
}, [southDependenciesPage]);

useEffect(() => {
fetchAllNorthDependencies({
to: [`${application.id}`],
});
}, [application, fetchAllNorthDependencies]);
fetchAllNorthDependencies();
}, [fetchAllNorthDependencies]);

useEffect(() => {
fetchAllSouthDependencies({
from: [`${application.id}`],
});
}, [application, fetchAllSouthDependencies]);
fetchAllSouthDependencies();
}, [fetchAllSouthDependencies]);

// Applications

const {
applications,
data: applicationsPage,
isFetching: isFetchingApplications,
fetchError: fetchErrorApplications,
fetchAllApplications,
} = useFetchApplications();
requestFetch: fetchAllApplications,
} = useFetch<ApplicationPage>({
defaultIsFetching: true,
onFetch: getAllApplications,
});

const applications = useMemo(() => {
return applicationsPage
? applicationPageMapper(applicationsPage)
: undefined;
}, [applicationsPage]);

useEffect(() => {
fetchAllApplications();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,32 @@ import {
MultiSelectFetchFormikField,
OptionWithValue,
} from "shared/components";
import { useFetchBusinessServices, useFetchTagTypes } from "shared/hooks";
import { useFetch } from "shared/hooks";

import { DEFAULT_SELECT_MAX_HEIGHT } from "Constants";
import { createApplication, TagTypeSortBy, updateApplication } from "api/rest";
import { Application, BusinessService, Tag } from "api/models";
import {
Application,
BusinessService,
BusinessServicePage,
Tag,
TagTypePage,
} from "api/models";
import {
getAxiosErrorMessage,
getValidatedFromError,
getValidatedFromErrorTouched,
} from "utils/utils";
import {
bussinessServicePageMapper,
getAllBusinessServices,
getAllTagTypes,
tagTypePageMapper,
} from "api/apiUtils";

export const getAllTagTypesSortedByRank = () => {
return getAllTagTypes({ field: TagTypeSortBy.RANK });
};

const businesServiceToOption = (
value: BusinessService
Expand Down Expand Up @@ -72,11 +88,20 @@ export const ApplicationForm: React.FC<ApplicationFormProps> = ({
// Business services

const {
businessServices,
data: businessServicesPage,
isFetching: isFetchingBusinessServices,
fetchError: fetchErrorBusinessServices,
fetchAllBusinessServices,
} = useFetchBusinessServices();
requestFetch: fetchAllBusinessServices,
} = useFetch<BusinessServicePage>({
defaultIsFetching: true,
onFetch: getAllBusinessServices,
});

const businessServices = useMemo(() => {
return businessServicesPage
? bussinessServicePageMapper(businessServicesPage)
: undefined;
}, [businessServicesPage]);

useEffect(() => {
fetchAllBusinessServices();
Expand All @@ -85,14 +110,21 @@ export const ApplicationForm: React.FC<ApplicationFormProps> = ({
// TagTypes

const {
tagTypes,
data: tagTypesPage,
isFetching: isFetchingTagTypes,
fetchError: fetchErrorTagTypes,
fetchAllTagTypes,
} = useFetchTagTypes();
requestFetch: fetchAllTagTypes,
} = useFetch<TagTypePage>({
defaultIsFetching: true,
onFetch: getAllTagTypesSortedByRank,
});

const tagTypes = useMemo(() => {
return tagTypesPage ? tagTypePageMapper(tagTypesPage) : undefined;
}, [tagTypesPage]);

useEffect(() => {
fetchAllTagTypes({ field: TagTypeSortBy.RANK });
fetchAllTagTypes();
}, [fetchAllTagTypes]);

// Tags
Expand Down
54 changes: 30 additions & 24 deletions src/pages/controls/business-services/business-services.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from "react";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import { AxiosResponse } from "axios";
import { useTranslation } from "react-i18next";

Expand Down Expand Up @@ -32,12 +32,17 @@ import {
} from "shared/components";
import {
useTableControls,
useFetchBusinessServices,
useFetch,
useDeleteBusinessService,
} from "shared/hooks";

import { BusinessService, SortByQuery } from "api/models";
import { BusinessServiceSortBy, BusinessServiceSortByQuery } from "api/rest";
import { BusinessService, BusinessServicePage, SortByQuery } from "api/models";
import {
BusinessServiceSortBy,
BusinessServiceSortByQuery,
getBusinessServices,
} from "api/rest";
import { bussinessServicePageMapper } from "api/apiUtils";
import { getAxiosErrorMessage } from "utils/utils";

import { NewBusinessServiceModal } from "./components/new-business-service-modal";
Expand Down Expand Up @@ -107,13 +112,6 @@ export const BusinessServices: React.FC = () => {

const { deleteBusinessService } = useDeleteBusinessService();

const {
businessServices,
isFetching,
fetchError,
fetchBusinessServices,
} = useFetchBusinessServices(true);

const {
paginationQuery,
sortByQuery,
Expand All @@ -123,8 +121,8 @@ export const BusinessServices: React.FC = () => {
sortByQuery: { direction: "asc", index: 0 },
});

const refreshTable = useCallback(() => {
fetchBusinessServices(
const fetchBusinessServices = useCallback(() => {
return getBusinessServices(
{
name: filtersValue.get(FilterKey.NAME),
description: filtersValue.get(FilterKey.DESCRIPTION),
Expand All @@ -133,19 +131,27 @@ export const BusinessServices: React.FC = () => {
paginationQuery,
toSortByQuery(sortByQuery)
);
}, [filtersValue, paginationQuery, sortByQuery, fetchBusinessServices]);
}, [filtersValue, paginationQuery, sortByQuery]);

const {
data: businessServicesPage,
isFetching,
fetchError,
requestFetch: refreshTable,
} = useFetch<BusinessServicePage>({
defaultIsFetching: true,
onFetch: fetchBusinessServices,
});

const businessServices = useMemo(() => {
return businessServicesPage
? bussinessServicePageMapper(businessServicesPage)
: undefined;
}, [businessServicesPage]);

useEffect(() => {
fetchBusinessServices(
{
name: filtersValue.get(FilterKey.NAME),
description: filtersValue.get(FilterKey.DESCRIPTION),
owner: filtersValue.get(FilterKey.OWNER),
},
paginationQuery,
toSortByQuery(sortByQuery)
);
}, [filtersValue, paginationQuery, sortByQuery, fetchBusinessServices]);
refreshTable();
}, [filtersValue, paginationQuery, sortByQuery, refreshTable]);

const columns: ICell[] = [
{ title: t("terms.name"), transforms: [sortable, cellWidth(25)] },
Expand Down
Loading