aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-12-09 10:59:31 +0100
committerStas Vilchik <vilchiks@gmail.com>2016-12-09 14:28:10 +0100
commit15d4611e619fe343810f5ff5f67e58c8e0b3e3d0 (patch)
tree05f1f709b4535b4b44a77adf05776edc9c532d69 /server
parent25a0ec7276939bb217f422bedbc8708cb7044131 (diff)
downloadsonarqube-15d4611e619fe343810f5ff5f67e58c8e0b3e3d0.tar.gz
sonarqube-15d4611e619fe343810f5ff5f67e58c8e0b3e3d0.zip
add flow annotations in RecentHistory
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js30
1 files changed, 17 insertions, 13 deletions
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js b/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js
index e7dc3f06f09..d5bb1b2d587 100644
--- a/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js
+++ b/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js
@@ -17,11 +17,18 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+// @flow
const STORAGE_KEY = 'sonar_recent_history';
const HISTORY_LIMIT = 10;
+type History = Array<{
+ key: string,
+ name: string,
+ icon: string
+}>;
+
export default class RecentHistory {
- static get () {
+ static get (): History {
let history = localStorage.getItem(STORAGE_KEY);
if (history == null) {
history = [];
@@ -36,27 +43,24 @@ export default class RecentHistory {
return history;
}
- static set (newHistory) {
+ static set (newHistory: History): void {
localStorage.setItem(STORAGE_KEY, JSON.stringify(newHistory));
}
- static clear () {
+ static clear (): void {
localStorage.removeItem(STORAGE_KEY);
}
- static add (componentKey, componentName, icon) {
+ static add (componentKey: string, componentName: string, icon: string): void {
const sonarHistory = RecentHistory.get();
-
- if (componentKey) {
- const newEntry = { key: componentKey, name: componentName, icon };
- let newHistory = sonarHistory.filter(entry => entry.key !== newEntry.key);
- newHistory.unshift(newEntry);
- newHistory = newHistory.slice(0, HISTORY_LIMIT);
- RecentHistory.set(newHistory);
- }
+ const newEntry = { key: componentKey, name: componentName, icon };
+ let newHistory = sonarHistory.filter(entry => entry.key !== newEntry.key);
+ newHistory.unshift(newEntry);
+ newHistory = newHistory.slice(0, HISTORY_LIMIT);
+ RecentHistory.set(newHistory);
}
- static remove (componentKey) {
+ static remove (componentKey: string): void {
const history = RecentHistory.get();
const newHistory = history.filter(entry => entry.key !== componentKey);
RecentHistory.set(newHistory);