Skip to content

Commit

Permalink
working quite nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
theosanderson committed Jul 12, 2024
1 parent 135dbd8 commit 2eaebbc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
18 changes: 16 additions & 2 deletions website/src/components/SearchPage/SearchFullUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,13 @@ export const InnerSearchFullUI = ({
const detailsHook = hooks.useDetails({}, {});

const lapisSearchParameters = useMemo(() => {


return getLapisSearchParameters(fieldValues, referenceGenomesSequenceNames);
}, [fieldValues, referenceGenomesSequenceNames]);

useEffect(() => {

aggregatedHook.mutate({
...lapisSearchParameters,
fields: [],
Expand All @@ -199,17 +202,26 @@ export const InnerSearchFullUI = ({

const [oldData, setOldData] = useState<TableSequenceData[] | null>(null);
const [oldCount, setOldCount] = useState<number | null>(null);
const [firstClientSideLoadOfDataCompleted, setFirstClientSideLoadOfDataCompleted] = useState(false);
const [firstClientSideLoadOfCountCompleted, setFirstClientSideLoadOfCountCompleted] = useState(false);


useEffect(() => {

if (detailsHook.data?.data && oldData !== detailsHook.data.data) {
setOldData(detailsHook.data.data);
setFirstClientSideLoadOfDataCompleted(true);
}

}, [detailsHook.data?.data, oldData]);

useEffect(() => {

if (aggregatedHook.data?.data && oldCount !== aggregatedHook.data.data[0].count) {
setOldCount(aggregatedHook.data.data[0].count);
setFirstClientSideLoadOfCountCompleted(true);
}

}, [aggregatedHook.data?.data, oldCount]);


Expand Down Expand Up @@ -281,7 +293,9 @@ export const InnerSearchFullUI = ({
{!(totalSequences === undefined && oldCount === null && initialCount===undefined) && (

Check failure on line 293 in website/src/components/SearchPage/SearchFullUI.tsx

View workflow job for this annotation

GitHub Actions / Check format and types

Unnecessary conditional, the types have no overlap
<div
className={`
${detailsHook.isLoading || aggregatedHook.isLoading ? 'opacity-50 pointer-events-none' : ''}
${ (!(firstClientSideLoadOfCountCompleted&&firstClientSideLoadOfDataCompleted) ? "cursor-wait pointer-events-none" :
( (detailsHook.isLoading || aggregatedHook.isLoading)) ? 'opacity-50 pointer-events-none' : '')}
`}
>
<div className='text-sm text-gray-800 mb-6 justify-between flex md:px-6 items-baseline'>
Expand All @@ -294,7 +308,7 @@ export const InnerSearchFullUI = ({
: (initialCount !== undefined ? initialCount : '')}{' '}

Check failure on line 308 in website/src/components/SearchPage/SearchFullUI.tsx

View workflow job for this annotation

GitHub Actions / Check format and types

Unnecessary conditional, the types have no overlap
sequence
{totalSequences === 1 ? '' : 's'}
{detailsHook.isLoading || aggregatedHook.isLoading ? (
{(detailsHook.isLoading || aggregatedHook.isLoading || !firstClientSideLoadOfCountCompleted || !firstClientSideLoadOfDataCompleted) ? (
<span className='loading loading-spinner loading-xs ml-3 appearSlowly'></span>
) : null}
</div>
Expand Down
6 changes: 5 additions & 1 deletion website/src/components/SearchPage/useQueryAsState.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export default function useQueryAsState(defaultDict) {
for (const [key, value] of urlParams) {
newDict[key] = value;
}
setValueDict(newDict);

setValueDict( // only change if actually different
(prev) =>
JSON.stringify(prev) === JSON.stringify(newDict) ? prev : newDict
);
}, []);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/[organism]/search/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const myGroups = accessToken !== undefined ? await getMyGroups(accessToken) : []
const referenceGenomeSequenceNames = getReferenceGenomesSequenceNames(cleanedOrganism.key);
const initialQueryDict = Object.fromEntries(Astro.url.searchParams.entries());
const {data, totalCount} = await performLapisSearchQueries(initialQueryDict, schema, referenceGenomeSequenceNames, hiddenFieldValues, cleanedOrganism.key,1,100);
const {data, totalCount} = await performLapisSearchQueries(initialQueryDict, schema, referenceGenomeSequenceNames, hiddenFieldValues, cleanedOrganism.key);
---

<BaseLayout title={`${cleanedOrganism.displayName} - Browse`} noHorizontalPadding>
Expand Down
1 change: 1 addition & 0 deletions website/src/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const COLUMN_VISIBILITY_PREFIX = 'column_';

export const ORDER_KEY = 'orderBy';
export const ORDER_DIRECTION_KEY = 'order';
export const PAGE_KEY = 'page';


export type SearchResponse = {
Expand Down
7 changes: 4 additions & 3 deletions website/src/utils/serversideSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type { TableSequenceData } from '../components/SearchPage/Table';
import type { Schema } from '../types/config';
import type { ReferenceGenomesSequenceNames } from '../types/referencesGenomes';
import { LapisClient } from '../services/lapisClient';

Check failure on line 5 in website/src/utils/serversideSearch.ts

View workflow job for this annotation

GitHub Actions / Check format and types

`../services/lapisClient` import should occur before type import of `../types/config`
import { getFieldValuesFromQuery, getLapisSearchParameters, ORDER_DIRECTION_KEY, ORDER_KEY, getColumnVisibilitiesFromQuery } from './search';
import { getFieldValuesFromQuery, getLapisSearchParameters, ORDER_DIRECTION_KEY, ORDER_KEY, PAGE_KEY, getColumnVisibilitiesFromQuery } from './search';

Check failure on line 6 in website/src/utils/serversideSearch.ts

View workflow job for this annotation

GitHub Actions / Check format and types

`./search` import should occur before type import of `../components/SearchPage/Table`
import { pageSize } from '../settings';

Check failure on line 7 in website/src/utils/serversideSearch.ts

View workflow job for this annotation

GitHub Actions / Check format and types

`../settings` import should occur before type import of `../types/config`

// If these types are not already defined in the new file, you'll need to import or define them:
export type SearchResponse = {
Expand All @@ -19,8 +20,7 @@ export const performLapisSearchQueries = async (
referenceGenomesSequenceNames: ReferenceGenomesSequenceNames,
hiddenFieldValues: Record<string, any>,
organism: string,
page: number,
pageSize: number

): Promise<SearchResponse> => {
const fieldValues = getFieldValuesFromQuery(state, hiddenFieldValues, schema);
const lapisSearchParameters = getLapisSearchParameters(fieldValues, referenceGenomesSequenceNames);
Expand All @@ -29,6 +29,7 @@ export const performLapisSearchQueries = async (

const orderByField = state[ORDER_KEY] ?? schema.defaultOrderBy ?? schema.primaryKey;
const orderDirection = state[ORDER_DIRECTION_KEY] ?? schema.defaultOrder ?? 'ascending';
const page = state[PAGE_KEY] ? parseInt(state[PAGE_KEY]) : 1;

const columnVisibilities = getColumnVisibilitiesFromQuery(schema, state);

Expand Down

0 comments on commit 2eaebbc

Please sign in to comment.