Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ export function getDataReducer(types) {
};
}

export function getPageNumberReducer(types) {
return (state = 1, { type, pageNumber }) => {
switch (type) {
case types.updateFilter:
if (pageNumber) {
return pageNumber;
}
return state;
default:
return state;
}
};
}

export function getSearchFilterReducer(types) {
return (state = '', { type, searchFilter }) => {
switch (type) {
Expand Down Expand Up @@ -75,6 +61,6 @@ export default function getReducer(types, reducers = {}) {
...reducers,
status: getModuleStatusReducer(types),
searchFilter: getSearchFilterReducer(types),
pageNumber: getPageNumberReducer(types),
currentGroupId: getCurrentGroupIdReducer(types),
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import getModuleStatusReducer from '../../lib/getModuleStatusReducer';

import getReducer, {
getDataReducer,
getPageNumberReducer,
getSearchFilterReducer,
getCurrentGroupIdReducer,
getTimestampReducer,
Expand Down Expand Up @@ -62,41 +61,6 @@ describe('GlipGroups :: getDataReducer', () => {
});
});

describe('GlipGroups :: getPageNumberReducer', () => {
it('getPageNumberReducer should be a function', () => {
expect(getPageNumberReducer).to.be.a('function');
});
it('getPageNumberReducer should return a reducer', () => {
expect(getPageNumberReducer()).to.be.a('function');
});
describe('pageNumberReducer', () => {
const reducer = getPageNumberReducer(actionTypes);
it('should have initial state of 1', () => {
expect(reducer(undefined, {})).to.equal(1);
});

it('should return original state of actionTypes is not recognized', () => {
const originalState = {};
expect(reducer(originalState, { type: 'foo' }))
.to.equal(originalState);
});

it('should return pageNumber on updateFilter', () => {
expect(reducer(1, {
type: actionTypes.updateFilter,
pageNumber: 2,
})).to.equal(2);
});

it('should original state when pageNumber is undefined on updateFilter', () => {
expect(reducer(1, {
type: actionTypes.updateFilter,
})).to.equal(1);
});
});
});


describe('GlipGroups :: getSearchFilterReducer', () => {
it('getSearchFilterReducer should be a function', () => {
expect(getSearchFilterReducer).to.be.a('function');
Expand Down Expand Up @@ -204,11 +168,11 @@ describe('GlipGroups :: getReducer', () => {
const reducer = getReducer(actionTypes);
const statusReducer = getModuleStatusReducer(actionTypes);
const searchFilterReducer = getSearchFilterReducer(actionTypes);
const pageNumberReducer = getPageNumberReducer(actionTypes);
const currentGroupIdReducer = getCurrentGroupIdReducer(actionTypes);
expect(reducer(undefined, {})).to.deep.equal({
status: statusReducer(undefined, {}),
searchFilter: searchFilterReducer(undefined, {}),
pageNumber: pageNumberReducer(undefined, {}),
currentGroupId: currentGroupIdReducer(undefined, {}),
});
});
});
48 changes: 20 additions & 28 deletions packages/ringcentral-integration/modules/GlipGroups/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import proxify from '../../lib/proxy/proxify';

import getReducer, {
getDataReducer,
getCurrentGroupIdReducer,
getTimestampReducer,
} from './getReducer';
import actionTypes from './actionTypes';
Expand Down Expand Up @@ -154,7 +153,6 @@ export default class GlipGroups extends Pollable {

this._dataStorageKey = 'glipGroupsData';
this._timestampStorageKey = 'glipGroupsTimestamp';
this._currentGroupIdStorageKey = 'glipGroupsCurrentGroupId';

if (this._storage) {
this._reducer = getReducer(this.actionTypes);
Expand All @@ -167,15 +165,10 @@ export default class GlipGroups extends Pollable {
key: this._timestampStorageKey,
reducer: getTimestampReducer(this.actionTypes),
});
this._storage.registerReducer({
key: this._currentGroupIdStorageKey,
reducer: getCurrentGroupIdReducer(this.actionTypes),
});
} else {
this._reducer = getReducer(this.actionTypes, {
timestamp: getTimestampReducer(this.actionTypes),
data: getDataReducer(this.actionTypes),
currentGroupId: getCurrentGroupIdReducer(this.actionTypes),
});
}

Expand All @@ -198,7 +191,7 @@ export default class GlipGroups extends Pollable {
this.store.dispatch({
type: this.actionTypes.initSuccess,
});
this._onDataReady()
this._onDataReady();
} else if (this._shouldReset()) {
this._clearTimeout();
this._promise = null;
Expand Down Expand Up @@ -269,9 +262,6 @@ export default class GlipGroups extends Pollable {
if (this._glipPersons) {
this._glipPersons.loadPersons(this.groupMemberIds);
}
if (this.currentGroupId && !this.currentGroup.id) {
this.updateCurrentGroupId(this.groups[0] && this.groups[0].id);
}
if (this._preloadPosts) {
this._preloadedPosts = {};
this._preloadGroupPosts();
Expand Down Expand Up @@ -344,7 +334,8 @@ export default class GlipGroups extends Pollable {
}

async _preloadGroupPosts(force) {
for (const group of this.groups) {
const groups = this.groups.slice(0, 20);
for (const group of groups) {
if (!this._glipPosts) {
break;
}
Expand Down Expand Up @@ -481,17 +472,26 @@ export default class GlipGroups extends Pollable {
}
}

async createTeam(name, members, type = 'Team') {
const group = await this._client.glip().groups().post({
type,
name,
members,
isPublic: true,
description: ''
});
return group.id;
}

@getter
allGroups = createSelector(
() => this.data,
() => (this._glipPersons && this._glipPersons.personsMap) || {},
() => (this._glipPosts && this._glipPosts.postsMap) || {},
() => this._auth.ownerId,
(data, personsMap, postsMap, ownerId) => {
return (data || []).map(
group => formatGroup(group, personsMap, postsMap, ownerId)
);
},
(data, personsMap, postsMap, ownerId) => (data || []).map(
group => formatGroup(group, personsMap, postsMap, ownerId)
),
)

@getter
Expand Down Expand Up @@ -525,17 +525,15 @@ export default class GlipGroups extends Pollable {
@getter
groups = createSelector(
() => this.filteredGroups,
() => this.pageNumber,
(filteredGroups, pageNumber) => {
const count = pageNumber * this._perPage;
(filteredGroups) => {
const sortedGroups =
filteredGroups.sort((a, b) => {
if (a.updatedTime === b.updatedTime) return 0;
return a.updatedTime > b.updatedTime ?
-1 :
1;
});
return sortedGroups.slice(0, count);
return sortedGroups;
},
)

Expand Down Expand Up @@ -609,10 +607,6 @@ export default class GlipGroups extends Pollable {
return this.state.searchFilter;
}

get pageNumber() {
return this.state.pageNumber;
}

get data() {
return this._storage ?
this._storage.getItem(this._dataStorageKey) :
Expand All @@ -626,9 +620,7 @@ export default class GlipGroups extends Pollable {
}

get currentGroupId() {
return this._storage ?
this._storage.getItem(this._currentGroupIdStorageKey) :
this.state.currentGroupId;
return this.state.currentGroupId;
}

get status() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export function getGlipPostsStoreReducer(types) {
newPosts = (newState[groupId] && [...newState[groupId]]) || [];
if (oldRecordId) {
oldPostIndex = newPosts.findIndex(p => p.id === oldRecordId);
} else {
oldPostIndex = newPosts.findIndex(p => p.id === record.id);
}
if (oldPostIndex > -1) {
newPosts.splice(oldPostIndex, 1, record);
Expand All @@ -84,7 +86,9 @@ export function getGlipPostsStoreReducer(types) {
}

export function getGlipPostsInputsReducer(types) {
return (state = {}, { type, groupId, textValue }) => {
return (state = {}, {
type, groupId, textValue, mentions
}) => {
let newState;
switch (type) {
case types.updatePostInput:
Expand All @@ -93,6 +97,7 @@ export function getGlipPostsInputsReducer(types) {
};
newState[groupId] = {
text: textValue,
mentions,
};
return newState;
default:
Expand Down
18 changes: 14 additions & 4 deletions packages/ringcentral-integration/modules/GlipPosts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,19 @@ export default class GlipPosts extends RcModule {
}

async create({ groupId }) {
const text = this.postInputs[groupId] && this.postInputs[groupId].text;
let text = this.postInputs[groupId] && this.postInputs[groupId].text;
const mentions = this.postInputs[groupId] && this.postInputs[groupId].mentions;
if (isBlank(text) || !groupId) {
return;
}
if (mentions && mentions.length > 0) {
mentions.forEach((mention) => {
if (!mention.matcherId) {
return;
}
text = text.replace(mention.mention, `![:Person](${mention.matcherId})`);
});
}
const fakeId = `${Date.now()}`;
const fakeRecord = {
id: fakeId,
Expand All @@ -219,7 +228,7 @@ export default class GlipPosts extends RcModule {
groupId,
record: fakeRecord,
});
this.updatePostInput({ text: '', groupId });
this.updatePostInput({ text: '', groupId, mentions: [] });
const record = await this._client.glip().groups(groupId).posts().post({
text,
});
Expand All @@ -237,7 +246,7 @@ export default class GlipPosts extends RcModule {
groupId,
oldRecordId: fakeId,
});
this.updatePostInput({ text, groupId });
this.updatePostInput({ text, groupId, mentions });
}
}

Expand Down Expand Up @@ -270,10 +279,11 @@ export default class GlipPosts extends RcModule {
});
}

updatePostInput({ text, groupId }) {
updatePostInput({ text, groupId, mentions }) {
this.store.dispatch({
type: this.actionTypes.updatePostInput,
groupId,
mentions,
textValue: text,
});
}
Expand Down