Skip to content

Commit

Permalink
feat: add suggestion alert on dataset page
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov committed Nov 28, 2023
1 parent 76782a4 commit ddffe6a
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useRecoilState } from 'recoil'
import { Container as ContainerBase } from 'reactstrap'
import { SelectDatasetHelp } from 'src/components/Help/SelectDatasetHelp'
import { DatasetSelectorList } from 'src/components/Main/DatasetSelectorList'
import { SuggestionAlertDatasetPage } from 'src/components/Main/SuggestionAlertDatasetPage'
import { SuggestionPanel } from 'src/components/Main/SuggestionPanel'
import { useDatasetSuggestionResults } from 'src/hooks/useRunSeqAutodetect'
import { AutodetectRunState, autodetectRunStateAtom } from 'src/state/autodetect.state'
Expand Down Expand Up @@ -65,7 +66,10 @@ export function DatasetSelectorImpl({
</Header>

<Header>
<SuggestionPanel />
<div className="w-100 d-flex flex-column">
<SuggestionPanel />
<SuggestionAlertDatasetPage className="mt-1" />
</div>
</Header>

<Main>
Expand Down Expand Up @@ -106,7 +110,7 @@ const Main = styled.div`
overflow: hidden;
`

const Title = styled.h4`
const Title = styled.div`
display: flex;
flex: 1;
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ function DatasetCurrentOrSelectButton({ toDatasetSelection }: DatasetCurrentOrSe
</Main>

<Footer>
<div>
<div className="w-100 d-flex flex-column">
<SuggestionPanel />
<SuggestionAlertMainPage />
<SuggestionAlertMainPage className="mt-1" />
</div>
</Footer>
</Container>
Expand All @@ -163,7 +163,7 @@ function DatasetCurrentOrSelectButton({ toDatasetSelection }: DatasetCurrentOrSe
<Footer>
<div className="w-100 d-flex flex-column">
<SuggestionPanel />
<SuggestionAlertMainPage />
<SuggestionAlertMainPage className="mt-1" />
</div>
</Footer>

Expand All @@ -175,7 +175,7 @@ function DatasetCurrentOrSelectButton({ toDatasetSelection }: DatasetCurrentOrSe
)
}

const Title = styled.h4`
const Title = styled.div`
display: flex;
flex: 1;
`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, { useMemo } from 'react'
import { UncontrolledAlert } from 'reactstrap'
import { useRecoilValue } from 'recoil'
import styled from 'styled-components'
import { useTranslationSafe } from 'src/helpers/useTranslationSafe'
import { useDatasetSuggestionResults } from 'src/hooks/useRunSeqAutodetect'
import { AutodetectRunState, autodetectRunStateAtom } from 'src/state/autodetect.state'

export function SuggestionAlertDatasetPage({ ...restProps }) {
const { t } = useTranslationSafe()
const { numSuggestions } = useDatasetSuggestionResults()
const autodetectRunState = useRecoilValue(autodetectRunStateAtom)

const alert = useMemo(() => {
if (autodetectRunState === AutodetectRunState.Done) {
if (numSuggestions === 0) {
return (
<Alert closeClassName="d-none" fade={false} color="danger">
<p className="small">
{t(
'No datasets match your data. Select a dataset manually. If there is no suitable dataset, consider creating one and contributing it to Nextclade community dataset collection.',
)}
</p>
</Alert>
)
}
if (numSuggestions > 0) {
return (
<Alert closeClassName="d-none" fade={false} color="none">
<p className="small">
{t('{{ n }} datasets appear to match your data. Select the one to use.', {
n: numSuggestions,
})}
</p>
</Alert>
)
}
}
if (autodetectRunState === AutodetectRunState.Failed) {
return (
<Alert closeClassName="d-none" fade={false} color="danger">
<p className="small">{t('Suggestion algorithm failed. Please report this to developers.')}</p>
</Alert>
)
}

return null
}, [autodetectRunState, numSuggestions, t])

return <AlertWrapper {...restProps}>{alert}</AlertWrapper>
}

const AlertWrapper = styled.div`
display: flex;
width: 100%;
`

const Alert = styled(UncontrolledAlert)`
margin: 0;
padding: 0.75rem 1rem;
width: 100%;
p {
margin: 0;
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTranslationSafe } from 'src/helpers/useTranslationSafe'
import { useDatasetSuggestionResults } from 'src/hooks/useRunSeqAutodetect'
import { AutodetectRunState, autodetectRunStateAtom } from 'src/state/autodetect.state'

export function SuggestionAlertMainPage() {
export function SuggestionAlertMainPage({ ...restProps }) {
const { t } = useTranslationSafe()
const { numSuggestions } = useDatasetSuggestionResults()
const autodetectRunState = useRecoilValue(autodetectRunStateAtom)
Expand All @@ -16,10 +16,10 @@ export function SuggestionAlertMainPage() {
if (numSuggestions === 0) {
return (
<Alert closeClassName="d-none" fade={false} color="danger">
<h6 className="font-weight-bold">{t('No datasets found matching your sequences.')}</h6>
<h6 className="font-weight-bold">{t('No matching datasets.')}</h6>
<p className="small">
{t(
'Click "Change dataset" to select a dataset manually. If there is no suitable dataset, consider creating and contributing one to Nextclade community dataset collection.',
'Suggestion algorithm was unable to find a matching dataset. Select a dataset manually. If there is no suitable dataset, consider creating and contributing one to Nextclade community dataset collection.',
)}
</p>
</Alert>
Expand All @@ -28,7 +28,7 @@ export function SuggestionAlertMainPage() {
if (numSuggestions > 0) {
return (
<Alert closeClassName="d-none" fade={false} color="info">
<h6 className="font-weight-bold">{t('Multiple datasets found matching your sequences.')}</h6>
<h6 className="font-weight-bold">{t('Multiple matching datasets.')}</h6>
<p className="small">
{t('{{ n }} datasets appear to match your data. Click "Change dataset" to select the one to use.', {
n: numSuggestions,
Expand All @@ -50,7 +50,7 @@ export function SuggestionAlertMainPage() {
return null
}, [autodetectRunState, numSuggestions, t])

return <AlertWrapper>{alert}</AlertWrapper>
return <AlertWrapper {...restProps}>{alert}</AlertWrapper>
}

const AlertWrapper = styled.div`
Expand All @@ -60,6 +60,7 @@ const AlertWrapper = styled.div`
const Alert = styled(UncontrolledAlert)`
margin: 0;
padding: 0.75rem 1rem;
width: 100%;
p {
margin: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ const Container = styled.div`
const Form = styled(FormBase)`
display: flex;
width: 100%;
height: 100%;
min-height: 45px;
padding: 10px;
border: 1px #ccc9 solid;
Expand Down

0 comments on commit ddffe6a

Please sign in to comment.