Skip to content

Commit

Permalink
Merge pull request #1336 from nextstrain/feat/web-clear-dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov authored Dec 12, 2023
2 parents 863d4d2 + 40a503d commit b153442
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from 'react'
import { Col, Row } from 'reactstrap'
import { useRecoilState } from 'recoil'
import { useRecoilValue, useResetRecoilState } from 'recoil'
import { MdClear as IconClearBase } from 'react-icons/md'
import { ButtonTransparent } from 'src/components/Common/ButtonTransparent'
import { ButtonLoadExample } from 'src/components/Main/ButtonLoadExample'
import { useTranslationSafe } from 'src/helpers/useTranslationSafe'
import styled from 'styled-components'
import { useUpdatedDataset } from 'src/io/fetchDatasets'
import { datasetCurrentAtom } from 'src/state/dataset.state'
Expand All @@ -12,7 +15,10 @@ export function DatasetCurrentSummary() {
// Periodically checks if there's local update for the current dataset
useUpdatedDataset()

const [dataset, _0] = useRecoilState(datasetCurrentAtom)
const { t } = useTranslationSafe()

const dataset = useRecoilValue(datasetCurrentAtom)
const resetDataset = useResetRecoilState(datasetCurrentAtom)

if (!dataset) {
return null
Expand All @@ -25,6 +31,9 @@ export function DatasetCurrentSummary() {
<Row noGutters className="w-100">
<Col className="d-flex">
<DatasetInfo dataset={dataset} showSuggestions />
<ButtonClear onClick={resetDataset} title={t('Reset dataset')}>
<IconClear size={20} />
</ButtonClear>
</Col>
</Row>
<Row noGutters>
Expand All @@ -43,3 +52,16 @@ const Container = styled.div`
border: 1px #ccc9 solid;
border-radius: 5px;
`

const ButtonClear = styled(ButtonTransparent)`
display: inline;
margin: 0 auto;
height: 20px;
width: 20px;
`

const IconClear = styled(IconClearBase)`
* {
color: ${(props) => props.theme.gray500};
}
`
2 changes: 2 additions & 0 deletions packages_rs/nextclade-web/src/state/autodetect.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export const autodetectResultsAtom = selector<MinimizerSearchRecord[] | undefine
// If the operation is not 'reset', add the new items
if (!isDefaultValue(results) && !isNil(results)) {
results.forEach((result) => set(autodetectResultByIndexAtom(result.fastaRecord.index), result))
} else {
reset(autodetectRunStateAtom)
}
},
})
Expand Down
6 changes: 3 additions & 3 deletions packages_rs/nextclade-web/src/state/dataset.state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isNil } from 'lodash'
import { atom, DefaultValue, selector } from 'recoil'

import { autodetectResultsAtom } from 'src/state/autodetect.state'
import type { Dataset, MinimizerIndexVersion } from 'src/types'
import { persistAtom } from 'src/state/persist/localStorage'
import { isDefaultValue } from 'src/state/utils/isDefaultValue'
Expand Down Expand Up @@ -30,10 +30,10 @@ export const datasetCurrentAtom = selector<Dataset | undefined>({
return get(datasetCurrentStorageAtom)
},
set({ get, set, reset }, dataset: Dataset | undefined | DefaultValue) {
const datasetCurrent = get(datasetCurrentStorageAtom)
if (isDefaultValue(dataset) || isNil(dataset)) {
reset(autodetectResultsAtom)
reset(datasetCurrentStorageAtom)
} else if (!areDatasetsEqual(datasetCurrent, dataset)) {
} else if (!areDatasetsEqual(get(datasetCurrentStorageAtom), dataset)) {
set(datasetCurrentStorageAtom, dataset)
}
},
Expand Down

1 comment on commit b153442

@vercel
Copy link

@vercel vercel bot commented on b153442 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nextclade – ./

nextclade.vercel.app
nextclade-git-master-nextstrain.vercel.app
nextclade-nextstrain.vercel.app

Please sign in to comment.