-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23177b0
commit 60cc9e8
Showing
9 changed files
with
95 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,41 @@ | ||
import gql from 'graphql-tag'; | ||
import * as compose from 'lodash.flowright'; | ||
import { STORAGE_BOARD_KEY } from 'modules/boards/constants'; | ||
import { getBoardId } from 'modules/boards/containers/MainActionBar'; | ||
import { queries } from 'modules/boards/graphql'; | ||
import { PageHeader } from 'modules/boards/styles/header'; | ||
import { | ||
BoardsGetLastQueryResponse, | ||
BoardsQueryResponse | ||
} from 'modules/boards/types'; | ||
import { getDefaultBoardAndPipelines } from 'modules/boards/utils'; | ||
import Spinner from 'modules/common/components/Spinner'; | ||
import { IRouterProps } from 'modules/common/types'; | ||
import { router as routerUtils, withProps } from 'modules/common/utils'; | ||
import { BoardCountsQueryResponse } from 'modules/boards/types'; | ||
import { withProps } from 'modules/common/utils'; | ||
import React from 'react'; | ||
import { graphql } from 'react-apollo'; | ||
import { withRouter } from 'react-router'; | ||
import Home from '../../components/home/Home'; | ||
|
||
type Props = { | ||
id: string; | ||
state: string; | ||
} & IRouterProps; | ||
queryParams: any; | ||
}; | ||
|
||
type FinalProps = { | ||
boardsQuery: BoardsQueryResponse; | ||
boardGetLastQuery?: BoardsGetLastQueryResponse; | ||
boardCountsQuery: BoardCountsQueryResponse; | ||
} & Props; | ||
|
||
class HomeContainer extends React.Component<FinalProps> { | ||
render() { | ||
const { | ||
history, | ||
location, | ||
boardsQuery, | ||
boardGetLastQuery, | ||
state | ||
} = this.props; | ||
|
||
if (boardsQuery.loading) { | ||
return <PageHeader />; | ||
} | ||
|
||
const boardId = getBoardId({ location }); | ||
|
||
const { defaultBoards } = getDefaultBoardAndPipelines(); | ||
|
||
if (boardId) { | ||
defaultBoards.growthHack = boardId; | ||
|
||
localStorage.setItem(STORAGE_BOARD_KEY, JSON.stringify(defaultBoards)); | ||
} | ||
|
||
if (boardGetLastQuery && boardGetLastQuery.loading) { | ||
return <Spinner />; | ||
} | ||
|
||
const lastBoard = boardGetLastQuery && boardGetLastQuery.boardGetLast; | ||
|
||
// if there is no boardId in queryparams and there is one in localstorage | ||
// then put those in queryparams | ||
const defaultBoardId = defaultBoards.growthHack; | ||
|
||
if (!boardId && defaultBoardId) { | ||
routerUtils.setParams( | ||
history, | ||
{ | ||
id: defaultBoardId | ||
}, | ||
true | ||
); | ||
|
||
return null; | ||
} | ||
|
||
// if there is no boardId in queryparams and there is lastBoard | ||
// then put lastBoard._id and this board's first pipelineId to queryparams | ||
if ( | ||
!boardId && | ||
lastBoard && | ||
lastBoard.pipelines && | ||
lastBoard.pipelines.length > 0 | ||
) { | ||
routerUtils.setParams(history, { id: lastBoard._id }); | ||
|
||
return null; | ||
} | ||
const { boardCountsQuery, queryParams } = this.props; | ||
|
||
const props = { | ||
state, | ||
boardId, | ||
boards: boardsQuery.boards || [] | ||
queryParams, | ||
boardsWithCount: boardCountsQuery.boardCounts || [] | ||
}; | ||
|
||
return <Home {...props} />; | ||
} | ||
} | ||
|
||
export default withRouter( | ||
withProps<Props>( | ||
compose( | ||
graphql<Props, BoardsQueryResponse>(gql(queries.boards), { | ||
name: 'boardsQuery', | ||
options: () => ({ | ||
variables: { type: 'growthHack' } | ||
}) | ||
}), | ||
graphql<Props, BoardsGetLastQueryResponse>(gql(queries.boardGetLast), { | ||
name: 'boardGetLastQuery', | ||
skip: getBoardId, | ||
options: () => ({ | ||
variables: { type: 'growthHack' } | ||
}) | ||
export default withProps<Props>( | ||
compose( | ||
graphql<Props, BoardCountsQueryResponse>(gql(queries.boardCounts), { | ||
name: 'boardCountsQuery', | ||
options: () => ({ | ||
variables: { type: 'growthHack' }, | ||
fetchPolicy: 'network-only' | ||
}) | ||
)(HomeContainer) | ||
) | ||
}) | ||
)(HomeContainer) | ||
); |
Oops, something went wrong.