Skip to content

Commit

Permalink
Make it possible to hide fields from the table (#3532)
Browse files Browse the repository at this point in the history
* Make it possible to hide fields from the table

* Rename and document field

* Add test

* format
  • Loading branch information
fhennig authored Jan 16, 2025
1 parent 9aa28ab commit 16b07af
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/src/content/docs/reference/helm-chart-config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,12 @@ Each organism object has the following fields:
<td></td>
<td>If true, hides the field on the sequence details page.</td>
</tr>
<tr>
<td>`hideInSearchResultsTable`</td>
<td>Boolean</td>
<td></td>
<td>If true, hides the field in the search results table (and makes it impossible to show).</td>
</tr>
<tr>
<td>`perSegment`</td>
<td>Boolean</td>
Expand Down
3 changes: 3 additions & 0 deletions kubernetes/loculus/templates/_common-metadata.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ organisms:
{{- if .initiallyVisible }}
initiallyVisible: {{ .initiallyVisible }}
{{- end }}
{{- if .hideInSearchResultsTable }}
hideInSearchResultsTable: {{ .hideInSearchResultsTable }}
{{- end }}
{{- if or (or (eq .type "timestamp") (eq .type "date")) .rangeSearch }}
rangeSearch: true
{{- end }}
Expand Down
7 changes: 7 additions & 0 deletions kubernetes/loculus/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ defaultOrganismConfig: &defaultOrganismConfig
displayName: Collection date (lower bound)
type: date
initiallyVisible: true
hideInSearchResultsTable: true
header: Sample details
preprocessing:
function: parse_date_into_range
Expand All @@ -103,6 +104,7 @@ defaultOrganismConfig: &defaultOrganismConfig
displayName: Collection date (upper bound)
type: date
initiallyVisible: true
hideInSearchResultsTable: true
header: Sample details
preprocessing:
function: parse_date_into_range
Expand Down Expand Up @@ -1323,6 +1325,11 @@ defaultOrganisms:
required: true
type: string
lineageSystem: pangoLineage
- name: hiddenField
displayName: "Hidden Field"
initiallyVisible: false
type: string
hideInSearchResultsTable: true
website:
tableColumns:
- country
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 @@ -37,6 +37,7 @@ export const metadata = z.object({
type: metadataPossibleTypes,
autocomplete: z.boolean().optional(),
notSearchable: z.boolean().optional(),
hideInSearchResultsTable: z.boolean().optional(),
customDisplay: customDisplay.optional(),
truncateColumnDisplayTo: z.number().optional(),
initiallyVisible: z.boolean().optional(),
Expand Down
6 changes: 2 additions & 4 deletions website/src/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ export const getFieldVisibilitiesFromQuery = (schema: Schema, state: Record<stri

export const getColumnVisibilitiesFromQuery = (schema: Schema, state: Record<string, string>): Map<string, boolean> => {
const initiallyVisibleAccessor: InitialVisibilityAccessor = (field) => schema.tableColumns.includes(field.name);
// hacky, fix later -- https://github.com/loculus-project/loculus/issues/3325
const isFieldSelectable: VisiblitySelectableAccessor = (field) =>
field.name !== 'sampleCollectionDateRangeUpper' && field.name !== 'sampleCollectionDateRangeLower';
const isFieldSelectable: VisiblitySelectableAccessor = (field) => !(field.hideInSearchResultsTable ?? false);
return getFieldOrColumnVisibilitiesFromQuery(
schema,
state,
Expand All @@ -110,7 +108,7 @@ export const getColumnVisibilitiesFromQuery = (schema: Schema, state: Record<str
};

export const getMetadataSchemaWithExpandedRanges = (metadataSchema: Metadata[]): MetadataFilter[] => {
const result = [];
const result: MetadataFilter[] = [];
for (const field of metadataSchema) {
if (field.rangeOverlapSearch) {
const fieldGroupProps = {
Expand Down
8 changes: 8 additions & 0 deletions website/tests/pages/search/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,12 @@ test.describe('The search page', () => {

expect(filePath).toBeTruthy();
});

test('should show visible columns and hide others in the customization modal', async ({ searchPage, page }) => {
await searchPage.goto();
await page.getByText('Customize columns').click();
void page.getByText('Toggle the visibility of columns').waitFor();
void expect(page.getByRole('checkbox', { name: 'Pango lineage' })).toBeVisible();
void expect(page.getByRole('checkbox', { name: 'Hidden Field' })).not.toBeVisible();
});
});

0 comments on commit 16b07af

Please sign in to comment.