Skip to content

Commit

Permalink
auto-remove items from the Recent Apis list if they no longer exist i…
Browse files Browse the repository at this point in the history
…n the all-apis list. fixes #150
  • Loading branch information
EricWittmann committed Jul 17, 2017
1 parent 0d446ab commit 3422de4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions front-end/app/studio/pages/dashboard/dashboard.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ <h2 class="card-pf-title">
</div>
<h1>No APIs Found</h1>
<p>
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!
</p>
<div class="blank-slate-pf-main-action">
<div class="btn-group">
Expand All @@ -51,6 +52,7 @@ <h1>No APIs Found</h1>
<li><a routerLink="/apis/create">Create New API</a></li>
</ul>
</div>
<a routerLink="/apis" class="btn btn-lg btn-default" style="margin-left: 10px">List All APIs</a>
</div>
</div>
</div>
Expand Down
21 changes: 21 additions & 0 deletions front-end/app/studio/services/apis-hub.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
});
}
}

0 comments on commit 3422de4

Please sign in to comment.