From ad61c238738e36f3ee13f101ee24e3c06621693c Mon Sep 17 00:00:00 2001 From: Diogo Castro Date: Sun, 14 May 2023 12:36:05 +0200 Subject: [PATCH 1/3] Allow deletion of named servers --- .../ServerDashboard/ServerDashboard.jsx | 70 ++++++++++++++++--- jsx/src/util/withAPI.js | 10 ++- 2 files changed, 68 insertions(+), 12 deletions(-) diff --git a/jsx/src/components/ServerDashboard/ServerDashboard.jsx b/jsx/src/components/ServerDashboard/ServerDashboard.jsx index d177fb98..616f5a68 100644 --- a/jsx/src/components/ServerDashboard/ServerDashboard.jsx +++ b/jsx/src/components/ServerDashboard/ServerDashboard.jsx @@ -45,11 +45,11 @@ const ServerDashboard = (props) => { adminAsc = (e) => e.sort((a) => (a.admin ? 1 : -1)), dateDesc = (e) => e.sort((a, b) => - new Date(a.last_activity) - new Date(b.last_activity) > 0 ? -1 : 1, + new Date(a.last_activity) - new Date(b.last_activity) > 0 ? -1 : 1 ), dateAsc = (e) => e.sort((a, b) => - new Date(a.last_activity) - new Date(b.last_activity) > 0 ? 1 : -1, + new Date(a.last_activity) - new Date(b.last_activity) > 0 ? 1 : -1 ), runningAsc = (e) => e.sort((a) => (a.server == null ? -1 : 1)), runningDesc = (e) => e.sort((a) => (a.server == null ? 1 : -1)); @@ -74,6 +74,7 @@ const ServerDashboard = (props) => { shutdownHub, startServer, stopServer, + deleteServer, startAll, stopAll, history, @@ -143,7 +144,7 @@ const ServerDashboard = (props) => { dispatchPageUpdate( data.items, data._pagination, - name_filter, + name_filter ); }) .catch(() => { @@ -167,6 +168,50 @@ const ServerDashboard = (props) => { ); }; + const DeleteServerButton = ({ serverName, userName }) => { + if (serverName === "") { + return null; + } + var [isDisabled, setIsDisabled] = useState(false); + return ( + + ); + }; + const StartServerButton = ({ serverName, userName }) => { var [isDisabled, setIsDisabled] = useState(false); return ( @@ -183,7 +228,7 @@ const ServerDashboard = (props) => { dispatchPageUpdate( data.items, data._pagination, - name_filter, + name_filter ); }) .catch(() => { @@ -324,6 +369,10 @@ const ServerDashboard = (props) => { userName={user.name} style={{ marginRight: 20 }} /> + { failedServers.length > 1 ? "servers" : "server" }. ${ failedServers.length > 1 ? "Are they " : "Is it " - } already running?`, + } already running?` ); } return res; @@ -494,11 +543,11 @@ const ServerDashboard = (props) => { dispatchPageUpdate( data.items, data._pagination, - name_filter, + name_filter ); }) .catch(() => - setErrorAlert(`Failed to update users list.`), + setErrorAlert(`Failed to update users list.`) ); return res; }) @@ -523,7 +572,7 @@ const ServerDashboard = (props) => { failedServers.length > 1 ? "servers" : "server" }. ${ failedServers.length > 1 ? "Are they " : "Is it " - } already stopped?`, + } already stopped?` ); } return res; @@ -534,11 +583,11 @@ const ServerDashboard = (props) => { dispatchPageUpdate( data.items, data._pagination, - name_filter, + name_filter ); }) .catch(() => - setErrorAlert(`Failed to update users list.`), + setErrorAlert(`Failed to update users list.`) ); return res; }) @@ -582,6 +631,7 @@ ServerDashboard.propTypes = { shutdownHub: PropTypes.func, startServer: PropTypes.func, stopServer: PropTypes.func, + deleteServer: PropTypes.func, startAll: PropTypes.func, stopAll: PropTypes.func, dispatch: PropTypes.func, diff --git a/jsx/src/util/withAPI.js b/jsx/src/util/withAPI.js index 28cb25d8..abce6a5f 100644 --- a/jsx/src/util/withAPI.js +++ b/jsx/src/util/withAPI.js @@ -7,17 +7,23 @@ const withAPI = withProps(() => ({ `/users?include_stopped_servers&offset=${offset}&limit=${limit}&name_filter=${ name_filter || "" }`, - "GET", + "GET" ).then((data) => data.json()), updateGroups: (offset, limit) => jhapiRequest(`/groups?offset=${offset}&limit=${limit}`, "GET").then( - (data) => data.json(), + (data) => data.json() ), shutdownHub: () => jhapiRequest("/shutdown", "POST"), startServer: (name, serverName = "") => jhapiRequest("/users/" + name + "/servers/" + (serverName || ""), "POST"), stopServer: (name, serverName = "") => jhapiRequest("/users/" + name + "/servers/" + (serverName || ""), "DELETE"), + deleteServer: (name, serverName = "") => + jhapiRequest( + "/users/" + name + "/servers/" + (serverName || ""), + "DELETE", + { remove: true } + ), startAll: (names) => names.map((e) => jhapiRequest("/users/" + e + "/server", "POST")), stopAll: (names) => From 9d68107722f45290f64dcae2f16c243524591ffe Mon Sep 17 00:00:00 2001 From: Diogo Castro Date: Sun, 14 May 2023 18:23:52 +0200 Subject: [PATCH 2/3] Add test case for named servers Adapt all tests --- .../ServerDashboard/ServerDashboard.jsx | 6 +- .../ServerDashboard/ServerDashboard.test.js | 107 ++++++++++++------ 2 files changed, 79 insertions(+), 34 deletions(-) diff --git a/jsx/src/components/ServerDashboard/ServerDashboard.jsx b/jsx/src/components/ServerDashboard/ServerDashboard.jsx index 616f5a68..260ddb7f 100644 --- a/jsx/src/components/ServerDashboard/ServerDashboard.jsx +++ b/jsx/src/components/ServerDashboard/ServerDashboard.jsx @@ -323,7 +323,11 @@ const ServerDashboard = (props) => { const userServerName = user.name + serverNameDash; const open = collapseStates[userServerName] || false; return [ - +