* 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>
149 lines
5 KiB
TypeScript
149 lines
5 KiB
TypeScript
import React, { useEffect, useState } from 'react';
|
|
import { Conditions } from 'App/mstore/types/FeatureFlag';
|
|
import { Icon, Input, Loader } from 'UI';
|
|
import { useStore } from 'App/mstore';
|
|
import { observer } from 'mobx-react-lite';
|
|
import cn from 'classnames';
|
|
import { Switch, Drawer, Button, Tooltip } from 'antd';
|
|
import ConditionalRecordingSettings from 'Shared/SessionSettings/components/ConditionalRecordingSettings';
|
|
|
|
type Props = {
|
|
projectId?: string;
|
|
setShowCaptureRate: (show: boolean) => void;
|
|
open: boolean;
|
|
showCaptureRate: boolean;
|
|
isMobile?: boolean;
|
|
};
|
|
|
|
function CaptureRate(props: Props) {
|
|
const [conditions, setConditions] = React.useState<Conditions[]>([]);
|
|
const { projectId, isMobile } = props;
|
|
const { settingsStore, userStore } = useStore();
|
|
const isAdmin = userStore.account.admin || userStore.account.superAdmin;
|
|
const isEnterprise = userStore.isEnterprise;
|
|
const [changed, setChanged] = useState(false);
|
|
const {
|
|
sessionSettings: {
|
|
captureRate,
|
|
changeCaptureRate,
|
|
conditionalCapture,
|
|
changeConditionalCapture,
|
|
captureConditions,
|
|
},
|
|
loadingCaptureRate,
|
|
updateCaptureConditions,
|
|
fetchCaptureConditions,
|
|
} = settingsStore;
|
|
|
|
useEffect(() => {
|
|
if (projectId) {
|
|
void fetchCaptureConditions(projectId);
|
|
}
|
|
}, [projectId]);
|
|
|
|
React.useEffect(() => {
|
|
setConditions(captureConditions.map((condition: any) => new Conditions(condition, true, isMobile)));
|
|
}, [captureConditions]);
|
|
|
|
const onCaptureRateChange = (input: string) => {
|
|
setChanged(true);
|
|
changeCaptureRate(input);
|
|
};
|
|
|
|
const toggleRate = () => {
|
|
setChanged(true);
|
|
const newValue = !conditionalCapture;
|
|
changeConditionalCapture(newValue);
|
|
if (newValue) {
|
|
changeCaptureRate('100');
|
|
}
|
|
};
|
|
|
|
const onUpdate = () => {
|
|
updateCaptureConditions(projectId!, {
|
|
rate: parseInt(captureRate, 10),
|
|
conditionalCapture: conditionalCapture,
|
|
conditions: isEnterprise ? conditions.map((c) => c.toCaptureCondition()) : [],
|
|
})
|
|
setChanged(false)
|
|
};
|
|
|
|
const updateDisabled = !changed || !isAdmin || (isEnterprise && (conditionalCapture && conditions.length === 0));
|
|
return (
|
|
<Drawer
|
|
size={'large'}
|
|
open={props.open}
|
|
styles={{ content: { background: '#F6F6F6' } }}
|
|
onClose={() => props.setShowCaptureRate(false)}
|
|
title={
|
|
<div className={'flex items-center w-full gap-2'}>
|
|
<span className={'font-semibold'}>Capture Rate</span>
|
|
<div className={'ml-auto'}></div>
|
|
<Button type={'primary'} ghost onClick={() => props.setShowCaptureRate(false)}>
|
|
Cancel
|
|
</Button>
|
|
<Button disabled={updateDisabled} type={'primary'} onClick={onUpdate}>
|
|
Update
|
|
</Button>
|
|
</div>
|
|
}
|
|
closable={false}
|
|
destroyOnClose
|
|
>
|
|
<Loader loading={loadingCaptureRate || !projectId}>
|
|
<Tooltip title={isAdmin ? '' : "You don't have permission to change."}>
|
|
<div className="my-2 flex items-center gap-2 h-8">
|
|
<div className="font-semibold">The percentage of session you want to capture</div>
|
|
<Tooltip
|
|
title={
|
|
'Define the percentage of user sessions to be recorded for detailed replay and analysis.' +
|
|
'\nSessions exceeding this specified limit will not be captured or stored.'
|
|
}
|
|
>
|
|
<Icon size={16} color={'black'} name={'info-circle'} />
|
|
</Tooltip>
|
|
<Switch
|
|
checked={conditionalCapture}
|
|
onChange={toggleRate}
|
|
checkedChildren={!isEnterprise ? '100%' : 'Conditional'}
|
|
disabled={!isAdmin}
|
|
unCheckedChildren={!isEnterprise ? 'Custom' : 'Capture Rate'}
|
|
/>
|
|
{!conditionalCapture ? (
|
|
<div className={cn('relative', { disabled: !isAdmin })}>
|
|
<Input
|
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
if (/^\d+$/.test(e.target.value) || e.target.value === '') {
|
|
onCaptureRateChange(e.target.value);
|
|
}
|
|
}}
|
|
value={captureRate.toString()}
|
|
style={{ height: '38px', width: '70px' }}
|
|
disabled={conditionalCapture}
|
|
min={0}
|
|
max={100}
|
|
/>
|
|
<Icon
|
|
className="absolute right-0 mr-2 top-0 bottom-0 m-auto"
|
|
name="percent"
|
|
color="gray-medium"
|
|
size="18"
|
|
/>
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
{conditionalCapture && isEnterprise ? (
|
|
<ConditionalRecordingSettings
|
|
setChanged={setChanged}
|
|
conditions={conditions}
|
|
setConditions={setConditions}
|
|
isMobile={isMobile}
|
|
/>
|
|
) : null}
|
|
</Tooltip>
|
|
</Loader>
|
|
</Drawer>
|
|
);
|
|
}
|
|
|
|
export default observer(CaptureRate);
|