Feature: Adds connectWithCleanup HOC (#19392)

* Feature: Adds connectWithCleanup HOC

* Refactor: Small typings

* Refactor: Makes UseEffect run on Mount and UnMount only

* Refactor: Adds tests and rootReducer
This commit is contained in:
Hugo Häggmark
2019-10-04 04:37:16 -07:00
committed by GitHub
parent 81dd57524d
commit 989f98efda
8 changed files with 250 additions and 48 deletions

View File

@@ -1,17 +1,17 @@
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import { hot } from 'react-hot-loader';
import Page from 'app/core/components/Page/Page';
import { DeleteButton } from '@grafana/ui';
import { NavModel } from '@grafana/data';
import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA';
import { Team, OrgRole } from 'app/types';
import { Team, OrgRole, StoreState } from 'app/types';
import { loadTeams, deleteTeam, setSearchQuery } from './state/actions';
import { getSearchQuery, getTeams, getTeamsCount, isPermissionTeamAdmin } from './state/selectors';
import { getNavModel } from 'app/core/selectors/navModel';
import { FilterInput } from 'app/core/components/FilterInput/FilterInput';
import { config } from 'app/core/config';
import { contextSrv, User } from 'app/core/services/context_srv';
import { connectWithCleanUp } from '../../core/components/connectWithCleanUp';
export interface Props {
navModel: NavModel;
@@ -152,7 +152,7 @@ export class TeamList extends PureComponent<Props, any> {
}
}
function mapStateToProps(state: any) {
function mapStateToProps(state: StoreState) {
return {
navModel: getNavModel(state.navIndex, 'teams'),
teams: getTeams(state.teams),
@@ -170,9 +170,4 @@ const mapDispatchToProps = {
setSearchQuery,
};
export default hot(module)(
connect(
mapStateToProps,
mapDispatchToProps
)(TeamList)
);
export default hot(module)(connectWithCleanUp(mapStateToProps, mapDispatchToProps, state => state.teams)(TeamList));