From f31753d86186337bf03cbb720bff2ee4bd9ff88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigurd=20Gr=C3=B8neng?= Date: Thu, 17 Aug 2023 14:42:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20=20Dont=20use=20fnr=20in=20path?= =?UTF-8?q?=20(#474)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * WIP: Dont use fnr in path * Hardcode basename for internflate * Reset url when switching tab to dialog or aktivitetsplan * Redirect to base if no dialog * Add redirect to dialog without fnr * Use link to aktivitetsplan without fnr * Fix link when aktivitetsplan-url is not set * Use correct fallback operator * Cleanup * Fix cache invalidation option name * Fix redirect for /ny * Use no-cache from nais-action * Split redirects into separate components * Test cdn-no-cache-paths * don't use nais action no-cache argument * fix ny redirect queryPart --------- Co-authored-by: Hans Petter Simonsen Co-authored-by: johannetronstad --- .github/workflows/deploy-intern.yml | 2 +- src/App.tsx | 32 +++++++++++++++---- src/view/aktivitet/AktivitetskortLenke.tsx | 12 +++---- .../aktivitet/DialogMedAktivitetHeader.tsx | 3 +- src/view/dialog/Dialog.tsx | 9 ++++-- src/view/dialog/IngenDialog.tsx | 12 ------- src/view/utils/utils.ts | 4 --- 7 files changed, 39 insertions(+), 35 deletions(-) delete mode 100644 src/view/dialog/IngenDialog.tsx diff --git a/.github/workflows/deploy-intern.yml b/.github/workflows/deploy-intern.yml index 523d1334..323a4c15 100644 --- a/.github/workflows/deploy-intern.yml +++ b/.github/workflows/deploy-intern.yml @@ -43,7 +43,7 @@ jobs: cdn-team-name: dab source: ./build/ destination: /${{ inputs.bucket }}/ - cache-invalidate: true + cache-invalidation: true - name: Setup gcloud uses: google-github-actions/setup-gcloud@v0 - name: Set Cache policy no-store for asset-manifest diff --git a/src/App.tsx b/src/App.tsx index 6b613955..18a50bff 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,8 +2,8 @@ import path from 'path'; import cx from 'classnames'; import React from 'react'; -import { RouterProvider } from 'react-router'; -import { createBrowserRouter, createHashRouter } from 'react-router-dom'; +import { Navigate, RouterProvider, useParams } from 'react-router'; +import { createBrowserRouter, createHashRouter, useSearchParams } from 'react-router-dom'; import { stripTrailingSlash } from './api/UseApiBasePath'; import { USE_HASH_ROUTER, erInternFlate } from './constants'; @@ -13,7 +13,7 @@ import AppBody from './view/AppBody'; import Dialog from './view/dialog/Dialog'; import DialogInfoMelding from './view/dialog/DialogInfoMelding'; import NyDialog from './view/dialog/NyDialog'; -import { Provider, useFnrContext } from './view/Provider'; +import { Provider } from './view/Provider'; import StatusAdvarsel from './view/statusAdvarsel/StatusAdvarsel'; interface Props { @@ -21,6 +21,19 @@ interface Props { enhet?: string; } +const RedirectToDialogWithoutFnr = () => { + // /:fnr/:dialogId -> /:dialogId + const params = useParams(); + return ; +}; +const RedirectToNyDialogWithoutFnr = () => { + // Handle route /:fnr/ny?aktivitetId= -> /ny?aktivitetId= + const [queryParams, _] = useSearchParams(); + const aktivitetId = queryParams.get('aktivitetId'); + const queryPart = aktivitetId ? '?aktivitetId=' + aktivitetId : ''; + return ; +}; + const dialogRoutes = [ { path: '/', @@ -47,19 +60,26 @@ const dialogRoutes = [ { path: '', element: + }, + { + path: ':fnr/ny', + element: + }, + { + path: ':fnr/:dialogId', + element: } ] } ]; const Routes = () => { - const fnr = useFnrContext(); if (USE_HASH_ROUTER) { const hashRouter = createHashRouter(dialogRoutes); return ; } - let basename = stripTrailingSlash(import.meta.env.BASE_URL + (fnr ?? '')); - if (erInternFlate) basename = `/${fnr}`; + let basename = stripTrailingSlash(import.meta.env.BASE_URL); + if (erInternFlate) basename = `/`; const browserRouter = createBrowserRouter(dialogRoutes, { basename }); return ; }; diff --git a/src/view/aktivitet/AktivitetskortLenke.tsx b/src/view/aktivitet/AktivitetskortLenke.tsx index ab46ed73..c6b08b23 100644 --- a/src/view/aktivitet/AktivitetskortLenke.tsx +++ b/src/view/aktivitet/AktivitetskortLenke.tsx @@ -1,17 +1,13 @@ -import React, { MouseEvent } from 'react'; +import { MouseEvent } from 'react'; import { AKTIVITETSPLAN_URL } from '../../constants'; -import { getContextPath } from '../utils/utils'; export const aktivitetLenke = (aktivitetId: string) => { - return `${AKTIVITETSPLAN_URL}/aktivitet/vis/${aktivitetId}`; + return `${AKTIVITETSPLAN_URL || ''}/aktivitet/vis/${aktivitetId}`; }; -export const visAktivitetsplan = (aktivitetID: string, fnrContext?: string) => (event: MouseEvent) => { - if (!fnrContext) { - return; - } +export const visAktivitetsplan = (aktivitetID: string) => (event: MouseEvent) => { event.preventDefault(); - window.history.replaceState({}, 'aktivitetsplan', `${getContextPath()}/${fnrContext}/aktivitet/vis/${aktivitetID}`); + window.history.replaceState({}, 'aktivitetsplan', `/aktivitet/vis/${aktivitetID}`); window.dispatchEvent(new CustomEvent('visAktivitetsplan', { detail: aktivitetID })); }; diff --git a/src/view/aktivitet/DialogMedAktivitetHeader.tsx b/src/view/aktivitet/DialogMedAktivitetHeader.tsx index a721a67a..80fdd27b 100644 --- a/src/view/aktivitet/DialogMedAktivitetHeader.tsx +++ b/src/view/aktivitet/DialogMedAktivitetHeader.tsx @@ -16,7 +16,6 @@ interface Props { export function DialogMedAktivitetHeader(props: Props) { const aktivitet = useSelectedAktivitet(); - const fnr = useFnrContext(); if (!aktivitet) { return null; @@ -39,7 +38,7 @@ export function DialogMedAktivitetHeader(props: Props) {
- + Gå til aktiviteten
diff --git a/src/view/dialog/Dialog.tsx b/src/view/dialog/Dialog.tsx index b4c1c098..5494e70d 100644 --- a/src/view/dialog/Dialog.tsx +++ b/src/view/dialog/Dialog.tsx @@ -1,6 +1,9 @@ +import { Loader } from '@navikt/ds-react'; import classNames from 'classnames'; import React, { useEffect, useState } from 'react'; +import { useNavigate } from 'react-router'; +import { useRoutes } from '../../routes'; import { UpdateTypes, dispatchUpdate } from '../../utils/UpdateEvent'; import useKansendeMelding from '../../utils/UseKanSendeMelding'; import { useUserInfoContext } from '../BrukerProvider'; @@ -14,7 +17,6 @@ import { endreDialogSomVises } from '../ViewState'; import ManagedDialogCheckboxes from './DialogCheckboxes'; import DialogInputBoxVisible from './henvendelseInput/MeldingInputBox'; import HistoriskInfo from './HistoriskInfo'; -import { IngenDialog } from './IngenDialog'; export function Dialog() { const oppfolgingContext = useOppfolgingContext(); @@ -63,8 +65,11 @@ export function Dialog() { } }, [dialogId, lest, activeTab, activePersonflateTab, lesDialog]); + const routes = useRoutes(); + const navigate = useNavigate(); if (!valgtDialog) { - return ; + navigate(routes.baseRoute(), { replace: true }); + return ; } const aktivDialog = !valgtDialog.historisk; diff --git a/src/view/dialog/IngenDialog.tsx b/src/view/dialog/IngenDialog.tsx deleted file mode 100644 index 33e1e983..00000000 --- a/src/view/dialog/IngenDialog.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { Alert } from '@navikt/ds-react'; -import React from 'react'; - -import styles from './Dialog.module.less'; - -export function IngenDialog() { - return ( -
- Dialogen eksisterer ikke. -
- ); -} diff --git a/src/view/utils/utils.ts b/src/view/utils/utils.ts index 39171485..290fec46 100644 --- a/src/view/utils/utils.ts +++ b/src/view/utils/utils.ts @@ -21,10 +21,6 @@ export const settSammenmedSlasher = (...ss: Array): string = else return ''; }; -const erGCP = (): boolean => window.location.hostname.endsWith('intern.nav.no'); - -export const getContextPath = (): string => (erGCP() ? '' : '/veilarbpersonflatefs'); - export const getAktivitetType = (aktivitet: Aktivitet | ArenaAktivitet): AlleAktivitetTypes => { if (aktivitet.type === AktivitetTypes.EKSTERN_AKTIVITET) { return aktivitet.eksternAktivitet!!.type;