Skip to content

Commit

Permalink
Fix template loading in application edit
Browse files Browse the repository at this point in the history
  • Loading branch information
brionmario committed Jan 12, 2021
1 parent e7f67ab commit e5ad429
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions apps/console/src/features/applications/pages/application-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
SupportedAuthProtocolTypes,
emptyApplication
} from "../models";
import { ApplicationManagementUtils } from "../utils";
import { ApplicationManagementUtils, ApplicationTemplateManagementUtils } from "../utils";

/**
* Proptypes for the applications edit page component.
Expand Down Expand Up @@ -141,6 +141,40 @@ const ApplicationEditPage: FunctionComponent<ApplicationEditPageInterface> = (
getApplication(id);
}, []);

/**
* Load the template that the application is built on.
*/
useEffect(() => {

if (!application
|| !(applicationTemplates
&& applicationTemplates instanceof Array
&& applicationTemplates.length > 0)) {

return;
}

const template = applicationTemplates.find((template) => template.id === application.templateId);

setApplicationTemplate(template);
}, [ applicationTemplates, application ]);

/**
* Fetch the application templates if list is not available in redux.
*/
useEffect(() => {
if (applicationTemplates !== undefined) {
return;
}

setApplicationTemplateRequestLoadingStatus(true);

ApplicationTemplateManagementUtils.getApplicationTemplates()
.finally(() => {
setApplicationTemplateRequestLoadingStatus(false);
});
}, [ applicationTemplates ]);

/**
* Push to 404 if application edit feature is disabled.
*/
Expand Down Expand Up @@ -406,13 +440,6 @@ const ApplicationEditPage: FunctionComponent<ApplicationEditPageInterface> = (

getApplicationDetails(id)
.then((response: ApplicationInterface) => {

const template = applicationTemplates
&& applicationTemplates instanceof Array
&& applicationTemplates.length > 0
&& applicationTemplates.find((template) => template.id === response.templateId);

setApplicationTemplate(template);
setApplication(response);
})
.catch((error) => {
Expand Down

0 comments on commit e5ad429

Please sign in to comment.