Skip to content

Commit

Permalink
💄 Fjerner hvit linje nederst på oversikten
Browse files Browse the repository at this point in the history
Den var der når det ikke ble vist noen driftsmeldinger fordi koden som
sjekket om det var noen driftsmeldinger å vise (og dermed legge på en
css-klasse) fikk et array med *alle* hentede driftsmeldinger å tygge på,
i stedet for bare de som ble vist (pga. filtreringen lå i
Driftsmeldinger.tsx, i stedet for i sanity.ts.
  • Loading branch information
havstein committed Jan 6, 2025
1 parent a55fb89 commit 72e824a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
11 changes: 4 additions & 7 deletions src/components/driftsmeldinger/Driftsmeldinger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ interface DriftsmeldingProps {
driftsmelding: DriftsmeldingType;
}

export const Driftsmeldinger = (): (ReactElement | null)[] => {
export const Driftsmeldinger = (): ReactElement[] => {
const { driftsmeldinger } = useDriftsmelding();

return R.sortBy(driftsmeldinger, [R.prop('opprettet'), 'desc']).map((driftsmelding, index) => {
const harGÃ¥tt30min = dayjs(driftsmelding._updatedAt).add(30, 'minutes').isBefore(dayjs());
if (harGÃ¥tt30min && driftsmelding.level === 'success') return null;

return <Driftsmelding key={index} driftsmelding={driftsmelding} />;
});
return R.sortBy(driftsmeldinger, [R.prop('opprettet'), 'desc']).map((driftsmelding, index) => (
<Driftsmelding key={index} driftsmelding={driftsmelding} />
));
};

const Driftsmelding = ({ driftsmelding }: DriftsmeldingProps): Maybe<ReactElement> => {
Expand Down
16 changes: 15 additions & 1 deletion src/external/sanity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import dayjs from 'dayjs';

import { erProd } from '@/env';
import { gql, useQuery } from '@apollo/client';
import { Maybe } from '@io/graphql';
Expand Down Expand Up @@ -135,6 +137,10 @@ export function useSkjønnsfastsettelsesMaler(skalVise828AndreLedd: boolean, har
};
}

/**
* Returnerer *aktive* driftsmeldinger, det vil si at "ferdigstilte" driftsmeldinger som kommer tilbake fra sanity blir
* filtrert vekk.
*/
export function useDriftsmelding() {
const { data, error, loading } = useQuery<DriftsmeldingerQueryResult, SanityQueryVariables>(
gql`
Expand All @@ -152,8 +158,16 @@ export function useDriftsmelding() {
},
);

const alleDriftsmeldinger = data?.sanity?.result.filter((it: Driftsmelding) => (erProd ? it.iProd : true)) ?? [];
const aktiveDriftsmeldinger = alleDriftsmeldinger
.map((driftsmelding) => {
const harGÃ¥tt30min = dayjs(driftsmelding._updatedAt).add(30, 'minutes').isBefore(dayjs());
return harGÃ¥tt30min && driftsmelding.level === 'success' ? null : driftsmelding;
})
.filter((driftsmelding) => driftsmelding !== null);

return {
driftsmeldinger: data?.sanity?.result.filter((it: Driftsmelding) => (erProd ? it.iProd : true)) ?? [],
driftsmeldinger: aktiveDriftsmeldinger,
loading,
error,
};
Expand Down
6 changes: 1 addition & 5 deletions src/routes/oversikt/Oversikt.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@

.fullHeight {
display: flex;
height: calc(100vh - 112px);
}

.driftsmelding {
height: calc(100vh - 201px);
overflow: hidden;
}

.Alert {
Expand Down
5 changes: 1 addition & 4 deletions src/routes/oversikt/Oversikt.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use client';

import classNames from 'classnames';
import dynamic from 'next/dynamic';
import React, { ReactElement } from 'react';

import { Alert } from '@navikt/ds-react';

import { EmojiTilbakemelding } from '@components/flexjar/EmojiTilbamelding';
import { Widget } from '@components/flexjar/Widget';
import { useDriftsmelding } from '@external/sanity';
import { useFjernPersonFraApolloCache } from '@hooks/useFjernPersonFraApolloCache';
import { useKeyboardShortcuts } from '@hooks/useKeyboardShortcuts';
import { useLoadingToast } from '@hooks/useLoadingToast';
Expand Down Expand Up @@ -41,7 +39,6 @@ export const Oversikt = (): ReactElement => {
const oppgaveFeed = useOppgaveFeed();
const aktivTab = useAktivTab();
const { allFilters } = useFilters();
const { driftsmeldinger } = useDriftsmelding();

useLoadingToast({ isLoading: oppgaveFeed.loading, message: 'Henter oppgaver' });
useKeyboardShortcuts();
Expand All @@ -56,7 +53,7 @@ export const Oversikt = (): ReactElement => {
</Alert>
)}
<Tabs />
<div className={classNames(styles.fullHeight, (driftsmeldinger?.length ?? 0) > 0 && styles.driftsmelding)}>
<div className={styles.fullHeight}>
<Filtermeny filters={allFilters} />
<section className={styles.Content}>
{aktivTab === TabType.BehandletIdag ? (
Expand Down

0 comments on commit 72e824a

Please sign in to comment.