From 3422de45d9bb053da9c8607c09cff4d710227954 Mon Sep 17 00:00:00 2001 From: Eric Wittmann Date: Mon, 17 Jul 2017 12:59:06 -0400 Subject: [PATCH] auto-remove items from the Recent Apis list if they no longer exist in the all-apis list. fixes #150 --- .../pages/dashboard/dashboard.page.html | 6 ++++-- .../app/studio/services/apis-hub.service.ts | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/front-end/app/studio/pages/dashboard/dashboard.page.html b/front-end/app/studio/pages/dashboard/dashboard.page.html index 2776eae7b..a707fb353 100644 --- a/front-end/app/studio/pages/dashboard/dashboard.page.html +++ b/front-end/app/studio/pages/dashboard/dashboard.page.html @@ -36,8 +36,9 @@

No APIs Found

- We couldn't find any APIs for you - it's likely that you have not yet created/added any APIs to the studio. - Not to worry, we can do that now! + We couldn't find any APIs for you - it's possible that you have not yet created/added any APIs to the studio. + Or perhaps you have some APIs but haven't worked on them recently. Pick an action below that makes sense + for you!

@@ -51,6 +52,7 @@

No APIs Found

  • Create New API
  • + List All APIs
    diff --git a/front-end/app/studio/services/apis-hub.service.ts b/front-end/app/studio/services/apis-hub.service.ts index 5f6c4f811..23ba26b86 100644 --- a/front-end/app/studio/services/apis-hub.service.ts +++ b/front-end/app/studio/services/apis-hub.service.ts @@ -94,6 +94,7 @@ export class HubApisService implements IApisService { this.theRecentApis = this.getRecentFromAllApis(apis); this._recentApis.next(this.theRecentApis); } + this.removeMissingRecentApis(apis); return apis; }).toPromise(); } @@ -471,4 +472,24 @@ export class HubApisService implements IApisService { this.theRecentApis = recent; return recent; } + + /** + * Removes any API from the "recent APIs" list that is not in the + * given list of "all" Apis. + * @param apis + */ + private removeMissingRecentApis(apis: Api[]) { + this.theRecentApis.filter( recentApi => { + let found: boolean = false; + apis.forEach( api => { + if (api.id === recentApi.id) { + found = true; + } + }); + return !found; + }).forEach( diffApi => { + console.info("[HubApisService] Removing '%s' from the recent APIs list.", diffApi.name); + this.theRecentApis.splice(this.theRecentApis.indexOf(diffApi), 1); + }); + } }