diff --git a/.npmignore b/.npmignore index 9b3e3c0c0..cc2014201 100644 --- a/.npmignore +++ b/.npmignore @@ -10,13 +10,10 @@ PULL_REQUEST_TEMPLATE.md .npmignore .npminstall .tmp -src .circleci jest.config.js babel.config.js -rollup.config.js -tsconfig.json .editorconfig .eslintignore mattermost-redux.iml -.eslintrc.json \ No newline at end of file +.eslintrc.json diff --git a/package.json b/package.json index 3a73fe628..1f91a36e1 100644 --- a/package.json +++ b/package.json @@ -90,4 +90,4 @@ "source-map-support": "0.5.12", "typescript": "3.6.3" } -} \ No newline at end of file +} diff --git a/src/actions/bots.ts b/src/actions/bots.ts index e63b81145..ec96b7a59 100644 --- a/src/actions/bots.ts +++ b/src/actions/bots.ts @@ -5,9 +5,11 @@ import {Client4} from 'client'; import {BotTypes} from 'action_types'; import {bindClientFunc} from './helpers'; +import {ActionFunc} from 'types/actions'; + const BOTS_PER_PAGE_DEFAULT = 20; -export function createBot(bot) { +export function createBot(bot): ActionFunc { return bindClientFunc({ clientFunc: Client4.createBot, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNT, @@ -17,7 +19,7 @@ export function createBot(bot) { }); } -export function patchBot(botUserId, botPatch) { +export function patchBot(botUserId, botPatch): ActionFunc { return bindClientFunc({ clientFunc: Client4.patchBot, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNT, @@ -28,7 +30,7 @@ export function patchBot(botUserId, botPatch) { }); } -export function loadBot(botUserId) { +export function loadBot(botUserId): ActionFunc { return bindClientFunc({ clientFunc: Client4.getBot, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNT, @@ -38,7 +40,7 @@ export function loadBot(botUserId) { }); } -export function loadBots(page = 0, perPage = BOTS_PER_PAGE_DEFAULT) { +export function loadBots(page = 0, perPage = BOTS_PER_PAGE_DEFAULT): ActionFunc { return bindClientFunc({ clientFunc: Client4.getBotsIncludeDeleted, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNTS, @@ -49,7 +51,7 @@ export function loadBots(page = 0, perPage = BOTS_PER_PAGE_DEFAULT) { }); } -export function disableBot(botUserId) { +export function disableBot(botUserId): ActionFunc { return bindClientFunc({ clientFunc: Client4.disableBot, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNT, @@ -59,7 +61,7 @@ export function disableBot(botUserId) { }); } -export function enableBot(botUserId) { +export function enableBot(botUserId): ActionFunc { return bindClientFunc({ clientFunc: Client4.enableBot, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNT, @@ -69,7 +71,7 @@ export function enableBot(botUserId) { }); } -export function assignBot(botUserId, newOwnerId) { +export function assignBot(botUserId, newOwnerId): ActionFunc { return bindClientFunc({ clientFunc: Client4.assignBot, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNT, diff --git a/src/actions/files.ts b/src/actions/files.ts index 55052248f..8a04d97c9 100644 --- a/src/actions/files.ts +++ b/src/actions/files.ts @@ -3,12 +3,12 @@ import {Client4} from 'client'; import {FileTypes} from 'action_types'; -import {Action, batchActions, DispatchFunc, GetStateFunc} from 'types/actions'; +import {Action, batchActions, DispatchFunc, GetStateFunc, ActionFunc} from 'types/actions'; import {logError} from './errors'; import {bindClientFunc, forceLogoutIfNecessary} from './helpers'; -export function getFilesForPost(postId: string) { +export function getFilesForPost(postId: string): ActionFunc { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { let files; @@ -30,7 +30,7 @@ export function getFilesForPost(postId: string) { }; } -export function uploadFile(channelId: string, rootId: string, clientIds: Array, fileFormData: File, formBoundary: string) { +export function uploadFile(channelId: string, rootId: string, clientIds: Array, fileFormData: File, formBoundary: string): ActionFunc { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { dispatch({type: FileTypes.UPLOAD_FILES_REQUEST, data: {}}, getState); @@ -75,7 +75,7 @@ export function uploadFile(channelId: string, rootId: string, clientIds: Array { dispatch({type: IntegrationTypes.DELETE_INCOMING_HOOK_REQUEST, data: {}}, getState); @@ -81,7 +81,7 @@ export function removeIncomingHook(hookId: string) { }; } -export function updateIncomingHook(hook: IncomingWebhook) { +export function updateIncomingHook(hook: IncomingWebhook): ActionFunc { return bindClientFunc({ clientFunc: Client4.updateIncomingWebhook, onRequest: IntegrationTypes.UPDATE_INCOMING_HOOK_REQUEST, @@ -93,7 +93,7 @@ export function updateIncomingHook(hook: IncomingWebhook) { }); } -export function createOutgoingHook(hook: OutgoingWebhook) { +export function createOutgoingHook(hook: OutgoingWebhook): ActionFunc { return bindClientFunc({ clientFunc: Client4.createOutgoingWebhook, onRequest: IntegrationTypes.CREATE_OUTGOING_HOOK_REQUEST, @@ -105,7 +105,7 @@ export function createOutgoingHook(hook: OutgoingWebhook) { }); } -export function getOutgoingHook(hookId: string) { +export function getOutgoingHook(hookId: string): ActionFunc { return bindClientFunc({ clientFunc: Client4.getOutgoingWebhook, onRequest: IntegrationTypes.GET_OUTGOING_HOOKS_REQUEST, @@ -117,7 +117,7 @@ export function getOutgoingHook(hookId: string) { }); } -export function getOutgoingHooks(channelId = '', teamId = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT) { +export function getOutgoingHooks(channelId = '', teamId = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): ActionFunc { return bindClientFunc({ clientFunc: Client4.getOutgoingWebhooks, onRequest: IntegrationTypes.GET_OUTGOING_HOOKS_REQUEST, @@ -132,7 +132,7 @@ export function getOutgoingHooks(channelId = '', teamId = '', page = 0, perPage: }); } -export function removeOutgoingHook(hookId: string) { +export function removeOutgoingHook(hookId: string): ActionFunc { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { dispatch({type: IntegrationTypes.DELETE_OUTGOING_HOOK_REQUEST, data: {}}, getState); @@ -162,7 +162,7 @@ export function removeOutgoingHook(hookId: string) { }; } -export function updateOutgoingHook(hook: OutgoingWebhook) { +export function updateOutgoingHook(hook: OutgoingWebhook): ActionFunc { return bindClientFunc({ clientFunc: Client4.updateOutgoingWebhook, onRequest: IntegrationTypes.UPDATE_OUTGOING_HOOK_REQUEST, @@ -174,7 +174,7 @@ export function updateOutgoingHook(hook: OutgoingWebhook) { }); } -export function regenOutgoingHookToken(hookId: string) { +export function regenOutgoingHookToken(hookId: string): ActionFunc { return bindClientFunc({ clientFunc: Client4.regenOutgoingHookToken, onRequest: IntegrationTypes.UPDATE_OUTGOING_HOOK_REQUEST, @@ -186,7 +186,7 @@ export function regenOutgoingHookToken(hookId: string) { }); } -export function getCommands(teamId: string) { +export function getCommands(teamId: string): ActionFunc { return bindClientFunc({ clientFunc: Client4.getCommandsList, onRequest: IntegrationTypes.GET_COMMANDS_REQUEST, @@ -198,7 +198,7 @@ export function getCommands(teamId: string) { }); } -export function getAutocompleteCommands(teamId: string, page = 0, perPage: number = General.PAGE_SIZE_DEFAULT) { +export function getAutocompleteCommands(teamId: string, page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): ActionFunc { return bindClientFunc({ clientFunc: Client4.getAutocompleteCommandsList, onRequest: IntegrationTypes.GET_AUTOCOMPLETE_COMMANDS_REQUEST, @@ -212,7 +212,7 @@ export function getAutocompleteCommands(teamId: string, page = 0, perPage: numbe }); } -export function getCustomTeamCommands(teamId: string) { +export function getCustomTeamCommands(teamId: string): ActionFunc { return bindClientFunc({ clientFunc: Client4.getCustomTeamCommands, onRequest: IntegrationTypes.GET_CUSTOM_TEAM_COMMANDS_REQUEST, @@ -224,7 +224,7 @@ export function getCustomTeamCommands(teamId: string) { }); } -export function addCommand(command: Command) { +export function addCommand(command: Command): ActionFunc { return bindClientFunc({ clientFunc: Client4.addCommand, onRequest: IntegrationTypes.ADD_COMMAND_REQUEST, @@ -236,7 +236,7 @@ export function addCommand(command: Command) { }); } -export function editCommand(command: Command) { +export function editCommand(command: Command): ActionFunc { return bindClientFunc({ clientFunc: Client4.editCommand, onRequest: IntegrationTypes.EDIT_COMMAND_REQUEST, @@ -248,7 +248,7 @@ export function editCommand(command: Command) { }); } -export function executeCommand(command: Command, args: Array) { +export function executeCommand(command: Command, args: Array): ActionFunc { return bindClientFunc({ clientFunc: Client4.executeCommand, onRequest: IntegrationTypes.EXECUTE_COMMAND_REQUEST, @@ -261,7 +261,7 @@ export function executeCommand(command: Command, args: Array) { }); } -export function regenCommandToken(id: string) { +export function regenCommandToken(id: string): ActionFunc { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { dispatch({type: IntegrationTypes.REGEN_COMMAND_TOKEN_REQUEST, data: {}}, getState); @@ -295,7 +295,7 @@ export function regenCommandToken(id: string) { }; } -export function deleteCommand(id: string) { +export function deleteCommand(id: string): ActionFunc { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { dispatch({type: IntegrationTypes.DELETE_COMMAND_REQUEST, data: {}}, getState); @@ -325,7 +325,7 @@ export function deleteCommand(id: string) { }; } -export function addOAuthApp(app: OAuthApp) { +export function addOAuthApp(app: OAuthApp): ActionFunc { return bindClientFunc({ clientFunc: Client4.createOAuthApp, onRequest: IntegrationTypes.ADD_OAUTH_APP_REQUEST, @@ -337,7 +337,7 @@ export function addOAuthApp(app: OAuthApp) { }); } -export function editOAuthApp(app: OAuthApp) { +export function editOAuthApp(app: OAuthApp): ActionFunc { return bindClientFunc({ clientFunc: Client4.editOAuthApp, onRequest: IntegrationTypes.UPDATE_OAUTH_APP_REQUEST, @@ -349,7 +349,7 @@ export function editOAuthApp(app: OAuthApp) { }); } -export function getOAuthApps(page = 0, perPage: number = General.PAGE_SIZE_DEFAULT) { +export function getOAuthApps(page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): ActionFunc { return bindClientFunc({ clientFunc: Client4.getOAuthApps, onRequest: IntegrationTypes.GET_OAUTH_APPS_REQUEST, @@ -362,7 +362,7 @@ export function getOAuthApps(page = 0, perPage: number = General.PAGE_SIZE_DEFAU }); } -export function getOAuthApp(appId: string) { +export function getOAuthApp(appId: string): ActionFunc { return bindClientFunc({ clientFunc: Client4.getOAuthApp, onRequest: IntegrationTypes.GET_OAUTH_APP_REQUEST, @@ -374,7 +374,7 @@ export function getOAuthApp(appId: string) { }); } -export function getAuthorizedOAuthApps() { +export function getAuthorizedOAuthApps(): ActionFunc { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { dispatch({type: IntegrationTypes.GET_AUTHORIZED_OAUTH_APPS_REQUEST, data: {}}); @@ -401,7 +401,7 @@ export function getAuthorizedOAuthApps() { }; } -export function deauthorizeOAuthApp(clientId: string) { +export function deauthorizeOAuthApp(clientId: string): ActionFunc { return bindClientFunc({ clientFunc: Client4.deauthorizeOAuthApp, onRequest: IntegrationTypes.DEAUTHORIZE_OAUTH_APP_REQUEST, @@ -411,7 +411,7 @@ export function deauthorizeOAuthApp(clientId: string) { }); } -export function deleteOAuthApp(id: string) { +export function deleteOAuthApp(id: string): ActionFunc { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { dispatch({type: IntegrationTypes.DELETE_OAUTH_APP_REQUEST, data: {}}, getState); @@ -441,7 +441,7 @@ export function deleteOAuthApp(id: string) { }; } -export function regenOAuthAppSecret(appId: string) { +export function regenOAuthAppSecret(appId: string): ActionFunc { return bindClientFunc({ clientFunc: Client4.regenOAuthAppSecret, onRequest: IntegrationTypes.UPDATE_OAUTH_APP_REQUEST, @@ -453,7 +453,7 @@ export function regenOAuthAppSecret(appId: string) { }); } -export function submitInteractiveDialog(submission: DialogSubmission) { +export function submitInteractiveDialog(submission: DialogSubmission): ActionFunc { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { dispatch({type: IntegrationTypes.SUBMIT_INTERACTIVE_DIALOG_REQUEST, data: {}}); diff --git a/src/actions/plugins.ts b/src/actions/plugins.ts index d5daa6866..7380a23cd 100644 --- a/src/actions/plugins.ts +++ b/src/actions/plugins.ts @@ -6,7 +6,9 @@ import {bindClientFunc} from './helpers'; import {PluginTypes} from 'action_types'; -export function getMarketplacePlugins(filter) { +import {ActionFunc} from 'types/actions'; + +export function getMarketplacePlugins(filter): ActionFunc { return bindClientFunc({ clientFunc: Client4.getMarketplacePlugins, onSuccess: PluginTypes.RECEIVED_MARKETPLACE_PLUGINS, diff --git a/src/actions/websocket.ts b/src/actions/websocket.ts index 24d2a79d0..b25f77f9e 100644 --- a/src/actions/websocket.ts +++ b/src/actions/websocket.ts @@ -16,7 +16,7 @@ import {fromAutoResponder} from 'utils/post_utils'; import EventEmitter from 'utils/event_emitter'; import {getMyPreferences} from './preferences'; -import {ActionFunc, DispatchFunc, GetStateFunc, PlatformType} from '../types/actions'; +import {ActionFunc, DispatchFunc, GetStateFunc, PlatformType} from 'types/actions'; import {getTeam, getMyTeamUnreads, getMyTeams, getMyTeamMembers} from './teams'; import {getPost, getPosts, getProfilesAndStatusesForPosts, getCustomEmojiForReaction, handleNewPost, postDeleted, receivedPost} from './posts'; diff --git a/src/reducers/entities/emojis.ts b/src/reducers/entities/emojis.ts index b88e46fac..373a95bb2 100644 --- a/src/reducers/entities/emojis.ts +++ b/src/reducers/entities/emojis.ts @@ -3,10 +3,9 @@ import {combineReducers} from 'redux'; import {EmojiTypes, PostTypes, UserTypes} from 'action_types'; import {EmojisState, CustomEmoji} from 'types/emojis'; -import {Post} from 'types/posts'; -import {GenericAction} from 'types/actions'; -import {IDMappedObjects} from 'types/utilities'; -export function customEmoji(state: IDMappedObjects = {}, action: GenericAction): IDMappedObjects { +import * as types from 'types'; + +export function customEmoji(state: types.utilities.IDMappedObjects = {}, action: types.actions.GenericAction): types.utilities.IDMappedObjects { switch (action.type) { case EmojiTypes.RECEIVED_CUSTOM_EMOJI: { const nextState = {...state}; @@ -31,7 +30,7 @@ export function customEmoji(state: IDMappedObjects = {}, action: Ge case PostTypes.RECEIVED_NEW_POST: case PostTypes.RECEIVED_POST: { - const post: Post = action.data; + const post: types.posts.Post = action.data; return storeEmojisForPost(state, post); } @@ -45,7 +44,7 @@ export function customEmoji(state: IDMappedObjects = {}, action: Ge } } -function storeEmojisForPost(state: IDMappedObjects, post: Post): IDMappedObjects { +function storeEmojisForPost(state: types.utilities.IDMappedObjects, post: types.posts.Post): types.utilities.IDMappedObjects { if (!post.metadata || !post.metadata.emojis) { return state; } @@ -63,7 +62,7 @@ function storeEmojisForPost(state: IDMappedObjects, post: Post): ID }, state); } -function nonExistentEmoji(state: Set = new Set(), action: GenericAction): Set { +function nonExistentEmoji(state: Set = new Set(), action: types.actions.GenericAction): Set { switch (action.type) { case EmojiTypes.CUSTOM_EMOJI_DOES_NOT_EXIST: { if (!state.has(action.data)) { @@ -110,4 +109,4 @@ export default (combineReducers({ // set containing custom emoji names that do not exist nonExistentEmoji, -}) as (b: EmojisState, a: GenericAction) => EmojisState); +}) as (b: EmojisState, a: types.actions.GenericAction) => EmojisState); diff --git a/src/reducers/requests/groups.ts b/src/reducers/requests/groups.ts index 034e96f74..96d7f02a3 100644 --- a/src/reducers/requests/groups.ts +++ b/src/reducers/requests/groups.ts @@ -3,8 +3,8 @@ import {combineReducers} from 'redux'; import {GroupTypes} from 'action_types'; -import {GenericAction} from '../../types/actions'; -import {RequestStatusType, GroupsRequestsStatuses} from '../../types/requests'; +import {GenericAction} from 'types/actions'; +import {RequestStatusType, GroupsRequestsStatuses} from 'types/requests'; import {handleRequest, initialRequestState} from './helpers'; diff --git a/src/selectors/entities/files.ts b/src/selectors/entities/files.ts index a72d753a7..2bba7cee1 100644 --- a/src/selectors/entities/files.ts +++ b/src/selectors/entities/files.ts @@ -1,17 +1,19 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSelector} from 'reselect'; +import * as reselect from 'reselect'; import {getCurrentUserLocale} from 'selectors/entities/i18n'; import {sortFileInfos} from 'utils/file_utils'; -function getAllFiles(state) { +import * as types from 'types'; + +function getAllFiles(state: types.store.GlobalState) { return state.entities.files.files; } -function getFilesIdsForPost(state, postId) { +function getFilesIdsForPost(state: types.store.GlobalState, postId: string) { if (postId) { return state.entities.files.fileIdsByPostId[postId] || []; } @@ -24,7 +26,7 @@ export function getFilePublicLink(state) { } export function makeGetFilesForPost() { - return createSelector( + return reselect.createSelector( [getAllFiles, getFilesIdsForPost, getCurrentUserLocale], (allFiles, fileIdsForPost, locale) => { const fileInfos = fileIdsForPost.map((id) => allFiles[id]).filter((id) => Boolean(id)); diff --git a/src/selectors/entities/groups.ts b/src/selectors/entities/groups.ts index b96253403..d93647e03 100644 --- a/src/selectors/entities/groups.ts +++ b/src/selectors/entities/groups.ts @@ -1,6 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSelector} from 'reselect'; +import * as reselect from 'reselect'; import {GlobalState} from 'types/store'; const emptyList = []; const emptySyncables = { @@ -49,17 +49,17 @@ const teamGroupIDs = (state: GlobalState, teamID) => (state.entities.teams.group const channelGroupIDs = (state: GlobalState, channelID) => (state.entities.channels.groupsAssociatedToChannel[channelID] == null ? undefined : state.entities.channels.groupsAssociatedToChannel[channelID].ids == null ? undefined : state.entities.channels.groupsAssociatedToChannel[channelID].ids) || []; -const getTeamGroupIDSet = createSelector( +const getTeamGroupIDSet = reselect.createSelector( teamGroupIDs, (teamIDs) => new Set(teamIDs), ); -const getChannelGroupIDSet = createSelector( +const getChannelGroupIDSet = reselect.createSelector( channelGroupIDs, (channelIDs) => new Set(channelIDs), ); -export const getGroupsNotAssociatedToTeam = createSelector( +export const getGroupsNotAssociatedToTeam = reselect.createSelector( getAllGroups, (state, teamID) => getTeamGroupIDSet(state, teamID), (allGroups, teamGroupIDSet) => { @@ -67,7 +67,7 @@ export const getGroupsNotAssociatedToTeam = createSelector( } ); -export const getGroupsAssociatedToTeam = createSelector( +export const getGroupsAssociatedToTeam = reselect.createSelector( getAllGroups, (state, teamID) => getTeamGroupIDSet(state, teamID), (allGroups, teamGroupIDSet) => { @@ -75,7 +75,7 @@ export const getGroupsAssociatedToTeam = createSelector( } ); -export const getGroupsNotAssociatedToChannel = createSelector( +export const getGroupsNotAssociatedToChannel = reselect.createSelector( getAllGroups, (state, channelID) => getChannelGroupIDSet(state, channelID), (allGroups, channelGroupIDSet) => { @@ -83,7 +83,7 @@ export const getGroupsNotAssociatedToChannel = createSelector( } ); -export const getGroupsAssociatedToChannel = createSelector( +export const getGroupsAssociatedToChannel = reselect.createSelector( getAllGroups, (state, channelID) => getChannelGroupIDSet(state, channelID), (allGroups, channelGroupIDSet) => { diff --git a/src/selectors/entities/integrations.ts b/src/selectors/entities/integrations.ts index 48f601110..8a0c872b7 100644 --- a/src/selectors/entities/integrations.ts +++ b/src/selectors/entities/integrations.ts @@ -1,35 +1,35 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSelector} from 'reselect'; +import * as reselect from 'reselect'; import {getCurrentTeamId} from 'selectors/entities/teams'; -import {GlobalState} from 'types/store'; +import * as types from 'types'; -export function getIncomingHooks(state: GlobalState) { +export function getIncomingHooks(state: types.store.GlobalState) { return state.entities.integrations.incomingHooks; } -export function getOutgoingHooks(state: GlobalState) { +export function getOutgoingHooks(state: types.store.GlobalState) { return state.entities.integrations.outgoingHooks; } -export function getCommands(state: GlobalState) { +export function getCommands(state: types.store.GlobalState) { return state.entities.integrations.commands; } -export function getOAuthApps(state: GlobalState) { +export function getOAuthApps(state: types.store.GlobalState) { return state.entities.integrations.oauthApps; } -export function getSystemCommands(state: GlobalState) { +export function getSystemCommands(state: types.store.GlobalState) { return state.entities.integrations.systemCommands; } /** * get outgoing hooks in current team */ -export const getOutgoingHooksInCurrentTeam = createSelector( +export const getOutgoingHooksInCurrentTeam = reselect.createSelector( getCurrentTeamId, getOutgoingHooks, (teamId, hooks) => { @@ -37,7 +37,7 @@ export const getOutgoingHooksInCurrentTeam = createSelector( } ); -export const getAllCommands = createSelector( +export const getAllCommands = reselect.createSelector( getCommands, getSystemCommands, (commands, systemCommands) => { @@ -48,7 +48,7 @@ export const getAllCommands = createSelector( } ); -export const getAutocompleteCommandsList = createSelector( +export const getAutocompleteCommandsList = reselect.createSelector( getAllCommands, getCurrentTeamId, (commands, currentTeamId) => { diff --git a/src/selectors/entities/plugins.ts b/src/selectors/entities/plugins.ts index b87e1cd39..bedd4c93c 100644 --- a/src/selectors/entities/plugins.ts +++ b/src/selectors/entities/plugins.ts @@ -1,13 +1,13 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSelector} from 'reselect'; +import * as reselect from 'reselect'; export function getMarketplacePlugins(state) { return state.entities.plugins.marketplacePlugins; } -export const getMarketplaceInstalledPlugins = createSelector( +export const getMarketplaceInstalledPlugins = reselect.createSelector( getMarketplacePlugins, (plugins) => { return Object.values(plugins).filter((p: any) => p.installed_version !== ''); diff --git a/src/selectors/entities/posts.ts b/src/selectors/entities/posts.ts index 5cb17491d..d75e24b58 100644 --- a/src/selectors/entities/posts.ts +++ b/src/selectors/entities/posts.ts @@ -12,7 +12,7 @@ import {Post, PostWithFormatData} from 'types/posts'; import {Reaction} from 'types/reactions'; import {UserProfile} from 'types/users'; import {Channel} from 'types/channels'; -import {$ID, IDMappedObjects, RelationOneToOne, RelationOneToMany} from '../../types/utilities'; +import {$ID, IDMappedObjects, RelationOneToOne, RelationOneToMany} from 'types/utilities'; export function getAllPosts(state: GlobalState) { return state.entities.posts.posts; } diff --git a/src/selectors/entities/preferences.ts b/src/selectors/entities/preferences.ts index f0bb874cd..e8746ec63 100644 --- a/src/selectors/entities/preferences.ts +++ b/src/selectors/entities/preferences.ts @@ -1,6 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSelector} from 'reselect'; +import * as reselect from 'reselect'; import {General, Preferences} from '../../constants'; import {getConfig} from 'selectors/entities/general'; import {getCurrentTeamId} from 'selectors/entities/teams'; @@ -34,7 +34,7 @@ export function getInt(state, category, name, defaultValue = 0) { } export function makeGetCategory() { - return createSelector( + return reselect.createSelector( getMyPreferences, (state, category) => category, (preferences, category) => { @@ -71,21 +71,21 @@ export function getFavoritesPreferences(state) { return favorites.filter((f) => f.value === 'true').map((f) => f.name); } -export const getVisibleTeammate = createSelector( +export const getVisibleTeammate = reselect.createSelector( getDirectShowPreferences, (direct) => { return direct.filter((dm) => dm.value === 'true' && dm.name).map((dm) => dm.name); } ); -export const getVisibleGroupIds = createSelector( +export const getVisibleGroupIds = reselect.createSelector( getGroupShowPreferences, (groups) => { return groups.filter((dm) => dm.value === 'true' && dm.name).map((dm) => dm.name); } ); -export const getTeammateNameDisplaySetting = createSelector( +export const getTeammateNameDisplaySetting = reselect.createSelector( getConfig, getMyPreferences, (config, preferences) => { @@ -99,7 +99,7 @@ export const getTeammateNameDisplaySetting = createSelector( } ); -const getThemePreference = createSelector( +const getThemePreference = reselect.createSelector( getMyPreferences, getCurrentTeamId, (myPreferences, currentTeamId) => { @@ -118,7 +118,7 @@ const getThemePreference = createSelector( } ); -const getDefaultTheme = createSelector(getConfig, (config) => { +const getDefaultTheme = reselect.createSelector(getConfig, (config) => { if (config.DefaultTheme) { const theme = Preferences.THEMES[config.DefaultTheme]; if (theme) { @@ -177,7 +177,7 @@ export const getTheme = createShallowSelector( ); export function makeGetStyleFromTheme() { - return createSelector( + return reselect.createSelector( getTheme, (state, getStyleFromTheme) => getStyleFromTheme, (theme, getStyleFromTheme) => { @@ -193,7 +193,7 @@ const defaultSidebarPrefs = { sorting: 'alpha', }; -export const getSidebarPreferences = createSelector( +export const getSidebarPreferences = reselect.createSelector( (state: GlobalState) => { const config = getConfig(state); return config.ExperimentalGroupUnreadChannels !== General.DISABLED && getBool( diff --git a/src/selectors/entities/roles.ts b/src/selectors/entities/roles.ts index ec33fa28d..7a9587267 100644 --- a/src/selectors/entities/roles.ts +++ b/src/selectors/entities/roles.ts @@ -1,14 +1,14 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSelector} from 'reselect'; +import * as reselect from 'reselect'; import {getCurrentUser, getCurrentChannelId} from 'selectors/entities/common'; import {getTeamMemberships, getCurrentTeamId} from './teams'; -import {GlobalState} from 'types/store'; +import * as types from 'types'; import {getMySystemPermissions, getMySystemRoles, getRoles} from 'selectors/entities/roles_helpers'; export {getMySystemPermissions, getMySystemRoles, getRoles}; -export const getMyTeamRoles = createSelector( +export const getMyTeamRoles = reselect.createSelector( getTeamMemberships, (teamsMemberships) => { const roles = {}; @@ -23,8 +23,8 @@ export const getMyTeamRoles = createSelector( } ); -export const getMyChannelRoles = createSelector( - (state: GlobalState) => state.entities.channels.myMembers, +export const getMyChannelRoles = reselect.createSelector( + (state: types.store.GlobalState) => state.entities.channels.myMembers, (channelsMemberships) => { const roles = {}; if (channelsMemberships) { @@ -38,7 +38,7 @@ export const getMyChannelRoles = createSelector( } ); -export const getMyRoles = createSelector( +export const getMyRoles = reselect.createSelector( getMySystemRoles, getMyTeamRoles, getMyChannelRoles, @@ -51,7 +51,7 @@ export const getMyRoles = createSelector( } ); -export const getRolesById = createSelector( +export const getRolesById = reselect.createSelector( getRoles, (rolesByName) => { const rolesById = {}; @@ -62,7 +62,7 @@ export const getRolesById = createSelector( } ); -export const getMyCurrentTeamPermissions = createSelector( +export const getMyCurrentTeamPermissions = reselect.createSelector( getMyTeamRoles, getRoles, getMySystemPermissions, @@ -85,7 +85,7 @@ export const getMyCurrentTeamPermissions = createSelector( } ); -export const getMyCurrentChannelPermissions = createSelector( +export const getMyCurrentChannelPermissions = reselect.createSelector( getMyChannelRoles, getRoles, getMyCurrentTeamPermissions, @@ -108,7 +108,7 @@ export const getMyCurrentChannelPermissions = createSelector( } ); -export const getMyTeamPermissions = createSelector( +export const getMyTeamPermissions = reselect.createSelector( getMyTeamRoles, getRoles, getMySystemPermissions, @@ -131,7 +131,7 @@ export const getMyTeamPermissions = createSelector( } ); -export const getMyChannelPermissions = createSelector( +export const getMyChannelPermissions = reselect.createSelector( getMyChannelRoles, getRoles, getMyTeamPermissions, @@ -154,7 +154,7 @@ export const getMyChannelPermissions = createSelector( } ); -export const haveISystemPermission = createSelector( +export const haveISystemPermission = reselect.createSelector( getMySystemPermissions, (state, options) => options.permission, (permissions, permission) => { @@ -162,7 +162,7 @@ export const haveISystemPermission = createSelector( } ); -export const haveITeamPermission = createSelector( +export const haveITeamPermission = reselect.createSelector( getMyTeamPermissions, (state, options) => options.permission, (permissions, permission) => { @@ -170,7 +170,7 @@ export const haveITeamPermission = createSelector( } ); -export const haveIChannelPermission = createSelector( +export const haveIChannelPermission = reselect.createSelector( getMyChannelPermissions, (state, options) => options.permission, (permissions, permission) => { @@ -178,7 +178,7 @@ export const haveIChannelPermission = createSelector( } ); -export const haveICurrentTeamPermission = createSelector( +export const haveICurrentTeamPermission = reselect.createSelector( getMyCurrentTeamPermissions, (state, options) => options.permission, (permissions, permission) => { @@ -186,7 +186,7 @@ export const haveICurrentTeamPermission = createSelector( } ); -export const haveICurrentChannelPermission = createSelector( +export const haveICurrentChannelPermission = reselect.createSelector( getMyCurrentChannelPermissions, (state, options) => options.permission, (permissions, permission) => { diff --git a/src/selectors/entities/roles_helpers.ts b/src/selectors/entities/roles_helpers.ts index 84b00631b..cc4f2e3b1 100644 --- a/src/selectors/entities/roles_helpers.ts +++ b/src/selectors/entities/roles_helpers.ts @@ -1,15 +1,15 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSelector} from 'reselect'; +import * as reselect from 'reselect'; import {GlobalState} from 'types/store'; import {getCurrentUser} from 'selectors/entities/common'; -import {UserProfile} from 'types/users'; +import * as types from 'types'; export function getRoles(state: GlobalState) { return state.entities.roles.roles; } -export const getMySystemRoles = createSelector(getCurrentUser, (user: UserProfile) => { +export const getMySystemRoles = reselect.createSelector(getCurrentUser, (user: types.users.UserProfile) => { if (user) { return new Set(user.roles.split(' ')); } @@ -17,7 +17,7 @@ export const getMySystemRoles = createSelector(getCurrentUser, (user: UserProfil return new Set(); }); -export const getMySystemPermissions = createSelector(getMySystemRoles, getRoles, (mySystemRoles: Set, roles) => { +export const getMySystemPermissions = reselect.createSelector(getMySystemRoles, getRoles, (mySystemRoles: Set, roles) => { const permissions = new Set(); for (const roleName of mySystemRoles) { @@ -31,6 +31,6 @@ export const getMySystemPermissions = createSelector(getMySystemRoles, getRoles, return permissions; }); -export const haveISystemPermission = createSelector(getMySystemPermissions, (state, options) => options.permission, (permissions, permission) => { +export const haveISystemPermission = reselect.createSelector(getMySystemPermissions, (state, options) => options.permission, (permissions, permission) => { return permissions.has(permission); }); diff --git a/src/selectors/entities/search.ts b/src/selectors/entities/search.ts index 000564fa9..46d16ecca 100644 --- a/src/selectors/entities/search.ts +++ b/src/selectors/entities/search.ts @@ -1,14 +1,16 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSelector} from 'reselect'; +import * as reselect from 'reselect'; import {getCurrentTeamId} from 'selectors/entities/teams'; -export const getCurrentSearchForCurrentTeam = createSelector( - (state) => state.entities.search.current, +import * as types from 'types'; + +export const getCurrentSearchForCurrentTeam = reselect.createSelector( + (state: types.store.GlobalState) => state.entities.search.current, getCurrentTeamId, (current, teamId) => { return current[teamId]; } -); \ No newline at end of file +); diff --git a/src/selectors/entities/teams.ts b/src/selectors/entities/teams.ts index f2df6ee47..a51cf96dd 100644 --- a/src/selectors/entities/teams.ts +++ b/src/selectors/entities/teams.ts @@ -1,6 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSelector} from 'reselect'; +import * as reselect from 'reselect'; import {Permissions} from '../../constants'; import {getConfig, getCurrentUrl, isCompatibleWithJoinViewTeamPermissions} from 'selectors/entities/general'; import {haveISystemPermission} from 'selectors/entities/roles_helpers'; @@ -14,7 +14,7 @@ export function getCurrentTeamId(state: GlobalState) { return state.entities.teams.currentTeamId; } -export const getTeamByName = createSelector(getTeams, (state, name) => name, (teams, name) => { +export const getTeamByName = reselect.createSelector(getTeams, (state, name) => name, (teams, name) => { return Object.values(teams).find((team: Team) => team.name === name); }); export function getTeams(state: GlobalState) { @@ -33,14 +33,14 @@ export function getMembersInTeams(state: GlobalState) { return state.entities.teams.membersInTeam; } -export const getTeamsList = createSelector( +export const getTeamsList = reselect.createSelector( getTeams, (teams) => { return Object.values(teams); } ); -export const getCurrentTeam = createSelector( +export const getCurrentTeam = reselect.createSelector( getTeams, getCurrentTeamId, (teams, currentTeamId) => { @@ -53,7 +53,7 @@ export function getTeam(state, id) { return teams[id]; } -export const getCurrentTeamMembership = createSelector( +export const getCurrentTeamMembership = reselect.createSelector( getCurrentTeamId, getTeamMemberships, (currentTeamId, teamMemberships) => { @@ -61,7 +61,7 @@ export const getCurrentTeamMembership = createSelector( } ); -export const isCurrentUserCurrentTeamAdmin = createSelector( +export const isCurrentUserCurrentTeamAdmin = reselect.createSelector( getCurrentTeamMembership, (member) => { if (member) { @@ -72,7 +72,7 @@ export const isCurrentUserCurrentTeamAdmin = createSelector( } ); -export const getCurrentTeamUrl = createSelector( +export const getCurrentTeamUrl = reselect.createSelector( getCurrentUrl, getCurrentTeam, (state) => getConfig(state).SiteURL, @@ -86,7 +86,7 @@ export const getCurrentTeamUrl = createSelector( } ); -export const getCurrentRelativeTeamUrl = createSelector( +export const getCurrentRelativeTeamUrl = reselect.createSelector( getCurrentTeam, (currentTeam) => { if (!currentTeam) { @@ -96,7 +96,7 @@ export const getCurrentRelativeTeamUrl = createSelector( } ); -export const getCurrentTeamStats = createSelector( +export const getCurrentTeamStats = reselect.createSelector( getCurrentTeamId, getTeamStats, (currentTeamId, teamStats) => { @@ -104,7 +104,7 @@ export const getCurrentTeamStats = createSelector( } ); -export const getMyTeams = createSelector( +export const getMyTeams = reselect.createSelector( getTeams, getTeamMemberships, (teams, members) => { @@ -112,7 +112,7 @@ export const getMyTeams = createSelector( } ); -export const getMyTeamMember = createSelector( +export const getMyTeamMember = reselect.createSelector( getTeamMemberships, (state, teamId) => teamId, (teamMemberships, teamId) => { @@ -120,7 +120,7 @@ export const getMyTeamMember = createSelector( } ); -export const getMembersInCurrentTeam = createSelector( +export const getMembersInCurrentTeam = reselect.createSelector( getCurrentTeamId, getMembersInTeams, (currentTeamId, teamMembers) => { @@ -156,7 +156,7 @@ export const getListableTeamIds = createIdsSelector( } ); -export const getListableTeams = createSelector( +export const getListableTeams = reselect.createSelector( getTeams, getListableTeamIds, (teams, listableTeamIds) => { @@ -164,7 +164,7 @@ export const getListableTeams = createSelector( } ); -export const getSortedListableTeams = createSelector( +export const getSortedListableTeams = reselect.createSelector( getTeams, getListableTeamIds, (state, locale) => locale, @@ -198,7 +198,7 @@ export const getJoinableTeamIds = createIdsSelector( } ); -export const getJoinableTeams = createSelector( +export const getJoinableTeams = reselect.createSelector( getTeams, getJoinableTeamIds, (teams, joinableTeamIds) => { @@ -206,7 +206,7 @@ export const getJoinableTeams = createSelector( } ); -export const getSortedJoinableTeams = createSelector( +export const getSortedJoinableTeams = reselect.createSelector( getTeams, getJoinableTeamIds, (state, locale) => locale, @@ -229,7 +229,7 @@ export const getMySortedTeamIds = createIdsSelector( } ); -export const getMyTeamsCount = createSelector( +export const getMyTeamsCount = reselect.createSelector( getMyTeams, (teams) => { return teams.length; @@ -240,7 +240,7 @@ export const getMyTeamsCount = createSelector( // > 0 means is returning the mention count // 0 means that there are no unread messages // -1 means that there are unread messages but no mentions -export const getChannelDrawerBadgeCount = createSelector( +export const getChannelDrawerBadgeCount = reselect.createSelector( getCurrentTeamId, getTeamMemberships, (currentTeamId, teamMembers) => { @@ -269,7 +269,7 @@ export const getChannelDrawerBadgeCount = createSelector( // 0 means that there are no unread messages // -1 means that there are unread messages but no mentions export function makeGetBadgeCountForTeamId() { - return createSelector( + return reselect.createSelector( getTeamMemberships, (state, id) => id, (members, teamId) => { diff --git a/src/store/configureStore.dev.ts b/src/store/configureStore.dev.ts index e8a6039f3..30367ad34 100644 --- a/src/store/configureStore.dev.ts +++ b/src/store/configureStore.dev.ts @@ -2,7 +2,7 @@ // See LICENSE.txt for license information. /* eslint-disable no-undefined */ -import {createStore} from 'redux'; +import * as redux from 'redux'; import devTools from 'remote-redux-devtools'; import {createOfflineReducer, networkStatusChangedAction, offlineCompose} from 'redux-offline'; import defaultOfflineConfig from 'redux-offline/lib/defaults'; @@ -43,7 +43,7 @@ export default function configureServiceStore(preloadedState, appReducer, userOf const loadReduxDevtools = process.env.NODE_ENV !== 'test'; //eslint-disable-line no-process-env - const store = createStore( + const store = redux.createStore( createOfflineReducer(createDevReducer(baseState, serviceReducer, appReducer)), baseState, offlineCompose(baseOfflineConfig)( diff --git a/src/store/configureStore.prod.ts b/src/store/configureStore.prod.ts index 60f839f4c..4318c3fcf 100644 --- a/src/store/configureStore.prod.ts +++ b/src/store/configureStore.prod.ts @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createStore} from 'redux'; +import * as redux from 'redux'; import {createOfflineReducer, networkStatusChangedAction, offlineCompose} from 'redux-offline'; import defaultOfflineConfig from 'redux-offline/lib/defaults'; import reducerRegistry from './reducer_registry'; @@ -28,7 +28,7 @@ export default function configureOfflineServiceStore(preloadedState, appReducer, const baseOfflineConfig = Object.assign({}, defaultOfflineConfig, offlineConfig, userOfflineConfig); - const store = createStore( + const store = redux.createStore( createOfflineReducer(createReducer(baseState, serviceReducer, appReducer)), baseState, offlineCompose(baseOfflineConfig)( diff --git a/src/store/middleware.ts b/src/store/middleware.ts index f7378f2c5..c07d75255 100644 --- a/src/store/middleware.ts +++ b/src/store/middleware.ts @@ -8,7 +8,7 @@ const defaultOptions = { enableBuffer: true, enableThunk: true, }; -export function createMiddleware(clientOptions) { +export function createMiddleware(clientOptions): ThunkMiddleware[] { const options = Object.assign({}, defaultOptions, clientOptions); const { additionalMiddleware, diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 68a1f0e90..6c83bea71 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -1,6 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSelectorCreator, defaultMemoize} from 'reselect'; +import * as reselect from 'reselect'; import shallowEqual from 'shallow-equals'; export function memoizeResult(func: F): any { let lastArgs: IArguments|null = null; @@ -23,10 +23,10 @@ export function memoizeResult(func: F): any { // Use this selector when you want a shallow comparison of the arguments and you want to memoize the result // try and use this only when your selector returns an array of ids -export const createIdsSelector = createSelectorCreator(memoizeResult); +export const createIdsSelector = reselect.createSelectorCreator(memoizeResult); // Use this selector when you want a shallow comparison of the arguments and you don't need to memoize the result -export const createShallowSelector = createSelectorCreator(defaultMemoize, shallowEqual); +export const createShallowSelector = reselect.createSelectorCreator(reselect.defaultMemoize, shallowEqual); // isMinimumServerVersion will return true if currentVersion is equal to higher or than the // the provided minimum version. A non-equal major version will ignore minor and dot diff --git a/src/utils/post_list.ts b/src/utils/post_list.ts index 7546df586..b0a28e58c 100644 --- a/src/utils/post_list.ts +++ b/src/utils/post_list.ts @@ -1,6 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSelector} from 'reselect'; +import * as reselect from 'reselect'; import moment from 'moment-timezone'; import {Posts, Preferences} from '../constants'; import {makeGetPostsForIds} from 'selectors/entities/posts'; @@ -10,7 +10,7 @@ import {getCurrentUser} from 'selectors/entities/users'; import {createIdsSelector, memoizeResult} from 'utils/helpers'; import {isUserActivityPost, shouldFilterJoinLeavePost} from 'utils/post_utils'; import {getUserCurrentTimezone} from 'utils/timezone_utils'; -import {Post} from 'types/posts'; +import * as types from 'types'; export const COMBINED_USER_ACTIVITY = 'user-activity-'; export const DATE_LINE = 'date-'; export const START_OF_NEW_MESSAGES = 'start-of-new-messages'; @@ -254,7 +254,7 @@ export function makeGenerateCombinedPost() { const getPostsForIds = makeGetPostsForIds(); const getPostIds = memoizeResult(getPostIdsForCombinedUserActivityPost); - return createSelector( + return reselect.createSelector( (state, combinedId) => combinedId, (state, combinedId) => getPostsForIds(state, getPostIds(combinedId)), (combinedId, posts) => { @@ -361,7 +361,7 @@ function extractUserActivityData(userActivities: any) { }; } -export function combineUserActivitySystemPost(systemPosts: Array = []) { +export function combineUserActivitySystemPost(systemPosts: Array = []) { if (systemPosts.length === 0) { return null; }