Render tabel cells with multiple data items as RowListItem

This commit is contained in:
Simon Li
2023-04-14 23:41:10 +01:00
parent 00c782fd40
commit 21cee1be31
2 changed files with 23 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, Fragment } from "react";
import { useSelector, useDispatch } from "react-redux";
import { debounce } from "lodash";
import PropTypes from "prop-types";
@@ -29,6 +29,13 @@ const AccessServerButton = ({ url }) => (
</a>
);
const RowListItem = ({ text }) => (
<span className="server-dashboard-row-list-item">{text}</span>
);
RowListItem.propTypes = {
text: PropTypes.string,
};
const ServerDashboard = (props) => {
let base_url = window.base_url || "/";
// sort methods
@@ -236,8 +243,13 @@ const ServerDashboard = (props) => {
break;
}
if (Array.isArray(value)) {
// cast arrays (e.g. roles, groups) to string
value = value.sort().join(", ");
value = (
<Fragment>
{value.sort().flatMap((v) => (
<RowListItem text={v} />
))}
</Fragment>
);
}
result[key] = value;
return result;
@@ -254,7 +266,6 @@ const ServerDashboard = (props) => {
}}
valueStyle={{
padding: "4px",
whiteSpace: "unset",
}}
data={sortedData}
/>

View File

@@ -30,3 +30,11 @@
tr.noborder > td {
border: none !important;
}
.server-dashboard-row-list-item {
display: inline-block;
padding: 0 5px;
margin: 2px;
border: 1px solid #ddd;
border-radius: 2px;
}