Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions website/src/components/pageStateSelectors/ApplyFilterButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ export function ApplyFilterButton<PageState extends object>({
newPageState,
setPageState,
className = '',
disabled = false,
}: WithClassName<{
pageStateHandler: PageStateHandler<PageState>;
newPageState: PageState;
setPageState: Dispatch<SetStateAction<PageState>>;
disabled?: boolean;
}>) {
const url = pageStateHandler.toUrl(newPageState);
const fullUrl = `${window.location.origin}${url}`;
Expand All @@ -25,18 +27,26 @@ export function ApplyFilterButton<PageState extends object>({
setPageState(newPageState);
};

return urlTooLong ? (
<>
<span role='button' className={`btn btn-primary btn-disabled ${className}`}>
Apply filters
</span>
<div className='alert alert-error mt-2'>
<span>
The URL is too long ({fullUrl.length} characters, maximum {MAX_URL_LENGTH}). Please reduce the
amount of data in the filters.
if (urlTooLong) {
return (
<>
<span role='button' className={`btn btn-primary btn-disabled ${className}`}>
Apply filters
</span>
</div>
</>
<div className='alert alert-error mt-2'>
<span>
The URL is too long ({fullUrl.length} characters, maximum {MAX_URL_LENGTH}). Please reduce the
amount of data in the filters.
</span>
</div>
</>
);
}

return disabled ? (
<span role='button' className={`btn btn-primary btn-disabled ${className}`}>
Apply filters
</span>
) : (
<button type='button' onClick={applyFilters} className={`btn btn-primary ${className}`}>
Apply filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export function WasapPageStateSelector({
<div className='flex flex-col gap-4'>
<SelectorHeadline>Filter dataset</SelectorHeadline>
<Inset className='p-2'>
<LabeledField label='Sampling location'>
<LabeledField
label='Sampling location'
error={!baseFilterState.locationName ? 'Location is required' : undefined}
>
<GsTextFilter
placeholderText='Sampling location'
lapisField={config.locationNameField}
Expand Down Expand Up @@ -226,6 +229,7 @@ export function WasapPageStateSelector({
pageStateHandler={pageStateHandler}
newPageState={getMergedPageState()}
setPageState={setPageState}
disabled={!baseFilterState.locationName}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ interface LabeledFieldProps {
* If provided, a help button will be shown next to the label.
*/
info?: ReactNode;
/**
* Optional error message displayed below the field.
*/
error?: string;
}

export function LabeledField({ label, children, info }: LabeledFieldProps) {
export function LabeledField({ label, children, info, error }: LabeledFieldProps) {
const modalRef = useModalRef();

return (
Expand All @@ -44,6 +48,11 @@ export function LabeledField({ label, children, info }: LabeledFieldProps) {
)}
</div>
{children}
{error !== undefined && (
<label className='label'>
<span className='label-text-alt text-error'>{error}</span>
</label>
)}
</div>
);
}