Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search page: use displayNames and allow column truncation #1461

Merged
merged 5 commits into from
Mar 28, 2024
Merged
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
3 changes: 3 additions & 0 deletions kubernetes/loculus/templates/_common-metadata.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ fields:
{{- if .displayName }}
displayName: {{ .displayName }}
{{- end }}
{{- if .truncateColumnDisplayTo }}
truncateColumnDisplayTo: {{ .truncateColumnDisplayTo }}
{{- end }}
{{- if .customDisplay }}
customDisplay:
type: {{ .customDisplay.type }}
Expand Down
1 change: 1 addition & 0 deletions kubernetes/loculus/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ defaultOrganisms:
type: string
generateIndex: true
autocomplete: true
truncateColumnDisplayTo: 15
- name: authors
displayName: Authors
type: string
Expand Down
29 changes: 24 additions & 5 deletions website/src/components/SearchPage/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { capitalCase } from 'change-case';
import type { FC, ReactElement } from 'react';
import { Tooltip } from 'react-tooltip';

import { routes, navigateToSearchLikePage, type ClassOfSearchPageType } from '../../routes/routes.ts';
import type { AccessionFilter, MetadataFilter, MutationFilter, Schema } from '../../types/config.ts';
import type { OrderBy } from '../../types/lapis.ts';
import MdiTriangle from '~icons/mdi/triangle';
import MdiTriangleDown from '~icons/mdi/triangle-down';

export type TableSequenceData = {
[key: string]: string | number | null;
};
Expand Down Expand Up @@ -37,9 +39,12 @@ export const Table: FC<TableProps> = ({
}) => {
const primaryKey = schema.primaryKey;

const maxLengths = Object.fromEntries(schema.metadata.map((m) => [m.name, m.truncateColumnDisplayTo ?? 100]));

const columns = schema.tableColumns.map((field) => ({
field,
headerName: capitalCase(field),
headerName: schema.metadata.find((m) => m.name === field)?.displayName ?? capitalCase(field),
maxLength: maxLengths[field],
}));

const handleSort = (field: string) => {
Expand Down Expand Up @@ -99,21 +104,22 @@ export const Table: FC<TableProps> = ({

return (
<div className='w-full overflow-x-auto text-sm'>
<Tooltip id='table-tip' />
{data.length !== 0 ? (
<table className='w-full text-left border-collapse'>
<thead>
<tr>
<th
onClick={() => handleSort(primaryKey)}
className='px-2 py-3 pl-6 text-xs font-medium tracking-wider text-gray-500 uppercase cursor-pointer'
className='px-2 py-3 pl-6 text-xs font-medium tracking-wider text-gray-500 uppercase cursor-pointer text-left'
>
{capitalCase(primaryKey)} {orderBy.field === primaryKey && orderIcon}
</th>
{columns.map((c) => (
<th
key={c.field}
onClick={() => handleSort(c.field)}
className='px-2 py-3 text-xs font-medium tracking-wider text-gray-500 uppercase cursor-pointer last:pr-6'
className='px-2 py-3 text-xs font-medium tracking-wider text-gray-500 uppercase cursor-pointer last:pr-6 text-left'
>
{c.headerName} {orderBy.field === c.field && orderIcon}
</th>
Expand All @@ -132,8 +138,21 @@ export const Table: FC<TableProps> = ({
</a>
</td>
{columns.map((c) => (
<td key={`${index}-${c.field}`} className='px-2 py-2 text-primary-900 last:pr-6'>
{row[c.field]}
<td
key={`${index}-${c.field}`}
className='px-2 py-2 text-primary-900 last:pr-6'
data-tooltip-content={
typeof row[c.field] === 'string' &&
row[c.field]!.toString().length > c.maxLength
? row[c.field]!.toString()
: ''
}
data-tooltip-id='table-tip'
>
{typeof row[c.field] === 'string' &&
row[c.field]!.toString().length > c.maxLength
? `${row[c.field]?.toString().slice(0, c.maxLength)}…`
: row[c.field]}
</td>
))}
</tr>
Expand Down
1 change: 1 addition & 0 deletions website/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const metadata = z.object({
autocomplete: z.boolean().optional(),
notSearchable: z.boolean().optional(),
customDisplay: customDisplay.optional(),
truncateColumnDisplayTo: z.number().optional(),
});

export type CustomDisplay = z.infer<typeof customDisplay>;
Expand Down
Loading