Skip to content

Commit

Permalink
[CLD-689] fix modal initial state (#265)
Browse files Browse the repository at this point in the history
* [CLD-689] fix modal initial state

* [CLD-689] update chaining fallback
  • Loading branch information
zlatanpham authored Jan 14, 2020
1 parent 583971a commit 292ad80
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/components/pages/__tests__/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
mapDispatchToProps,
handleAfterClose,
handleOnChange,
handleOnCardClick
handleOnCardClick,
onCardClickParams
} from '../client'
import { addQuery } from '@/utils/client-url-params'
import { AppSummaryModel } from '@reapit/foundations-ts-definitions'
Expand Down Expand Up @@ -216,10 +217,18 @@ describe('Client', () => {

describe('handleOnCardClick', () => {
it('should run correctly', () => {
const mockProps = {
const mockProps: onCardClickParams = {
setVisible: jest.fn(),
appDetail: {
appDetailData: appsDataStub.data,
authentication: {
loading: false,
code: '200'
},
error: false,
loading: false,
appDetailData: {
data: appsDataStub.data.data![0]
},
isStale: true
},
setStateViewBrowse: jest.fn(),
Expand Down
21 changes: 17 additions & 4 deletions src/components/pages/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,27 @@ export const handleAfterClose = ({ setVisible }) => () => setVisible(false)
export const handleOnChange = history => (page: number) => {
history.push(addQuery({ page }))
}
export const handleOnCardClick = ({ setVisible, setStateViewBrowse, appDetail, fetchAppDetail, clientId }) => (
app: AppSummaryModel
) => {

export interface onCardClickParams {
setVisible: (isVisible: boolean) => void
setStateViewBrowse: () => void
appDetail: AppDetailState
fetchAppDetail: (id: string, client: string) => void
clientId: string
}

export const handleOnCardClick = ({
setVisible,
setStateViewBrowse,
appDetail,
fetchAppDetail,
clientId
}: onCardClickParams) => (app: AppSummaryModel) => {
setVisible(true)
setStateViewBrowse()
const isCacheEmpty = !appDetail.appDetailData
const isCacheStale = appDetail.isStale
const currentAppIdNotMatchWithCachedAppId = appDetail.appDetailData.data.id !== app.id
const currentAppIdNotMatchWithCachedAppId = appDetail.appDetailData?.data?.id !== app.id

if (app.id && (isCacheEmpty || isCacheStale || currentAppIdNotMatchWithCachedAppId)) {
fetchAppDetail(app.id, clientId)
Expand Down

0 comments on commit 292ad80

Please sign in to comment.