import {useState} from 'react'; import {browserHistory} from 'react-router'; import styled from '@emotion/styled'; import debounce from 'lodash/debounce'; import {CompactSelect, SelectOption} from 'sentry/components/compactSelect'; import PageFilterBar from 'sentry/components/organizations/pageFilterBar'; import {DEFAULT_DEBOUNCE_DURATION} from 'sentry/constants'; import {t, tn} from 'sentry/locale'; import {space} from 'sentry/styles/space'; import {defined} from 'sentry/utils'; import {getFormattedDate} from 'sentry/utils/dates'; import {useLocation} from 'sentry/utils/useLocation'; import { useReleases, useReleaseSelection, useReleaseStats, } from 'sentry/views/starfish/queries/useReleases'; type Props = { selectorKey: string; selectorName?: string; selectorValue?: string; }; export function ReleaseSelector({selectorName, selectorKey, selectorValue}: Props) { const [searchTerm, setSearchTerm] = useState(undefined); const {data, isLoading} = useReleases(searchTerm); const {data: releaseStats} = useReleaseStats(); const location = useLocation(); const options: SelectOption[] = []; if (defined(selectorValue)) { const index = data?.findIndex(({version}) => version === selectorValue); const selectedRelease = defined(index) ? data?.[index] : undefined; let selectedReleaseDate: string | undefined = undefined; if (defined(selectedRelease)) { selectedReleaseDate = selectedRelease.dateCreated; } options.push({ value: selectorValue, label: selectorValue, details: ( ), }); } data ?.filter(({version}) => selectorValue !== version) .forEach(release => { const option = { value: release.version, label: release.version, details: ( ), }; options.push(option); }); return ( { setSearchTerm(val); }, DEFAULT_DEBOUNCE_DURATION)} onChange={newValue => { browserHistory.push({ ...location, query: { ...location.query, [selectorKey]: newValue.value, }, }); }} onClose={() => { setSearchTerm(undefined); }} /> ); } type LabelDetailsProps = { dateCreated?: string; sessionCount?: number; }; function LabelDetails(props: LabelDetailsProps) { return (
{defined(props.sessionCount) ? tn('%s session', '%s sessions', props.sessionCount) : '-'}
{defined(props.dateCreated) ? getFormattedDate(props.dateCreated, 'MMM D, YYYY') : null}
); } export function ReleaseComparisonSelector() { const {primaryRelease, secondaryRelease} = useReleaseSelection(); return ( ); } const StyledCompactSelect = styled(CompactSelect)` @media (min-width: ${p => p.theme.breakpoints.medium}) { max-width: 275px; } `; const DetailsContainer = styled('div')` display: flex; flex-direction: row; justify-content: space-between; gap: ${space(1)}; `;