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

chore: refactor SearchHitLayout component to use subComponents #746

Merged
merged 1 commit into from
Aug 20, 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
74 changes: 36 additions & 38 deletions apps/concept-catalog/app/[catalogId]/search-page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ export const SearchPageClient = ({
logo={logo}
logoDescription={design?.logoDescription}
/>
<SearchHitsPageLayout
buttonRow={
<SearchHitsPageLayout>
<SearchHitsPageLayout.ButtonRow>
<>
<LinkButton
href={`/${catalogId}/change-requests`}
Expand Down Expand Up @@ -369,46 +369,44 @@ export const SearchPageClient = ({
</UploadButton>
)}
</>
}
searchRow={
<>
<div>
<SearchField
ariaLabel={loc.search.search}
placeholder={loc.search.search}
onSearchSubmit={onSearchSubmit}
value={searchTerm ?? ''}
/>
<FilterChips />
</div>
</SearchHitsPageLayout.ButtonRow>
<SearchHitsPageLayout.SearchRow>
<div>
<SearchField
ariaLabel={loc.search.search}
placeholder={loc.search.search}
onSearchSubmit={onSearchSubmit}
value={searchTerm ?? ''}
/>
<FilterChips />
</div>

<div className={styles.searchOptions}>
<Select
label={loc.search.searchField}
onChange={(event) => onFieldSelect(event.target.value as SearchableField)}
>
{fieldOptions}
</Select>
<Select
label={loc.search.sort}
onChange={(event) => onSortSelect(event?.target.value as SortOption)}
value={selectedSortOption}
>
{sortOptions}
</Select>
</div>
</>
}
leftColumn={
<div className={styles.searchOptions}>
<Select
label={loc.search.searchField}
onChange={(event) => onFieldSelect(event.target.value as SearchableField)}
>
{fieldOptions}
</Select>
<Select
label={loc.search.sort}
onChange={(event) => onSortSelect(event?.target.value as SortOption)}
value={selectedSortOption}
>
{sortOptions}
</Select>
</div>
</SearchHitsPageLayout.SearchRow>
<SearchHitsPageLayout.LeftColumn>
<SearchFilter
catalogId={catalogId}
internalFields={fieldsResult?.internal}
subjectCodeList={subjectCodeList}
conceptStatuses={conceptStatuses}
/>
}
mainColumn={
status === 'pending' || importConcepts.status === 'pending' ? (
</SearchHitsPageLayout.LeftColumn>
<SearchHitsPageLayout.MainColumn>
{status === 'pending' || importConcepts.status === 'pending' ? (
<Spinner />
) : (
<SearchHitContainer
Expand All @@ -426,9 +424,9 @@ export const SearchPageClient = ({
/>
}
/>
)
}
/>
)}
</SearchHitsPageLayout.MainColumn>
</SearchHitsPageLayout>
</>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use client';

import React, { useState, useEffect } from 'react';
import { Dataset } from '@catalog-frontend/types';
import styles from './datasets-page.module.css';
Expand Down Expand Up @@ -71,37 +72,39 @@ const DatasetsPageClient = ({ datasets }: Props) => {

return (
<div className={styles.container}>
<SearchHitsPageLayout
searchRow={
<>
<div className={styles.searchContainer}>
<div className={styles.search}>
<Paragraph>{localization.datasetCatalog.searchDataset}</Paragraph>
<Search
variant='primary'
placeholder={localization.search.search}
onSearchClick={handleSearch}
onKeyDown={handleSearchKeyDown}
/>
</div>
<SearchHitsPageLayout>
<SearchHitsPageLayout.SearchRow>
<div className={styles.searchContainer}>
<div className={styles.search}>
<Paragraph>{localization.datasetCatalog.searchDataset}</Paragraph>
<Search
variant='primary'
placeholder={localization.search.search}
onSearchClick={handleSearch}
onKeyDown={handleSearchKeyDown}
/>
</div>
</>
}
leftColumn={
</div>
</SearchHitsPageLayout.SearchRow>
<SearchHitsPageLayout.LeftColumn>
<div className={styles.leftColumn}>
<div className={styles.paragraph}>
<div>
<Paragraph>Legg til...</Paragraph>
<Select onChange={handleSelectChange}>
<option value='blank'>{`${localization.choose}...`}</option>
<option value='dataset'>{localization.resourceType.dataset}</option>
<option value='datasetSeries'>{localization.resourceType.datasetSeries}</option>
</Select>
</div>

<Filter onStatusChange={handleStatusChange} />
</div>
}
mainColumn={<SearchHitTable datasets={filteredDatasets} />}
/>
</SearchHitsPageLayout.LeftColumn>

<SearchHitsPageLayout.MainColumn>
<SearchHitTable datasets={filteredDatasets} />
</SearchHitsPageLayout.MainColumn>
</SearchHitsPageLayout>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@
flex-direction: column;
gap: 1rem;
}

.paragraph {
margin-top: -26px;
}
2 changes: 2 additions & 0 deletions apps/dataset-catalog/components/search-hit-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@catalog-frontend/utils';
import { Dataset } from '@catalog-frontend/types';
import { useEffect, useState } from 'react';
import styles from './search-hit-table.module.css';

export interface BannerProps {
datasets: Dataset[];
Expand Down Expand Up @@ -65,6 +66,7 @@ export const SearchHitTable = ({ datasets }: BannerProps) => {
<Table
zebra
border
className={styles.table}
>
<Table.Head>
<Table.Row>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.table {
width: 100%;
margin-top: 26px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,39 +69,35 @@ const PublicServicePageClient = ({ services, hasWritePermission, catalogId, stat
const findServiceStatus = (service: Service) => statuses.find((s) => s.uri === service?.status);

return (
<SearchHitsPageLayout
searchRow={
<>
<SearchHitsPageLayout>
<SearchHitsPageLayout.SearchRow>
<div>
<Search
error=''
label={localization.search.search}
placeholder={localization.search.searchForPublicService}
size='small'
variant='primary'
onSearchClick={(value) => setSearchQuery(value)}
className={styles.search}
/>
<FilterChips
statusFilters={statusFilters}
publicationFilters={publicationFilters}
handleRemoveFilter={(filter: string, filterType: FilterType) => removeFilter(filter, filterType)}
statuses={statuses}
/>
</div>
{hasWritePermission && (
<div>
<Search
error=''
label={localization.search.search}
placeholder={localization.search.searchForPublicService}
size='small'
variant='primary'
onSearchClick={(value) => setSearchQuery(value)}
className={styles.search}
/>
<FilterChips
statusFilters={statusFilters}
publicationFilters={publicationFilters}
handleRemoveFilter={(filter: string, filterType: FilterType) => removeFilter(filter, filterType)}
statuses={statuses}
/>
<LinkButton href={`/catalogs/${catalogId}/public-services/new`}>
<PlusCircleIcon />
{localization.serviceCatalog.form.newPublic}
</LinkButton>
</div>
{hasWritePermission && (
<div>
<LinkButton href={`/catalogs/${catalogId}/public-services/new`}>
<>
<PlusCircleIcon />
{localization.serviceCatalog.form.newPublic}
</>
</LinkButton>
</div>
)}
</>
}
leftColumn={
)}
</SearchHitsPageLayout.SearchRow>
<SearchHitsPageLayout.LeftColumn>
<div>
<Filter
onStatusChange={setStatusFilters}
Expand All @@ -111,8 +107,8 @@ const PublicServicePageClient = ({ services, hasWritePermission, catalogId, stat
publicationState={publicationFilters}
/>
</div>
}
mainColumn={
</SearchHitsPageLayout.LeftColumn>
<SearchHitsPageLayout.MainColumn>
<SearchHitContainer
searchHits={
filteredServices &&
Expand Down Expand Up @@ -144,8 +140,8 @@ const PublicServicePageClient = ({ services, hasWritePermission, catalogId, stat
}
noSearchHits={filteredServices?.length < 1 ?? true}
/>
}
/>
</SearchHitsPageLayout.MainColumn>
</SearchHitsPageLayout>
);
};

Expand Down
Loading