diff --git a/frontend/app/components/shared/LiveSessionList/LiveSessionList.tsx b/frontend/app/components/shared/LiveSessionList/LiveSessionList.tsx index 99614b32a..75a09eb80 100644 --- a/frontend/app/components/shared/LiveSessionList/LiveSessionList.tsx +++ b/frontend/app/components/shared/LiveSessionList/LiveSessionList.tsx @@ -1,9 +1,9 @@ import React, { useEffect } from 'react'; import { connect } from 'react-redux'; -import { NoContent, Loader, Pagination } from 'UI'; +import { NoContent, Loader, Pagination, Popup } from 'UI'; import { List } from 'immutable'; import SessionItem from 'Shared/SessionItem'; -import withPermissions from 'HOCs/withPermissions' +import withPermissions from 'HOCs/withPermissions'; import { KEYS } from 'Types/filter/customFilter'; import { applyFilter } from 'Duck/liveSearch'; import { FilterKey } from 'App/types/filter/filterType'; @@ -12,175 +12,191 @@ import Select from 'Shared/Select'; import SortOrderButton from 'Shared/SortOrderButton'; import { capitalize } from 'App/utils'; import LiveSessionReloadButton from 'Shared/LiveSessionReloadButton'; +import cn from 'classnames'; -const AUTOREFRESH_INTERVAL = .5 * 60 * 1000 +const AUTOREFRESH_INTERVAL = 0.5 * 60 * 1000; const PER_PAGE = 10; interface Props { - loading: boolean, - metaListLoading: boolean - list: List, - // fetchLiveList: () => Promise, - applyFilter: (filter: any) => void, - filter: any, - // addAttribute: (obj: any) => void, - addFilterByKeyAndValue: (key: FilterKey, value: string) => void, - updateCurrentPage: (page: number) => void, - currentPage: number, - totla: number, - metaList: any, - sort: any, - total: number, + loading: boolean; + metaListLoading: boolean; + list: List; + // fetchLiveList: () => Promise, + applyFilter: (filter: any) => void; + filter: any; + // addAttribute: (obj: any) => void, + addFilterByKeyAndValue: (key: FilterKey, value: string) => void; + updateCurrentPage: (page: number) => void; + currentPage: number; + totla: number; + metaList: any; + sort: any; + total: number; } function LiveSessionList(props: Props) { - const { loading, metaListLoading, filter, list, currentPage, total, metaList = [], sort } = props; - var timeoutId: any; - const { filters } = filter; - const hasUserFilter = filters.map((i: any) => i.key).includes(KEYS.USERID); - const sortOptions = metaList.map((i: any) => ({ - label: capitalize(i), value: i - })).toJS(); + const { loading, metaListLoading, filter, list, currentPage, total, metaList = [], sort } = props; + var timeoutId: any; + const { filters } = filter; + const hasUserFilter = filters.map((i: any) => i.key).includes(KEYS.USERID); + const sortOptions = metaList + .map((i: any) => ({ + label: capitalize(i), + value: i, + })) + .toJS(); - // useEffect(() => { - // if (metaListLoading || metaList.size === 0 || !!filter.sort) return; + // useEffect(() => { + // if (metaListLoading || metaList.size === 0 || !!filter.sort) return; - // if (sortOptions[0]) { - // props.applyFilter({ sort: sortOptions[0].value }); - // } - // }, [metaListLoading]); + // if (sortOptions[0]) { + // props.applyFilter({ sort: sortOptions[0].value }); + // } + // }, [metaListLoading]); - // useEffect(() => { - // const filteredSessions = filters.size > 0 ? props.list.filter(session => { - // let hasValidFilter = true; - // filters.forEach(filter => { - // if (!hasValidFilter) return; + // useEffect(() => { + // const filteredSessions = filters.size > 0 ? props.list.filter(session => { + // let hasValidFilter = true; + // filters.forEach(filter => { + // if (!hasValidFilter) return; - // const _values = filter.value.filter(i => i !== '' && i !== null && i !== undefined).map(i => i.toLowerCase()); - // if (filter.key === FilterKey.USERID) { - // const _userId = session.userId ? session.userId.toLowerCase() : ''; - // hasValidFilter = _values.length > 0 ? (_values.includes(_userId) && hasValidFilter) || _values.some(i => _userId.includes(i)) : hasValidFilter; - // } - // if (filter.category === FilterCategory.METADATA) { - // const _source = session.metadata[filter.key] ? session.metadata[filter.key].toLowerCase() : ''; - // hasValidFilter = _values.length > 0 ? (_values.includes(_source) && hasValidFilter) || _values.some(i => _source.includes(i)) : hasValidFilter; - // } - // }) - // return hasValidFilter; - // }) : props.list; - // setSessions(filteredSessions); - // }, [filters, list]); + // const _values = filter.value.filter(i => i !== '' && i !== null && i !== undefined).map(i => i.toLowerCase()); + // if (filter.key === FilterKey.USERID) { + // const _userId = session.userId ? session.userId.toLowerCase() : ''; + // hasValidFilter = _values.length > 0 ? (_values.includes(_userId) && hasValidFilter) || _values.some(i => _userId.includes(i)) : hasValidFilter; + // } + // if (filter.category === FilterCategory.METADATA) { + // const _source = session.metadata[filter.key] ? session.metadata[filter.key].toLowerCase() : ''; + // hasValidFilter = _values.length > 0 ? (_values.includes(_source) && hasValidFilter) || _values.some(i => _source.includes(i)) : hasValidFilter; + // } + // }) + // return hasValidFilter; + // }) : props.list; + // setSessions(filteredSessions); + // }, [filters, list]); - useEffect(() => { - props.applyFilter({ ...filter}); - timeout(); - return () => { - clearTimeout(timeoutId) - } - }, []) + useEffect(() => { + props.applyFilter({ ...filter }); + timeout(); + return () => { + clearTimeout(timeoutId); + }; + }, []); - const onUserClick = (userId: string, userAnonymousId: string) => { - if (userId) { - props.addFilterByKeyAndValue(FilterKey.USERID, userId); - } else { - props.addFilterByKeyAndValue(FilterKey.USERANONYMOUSID, userAnonymousId); - } - } + const onUserClick = (userId: string, userAnonymousId: string) => { + if (userId) { + props.addFilterByKeyAndValue(FilterKey.USERID, userId); + } else { + props.addFilterByKeyAndValue(FilterKey.USERANONYMOUSID, userAnonymousId); + } + }; - const onSortChange = ({ value }: any) => { - props.applyFilter({ sort: value.value }); - } + const onSortChange = ({ value }: any) => { + props.applyFilter({ sort: value.value }); + }; - const timeout = () => { - timeoutId = setTimeout(() => { - props.applyFilter({ ...filter}); - timeout(); - }, AUTOREFRESH_INTERVAL); - } + const timeout = () => { + timeoutId = setTimeout(() => { + props.applyFilter({ ...filter }); + timeout(); + }, AUTOREFRESH_INTERVAL); + }; - return ( -
-
-
-

- Live Sessions - {total} -

+ return ( +
+
+
+

+ Live Sessions + {total} +

- props.applyFilter({ ...filter }) } /> -
-
-
- Sort By - i.value === filter.sort) || sortOptions[0]} + /> +
+ props.applyFilter({ order: state })} sortOrder={filter.order} /> +
+ +
+
-
- - -
- ) + + + See how to setup the{' '} + + {'Assist'} + {' '} + plugin, if you haven’t done that already. + + } + image={} + show={!loading && list.size === 0} + > +
+ {list.map((session) => ( + <> + +
+ + ))} + +
+ props.updateCurrentPage(page)} + limit={PER_PAGE} + /> +
+
+ + +
+ ); } -export default withPermissions(['ASSIST_LIVE'])(connect( - (state: any) => ({ - list: state.getIn(['liveSearch', 'list']), - loading: state.getIn([ 'liveSearch', 'fetchList', 'loading' ]), - metaListLoading: state.getIn([ 'customFields', 'fetchRequest', 'loading' ]), - filter: state.getIn([ 'liveSearch', 'instance' ]), - total: state.getIn([ 'liveSearch', 'total' ]), - currentPage: state.getIn(["liveSearch", "currentPage"]), - metaList: state.getIn(['customFields', 'list']).map((i: any) => i.key), - sort: state.getIn(['liveSearch', 'sort']), - }), - { - applyFilter, - addFilterByKeyAndValue, - updateCurrentPage, - } -)(LiveSessionList)); +export default withPermissions(['ASSIST_LIVE'])( + connect( + (state: any) => ({ + list: state.getIn(['liveSearch', 'list']), + loading: state.getIn(['liveSearch', 'fetchList', 'loading']), + metaListLoading: state.getIn(['customFields', 'fetchRequest', 'loading']), + filter: state.getIn(['liveSearch', 'instance']), + total: state.getIn(['liveSearch', 'total']), + currentPage: state.getIn(['liveSearch', 'currentPage']), + metaList: state.getIn(['customFields', 'list']).map((i: any) => i.key), + sort: state.getIn(['liveSearch', 'sort']), + }), + { + applyFilter, + addFilterByKeyAndValue, + updateCurrentPage, + } + )(LiveSessionList) +);