]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9175 Remember the last selection for My Issues / All filter
authorStas Vilchik <vilchiks@gmail.com>
Tue, 9 May 2017 14:40:53 +0000 (16:40 +0200)
committerStas Vilchik <stas-vilchik@users.noreply.github.com>
Wed, 10 May 2017 07:40:15 +0000 (09:40 +0200)
server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js
server/sonar-web/src/main/js/apps/issues/components/App.js
server/sonar-web/src/main/js/apps/issues/utils.js

index d33107fca5f9048cc9f8ca7836c59d9de0cf37ff..1cedcf94211c9ee887a2a198d0bf8940dfe47dff 100644 (file)
@@ -21,6 +21,7 @@ import React from 'react';
 import { Link } from 'react-router';
 import { translate } from '../../../../helpers/l10n';
 import { isUserAdmin } from '../../../../helpers/users';
+import { isMySet } from '../../../../apps/issues/utils';
 
 export default class GlobalNavMenu extends React.PureComponent {
   static propTypes = {
@@ -61,7 +62,7 @@ export default class GlobalNavMenu extends React.PureComponent {
   }
 
   renderIssuesLink() {
-    const query = this.props.currentUser.isLoggedIn
+    const query = this.props.currentUser.isLoggedIn && isMySet()
       ? { resolved: 'false', myIssues: 'true' }
       : { resolved: 'false' };
     const active = this.props.location.pathname === 'issues';
index 6361d5cc85f2d4d347d6bf5901414972c1366d0f..a91ef8ea68ff4de00b3e4838290cdf28190946a4 100644 (file)
@@ -40,7 +40,8 @@ import {
   getOpen,
   serializeQuery,
   parseFacets,
-  mapFacet
+  mapFacet,
+  saveMyIssues
 } from '../utils';
 import type {
   Query,
@@ -524,6 +525,9 @@ export default class App extends React.PureComponent {
 
   handleMyIssuesChange = (myIssues: boolean) => {
     this.closeFacet('assignees');
+    if (!this.props.component) {
+      saveMyIssues(myIssues);
+    }
     this.props.router.push({
       pathname: this.props.location.pathname,
       query: {
index 712b00024dbd69834cf81112ce615fd61c561a41..140aea14e251d211f908a5ca8a84946cc3064413 100644 (file)
@@ -244,3 +244,24 @@ export const searchAssignees = (query: string, component?: Component) => {
         }))
       );
 };
+
+const LOCALSTORAGE_KEY = 'sonarqube.issues.default';
+const LOCALSTORAGE_MY = 'my';
+const LOCALSTORAGE_ALL = 'all';
+
+export const isMySet = (): boolean => {
+  const setting = window.localStorage.getItem(LOCALSTORAGE_KEY);
+  return setting === LOCALSTORAGE_MY;
+};
+
+const save = (value: string) => {
+  try {
+    window.localStorage.setItem(LOCALSTORAGE_KEY, value);
+  } catch (e) {
+    // usually that means the storage is full
+    // just do nothing in this case
+  }
+};
+
+export const saveMyIssues = (myIssues: boolean) =>
+  save(myIssues ? LOCALSTORAGE_MY : LOCALSTORAGE_ALL);