forked from os2display/display-api-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroups-columns.jsx
More file actions
83 lines (74 loc) · 2.34 KB
/
Copy pathgroups-columns.jsx
File metadata and controls
83 lines (74 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { useTranslation } from "react-i18next";
import ColumnHoc from "../util/column-hoc";
import SelectColumnHoc from "../util/select-column-hoc";
import useModal from "../../context/modal-context/modal-context-hook.jsx";
import { useDispatch } from "react-redux";
import idFromUrl from "../util/helpers/id-from-url.jsx";
import getAllPages from "../util/helpers/get-all-pages.js";
import { Link } from "react-router-dom";
import { Button } from "react-bootstrap";
import { enhancedApi } from "../../redux/enhanced-api.ts";
function ScreensButton({ group }) {
const { t } = useTranslation("common", { keyPrefix: "groups-columns" });
const { setModal } = useModal();
const dispatch = useDispatch();
const onClick = () => {
getAllPages(dispatch, enhancedApi.endpoints.getV2ScreenGroupsByIdScreens, {
id: idFromUrl(group.id),
}).then((screens) => {
const content = (
<ul>
{screens.map((screen) => (
<li key={screen["@id"]}>
<Link
to={`screen/edit/${idFromUrl(screen["@id"])}`}
target="_blank"
>
{screen.title}
</Link>
</li>
))}
</ul>
);
setModal({
info: true,
modalTitle: t("screens-modal-title"),
content,
});
});
};
return (
<Button
variant="secondary"
type="button"
onClick={onClick}
disabled={group.screensLength === 0}
>
{group.screensLength}
</Button>
);
}
/**
* Columns for group lists.
*
* @param {object} props - The props.
* @param {Function} props.apiCall - The api to call
* @param {string} props.infoModalRedirect - The url for redirecting in the info modal.
* @param {string} props.infoModalTitle - The info modal title.
* @returns {object} The columns for the group lists.
*/
function getGroupColumns({ apiCall, infoModalRedirect, infoModalTitle }) {
const { t } = useTranslation("common", { keyPrefix: "groups-columns" });
const columns = [
{
// eslint-disable-next-line react/prop-types
content: (group) => <ScreensButton group={group} />,
key: "screens",
label: t("screens"),
},
];
return columns;
}
const GroupColumns = ColumnHoc(getGroupColumns);
const SelectGroupColumns = SelectColumnHoc(getGroupColumns);
export { SelectGroupColumns, GroupColumns };