Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit b5542b7

Browse files
authored
Fixing urls part 2 (#380)
* use react-router for urls, fix front page link
1 parent 4d298d3 commit b5542b7

7 files changed

Lines changed: 32 additions & 26 deletions

File tree

admin-ui/src/common/urls.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { publicUrl } from "./const";
2-
31
export const prefixes = {
42
recurringReservations: "/recurring-reservations",
53
reservations: "/reservations",
@@ -10,19 +8,19 @@ export const prefixes = {
108
export const applicationRoundUrl = (
119
applicationRoundId: number | string
1210
): string =>
13-
`${publicUrl}${prefixes.recurringReservations}/application-rounds/${applicationRoundId}`;
11+
`${prefixes.recurringReservations}/application-rounds/${applicationRoundId}`;
1412

1513
export const applicationUrl = (applicationId: number | string): string =>
16-
`${publicUrl}${prefixes.applications}/${applicationId}`;
14+
`${prefixes.applications}/${applicationId}`;
1715

1816
export const reservationUrl = (reservationId: number | string): string =>
19-
`${publicUrl}${prefixes.reservations}/${reservationId}`;
17+
`${prefixes.reservations}/${reservationId}`;
2018

2119
export const requestedReservationsUrl = (): string =>
22-
`${publicUrl}${prefixes.reservations}/requested`;
20+
`${prefixes.reservations}/requested`;
2321

2422
export const applicationDetailsUrl = (applicationId: number | string): string =>
25-
`${publicUrl}${prefixes.applications}/${applicationId}/details`;
23+
`${prefixes.applications}/${applicationId}/details`;
2624

2725
export const applicationRoundApplications = (
2826
applicationRoundId: number | string | null
@@ -31,8 +29,12 @@ export const applicationRoundApplications = (
3129
export const reservationUnitUrl = (
3230
reservationUnitId: number,
3331
unitId: number
34-
): string =>
35-
`${publicUrl}/unit/${unitId}/reservationUnit/edit/${reservationUnitId}`;
32+
): string => `/unit/${unitId}/reservationUnit/edit/${reservationUnitId}`;
33+
34+
export const spaceUrl = (spaceId: number, unitId: number): string =>
35+
`/unit/${unitId}/space/edit/${spaceId}`;
36+
37+
export const resourceUrl = (resourceId: number, unitId: number): string =>
38+
`/unit/${unitId}/resource/edit/${resourceId}`;
3639

37-
export const unitUrl = (unitId: number): string =>
38-
`${publicUrl}/unit/${unitId}`;
40+
export const unitUrl = (unitId: number): string => `/unit/${unitId}`;

admin-ui/src/component/BreadcrumbWrapper.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Breadcrumb } from "common";
55
import { useTranslation } from "react-i18next";
66
import { trim } from "lodash";
77
import { breakpoints } from "../styles/util";
8+
import { publicUrl } from "../common/const";
89

910
type Alias = {
1011
slug: string;
@@ -47,7 +48,10 @@ const BreadcrumbWrapper = ({ route, aliases }: Props): JSX.Element => {
4748
return (
4849
<Wrapper>
4950
<StyledBreadcrumb
50-
routes={[{ title: t("breadcrumb.frontpage"), slug: "/" }, ...routes]}
51+
routes={[
52+
{ title: t("breadcrumb.frontpage"), slug: publicUrl },
53+
...routes,
54+
]}
5155
isMobile={isMobile}
5256
/>
5357
</Wrapper>

admin-ui/src/component/DataTable.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
IconSliders,
1616
} from "hds-react";
1717
import { useTranslation } from "react-i18next";
18-
import { useHistory } from "react-router-dom";
18+
import { Link, useHistory } from "react-router-dom";
1919
import get from "lodash/get";
2020
import isEqual from "lodash/isEqual";
2121
import pullAll from "lodash/pullAll";
@@ -37,7 +37,6 @@ import {
3737
filterData,
3838
} from "../common/util";
3939
import FilterContainer, { FilterBtn } from "./FilterContainer";
40-
import { publicUrl } from "../common/const";
4140

4241
export type OrderTypes = "asc" | "desc";
4342

@@ -228,7 +227,7 @@ export const Heading = styled.thead`
228227
}
229228
`;
230229

231-
const A = styled.a`
230+
const A = styled(Link)`
232231
&,
233232
:visited,
234233
:hover,
@@ -829,10 +828,7 @@ function DataTable({
829828
return (
830829
<Cell key={colKey}>
831830
{link ? (
832-
<A
833-
href={`${publicUrl}${link}`}
834-
className="cellContent"
835-
>
831+
<A to={`${link}`} className="cellContent">
836832
<span className="cellContent">
837833
{value}
838834
</span>

admin-ui/src/component/Resources/ResourcesList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { RESOURCES_QUERY } from "../../common/queries";
2020
import { Query, ResourceType } from "../../common/gql-types";
2121
import BreadcrumbWrapper from "../BreadcrumbWrapper";
2222
import { useNotification } from "../../context/NotificationContext";
23+
import { resourceUrl } from "../../common/urls";
2324

2425
const Wrapper = styled.div`
2526
padding: var(--spacing-layout-xl) 0;
@@ -100,7 +101,7 @@ const getCellConfig = (t: TFunction): CellConfig => {
100101
sorting: "name",
101102
order: "asc",
102103
rowLink: ({ space, pk }: ResourceType) =>
103-
`/unit/${space?.unit?.pk}/resource/edit/${pk}`,
104+
resourceUrl(Number(pk), Number(space?.unit?.pk)),
104105
};
105106
};
106107

@@ -114,7 +115,6 @@ const getFilterConfig = (
114115
const types = uniq(resources.map((resource) => resource.locationType)).filter(
115116
(n) => n
116117
);
117-
// const districts = uniq(spaces.map((space: Space) => space.building.district));
118118

119119
return [
120120
{

admin-ui/src/component/Spaces/SpacesList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { SPACES_QUERY } from "../../common/queries";
1818
import { Query, SpaceType } from "../../common/gql-types";
1919
import BreadcrumbWrapper from "../BreadcrumbWrapper";
2020
import { useNotification } from "../../context/NotificationContext";
21+
import { spaceUrl } from "../../common/urls";
2122

2223
const Wrapper = styled.div`
2324
padding: var(--spacing-layout-xl) 0;
@@ -115,7 +116,8 @@ const getCellConfig = (t: TFunction): CellConfig => {
115116
index: "pk",
116117
sorting: "name",
117118
order: "asc",
118-
rowLink: ({ pk, unit }: SpaceType) => `unit/${unit?.pk}/space/edit/${pk}`,
119+
rowLink: ({ pk, unit }: SpaceType) =>
120+
spaceUrl(Number(pk), Number(unit?.pk)),
119121
};
120122
};
121123

admin-ui/src/component/Unit/ResourcesTable.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
ResourceType,
1616
UnitByPkType,
1717
} from "../../common/gql-types";
18+
import { resourceUrl } from "../../common/urls";
1819

1920
interface IProps {
2021
resources: ResourceType[] | undefined;
@@ -86,7 +87,7 @@ const ResourcesTable = ({
8687
{
8788
name: t("ResourceTable.menuEditResource"),
8889
onClick: () => {
89-
history.push(`/unit/${unit.pk}/resource/edit/${pk}`);
90+
history.push(resourceUrl(Number(pk), Number(unit.pk)));
9091
},
9192
},
9293
{
@@ -122,7 +123,7 @@ const ResourcesTable = ({
122123
index: "pk",
123124
sorting: "nameFi",
124125
order: "asc",
125-
rowLink: ({ pk }: ResourceType) => `/unit/${unit.pk}/resource/edit/${pk}`,
126+
rowLink: ({ pk }: ResourceType) => resourceUrl(Number(pk), Number(unit.pk)),
126127
} as CellConfig;
127128

128129
return (

admin-ui/src/component/lists/components.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { get } from "lodash";
22
import React from "react";
3+
import { Link } from "react-router-dom";
34
import styled from "styled-components";
45
import { Table, TableProps } from "../../common/hds-fork/table/Table";
56
import { breakpoints } from "../../styles/util";
@@ -68,7 +69,7 @@ const NoDataMessage = styled.span`
6869
line-height: 4;
6970
`;
7071

71-
const A = styled.a`
72+
const A = styled(Link)`
7273
color: black;
7374
`;
7475

@@ -78,7 +79,7 @@ export const TableLink = ({
7879
}: {
7980
href: string;
8081
children: React.ReactNode;
81-
}): JSX.Element => <A href={href}>{children}</A>;
82+
}): JSX.Element => <A to={href}>{children}</A>;
8283

8384
/**
8485
*

0 commit comments

Comments
 (0)