Skip to content

Commit 2d27343

Browse files
committed
Added null handling for urls
1 parent 74ddf9e commit 2d27343

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/helpers/PageHelper.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ export class PageHelper {
66

77
static sortLevel(items: PageLink[]) {
88
return items.sort((a, b) => {
9-
if (a.url < b.url) return -1;
10-
if (a.url > b.url) return 1;
9+
const aUrl = a.url || "";
10+
const bUrl = b.url || "";
11+
if (aUrl < bUrl) return -1;
12+
if (aUrl > bUrl) return 1;
1113
return 0;
1214
});
1315
}
@@ -19,8 +21,9 @@ export class PageHelper {
1921

2022
const groupPage = result.find((p) => p.url === "/groups");
2123
customPages.forEach((p: any) => {
22-
const page: PageLink = { pageId: p.id, title: p.title, url: p.url, custom: true };
23-
if (p.url.indexOf("/groups") === -1) {
24+
const url = p.url || "";
25+
const page: PageLink = { pageId: p.id, title: p.title, url: url, custom: true };
26+
if (url.indexOf("/groups") === -1) {
2427
const existing = result.find((r) => r.url === p.url);
2528
if (existing) { existing.title = p.title; existing.custom = true; existing.pageId = p.id; } else result.push(page);
2629
} else {

src/site/PagesPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const PagesPage = () => {
5656
const result: React.ReactElement[] = [];
5757
items.forEach((item) => {
5858
result.push(
59-
<TableRow key={item.url} sx={{ "&:hover": { backgroundColor: "action.hover" }, transition: "background-color 0.2s ease" }}>
59+
<TableRow key={item.url || item.pageId || item.title} sx={{ "&:hover": { backgroundColor: "action.hover" }, transition: "background-color 0.2s ease" }}>
6060
<TableCell sx={{ width: 120 }}>
6161
{item.custom ? (
6262
<Button

src/site/components/AddPageModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export function AddPageModal(props: Props) {
218218
url: SlugHelper.slugifyString(
219219
"/" + assembledPage.title.toLowerCase().replace(/\s+/g, "-"),
220220
"urlPath"
221-
)
221+
) || "/untitled"
222222
};
223223

224224
// Create page record
@@ -278,6 +278,7 @@ export function AddPageModal(props: Props) {
278278
const p = { ...page };
279279
const slugString = link?.text || page.title || "new-page";
280280
p.url = props.requestedSlug || SlugHelper.slugifyString("/" + slugString.toLowerCase().replace(" ", "-"), "urlPath");
281+
if (!p.url) p.url = "/untitled";
281282

282283
pageData = await ApiHelper.post("/pages", [p], "ContentApi").then((data: any) => {
283284
setPage(data[0]);

0 commit comments

Comments
 (0)