Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit d3e93fa

Browse files
authored
The table of contents has been simplified by removing the ability to choose which content items appear (#859)
1 parent b666cd1 commit d3e93fa

File tree

8 files changed

+64
-396
lines changed

8 files changed

+64
-396
lines changed

backend/src/lib/factories/dashboard-factory.ts

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,25 @@ function createNew(
3636
};
3737
}
3838

39-
function createDraftFromDashboard(
39+
function createNewFromDashboard(
4040
dashboard: Dashboard,
41-
user: User,
42-
version: number
41+
id: string,
42+
name: string,
43+
version: number,
44+
parentDashboardId: string,
45+
user: User
4346
): Dashboard {
44-
const id = uuidv4();
45-
4647
let widgets: Array<Widget> = [];
48+
const tableOfContents: { [key: string]: boolean } = {};
4749
if (dashboard.widgets) {
4850
// Duplicate all widgets related to this dashboard
49-
widgets = dashboard.widgets.map((widget) =>
50-
WidgetFactory.createFromWidget(id, widget)
51-
);
51+
widgets = dashboard.widgets.map((widget) => {
52+
const newWidget = WidgetFactory.createFromWidget(id, widget);
53+
if (dashboard.tableOfContents) {
54+
tableOfContents[newWidget.id] = dashboard.tableOfContents[widget.id];
55+
}
56+
return newWidget;
57+
});
5258
for (const widget of widgets) {
5359
if (widget.section) {
5460
const sectionIndex = dashboard.widgets.findIndex(
@@ -69,13 +75,13 @@ function createDraftFromDashboard(
6975

7076
return {
7177
id,
72-
name: dashboard.name,
73-
version: version,
74-
parentDashboardId: dashboard.parentDashboardId,
78+
name,
79+
version,
80+
parentDashboardId,
7581
topicAreaId: dashboard.topicAreaId,
7682
topicAreaName: dashboard.topicAreaName,
7783
displayTableOfContents: dashboard.displayTableOfContents,
78-
tableOfContents: dashboard.tableOfContents,
84+
tableOfContents,
7985
description: dashboard.description,
8086
state: DashboardState.Draft,
8187
createdBy: user.userId,
@@ -86,53 +92,26 @@ function createDraftFromDashboard(
8692
};
8793
}
8894

95+
function createDraftFromDashboard(
96+
dashboard: Dashboard,
97+
user: User,
98+
version: number
99+
): Dashboard {
100+
return createNewFromDashboard(
101+
dashboard,
102+
uuidv4(),
103+
dashboard.name,
104+
version,
105+
dashboard.parentDashboardId,
106+
user
107+
);
108+
}
109+
89110
function createCopyFromDashboard(dashboard: Dashboard, user: User): Dashboard {
90111
const id = uuidv4();
91-
92-
// Copy all widgets associated with the dashboard.
93-
let widgets: Array<Widget> = [];
94-
if (dashboard.widgets) {
95-
widgets = dashboard.widgets.map((widget) =>
96-
WidgetFactory.createFromWidget(id, widget)
97-
);
98-
for (const widget of widgets) {
99-
if (widget.section) {
100-
const sectionIndex = dashboard.widgets.findIndex(
101-
(w) => w.id === widget.section
102-
);
103-
widget.section = widgets[sectionIndex].id;
104-
}
105-
if (widget.content && widget.content.widgetIds) {
106-
const widgetIds: string[] = [];
107-
for (const id of widget.content.widgetIds) {
108-
const widgetIndex = dashboard.widgets.findIndex((w) => w.id === id);
109-
widgetIds.push(widgets[widgetIndex].id);
110-
}
111-
widget.content.widgetIds = widgetIds;
112-
}
113-
}
114-
}
115-
116-
return {
117-
id,
118-
name: "Copy of " + dashboard.name,
119-
version: 1,
120-
parentDashboardId: id,
121-
topicAreaId: dashboard.topicAreaId,
122-
topicAreaName: dashboard.topicAreaName,
123-
displayTableOfContents: dashboard.displayTableOfContents,
124-
tableOfContents: dashboard.tableOfContents,
125-
description: dashboard.description,
126-
state: DashboardState.Draft,
127-
createdBy: user.userId,
128-
updatedAt: new Date(),
129-
updatedBy: user.userId,
130-
submittedBy: undefined,
131-
publishedBy: undefined,
132-
archivedBy: undefined,
133-
widgets,
134-
friendlyURL: undefined,
135-
};
112+
const name = "Copy of " + dashboard.name;
113+
const version = 1;
114+
return createNewFromDashboard(dashboard, id, name, version, id, user);
136115
}
137116

138117
/**

backend/src/lib/models/dashboard.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export interface Dashboard {
2929
topicAreaId: string;
3030
topicAreaName: string;
3131
displayTableOfContents: boolean;
32+
/**
33+
* @type {any}
34+
* @deprecated no longer supported
35+
*/
3236
tableOfContents?: any;
3337
description: string;
3438
createdBy: string;

frontend/src/App.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import HomeWithSearch from "./containers/HomeWithSearch";
1111
import DashboardListing from "./containers/DashboardListing";
1212
import CreateDashboard from "./containers/CreateDashboard";
1313
import EditDetails from "./containers/EditDetails";
14-
import EditTableOfContents from "./containers/EditTableOfContents";
1514
import AddContent from "./containers/AddContent";
1615
import EditDashboard from "./containers/EditDashboard";
1716
import DashboardHistory from "./containers/DashboardHistory";
@@ -201,11 +200,6 @@ function App() {
201200
title: t("PageTitle.EditDashboardHeader"),
202201
component: EditDetails,
203202
},
204-
{
205-
path: "/admin/dashboard/edit/:dashboardId/tableofcontents",
206-
title: t("PageTitle.EditTableOfContents"),
207-
component: EditTableOfContents,
208-
},
209203
{
210204
path: "/admin/dashboard/:dashboardId/edit-table/:widgetId",
211205
title: t("PageTitle.EditTable"),

frontend/src/containers/EditDetails.tsx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ function EditDetails() {
5555
const topicAreaId = watch("topicAreaId");
5656
const displayTableOfContents = watch("displayTableOfContents");
5757

58-
useEffect(() => {
59-
const routeTableOfContents = (history.location.state as any)
60-
?.tableOfContents;
61-
if (dashboard && routeTableOfContents) {
62-
dashboard.displayTableOfContents = true;
63-
dashboard.tableOfContents = routeTableOfContents;
64-
}
65-
}, [dashboard, history.location.state]);
66-
6758
useEffect(() => {
6859
if (dashboard) {
6960
const name = dashboard.name;
@@ -117,12 +108,6 @@ function EditDetails() {
117108
return topicareas.find((t) => t.id === topicAreaId)?.name || "";
118109
};
119110

120-
const onTableOfContentsEdit = () => {
121-
history.push(`/admin/dashboard/edit/${dashboardId}/tableofcontents`, {
122-
tableOfContents: dashboard?.tableOfContents,
123-
});
124-
};
125-
126111
const onCancel = () => {
127112
history.push(`/admin/dashboard/edit/${dashboardId}`);
128113
};
@@ -234,15 +219,6 @@ function EditDetails() {
234219
</label>
235220
</div>
236221
</div>
237-
<div className="grid-col text-right">
238-
<Button
239-
variant="outline"
240-
disabled={!displayTableOfContents}
241-
onClick={onTableOfContentsEdit}
242-
>
243-
{t("Edit")}
244-
</Button>
245-
</div>
246222
</div>
247223
</div>
248224

0 commit comments

Comments
 (0)