Skip to content

Commit

Permalink
chore(beacon): don't clear chrom if availableContigs stays blank
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Nov 26, 2024
1 parent 08b182b commit 688e749
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/js/components/Beacon/BeaconCommon/VariantsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type CSSProperties, useEffect, useMemo } from 'react';
import { type CSSProperties, useEffect, useState } from 'react';

import { Col, Form, Row } from 'antd';
import type { DefaultOptionType } from 'antd/es/select/index';
Expand Down Expand Up @@ -70,17 +70,24 @@ const VariantsForm = ({ isNetworkQuery, beaconAssemblyIds }: VariantsFormProps)
const form = Form.useFormInstance();
const currentAssemblyID = Form.useWatch('Assembly ID', form);

// Right now, we cannot figure out the contig options for the network, so we fall back to a normal input box.
const availableContigs = useMemo<ContigOptionType[]>(
() =>
!isNetworkQuery && currentAssemblyID && genomesByID[currentAssemblyID]
? genomesByID[currentAssemblyID].contigs
.map(contigToOption)
.sort(contigOptionSort)
.filter(filterOutHumanLikeExtraContigs)
: [],
[isNetworkQuery, currentAssemblyID, genomesByID]
);
const [availableContigs, setAvailableContigs] = useState<ContigOptionType[]>([]);

useEffect(() => {
// Right now, we cannot figure out the contig options for the network, so we fall back to a normal input box.
if (!isNetworkQuery && currentAssemblyID && genomesByID[currentAssemblyID]) {
setAvailableContigs(
genomesByID[currentAssemblyID].contigs
.map(contigToOption)
.sort(contigOptionSort)
.filter(filterOutHumanLikeExtraContigs)
);
} else {
// Keep existing memory address for existing empty array if availableContigs was already empty, to avoid
// re-render/clearing effect.
setAvailableContigs((ac) => (ac.length ? [] : ac));
}
}, [isNetworkQuery, currentAssemblyID, genomesByID]);

const assemblySelect = !!availableContigs.length;

useEffect(() => {
Expand Down

0 comments on commit 688e749

Please sign in to comment.