openreplay/frontend/app/components/shared/LiveSessionList/LiveSessionList.tsx
Delirium a71381da40
getting rid of redux for good (#2556)
* start moving ui to redux tlk

* remove unused reducer

* changes for gdpr and site types

* ui: migrating duck/roles to mobx

* ui: drop unreferenced types

* ui: drop unreferenced types

* ui: move player slice reducer to mobx family

* ui: move assignments to issueReportingStore.ts

* remove issues store

* some fixes after issues store

* remove errors reducer, drop old components

* finish removing errors reducer

* start moving integrations state to mobx

* change(ui): funnel duck cleanup

* change(ui): custom fields

* change(ui): customMetrics cleanup

* change(ui): customMetrics cleanup

* change(ui): duck/filters minor cleanup

* change(ui): duck/filters cleanup

* change(ui): duck/customMetrics cleanup and upgrades

* fix integrations service, fix babel config to >.25 + not ie

* refactoring integrations reducers etc WIP

* finish removing integrations state

* some fixes for integrated check

* start of projects refactoring

* move api and "few" files to new project store

* new batch for site -> projects

* fix setid context

* move all critical components, drop site duck

* remove all duck/site refs, remove old components

* fixup for SessionTags.tsx, remove duck/sources (?)

* move session store

* init sessionstore outside of context

* fix userfilter

* replace simple actions for session store

* sessions sotre

* Rtm temp (#2597)

* change(ui): duck/search wip

* change(ui): duck/search wip

* change(ui): duck/search wip

* change(ui): duck/searchLive wip

* change(ui): duck/searchLive wip

* change(ui): duck/searchLive wip

* change(ui): duck/searchLive wip

* change(ui): search states

* change(ui): search states

* change(ui): search states

* change(ui): fix savedSearch store

* change(ui): fix savedSearch store

* some fixes for session connector

* change(ui): fix savedSearch store

* change(ui): fix searchLive

* change(ui): fix searchLive

* fixes for session replay

* change(ui): bookmark fetch

* last components for sessions

* add fetchautoplaylist

* finish session reducer, remove deleted reducers

* change(ui): fix the search fetch

* change(ui): fix the search fetch

* fix integrations call ctx

* ensure ctx for sessionstore

* fix(ui): checking for latest sessions path

* start removing user reducer

* removing user reducer pt2...

* finish user store

* remove rand log

* fix crashes

* tinkering workflow file for tracker test

* making sure prefetched sessions work properly

* fix conflict

* fix router redirects during loading

---------

Co-authored-by: Shekar Siri <sshekarsiri@gmail.com>
2024-10-03 11:38:36 +02:00

180 lines
6.3 KiB
TypeScript

import React, { useEffect } from 'react';
import { NoContent, Loader, Pagination, Button } from 'UI';
import SessionItem from 'Shared/SessionItem';
import withPermissions from 'HOCs/withPermissions';
import { KEYS } from 'Types/filter/customFilter';
import { FilterKey } from 'App/types/filter/filterType';
import Select from 'Shared/Select';
import SortOrderButton from 'Shared/SortOrderButton';
import { capitalize } from 'App/utils';
import LiveSessionReloadButton from 'Shared/LiveSessionReloadButton';
import cn from 'classnames';
import AnimatedSVG, { ICONS } from 'Shared/AnimatedSVG/AnimatedSVG';
import { numberWithCommas } from 'App/utils';
import { useStore } from 'App/mstore';
import { observer } from 'mobx-react-lite';
const AUTOREFRESH_INTERVAL = 2 * 60 * 1000;
const PER_PAGE = 10;
function LiveSessionList() {
const { searchStoreLive, sessionStore, customFieldStore } = useStore();
const filter = searchStoreLive.instance;
const list = sessionStore.liveSessions;
const loading = sessionStore.loadingLiveSessions;
const { currentPage, total } = searchStoreLive;
const metaList = customFieldStore.list;
const metaListLoading = customFieldStore.isLoading;
var timeoutId: any;
const { filters } = filter;
const hasUserFilter = filters.map((i: any) => i.key).includes(KEYS.USERID);
const sortOptions = [{ label: 'Start Time', value: 'timestamp' }].concat(
metaList
.map((i: any) => ({
label: capitalize(i),
value: i
}))
);
useEffect(() => {
if (metaListLoading) return;
const _filter = { ...filter };
if (sortOptions[1] && !filter.sort) {
_filter.sort = sortOptions[1].value;
}
searchStoreLive.edit(_filter);
timeout();
return () => {
clearTimeout(timeoutId);
};
}, [metaListLoading]);
const onUserClick = (userId: string, userAnonymousId: string) => {
if (userId) {
searchStoreLive.addFilterByKeyAndValue(FilterKey.USERID, userId);
} else {
searchStoreLive.addFilterByKeyAndValue(FilterKey.USERANONYMOUSID, userAnonymousId);
}
};
const onSortChange = ({ value }: any) => {
searchStoreLive.edit({ sort: value.value });
};
const timeout = () => {
timeoutId = setTimeout(() => {
searchStoreLive.edit({ ...filter });
timeout();
}, AUTOREFRESH_INTERVAL);
};
return (
<div>
<div className="bg-white p-3 rounded-lg border shadow-sm">
<div className="flex mb-6 justify-between items-center">
<div className="flex items-center">
<h3 className="text-2xl capitalize mr-2">
<span>Co-Browse</span>
{/* <span className="ml-2 font-normal color-gray-medium">{numberWithCommas(total)}</span> */}
</h3>
<LiveSessionReloadButton onClick={() => searchStoreLive.edit({ ...filter })} />
</div>
<div className="flex items-center">
<div className="flex items-center ml-6">
<span className="mr-2 color-gray-medium">Sort By</span>
<div className={cn('flex items-center', { disabled: sortOptions.length === 0 })}>
<Select
plain
right
options={sortOptions}
onChange={onSortChange}
value={sortOptions.find((i: any) => i.value === filter.sort) || sortOptions[0]}
/>
<div className="mx-2" />
<SortOrderButton
onChange={(state: any) => searchStoreLive.edit({ order: state })}
sortOrder={filter.order}
/>
</div>
</div>
</div>
</div>
<Loader loading={loading}>
<NoContent
title={
<div className="flex items-center justify-center flex-col">
<AnimatedSVG name={ICONS.NO_LIVE_SESSIONS} size={60} />
<div className="mt-4" />
<div className="text-center text-lg font-medium">No live sessions found</div>
</div>
}
subtext={
<div className="text-center flex justify-center items-center flex-col">
<span>
Support users with live sessions, cobrowsing, and video calls.
<a
target="_blank"
className="link ml-1"
href="https://docs.openreplay.com/plugins/assist"
>
{'Learn More'}
</a>
</span>
<Button
variant="text-primary"
className="mt-4"
icon="arrow-repeat"
iconSize={20}
onClick={() => searchStoreLive.edit({ ...filter })}
>
Refresh
</Button>
</div>
}
// image={<img src="/assets/img/live-sessions.png" style={{ width: '70%', marginBottom: '30px' }} />}
show={!loading && list.length === 0}
>
<div>
{list.map((session) => (
<React.Fragment key={session.sessionId}>
<SessionItem
session={session}
live
hasUserFilter={hasUserFilter}
onUserClick={onUserClick}
metaList={metaList}
/>
<div className="border-b" />
</React.Fragment>
))}
</div>
<div className={cn('flex items-center justify-between p-5', { disabled: loading })}>
<div>
Showing <span className="font-medium">{(currentPage - 1) * PER_PAGE + 1}</span> to{' '}
<span className="font-medium">{(currentPage - 1) * PER_PAGE + list.length}</span> of{' '}
<span className="font-medium">{numberWithCommas(total)}</span> sessions.
</div>
<Pagination
page={currentPage}
total={total}
onPageChange={(page: any) => searchStoreLive.updateCurrentPage(page)}
limit={PER_PAGE}
debounceRequest={500}
/>
</div>
</NoContent>
</Loader>
</div>
</div>
);
}
export default withPermissions(
['ASSIST_LIVE', 'SERVICE_ASSIST_LIVE'], '', false, false)(
observer(LiveSessionList)
);