Improve Redux types part 1 (#25872)
* Always dispatch thunk actions instead of calling them * Properly dispatch actions in SwitchChannelProvider * Fix tests relying on bad types * Properly pass actions into ManageTokens * Make other logic changes to support new types * Do the big type migrations without any logic changes * Revert "Properly dispatch actions in SwitchChannelProvider" This reverts commit 28c8c7af2ef324c6814087a81baca66c60477daa. * Revert "Revert "Properly dispatch actions in SwitchChannelProvider"" This reverts commit 47115c5217ae90547040e7b7de32979a33f0845b.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0a4e9eeb92
Коммит
978f335925
@@ -3,14 +3,13 @@
|
||||
|
||||
import {connect} from 'react-redux';
|
||||
import {bindActionCreators} from 'redux';
|
||||
import type {Dispatch, ActionCreatorsMapObject} from 'redux';
|
||||
import type {Dispatch} from 'redux';
|
||||
|
||||
import type {GetGroupsForUserParams, GetGroupsParams, Group, GroupSearchParams} from '@mattermost/types/groups';
|
||||
import type {Group} from '@mattermost/types/groups';
|
||||
|
||||
import {getGroups, getGroupsByUserIdPaginated, searchGroups} from 'mattermost-redux/actions/groups';
|
||||
import {makeGetAllAssociatedGroupsForReference, makeGetMyAllowReferencedGroups, searchAllowReferencedGroups, searchMyAllowReferencedGroups, searchArchivedGroups, getArchivedGroups} from 'mattermost-redux/selectors/entities/groups';
|
||||
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
|
||||
import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions';
|
||||
|
||||
import {setModalSearchTerm} from 'actions/views/search';
|
||||
import {isModalOpen} from 'selectors/views/modals';
|
||||
@@ -21,19 +20,6 @@ import type {GlobalState} from 'types/store';
|
||||
|
||||
import UserGroupsModal from './user_groups_modal';
|
||||
|
||||
type Actions = {
|
||||
getGroups: (
|
||||
groupsParams: GetGroupsParams,
|
||||
) => Promise<{data: Group[]}>;
|
||||
setModalSearchTerm: (term: string) => void;
|
||||
getGroupsByUserIdPaginated: (
|
||||
opts: GetGroupsForUserParams,
|
||||
) => Promise<{data: Group[]}>;
|
||||
searchGroups: (
|
||||
params: GroupSearchParams,
|
||||
) => Promise<{data: Group[]}>;
|
||||
};
|
||||
|
||||
function makeMapStateToProps() {
|
||||
const getAllAssociatedGroupsForReference = makeGetAllAssociatedGroupsForReference();
|
||||
const getMyAllowReferencedGroups = makeGetMyAllowReferencedGroups();
|
||||
@@ -67,7 +53,7 @@ function makeMapStateToProps() {
|
||||
|
||||
function mapDispatchToProps(dispatch: Dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators<ActionCreatorsMapObject<ActionFunc | GenericAction>, Actions>({
|
||||
actions: bindActionCreators({
|
||||
getGroups,
|
||||
setModalSearchTerm,
|
||||
getGroupsByUserIdPaginated,
|
||||
|
||||
@@ -3,25 +3,17 @@
|
||||
|
||||
import {connect} from 'react-redux';
|
||||
import {bindActionCreators} from 'redux';
|
||||
import type {Dispatch, ActionCreatorsMapObject} from 'redux';
|
||||
import type {Dispatch} from 'redux';
|
||||
|
||||
import {archiveGroup, restoreGroup} from 'mattermost-redux/actions/groups';
|
||||
import {getGroupListPermissions} from 'mattermost-redux/selectors/entities/roles';
|
||||
import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions';
|
||||
|
||||
import {openModal} from 'actions/views/modals';
|
||||
|
||||
import type {ModalData} from 'types/actions';
|
||||
import type {GlobalState} from 'types/store';
|
||||
|
||||
import UserGroupsList from './user_groups_list';
|
||||
|
||||
type Actions = {
|
||||
openModal: <P>(modalData: ModalData<P>) => void;
|
||||
archiveGroup: (groupId: string) => Promise<ActionResult>;
|
||||
restoreGroup: (groupId: string) => Promise<ActionResult>;
|
||||
};
|
||||
|
||||
function mapStateToProps(state: GlobalState) {
|
||||
const groupPermissionsMap = getGroupListPermissions(state);
|
||||
return {
|
||||
@@ -31,7 +23,7 @@ function mapStateToProps(state: GlobalState) {
|
||||
|
||||
function mapDispatchToProps(dispatch: Dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators<ActionCreatorsMapObject<ActionFunc | GenericAction>, Actions>({
|
||||
actions: bindActionCreators({
|
||||
openModal,
|
||||
archiveGroup,
|
||||
restoreGroup,
|
||||
|
||||
@@ -7,6 +7,8 @@ import {Modal} from 'react-bootstrap';
|
||||
import type {GetGroupsForUserParams, GetGroupsParams, Group, GroupSearchParams} from '@mattermost/types/groups';
|
||||
|
||||
import './user_groups_modal.scss';
|
||||
import type {ActionResult} from 'mattermost-redux/types/actions';
|
||||
|
||||
import NoResultsIndicator from 'components/no_results_indicator';
|
||||
import {NoResultsVariant} from 'components/no_results_indicator/types';
|
||||
import Input from 'components/widgets/inputs/input/input';
|
||||
@@ -33,14 +35,14 @@ export type Props = {
|
||||
actions: {
|
||||
getGroups: (
|
||||
opts: GetGroupsParams,
|
||||
) => Promise<{data: Group[]}>;
|
||||
) => Promise<ActionResult<Group[]>>;
|
||||
setModalSearchTerm: (term: string) => void;
|
||||
getGroupsByUserIdPaginated: (
|
||||
opts: GetGroupsForUserParams,
|
||||
) => Promise<{data: Group[]}>;
|
||||
) => Promise<ActionResult<Group[]>>;
|
||||
searchGroups: (
|
||||
params: GroupSearchParams,
|
||||
) => Promise<{data: Group[]}>;
|
||||
) => Promise<ActionResult>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,7 +81,7 @@ const UserGroupsModal = (props: Props) => {
|
||||
per_page: GROUPS_PER_PAGE,
|
||||
include_member_count: true,
|
||||
};
|
||||
let data: {data: Group[]} = {data: []};
|
||||
let data: ActionResult<Group[]> = {data: []};
|
||||
|
||||
if (groupType === 'all') {
|
||||
groupsParams.include_archived = true;
|
||||
@@ -96,7 +98,7 @@ const UserGroupsModal = (props: Props) => {
|
||||
data = await actions.getGroups(groupsParams);
|
||||
}
|
||||
|
||||
if (data && data.data.length === 0) {
|
||||
if (data && data.data!.length === 0) {
|
||||
setGroupsFull(true);
|
||||
} else {
|
||||
setGroupsFull(false);
|
||||
|
||||
@@ -3,23 +3,17 @@
|
||||
|
||||
import {connect} from 'react-redux';
|
||||
import {bindActionCreators} from 'redux';
|
||||
import type {Dispatch, ActionCreatorsMapObject} from 'redux';
|
||||
import type {Dispatch} from 'redux';
|
||||
|
||||
import {Permissions} from 'mattermost-redux/constants';
|
||||
import {haveISystemPermission} from 'mattermost-redux/selectors/entities/roles';
|
||||
import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions';
|
||||
|
||||
import {openModal} from 'actions/views/modals';
|
||||
|
||||
import type {ModalData} from 'types/actions';
|
||||
import type {GlobalState} from 'types/store';
|
||||
|
||||
import UserGroupsModalHeader from './user_groups_modal_header';
|
||||
|
||||
type Actions = {
|
||||
openModal: <P>(modalData: ModalData<P>) => void;
|
||||
};
|
||||
|
||||
function mapStateToProps(state: GlobalState) {
|
||||
const canCreateCustomGroups = haveISystemPermission(state, {permission: Permissions.CREATE_CUSTOM_GROUP});
|
||||
|
||||
@@ -30,7 +24,7 @@ function mapStateToProps(state: GlobalState) {
|
||||
|
||||
function mapDispatchToProps(dispatch: Dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators<ActionCreatorsMapObject<ActionFunc | GenericAction>, Actions>({
|
||||
actions: bindActionCreators({
|
||||
openModal,
|
||||
}, dispatch),
|
||||
};
|
||||
|
||||
Ссылка в новой задаче
Block a user