From c8ef07177444a4031b08d19c9e56f445829cbebd Mon Sep 17 00:00:00 2001 From: sylenien Date: Mon, 5 Dec 2022 13:46:59 +0100 Subject: [PATCH] change(ui): change url with added multi sessions to allow sharing, add refresh button and memo to sub comps --- frontend/app/Router.js | 14 ++- .../Session_/Multiview/Multiview.tsx | 109 +++++++++++++----- .../AssistSessionsModal.tsx | 17 +-- .../AssistSessionsTabs/AssistSessionsTabs.tsx | 18 +-- .../shared/SessionItem/SessionItem.tsx | 12 +- frontend/app/duck/liveSearch.js | 5 + frontend/app/mstore/assistMultiviewStore.ts | 68 ++++++++--- frontend/app/routes.js | 6 +- frontend/app/services/SessionService.ts | 7 ++ 9 files changed, 183 insertions(+), 73 deletions(-) diff --git a/frontend/app/Router.js b/frontend/app/Router.js index 04a0c5712..e99ee2546 100644 --- a/frontend/app/Router.js +++ b/frontend/app/Router.js @@ -83,6 +83,7 @@ const CLIENT_PATH = routes.client(); const ONBOARDING_PATH = routes.onboarding(); const ONBOARDING_REDIRECT_PATH = routes.onboarding(OB_DEFAULT_TAB); const MULTIVIEW_PATH = routes.multiview(); +const MULTIVIEW_INDEX_PATH = routes.multiviewIndex(); @withStore @withRouter @@ -173,8 +174,14 @@ class Router extends React.Component { render() { const { isLoggedIn, jwt, siteId, sites, loading, changePassword, location, existingTenant, onboarding, isEnterprise } = this.props; const siteIdList = sites.map(({ id }) => id).toJS(); - const hideHeader = (location.pathname && location.pathname.includes('/session/')) || location.pathname.includes('/assist/'); - const isPlayer = isRoute(SESSION_PATH, location.pathname) || isRoute(LIVE_SESSION_PATH, location.pathname) || isRoute(MULTIVIEW_PATH, location.pathname); + const hideHeader = (location.pathname && location.pathname.includes('/session/')) + || location.pathname.includes('/assist/') + || location.pathname.includes('multiview'); + const isPlayer = isRoute(SESSION_PATH, location.pathname) + || isRoute(LIVE_SESSION_PATH, location.pathname) + || isRoute(MULTIVIEW_PATH, location.pathname) + || isRoute(MULTIVIEW_INDEX_PATH, location.pathname); + const redirectToOnboarding = !onboarding && localStorage.getItem(GLOBAL_HAS_NO_RECORDINGS) === 'true' return isLoggedIn ? ( @@ -221,7 +228,8 @@ class Router extends React.Component { - + + diff --git a/frontend/app/components/Session_/Multiview/Multiview.tsx b/frontend/app/components/Session_/Multiview/Multiview.tsx index d9986a800..82ee3be35 100644 --- a/frontend/app/components/Session_/Multiview/Multiview.tsx +++ b/frontend/app/components/Session_/Multiview/Multiview.tsx @@ -1,73 +1,121 @@ import React from 'react'; import { useStore } from 'App/mstore'; -import { BackLink, Icon } from 'UI' +import { BackLink, Icon } from 'UI'; import { observer } from 'mobx-react-lite'; import { connect } from 'react-redux'; -import { fetchSessions } from 'Duck/liveSearch'; -import { useHistory } from 'react-router-dom'; -import { liveSession, assist, withSiteId } from 'App/routes'; +import { fetchSessions, customSetSessions } from 'Duck/liveSearch'; +import { useHistory, useParams } from 'react-router-dom'; +import { liveSession, assist, withSiteId, multiview } from 'App/routes'; import AssistSessionsModal from 'App/components/Session_/Player/Controls/AssistSessionsModal'; import { useModal } from 'App/components/Modal'; import LivePlayer from 'App/components/Session/LivePlayer'; -import { InactiveTab } from 'App/components/Session_/Player/Controls/AssistSessionsTabs' +import { InactiveTab } from 'App/components/Session_/Player/Controls/AssistSessionsTabs'; -function Multiview({ total, fetchSessions, siteId, assistCredendials }: { total: number; fetchSessions: (filter: any) => void, siteId: string, assistCredendials: any }) { +function Multiview({ + total, + fetchSessions, + siteId, + assistCredendials, + customSetSessions, +}: { + total: number; + customSetSessions: (data: any) => void; + fetchSessions: (filter: any) => void; + siteId: string; + assistCredendials: any; + list: Record[]; +}) { const { showModal, hideModal } = useModal(); const { assistMultiviewStore } = useStore(); const history = useHistory(); + // @ts-ignore + const { sessionsquery } = useParams(); + + const onSessionsChange = (sessions: Record[]) => { + const sessionIdQuery = encodeURIComponent(sessions.map((s) => s.sessionId).join(',')); + return history.replace(withSiteId(multiview(sessionIdQuery), siteId)); + }; React.useEffect(() => { - if (total === 0) { + assistMultiviewStore.setOnChange(onSessionsChange); + + if (sessionsquery) { + const sessionIds = decodeURIComponent(sessionsquery).split(','); + // preset + assistMultiviewStore.presetSessions(sessionIds).then((data) => { + customSetSessions(data); + }); + } else { fetchSessions({}); } }, []); const openLiveSession = (e: React.MouseEvent, sessionId: string) => { - e.stopPropagation() + e.stopPropagation(); assistMultiviewStore.setActiveSession(sessionId); history.push(withSiteId(liveSession(sessionId), siteId)); }; + const openList = () => { - history.push(withSiteId(assist(), siteId)) - } + history.push(withSiteId(assist(), siteId)); + }; + const openListModal = () => { showModal(, { right: true }); - } + }; + const replaceSession = (e: React.MouseEvent, sessionId: string) => { - e.stopPropagation() + e.stopPropagation(); showModal(, { right: true }); - } + }; + const deleteSession = (e: React.MouseEvent, sessionId: string) => { - e.stopPropagation() - assistMultiviewStore.removeSession(sessionId) - } + e.stopPropagation(); + assistMultiviewStore.removeSession(sessionId); + }; const placeholder = new Array(4 - assistMultiviewStore.sessions.length).fill(0); return (
- {/* @ts-ignore */} -
+
+ {/* @ts-ignore */} + +
{`Watching ${assistMultiviewStore.sessions.length} of ${total} Live Sessions`}
- {assistMultiviewStore.sortedSessions.map((session) => ( + {assistMultiviewStore.sortedSessions.map((session: Record) => (
openLiveSession(e, session.sessionId)} className="w-full h-full"> - {session.agentToken ? :
Loading session
} + {session.agentToken ? ( + + ) : ( +
Loading session
+ )}
{session.userDisplayName}
-
replaceSession(e, session.sessionId)}> - Replace Session +
replaceSession(e, session.sessionId)} + > + Replace Session
-
deleteSession(e, session.sessionId)}> +
deleteSession(e, session.sessionId)} + >
@@ -75,9 +123,13 @@ function Multiview({ total, fetchSessions, siteId, assistCredendials }: { total:
))} {placeholder.map((_, i) => ( -
- - Add Session +
+ + Add Session
))}
@@ -88,9 +140,10 @@ function Multiview({ total, fetchSessions, siteId, assistCredendials }: { total: export default connect( (state: any) => ({ total: state.getIn(['liveSearch', 'total']), - siteId: state.getIn([ 'site', 'siteId' ]) + siteId: state.getIn(['site', 'siteId']), }), { fetchSessions, + customSetSessions, } -)(observer(Multiview)) +)(observer(Multiview)); diff --git a/frontend/app/components/Session_/Player/Controls/AssistSessionsModal/AssistSessionsModal.tsx b/frontend/app/components/Session_/Player/Controls/AssistSessionsModal/AssistSessionsModal.tsx index 79f8331a7..223cfd7cb 100644 --- a/frontend/app/components/Session_/Player/Controls/AssistSessionsModal/AssistSessionsModal.tsx +++ b/frontend/app/components/Session_/Player/Controls/AssistSessionsModal/AssistSessionsModal.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Loader, Pagination, Tooltip } from 'UI'; +import { Loader, Pagination, Tooltip, Button } from 'UI'; import { connect } from 'react-redux'; import SessionItem from 'Shared/SessionItem'; import { addFilterByKeyAndValue, updateCurrentPage, applyFilter } from 'Duck/liveSearch'; @@ -51,8 +51,11 @@ function AssistSessionsModal(props: Props) { .toJS(); React.useEffect(() => { - props.applyFilter({ ...filter }); + if (total === 0) { + reloadSessions() + } }, []); + const reloadSessions = () => props.applyFilter({ ...filter }); const onSortChange = ({ value }: any) => { props.applyFilter({ sort: value.value }); }; @@ -68,8 +71,9 @@ function AssistSessionsModal(props: Props) { return (
-
- Sort By +
+ + Sort By 0}>