diff --git a/assets/src/bundles/add_forge/moderation-dashboard.js b/assets/src/bundles/add_forge/moderation-dashboard.js
--- a/assets/src/bundles/add_forge/moderation-dashboard.js
+++ b/assets/src/bundles/add_forge/moderation-dashboard.js
@@ -5,7 +5,7 @@
* See top-level LICENSE file for more information
*/
-import {getHumanReadableDate} from 'utils/functions';
+import {getHumanReadableDate, genLink} from 'utils/functions';
export function onModerationPageLoad() {
populateModerationList();
@@ -48,7 +48,9 @@
{
data: 'forge_url',
name: 'forge_url',
- render: $.fn.dataTable.render.text()
+ render: (data, type, row) => {
+ return genLink(data, type, true);
+ }
},
{
data: 'last_moderator',
diff --git a/assets/src/bundles/admin/deposit.js b/assets/src/bundles/admin/deposit.js
--- a/assets/src/bundles/admin/deposit.js
+++ b/assets/src/bundles/admin/deposit.js
@@ -5,7 +5,7 @@
* See top-level LICENSE file for more information
*/
-import {getHumanReadableDate} from 'utils/functions';
+import {getHumanReadableDate, genLink} from 'utils/functions';
function genSwhLink(data, type, linkText = '') {
if (type === 'display' && data && data.startsWith('swh')) {
@@ -19,21 +19,6 @@
return data;
}
-function genLink(data, type, openInNewTab = false, linkText = '') {
- if (type === 'display' && data) {
- const sData = encodeURI(data);
- if (!linkText) {
- linkText = sData;
- }
- let attrs = '';
- if (openInNewTab) {
- attrs = 'target="_blank" rel="noopener noreferrer"';
- }
- return `${linkText}`;
- }
- return data;
-}
-
export function initDepositAdmin(username, isStaff) {
let depositsTable;
$(document).ready(() => {
diff --git a/assets/src/utils/functions.js b/assets/src/utils/functions.js
--- a/assets/src/utils/functions.js
+++ b/assets/src/utils/functions.js
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2018-2020 The Software Heritage developers
+ * Copyright (C) 2018-2022 The Software Heritage developers
* See the AUTHORS file at the top-level directory of this distribution
* License: GNU Affero General Public License version 3, or any later version
* See top-level LICENSE file for more information
@@ -166,3 +166,19 @@
const date = new Date(data);
return date.toLocaleString();
}
+
+export function genLink(data, type, openInNewTab = false, linkText = '') {
+ // Display link
+ if (type === 'display' && data) {
+ const sanitizedUrl = encodeURI(data);
+ if (!linkText) {
+ linkText = sanitizedUrl;
+ }
+ let attrs = '';
+ if (openInNewTab) {
+ attrs = 'target="_blank" rel="noopener noreferrer"';
+ }
+ return `${linkText}`;
+ }
+ return data;
+}