Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
theosanderson committed May 20, 2024
1 parent 1cf2fc2 commit 5b2bfa8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
5 changes: 4 additions & 1 deletion website/src/components/SearchPage/CustomizeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface CustomizeModalProps {
alwaysPresentFieldNames: string[];
visibilities: Map<string, boolean>;
setAVisibility: (fieldName: string, isVisible: boolean) => void;
nameToLabelMap: Record<string, string>;
}

export const CustomizeModal: React.FC<CustomizeModalProps> = ({
Expand All @@ -36,7 +37,9 @@ export const CustomizeModal: React.FC<CustomizeModalProps> = ({
alwaysPresentFieldNames,
visibilities,
setAVisibility,
nameToLabelMap
}) => {
console.log('nameToLabelMap', nameToLabelMap);

return (
<Transition appear show={isCustomizeModalOpen}>
Expand All @@ -63,7 +66,7 @@ export const CustomizeModal: React.FC<CustomizeModalProps> = ({
{Array.from(visibilities).map(([fieldName, visible]) => (
<CheckboxField
key={fieldName}
label={fieldName}
label={nameToLabelMap[fieldName]}
checked={visible}
onChange={(e) => {
setAVisibility(fieldName, e.target.checked);
Expand Down
19 changes: 12 additions & 7 deletions website/src/components/SearchPage/SearchForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('SearchForm', () => {
await new Promise((resolve) => setTimeout(resolve, 1000));
}
);
screen.logTestingPlaygroundURL();

throw new Error('stop here'+ valuer);

expect(setAFieldValue).toHaveBeenCalledWith('field1', filterValue);
Expand Down Expand Up @@ -202,7 +202,13 @@ describe('SearchForm', () => {
});

test('toggle field visibility', async () => {
renderSearchForm();
renderSearchForm({
visibilities: new Map([
['field1', true],
['field2', true],
['field3', true],
]),
});

expect(await screen.findByLabelText('Field 1')).toBeVisible();

Expand All @@ -216,11 +222,10 @@ describe('SearchForm', () => {

const closeButton = await screen.findByRole('button', { name: 'Close' });
await userEvent.click(closeButton);

await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 1000));
});

// wait for the label to disappear
await screen.findByLabelText('Field 1');
screen.logTestingPlaygroundURL();
expect(screen.queryByLabelText('Field 1')).not.toBeInTheDocument();

});
});
6 changes: 6 additions & 0 deletions website/src/components/SearchPage/SearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export const SearchForm = ({
alwaysPresentFieldNames={[]}
visibilities={visibilities}
setAVisibility={setAVisibility}
nameToLabelMap={
consolidatedMetadataSchema.reduce((acc, field) => {
acc[field.name] = field.displayName ?? field.label ?? sentenceCase(field.name);
return acc;
}, {} as Record<string, string>)
}
/>
<div className='flex flex-col'>
<AccessionField
Expand Down
5 changes: 3 additions & 2 deletions website/src/components/SearchPage/SearchFullUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { OrderBy } from '../../types/lapis.ts';
import type { ReferenceGenomesSequenceNames } from '../../types/referencesGenomes.ts';
import type { ClientConfig } from '../../types/runtimeConfig.ts';
import type { SearchResponse } from '../../utils/search.ts';
import { sentenceCase } from 'change-case';

const orderKey = 'orderBy';
const orderDirectionKey = 'order';
Expand Down Expand Up @@ -55,14 +56,14 @@ export const InnerSearchFullUI = ({
name: `${field.name}From`,
label: `From`,
fieldGroup: field.name,
fieldGroupDisplayName: field.displayName,
fieldGroupDisplayName: field.displayName ?? sentenceCase(field.name),
};
const toField = {
...field,
name: `${field.name}To`,
label: `To`,
fieldGroup: field.name,
fieldGroupDisplayName: field.displayName,
fieldGroupDisplayName: field.displayName ?? sentenceCase(field.name),
};
result.push(fromField);
result.push(toField);
Expand Down

0 comments on commit 5b2bfa8

Please sign in to comment.