Skip to content

Commit

Permalink
Incorrect app sorting after installing an application #1801
Browse files Browse the repository at this point in the history
  • Loading branch information
ashklianko authored and alansemenov committed Jan 21, 2025
1 parent 02d8c30 commit 7f5f814
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
62 changes: 40 additions & 22 deletions src/main/resources/assets/js/app/browse/ApplicationBrowsePanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {UninstallApplicationEvent} from './UninstallApplicationEvent';
import {ApplicationUploadStartedEvent} from './ApplicationUploadStartedEvent';
import {ApplicationActionRequest} from '../resource/ApplicationActionRequest';
import {BrowsePanel} from '@enonic/lib-admin-ui/app/browse/BrowsePanel';
import {Application, ApplicationUploadMock} from '@enonic/lib-admin-ui/application/Application';
import {Application, ApplicationBuilder, ApplicationUploadMock} from '@enonic/lib-admin-ui/application/Application';
import {DefaultErrorHandler} from '@enonic/lib-admin-ui/DefaultErrorHandler';
import {ApplicationKey} from '@enonic/lib-admin-ui/application/ApplicationKey';
import {TreeGridActions} from '@enonic/lib-admin-ui/ui/treegrid/actions/TreeGridActions';
Expand Down Expand Up @@ -151,7 +151,7 @@ export class ApplicationBrowsePanel
this.getBrowseItemPanel().toggleClass('highlighted', hasHighlighted);
}

private registerEvents() {
private registerEvents(): void {
StopApplicationEvent.on((event: StopApplicationEvent) =>
ApplicationBrowsePanel.sendApplicationActionRequest('stop', event.getApplications()));
StartApplicationEvent.on((event: StartApplicationEvent) =>
Expand All @@ -169,7 +169,7 @@ export class ApplicationBrowsePanel
}

private handleAppEvent(event: ApplicationEvent) {
if (event.isSystemApplication()) {
if (event.isSystemApplication() || event.getApplicationKey().toString() === 'com.enonic.xp.app.applications') {
return;
}

Expand All @@ -186,51 +186,69 @@ export class ApplicationBrowsePanel
}

if (event.isNeedToUpdateApplication() && event.getApplicationKey()) {
this.updateAppByKey(event.getApplicationKey());
this.updateAppByKey(event.getApplicationKey()).catch(DefaultErrorHandler.handle);
}
}

private updateAppByKey(key: ApplicationKey): void {
this.fetchAppByKey(key).then((application: Application) => {
private updateAppByKey(key: ApplicationKey): Q.Promise<Application> {
return this.fetchAppByKey(key).then((application: Application) => {
this.treeListBox.replaceItems(application);
}).catch(DefaultErrorHandler.handle);
return application;
});
}

private fetchAppByKey(applicationKey: ApplicationKey): Q.Promise<Application> {
return new GetApplicationRequest(applicationKey, true).sendAndParse();
}

private handleAppInstalledEvent(event: ApplicationEvent) {
this.fetchAppByKey(event.getApplicationKey()).then((application: Application) => {
setTimeout(() => { // timeout lets grid to remove UploadMockNode so that its not counted in the toolbar
showFeedback(i18n('notify.installed', application.getDisplayName()));
this.treeListBox.addItems(application, false, 0);
new AppInstalledEvent(application).fire();
}, 200);
// if updating local app
this.removeItemFromList(event.getApplicationKey().toString());
this.treeListBox.addItems(this.createAppFromEvent(event), false, 0);

this.updateAppByKey(event.getApplicationKey()).then((application) => {
showFeedback(i18n('notify.installed', application.getDisplayName()));
new AppInstalledEvent(application).fire();
}).catch(DefaultErrorHandler.handle);
}

private handleAppUninstalledEvent(event: ApplicationEvent) {
const uninstalledApp: Application = this.treeListBox.getItem(event.getApplicationKey().getName());
const uninstalledAppName: string = uninstalledApp ? uninstalledApp.getDisplayName() : event.getApplicationKey().toString();
showFeedback(i18n('notify.uninstalled', uninstalledAppName));
this.removeItemFromList(event.getApplicationKey().toString(), true);

new AppUninstalledEvent(uninstalledApp).fire();
}

private createAppFromEvent(event: ApplicationEvent): Application {
const builder = new ApplicationBuilder();
builder.id = event.getApplicationKey().toString();
builder.applicationKey = event.getApplicationKey();
builder.displayName = event.getName();
builder.url = event.getApplicationUrl();
return builder.build();
}

private removeItemFromList(appKeyAsString: string, deselect?: boolean) {
const itemToRemove = this.treeListBox.getItems().find(
(item: Application) => item.getApplicationKey().getName() === event.getApplicationKey().getName());
(item: Application) => item.getApplicationKey().getName() === appKeyAsString);

if (itemToRemove) {
this.selectionWrapper.deselect(itemToRemove);
if (deselect) {
this.selectionWrapper.deselect(itemToRemove);
}

this.treeListBox.removeItems(itemToRemove);
}

new AppUninstalledEvent(uninstalledApp).fire();
}

private handleAppStoppedEvent(event: ApplicationEvent) {
const stoppedApp: Application = this.treeListBox.getItem(event.getApplicationKey().getName());
// seems to be present in the grid and xp is running
if (stoppedApp && ServerEventsConnection.get(CONFIG.getString('eventApiUrl')).isConnected()) {
this.updateAppByKey(event.getApplicationKey());
}
const stoppedApp: Application = this.treeListBox.getItem(event.getApplicationKey().getName());
// seems to be present in the grid and xp is running
if (stoppedApp && ServerEventsConnection.get(CONFIG.getString('eventApiUrl')).isConnected()) {
this.updateAppByKey(event.getApplicationKey()).catch(DefaultErrorHandler.handle);
}
}

private handleNewAppUpload(event: ApplicationUploadStartedEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ export class MarketAppsTreeGrid
}

updateAppUninstalled(uninstalled: Application): void {
const uninstalledKey = uninstalled.getApplicationKey().toString();
this.installedApplications =
this.installedApplications.filter((app: Application) => app.getApplicationKey() !== uninstalled.getApplicationKey());
this.installedApplications.filter((app: Application) => app.getApplicationKey().toString() !== uninstalledKey);
this.updateApp(uninstalled);
}

Expand Down

0 comments on commit 7f5f814

Please sign in to comment.