import React, { useEffect, useMemo, useState } from 'react'; import { Button, Space, Switch, Tooltip, Input, Typography } from 'antd'; import { Icon, Loader } from 'UI'; import cn from 'classnames'; import ConditionalRecordingSettings from 'Shared/SessionSettings/components/ConditionalRecordingSettings'; import { Conditions } from '@/mstore/types/FeatureFlag'; import { useStore } from '@/mstore'; import Project from '@/mstore/types/project'; import { observer } from 'mobx-react-lite'; interface Props { project: Project; } function ProjectCaptureRate(props: Props) { const [conditions, setConditions] = React.useState([]); const { projectId, platform } = props.project; const isMobile = platform !== 'web'; const { settingsStore, userStore, customFieldStore } = 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) { setChanged(false); const fetchData = async () => { if (isEnterprise) { await customFieldStore.fetchListActive(projectId + ''); } void fetchCaptureConditions(projectId); }; void fetchData(); } }, [projectId]); 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 (
Define percentage of sessions you want to capture {!conditionalCapture ? (
) => { if (/^\d+$/.test(e.target.value) || e.target.value === '') { onCaptureRateChange(e.target.value); } }} value={captureRate.toString()} style={{ height: '26px', width: '70px' }} disabled={conditionalCapture} min={0} max={100} />
) : null}
{conditionalCapture && isEnterprise ? ( ) : null}
); } export default observer(ProjectCaptureRate);