Refetch extension list when installing or uninstalling Apps (#1884)

This commit is contained in:
Dawid Tarasiuk 2022-03-21 13:35:32 +01:00 committed by GitHub
parent f85786f203
commit d35ca150dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View file

@ -86,3 +86,5 @@ export const extensionList = gql`
} }
} }
`; `;
export const EXTENSION_LIST_QUERY = "ExtensionList";

View file

@ -1,3 +1,4 @@
import { useApolloClient } from "@apollo/client";
import { import {
AppDeleteFailedInstallationMutation, AppDeleteFailedInstallationMutation,
AppDeleteMutation, AppDeleteMutation,
@ -29,6 +30,7 @@ import { useIntl } from "react-intl";
import AppDeleteDialog from "../../components/AppDeleteDialog"; import AppDeleteDialog from "../../components/AppDeleteDialog";
import AppInProgressDeleteDialog from "../../components/AppInProgressDeleteDialog"; import AppInProgressDeleteDialog from "../../components/AppInProgressDeleteDialog";
import AppsListPage from "../../components/AppsListPage"; import AppsListPage from "../../components/AppsListPage";
import { EXTENSION_LIST_QUERY } from "../../queries";
import { import {
appDetailsUrl, appDetailsUrl,
AppListUrlDialog, AppListUrlDialog,
@ -55,6 +57,7 @@ interface AppsListProps {
export const AppsList: React.FC<AppsListProps> = ({ params }) => { export const AppsList: React.FC<AppsListProps> = ({ params }) => {
const { action } = params; const { action } = params;
const client = useApolloClient();
const [activeInstallations, setActiveInstallations] = useLocalStorage< const [activeInstallations, setActiveInstallations] = useLocalStorage<
Array<Record<"id" | "name", string>> Array<Record<"id" | "name", string>>
>("activeInstallations", []); >("activeInstallations", []);
@ -116,6 +119,12 @@ export const AppsList: React.FC<AppsListProps> = ({ params }) => {
} }
}); });
const refetchExtensionList = () => {
client.refetchQueries({
include: [EXTENSION_LIST_QUERY]
});
};
const installedAppNotify = (name: string) => { const installedAppNotify = (name: string) => {
notify({ notify({
status: "success", status: "success",
@ -153,6 +162,7 @@ export const AppsList: React.FC<AppsListProps> = ({ params }) => {
refetch(); refetch();
} }
closeModal(); closeModal();
refetchExtensionList();
removeAppNotify(); removeAppNotify();
} else { } else {
errors.forEach(error => errors.forEach(error =>
@ -187,16 +197,19 @@ export const AppsList: React.FC<AppsListProps> = ({ params }) => {
2000 2000
); );
} }
let newAppInstalled = false;
activeInstallations.forEach(installation => { activeInstallations.forEach(installation => {
const item = appsInProgress?.find(app => app.id === installation.id); const item = appsInProgress?.find(app => app.id === installation.id);
if (!item) { if (!item) {
removeInstallation(installation.id); removeInstallation(installation.id);
installedAppNotify(installation.name); installedAppNotify(installation.name);
appsInProgressRefetch(); appsInProgressRefetch();
newAppInstalled = true;
} else if (item.status === JobStatusEnum.SUCCESS) { } else if (item.status === JobStatusEnum.SUCCESS) {
removeInstallation(installation.id); removeInstallation(installation.id);
installedAppNotify(item.appName); installedAppNotify(item.appName);
refetch(); refetch();
newAppInstalled = true;
} else if (item.status === JobStatusEnum.FAILED) { } else if (item.status === JobStatusEnum.FAILED) {
removeInstallation(installation.id); removeInstallation(installation.id);
notify({ notify({
@ -208,6 +221,9 @@ export const AppsList: React.FC<AppsListProps> = ({ params }) => {
}); });
} }
}); });
if (newAppInstalled) {
refetchExtensionList();
}
} }
if (!activeInstallations.length && intervalId.current) { if (!activeInstallations.length && intervalId.current) {
clearInterval(intervalId.current); clearInterval(intervalId.current);