-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Uptime] clear ping state when PingList component in unmounted #88321
Changes from 2 commits
944704c
145e69d
751e881
1b6e12d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import { PingTimestamp } from './columns/ping_timestamp'; | |
import { FailedStep } from './columns/failed_step'; | ||
import { usePingsList } from './use_pings'; | ||
import { PingListHeader } from './ping_list_header'; | ||
import { clearPings } from '../../../state/actions'; | ||
|
||
export const SpanWithMargin = styled.span` | ||
margin-right: 16px; | ||
|
@@ -54,6 +55,12 @@ export const PingList = () => { | |
Object.keys(expandedRows).filter((e) => !pings.some(({ docId }) => docId === e)) | ||
); | ||
|
||
useEffect(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice simple strategy here, small footprint, runs once. I smoke tested this and it seemed to work great. |
||
return () => { | ||
dispatch(clearPings()); | ||
}; | ||
}, [dispatch]); | ||
|
||
useEffect(() => { | ||
const parsed = JSON.parse(expandedIdsToRemove); | ||
if (parsed.length) { | ||
|
@@ -200,6 +207,15 @@ export const PingList = () => { | |
itemId="docId" | ||
itemIdToExpandedRowMap={expandedRows} | ||
pagination={pagination} | ||
noItemsMessage={ | ||
loading | ||
? i18n.translate('xpack.uptime.pingList.pingsLoadingMesssage', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure who determines what the appropriate content is in these cases. Please let me know if this default content is appropriate or need to be run past product. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the ticket Paul suggested the more generic |
||
defaultMessage: 'Loading ping history', | ||
}) | ||
: i18n.translate('xpack.uptime.pingList.pingsUnavailableMessage', { | ||
defaultMessage: 'No pings found', | ||
}) | ||
} | ||
onChange={(criteria: any) => { | ||
setPageSize(criteria.page!.size); | ||
setPageIndex(criteria.page!.index); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,10 @@ export function mockReduxHooks(response?: any) { | |
jest.spyOn(redux, 'useSelector').mockReturnValue(response); | ||
} | ||
|
||
export function mockDispatch() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mocking useSelector was causing issues for me, since this component called on two different selectors, so I am only mocking dispatch. Mocking useSelector is less critical when using the default app state within a mock redux provider, as we are in the new rtl custom render. |
||
jest.spyOn(redux, 'useDispatch').mockReturnValue(jest.fn()); | ||
} | ||
|
||
export function mockReactRouterDomHooks({ useParamsResponse }: { useParamsResponse: any }) { | ||
jest.spyOn(reactRouterDom, 'useParams').mockReturnValue(useParamsResponse); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ import { | |
GetPingsParams, | ||
} from '../../../common/runtime_types'; | ||
|
||
export const clearPings = createAction('CLEAR PINGS'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see some actions use SNAKE_CASE and others just use spaces. Which should I be using, or does it matter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think largely we are not super strict on the formatting of these since in practice no one sees them or needs to do anything with them. |
||
|
||
export const getPingHistogram = createAction<GetPingHistogramParams>('GET_PING_HISTOGRAM'); | ||
export const getPingHistogramSuccess = createAction<HistogramResult>('GET_PING_HISTOGRAM_SUCCESS'); | ||
export const getPingHistogramFail = createAction<Error>('GET_PING_HISTOGRAM_FAIL'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
import { handleActions, Action } from 'redux-actions'; | ||
import { PingsResponse } from '../../../common/runtime_types'; | ||
import { getPings, getPingsSuccess, getPingsFail } from '../actions'; | ||
import { clearPings, getPings, getPingsSuccess, getPingsFail } from '../actions'; | ||
|
||
export interface PingListState { | ||
pingList: PingsResponse; | ||
|
@@ -26,6 +26,10 @@ type PingListPayload = PingsResponse & Error; | |
|
||
export const pingListReducer = handleActions<PingListState, PingListPayload>( | ||
{ | ||
[String(clearPings)]: (state) => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also be resetPings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with |
||
...state, | ||
...initialState, | ||
}), | ||
[String(getPings)]: (state) => ({ | ||
...state, | ||
loading: true, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Been doing these all week, it's making the test suites so much nicer.