-
Notifications
You must be signed in to change notification settings - Fork 181
/
list.tsx
180 lines (168 loc) · 5.43 KB
/
list.tsx
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import * as React from "react";
import { useRef } from "react";
import { AsyncButton } from "components/buttons";
import { ActionConfirm } from "components/dialog/ActionConfirm";
import { IconTag } from "components/icontag";
import { Form, Radio, Select } from "components/input";
import { Column } from "components/table/Column";
import { SearchField } from "components/table/SearchField";
import { Table, TableRef } from "components/table/Table";
import { MessagesContainer, showSuccessToastr } from "components/toastr/toastr";
import { Utils } from "utils/functions";
import Network from "utils/network";
type Props = {
/** Locale of the help links */
docsLocale: string;
/** List of selected package ids */
selected: Array<string>;
/** The entry to select in the channel field */
selectedChannel: string | null;
};
export function PackageList(props: Props) {
const [open, setOpen] = React.useState(false);
const [selectedPackages, setSelectedPackages] = React.useState<string[]>(props.selected);
const [formModel, setFormModel] = React.useState<object>({ binary: "binary", channel: props.selectedChannel });
const [channels, setChannels] = React.useState([]);
const tableRef = useRef<TableRef>(null);
React.useEffect(() => {
let ignore = false;
Network.get("/rhn/manager/api/channels/owned")
.then((resp) => {
if (!ignore) {
setChannels(
resp.data.map((c) => {
return {
value: `channel/${c["id"]}`,
label: c["name"],
hasParent: c["parentId"] != null,
};
})
);
}
})
.catch(Network.showResponseErrorToastr);
return () => {
ignore = true;
};
}, []);
const handleSelectedPackages = (items: string[]) => {
setSelectedPackages(items);
};
const deleteSelected = () => {
Network.post("/rhn/manager/api/packages/delete", selectedPackages)
.then(() => {
setSelectedPackages([]);
tableRef.current?.refresh();
showSuccessToastr("Selected package(s) removed");
})
.catch(Network.showResponseErrorToastr);
};
const deleteButton = [
<AsyncButton
key="delete-btn"
defaultType="btn-warning"
text={t("Delete")}
icon="fa-trash"
action={() => setOpen(true)}
disabled={selectedPackages.length === 0}
/>,
];
const selectOptions = [
{ value: "orphans", label: t("Packages in no channel") },
{ value: "all", label: t("All managed packages") },
].concat(channels);
return (
<>
<MessagesContainer />
<h1>
<IconTag type="header-package" />
{t(" Package Management ")}
<a
href={`/docs/${props.docsLocale}/reference/software/manage-packages.html`}
target="_blank"
rel="noopener noreferrer"
>
<IconTag type="header-help" />
</a>
</h1>
<Form model={formModel} onChange={(model: object) => setFormModel({ ...model })}>
<Select
name="channel"
label={t("Channel")}
required
options={selectOptions}
labelClass="col-lg-3"
divClass="col-lg-6"
formatOptionLabel={(option, { context }) => {
const prefix = option.hasParent && context === "menu" ? "⤷" : "";
return `${prefix}${option.label}`;
}}
/>
<Radio
name="binary"
inline={true}
divClass="col-lg-offset-3 offset-lg-3 col-lg-6"
items={[
{ label: t("Binary packages"), value: "binary" },
{ label: t("Source packages"), value: "source" },
]}
/>
</Form>
<ActionConfirm
id="confirmModal"
type="remove"
name={t("Delete")}
itemName={t("package")}
icon="fa-trash"
selected={selectedPackages}
onConfirm={deleteSelected}
canForce={false}
isOpen={open}
onClose={() => setOpen(false)}
/>
{formModel["channel"] != null && formModel["channel"] !== "" && (
<Table
ref={tableRef}
data={`/rhn/manager/api/packages/list/${formModel["binary"]}/${formModel["channel"]}`}
identifier={(item) => item.id}
initialSortColumnKey="nvrea"
selectable={(item) => item.hasOwnProperty("id")}
selectedItems={selectedPackages}
onSelect={handleSelectedPackages}
searchField={<SearchField placeholder={t("Filter by package name")} />}
defaultSearchField={"nvrea"}
emptyText={t("No Packages.")}
titleButtons={deleteButton}
>
<Column
columnKey="nvrea"
comparator={Utils.sortByText}
header={t("Package")}
cell={(item) => <a href={`/rhn/software/packages/Details.do?pid=${item.id}`}>{item.nvrea}</a>}
/>
<Column
columnKey="channels"
comparator={Utils.sortByText}
header={t("Channels")}
sortable={false}
cell={(item) =>
item.packageChannels.map((c) => (
<>
{c.name}
<br />
</>
))
}
/>
<Column
columnKey="provider"
comparator={Utils.sortByText}
header={t("Content Provider")}
sortable={false}
cell={(item) => item.provider}
/>
</Table>
)}
</>
);
}