Skip to content

Commit

Permalink
IS-2728: Combine filterpanel to one
Browse files Browse the repository at this point in the history
  • Loading branch information
ingring committed Nov 25, 2024
1 parent d82a9a6 commit bba0c44
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 88 deletions.
58 changes: 20 additions & 38 deletions src/components/Filter/PersonFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { ReactElement, useState } from 'react';
import Ekspanderbartpanel from 'nav-frontend-ekspanderbartpanel';
import React, { ReactElement } from 'react';
import BirthDateFilter from '../filters/BirthDateFilter';
import CompanyFilter from '../filters/CompanyFilter';
import { PersonregisterState } from '@/api/types/personregisterTypes';
Expand All @@ -13,12 +12,6 @@ import {
} from '@/utils/hendelseFilteringUtils';
import { AgeFilter } from '@/components/filters/AgeFilter';

const texts = {
panelTitle: 'Filter',
trackingLabelCompanies: 'Filter - Virksomheter',
trackingLabelDate: 'Filter - Fødselsdato',
};

interface PersonFilterProps {
personregister: PersonregisterState;
}
Expand All @@ -27,11 +20,6 @@ export const PersonFilter = ({
personregister,
}: PersonFilterProps): ReactElement => {
const { filterState, dispatch: dispatchFilterAction } = useFilters();
const [panelOpen, setPanelOpen] = useState(true);

const togglePanel = () => {
setPanelOpen(panelOpen);
};

const onBirthDateChange = (birthDates: string[]) => {
dispatchFilterAction({
Expand Down Expand Up @@ -62,30 +50,24 @@ export const PersonFilter = ({
};

return (
<Ekspanderbartpanel
apen={panelOpen}
onClick={togglePanel}
tittel={texts.panelTitle}
>
<div className="flex flex-col gap-4">
<CompanyFilter
selectedCompanies={filterState.selectedCompanies}
options={mapPersonregisterToCompanyList(personregister)}
onSelect={onCompanyChange}
/>
<BirthDateFilter
onSelect={onBirthDateChange}
selectedDates={filterState.selectedBirthDates}
/>
<AgeFilter
onChange={onAgeFilterChange}
selectedAgeFilters={filterState.selectedAgeFilters}
/>
<FristFilter
onChange={onFristFilterChange}
selectedFristFilters={filterState.selectedFristFilters}
/>
</div>
</Ekspanderbartpanel>
<div className="flex flex-col gap-4">
<CompanyFilter
selectedCompanies={filterState.selectedCompanies}
options={mapPersonregisterToCompanyList(personregister)}
onSelect={onCompanyChange}
/>
<BirthDateFilter
onSelect={onBirthDateChange}
selectedDates={filterState.selectedBirthDates}
/>
<AgeFilter
onChange={onAgeFilterChange}
selectedAgeFilters={filterState.selectedAgeFilters}
/>
<FristFilter
onChange={onFristFilterChange}
selectedFristFilters={filterState.selectedFristFilters}
/>
</div>
);
};
37 changes: 17 additions & 20 deletions src/components/HendelseFilterPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import EkspanderbartPanel from 'nav-frontend-ekspanderbartpanel';
import { PersonregisterState } from '@/api/types/personregisterTypes';
import { filterOnPersonregister } from '@/utils/hendelseFilteringUtils';
import { OverviewTabType } from '@/konstanter';
Expand Down Expand Up @@ -268,24 +267,22 @@ export function HendelseFilterPanel({ personRegister }: Props) {
};

return (
<EkspanderbartPanel apen tittel="Hendelse" className="mb-4">
<CheckboxGroup legend="Hendelse" hideLegend={true} size="small">
{checkboxElements.map((checkbox) => {
return (
<Checkbox
key={checkbox.hendelse}
checked={checkbox.isChecked}
value={checkbox.hendelse}
onChange={(e) => onChange(e.target.value)}
>
<CheckboxLabel
labelText={checkbox.tekst}
antallHendelser={checkbox.antallHendelser}
/>
</Checkbox>
);
})}
</CheckboxGroup>
</EkspanderbartPanel>
<CheckboxGroup legend="Hendelse" size="small">
{checkboxElements.map((checkbox) => {
return (
<Checkbox
key={checkbox.hendelse}
checked={checkbox.isChecked}
value={checkbox.hendelse}
onChange={(e) => onChange(e.target.value)}
>
<CheckboxLabel
labelText={checkbox.tekst}
antallHendelser={checkbox.antallHendelser}
/>
</Checkbox>
);
})}
</CheckboxGroup>
);
}
5 changes: 1 addition & 4 deletions src/components/filters/ClearFiltersButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ const ClearFiltersWrapper = styled.div`
display: inline-flex;
align-items: center;
box-sizing: border-box;
border: 2px solid transparent;
justify-content: flex-end;
border-radius: 2px;
color: ${themes.color.navBla};
margin-bottom: 0.5em;
font-size: 1em;
font-weight: 500;
padding: 0.25em;
padding: 0.5rem 0.25rem;
-webkit-user-select: none;
user-select: none;
:hover {
Expand Down
35 changes: 12 additions & 23 deletions src/components/filters/TekstFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
import React, { ReactElement } from 'react';
import { useFilters } from '@/context/filters/FilterContext';
import { ActionType } from '@/context/filters/filterContextActions';
import { Box, Heading, TextField } from '@navikt/ds-react';
import { TextField } from '@navikt/ds-react';

const texts = {
undertittel: 'Navn / Fødselsnummer',
placeholder: 'Søk på navn eller fødselsnummer',
};

export const TekstFilter = (): ReactElement => {
const { filterState, dispatch: dispatchFilterAction } = useFilters();

return (
<Box
borderRadius="medium"
background="surface-default"
borderColor="border-strong"
padding="4"
borderWidth="1"
className="mb-4"
>
<TextField
size="small"
label={<Heading size="small">{texts.undertittel}</Heading>}
description={texts.placeholder}
value={filterState.tekstFilter}
onChange={(e) => {
dispatchFilterAction({
type: ActionType.SetTekstFilter,
tekstFilter: e.target.value,
});
}}
/>
</Box>
<TextField
size="small"
label={texts.undertittel}
value={filterState.tekstFilter}
onChange={(e) => {
dispatchFilterAction({
type: ActionType.SetTekstFilter,
tekstFilter: e.target.value,
});
}}
/>
);
};
16 changes: 13 additions & 3 deletions src/containers/Oversikt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useFilters } from '@/context/filters/FilterContext';
import { useTabType } from '@/context/tab/TabTypeContext';
import { useAktivVeilederQuery } from '@/data/veiledereQueryHooks';
import { HendelseFilterPanel } from '@/components/HendelseFilterPanel';
import { Box } from '@navikt/ds-react';

const SokeresultatFiltre = styled.div`
margin-right: 1rem;
Expand Down Expand Up @@ -72,10 +73,19 @@ export const Oversikt = ({
<OversiktContainerInnhold>
<SokeresultatFiltre>
<ClearFiltersButton />
<TekstFilter />
<HendelseFilterPanel personRegister={allEvents.value} />
<Box
borderRadius="medium"
background="surface-default"
borderColor="border-strong"
padding="4"
borderWidth="1"
className="mb-4 flex flex-col gap-4"
>
<TekstFilter />
<HendelseFilterPanel personRegister={allEvents.value} />

<PersonFilter personregister={personData} />
<PersonFilter personregister={personData} />
</Box>
</SokeresultatFiltre>

<Sokeresultat allEvents={allEvents} />
Expand Down

0 comments on commit bba0c44

Please sign in to comment.