Skip to content

Commit 33bfb56

Browse files
authored
Merge pull request #166 from canonical/WD-16247-dev-highlight-webpages-that-are-new-or-to-be-deleted
WD-16247 Dev highlight webpages that are new or to be deleted
2 parents 74da5b2 + be01d9d commit 33bfb56

File tree

9 files changed

+98
-22
lines changed

9 files changed

+98
-22
lines changed

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ GOOGLE_CREDENTIALS=googlecreds
1717
GOOGLE_DRIVE_FOLDER_ID=googlecreds
1818
COPYDOC_TEMPLATE_ID=googlecreds
1919
GOOGLE_PRIVATE_KEY=base64encodedprivatekey
20-
GOOGLE_PRIVATE_KEY_ID=privatekeyid
20+
GOOGLE_PRIVATE_KEY_ID=privatekeyid

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"react-dom": "18.3.1",
2525
"react-query": "3.39.3",
2626
"react-router-dom": "6.29.0",
27-
"vanilla-framework": "4.16.0",
27+
"vanilla-framework": "4.21.0",
2828
"zustand": "4.5.6"
2929
},
3030
"devDependencies": {

static/client/App.scss

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
// Icons
2020
@include vf-p-icons;
2121
@include vf-p-icons-common;
22+
@include vf-p-icon-edit;
23+
@include vf-p-icon-archive;
2224

2325
// Utilities
2426
@include vf-u-align;

static/client/components/Navigation/NavigationElement/NavigationElement.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { type MouseEvent, useCallback, useEffect, useRef, useState } from
33
import { useLocation } from "react-router-dom";
44

55
import { type INavigationElementProps } from "./NavigationElement.types";
6+
import NavigationElementBadge from "./NavigationElementBadge";
67

78
import type { IPage } from "@/services/api/types/pages";
89
import { NavigationServices } from "@/services/navigation";
@@ -74,6 +75,7 @@ const NavigationElement = ({ activePageName, page, project, onSelect }: INavigat
7475
ref={expandButtonRef}
7576
>
7677
{NavigationServices.formatPageName(page.name)}
78+
<NavigationElementBadge page={page} />
7779
</button>
7880
</>
7981
<ul
@@ -93,6 +95,7 @@ const NavigationElement = ({ activePageName, page, project, onSelect }: INavigat
9395
) : (
9496
<div className={`p-list-tree__link ${page.name === activePageName ? "is-active" : ""}`} onClick={handleSelect}>
9597
{NavigationServices.formatPageName(page.name)}
98+
<NavigationElementBadge page={page} />
9699
</div>
97100
)}
98101
</li>

static/client/components/Navigation/NavigationElement/NavigationElement.types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ export interface INavigationElementProps {
66
project: string;
77
onSelect: (path: string) => void;
88
}
9+
10+
export interface INavigationElementBadgeProps {
11+
page: IPage;
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React, { useMemo } from "react";
2+
3+
import { Tooltip } from "@canonical/react-components";
4+
5+
import type { INavigationElementBadgeProps } from "./NavigationElement.types";
6+
7+
import { PageStatus } from "@/services/api/types/pages";
8+
9+
const NavigationElementBadge = ({ page }: INavigationElementBadgeProps): JSX.Element => {
10+
const getIcon = useMemo(() => {
11+
switch (page.status) {
12+
case PageStatus.NEW:
13+
return <i className="p-icon--edit is-dark" />;
14+
case PageStatus.TO_DELETE:
15+
return <i className="p-icon--archive is-dark" />;
16+
default:
17+
return <></>;
18+
}
19+
}, [page.status]);
20+
21+
const getTitle = useMemo(() => {
22+
switch (page.status) {
23+
case PageStatus.NEW:
24+
return "In drafts";
25+
case PageStatus.TO_DELETE:
26+
return "To be deleted";
27+
default:
28+
return null;
29+
}
30+
}, [page.status]);
31+
32+
const getText = useMemo(() => {
33+
switch (page.status) {
34+
case PageStatus.NEW:
35+
return "This page isn't live yet.";
36+
case PageStatus.TO_DELETE:
37+
return "This page is being deleted.";
38+
default:
39+
return null;
40+
}
41+
}, [page.status]);
42+
43+
return (
44+
<Tooltip
45+
autoAdjust
46+
message={
47+
<>
48+
<b>{getTitle}</b>
49+
<br />
50+
{getText}
51+
</>
52+
}
53+
position="right"
54+
zIndex={1000}
55+
>
56+
<div>{getIcon}</div>
57+
</Tooltip>
58+
);
59+
};
60+
61+
export default NavigationElementBadge;

static/client/components/Navigation/NavigationElement/_NavigationElement.scss

+5
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@
1212
.p-list-tree__toggle {
1313
margin-right: 0;
1414
padding-right: 0;
15+
}
16+
17+
.p-list-tree__link {
18+
display: flex;
19+
gap: 0.3rem;
1520
}

static/client/components/RequestTaskModal/RequestTaskModal.tsx

+17-16
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,26 @@ const RequestTaskModal = ({
7777
})
7878
.then(() => {
7979
onClose();
80-
if (webpage.status === PageStatus.NEW) {
81-
if (refetch) {
82-
refetch()
83-
.then((data) => {
84-
if (data?.length) {
85-
const project = data.find((p) => p.data?.data?.name === selectedProject?.name);
86-
if (project && project.data?.data) {
87-
setSelectedProject(project.data.data);
88-
}
89-
}
90-
})
91-
.finally(() => {
92-
navigate("/app", { replace: true });
93-
});
94-
} else {
80+
const afterRefetch = () => {
81+
if (webpage.status === PageStatus.NEW) {
9582
navigate("/app", { replace: true });
83+
} else {
84+
window.location.reload();
9685
}
86+
};
87+
if (refetch) {
88+
refetch()
89+
.then((data) => {
90+
if (data?.length) {
91+
const project = data.find((p) => p.data?.data?.name === selectedProject?.name);
92+
if (project && project.data?.data) {
93+
setSelectedProject(project.data.data);
94+
}
95+
}
96+
})
97+
.finally(afterRefetch);
9798
} else {
98-
window.location.reload();
99+
afterRefetch();
99100
}
100101
})
101102
.catch((error) => {

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -6941,10 +6941,10 @@ validate-npm-package-name@^5.0.1:
69416941
resolved "https://registry.yarnpkg.com/validate-npm-package-name/-/validate-npm-package-name-5.0.1.tgz#a316573e9b49f3ccd90dbb6eb52b3f06c6d604e8"
69426942
integrity sha512-OljLrQ9SQdOUqTaQxqL5dEfZWrXExyyWsozYlAWFawPVNuD83igl7uJD2RTkNMbniIYgt8l81eCJGIdQF7avLQ==
69436943

6944-
vanilla-framework@4.16.0:
6945-
version "4.16.0"
6946-
resolved "https://registry.yarnpkg.com/vanilla-framework/-/vanilla-framework-4.16.0.tgz#54e7a51e073de043d45a7bac37ffaa4f4351ac4a"
6947-
integrity sha512-LrxZLiNOm0cTpG++1X4MMy2efg8Xhc08JUAwNAybeSQ5FaaBGiAodbV1Fx3QvJxlaPFQqsjOdT6uZDwuOD7YJg==
6944+
vanilla-framework@4.21.0:
6945+
version "4.21.0"
6946+
resolved "https://registry.yarnpkg.com/vanilla-framework/-/vanilla-framework-4.21.0.tgz#745e6d4cff71b9d2a976540fc8041478d43127ae"
6947+
integrity sha512-/qQu0J5L17Oumpd9AD+kqEYgkBm/JjOJNO3ArObnw9Hx9Dk1Vt3dIasYEo9IR6QFAMU64daOXqbFB+Dz8fZmxw==
69486948

69496949
verbalize@^0.1.2:
69506950
version "0.1.2"

0 commit comments

Comments
 (0)