diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2018-07-06 11:40:29 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-07-11 20:21:22 +0200 |
commit | 29b0f28f9e4fc05ce662212a55aef45ad0278201 (patch) | |
tree | e167021989b32129e7f7695ff1fc5d43b797a05f /server/sonar-web/src/main/js/store | |
parent | d34f9f46391d73cb89e9b7ead8e828dc65362829 (diff) | |
download | sonarqube-29b0f28f9e4fc05ce662212a55aef45ad0278201.tar.gz sonarqube-29b0f28f9e4fc05ce662212a55aef45ad0278201.zip |
Migrate remaining of organization app to TS
Diffstat (limited to 'server/sonar-web/src/main/js/store')
-rw-r--r-- | server/sonar-web/src/main/js/store/organizations/__tests__/__snapshots__/duck-test.ts.snap (renamed from server/sonar-web/src/main/js/store/organizations/__tests__/__snapshots__/duck-test.js.snap) | 0 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/store/organizations/__tests__/duck-test.ts (renamed from server/sonar-web/src/main/js/store/organizations/__tests__/duck-test.js) | 14 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/store/organizations/duck.ts | 9 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/store/organizations/utils.ts (renamed from server/sonar-web/src/main/js/store/organizations/utils.js) | 3 |
4 files changed, 14 insertions, 12 deletions
diff --git a/server/sonar-web/src/main/js/store/organizations/__tests__/__snapshots__/duck-test.js.snap b/server/sonar-web/src/main/js/store/organizations/__tests__/__snapshots__/duck-test.ts.snap index c5ad9b73625..c5ad9b73625 100644 --- a/server/sonar-web/src/main/js/store/organizations/__tests__/__snapshots__/duck-test.js.snap +++ b/server/sonar-web/src/main/js/store/organizations/__tests__/__snapshots__/duck-test.ts.snap diff --git a/server/sonar-web/src/main/js/store/organizations/__tests__/duck-test.js b/server/sonar-web/src/main/js/store/organizations/__tests__/duck-test.ts index 2180d6af6f0..e9321e29f90 100644 --- a/server/sonar-web/src/main/js/store/organizations/__tests__/duck-test.js +++ b/server/sonar-web/src/main/js/store/organizations/__tests__/duck-test.ts @@ -19,14 +19,14 @@ */ import organizations, { getOrganizationByKey, areThereCustomOrganizations } from '../duck'; +const state0 = { byKey: {}, my: [], groups: {} }; + describe('Reducer', () => { it('should have initial state', () => { - expect(organizations(undefined, {})).toMatchSnapshot(); + expect((organizations as any)(undefined, {})).toMatchSnapshot(); }); it('should receive organizations', () => { - const state0 = { byKey: {} }; - const action1 = { type: 'RECEIVE_ORGANIZATIONS', organizations: [{ key: 'foo', name: 'Foo' }, { key: 'bar', name: 'Bar' }] @@ -46,7 +46,7 @@ describe('Reducer', () => { describe('Selectors', () => { it('getOrganizationByKey', () => { const foo = { key: 'foo', name: 'Foo' }; - const state = { byKey: { foo } }; + const state = { ...state0, byKey: { foo } }; expect(getOrganizationByKey(state, 'foo')).toBe(foo); expect(getOrganizationByKey(state, 'bar')).toBeFalsy(); }); @@ -54,8 +54,8 @@ describe('Selectors', () => { it('areThereCustomOrganizations', () => { const foo = { key: 'foo', name: 'Foo' }; const bar = { key: 'bar', name: 'Bar' }; - expect(areThereCustomOrganizations({ byKey: {} }, 'foo')).toBe(false); - expect(areThereCustomOrganizations({ byKey: { foo } }, 'foo')).toBe(false); - expect(areThereCustomOrganizations({ byKey: { foo, bar } }, 'foo')).toBe(true); + expect(areThereCustomOrganizations({ ...state0, byKey: {} })).toBe(false); + expect(areThereCustomOrganizations({ ...state0, byKey: { foo } })).toBe(false); + expect(areThereCustomOrganizations({ ...state0, byKey: { foo, bar } })).toBe(true); }); }); diff --git a/server/sonar-web/src/main/js/store/organizations/duck.ts b/server/sonar-web/src/main/js/store/organizations/duck.ts index 8b6c76e3993..5f01ac95261 100644 --- a/server/sonar-web/src/main/js/store/organizations/duck.ts +++ b/server/sonar-web/src/main/js/store/organizations/duck.ts @@ -19,7 +19,7 @@ */ import { combineReducers } from 'redux'; import { omit, uniq, without } from 'lodash'; -import { Group, Organization } from '../../app/types'; +import { Group, Organization, OrganizationBase } from '../../app/types'; interface ReceiveOrganizationsAction { type: 'RECEIVE_ORGANIZATIONS'; @@ -108,7 +108,10 @@ export function createOrganization(organization: Organization): CreateOrganizati }; } -export function updateOrganization(key: string, changes: {}): UpdateOrganizationAction { +export function updateOrganization( + key: string, + changes: OrganizationBase +): UpdateOrganizationAction { return { type: 'UPDATE_ORGANIZATION', key, @@ -177,7 +180,7 @@ function groups(state: GroupsState = {}, action: Action) { return state; } -export default combineReducers({ byKey, my, groups }); +export default combineReducers<State>({ byKey, my, groups }); export function getOrganizationByKey(state: State, key: string): Organization | undefined { return state.byKey[key]; diff --git a/server/sonar-web/src/main/js/store/organizations/utils.js b/server/sonar-web/src/main/js/store/organizations/utils.ts index adf5ed2c5e3..5b3957e1f6c 100644 --- a/server/sonar-web/src/main/js/store/organizations/utils.js +++ b/server/sonar-web/src/main/js/store/organizations/utils.ts @@ -17,14 +17,13 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -// @flow import getStore from '../../app/utils/getStore'; import { getOrganizationByKey, areThereCustomOrganizations as customOrganizations } from '../rootReducer'; -export function getOrganization(key /*: string */) { +export function getOrganization(key: string) { const store = getStore(); const state = store.getState(); return getOrganizationByKey(state, key); |