forked from uyuni-project/uyuni
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage-stores.tsx
More file actions
251 lines (231 loc) · 6.98 KB
/
image-stores.tsx
File metadata and controls
251 lines (231 loc) · 6.98 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import * as React from "react";
import SpaRenderer from "core/spa/spa-renderer";
import { AsyncButton, LinkButton } from "components/buttons";
import { DeleteDialog } from "components/dialog/DeleteDialog";
import { ModalButton } from "components/dialog/ModalButton";
import { Messages } from "components/messages";
import { TopPanel } from "components/panels/TopPanel";
import { Column } from "components/table/Column";
import { SearchField } from "components/table/SearchField";
import { Table } from "components/table/Table";
import { Utils } from "utils/functions";
import { DEPRECATED_unsafeEquals } from "utils/legacy";
import Network from "utils/network";
// See java/code/src/com/suse/manager/webui/templates/content_management/list-stores.jade
declare global {
interface Window {
isAdmin?: any;
}
}
const msgMap = {
not_found: t("Image store cannot be found."),
delete_success: t("Image store has been deleted."),
delete_success_p: t("Image stores have been deleted."),
};
const typeMap = {
registry: "Registry",
os_image: "OS Image",
};
type Props = {};
type State = {
messages: any;
imagestores: any;
selectedItems: any;
selected?: any;
};
class ImageStores extends React.Component<Props, State> {
constructor(props) {
super(props);
this.state = {
messages: [],
imagestores: [],
selectedItems: [],
};
}
componentDidMount() {
this.reloadData();
}
searchData(row, criteria) {
if (criteria) {
return row.label.toLocaleLowerCase().includes(criteria.toLocaleLowerCase());
}
return true;
}
reloadData = () => {
Network.get("/rhn/manager/api/cm/imagestores").then((data) => {
this.setState({
imagestores: data,
});
});
this.clearMessages();
};
clearMessages() {
this.setState({
messages: undefined,
});
}
handleSelectItems = (items) => {
this.setState({
selectedItems: items,
});
};
selectStore = (row) => {
this.setState({
selected: row,
});
};
deleteStores = (idList) => {
return Network.post("/rhn/manager/api/cm/imagestores/delete", idList).then((data) => {
if (data.success) {
this.setState({
messages: (
<Messages
items={[
{
severity: "success",
text: msgMap[idList.length > 1 ? "delete_success_p" : "delete_success"],
},
]}
/>
),
imagestores: this.state.imagestores.filter((store) => !idList.includes(store.id)),
selectedItems: this.state.selectedItems.filter((item) => !idList.includes(item)),
});
} else {
this.setState({
messages: (
<Messages
items={data.messages.map((msg) => {
return { severity: "error", text: msgMap[msg] };
})}
/>
),
});
}
});
};
isFiltered(criteria) {
return criteria && criteria.length > 0;
}
render() {
const panelButtons = (
<div className="pull-right btn-group">
{window.isAdmin && this.state.selectedItems.length > 0 && (
<ModalButton
id="delete-selected"
icon="fa-trash"
className="btn-default"
text={t("Delete")}
title={t("Delete selected")}
target="delete-selected-modal"
/>
)}
{window.isAdmin && (
<LinkButton
id="create"
icon="fa-plus"
className="btn-default"
title={t("Create")}
text={t("Create")}
href="/rhn/manager/cm/imagestores/create"
/>
)}
<AsyncButton id="reload" icon="fa-refresh" text={t("Refresh")} action={this.reloadData} />
</div>
);
return (
<span>
<TopPanel
title={t("Image Stores")}
icon="fa-list"
helpUrl="reference/images/images-stores.html"
button={panelButtons}
>
{this.state.messages}
<Table
data={this.state.imagestores}
identifier={(imagestore) => imagestore.id}
initialSortColumnKey="id"
searchField={<SearchField filter={this.searchData} />}
selectable
selectedItems={this.state.selectedItems}
onSelect={this.handleSelectItems}
>
<Column
columnKey="label"
width="50%"
comparator={Utils.sortByText}
header={t("Label")}
cell={(row) => row.label}
/>
<Column
columnKey="type"
width="35%"
comparator={Utils.sortByText}
header={t("Type")}
cell={(row) => typeMap[row.type]}
/>
{window.isAdmin && (
<Column
width="15%"
columnClass="text-right"
headerClass="text-right"
header={t("Actions")}
cell={(row) => {
return (
<div className="btn-group">
<LinkButton
className="btn-default btn-sm"
title={t("Edit")}
icon="fa-edit"
href={"/rhn/manager/cm/imagestores/edit/" + row.id}
/>
<ModalButton
className="btn-default btn-sm"
title={t("Delete")}
icon="fa-trash"
target="delete-modal"
item={row}
onClick={this.selectStore}
/>
</div>
);
}}
/>
)}
</Table>
</TopPanel>
<DeleteDialog
id="delete-modal"
title={t("Delete Store")}
content={
<span>
{t("Are you sure you want to delete store")}{" "}
<strong>{this.state.selected ? this.state.selected.label : ""}</strong>?
</span>
}
item={this.state.selected}
onConfirm={(item) => this.deleteStores([item.id])}
onClosePopUp={() => this.selectStore(undefined)}
/>
<DeleteDialog
id="delete-selected-modal"
title={t("Delete Selected Store(s)")}
content={
<span>
{DEPRECATED_unsafeEquals(this.state.selectedItems.length, 1)
? t("Are you sure you want to delete the selected store?")
: t(
"Are you sure you want to delete selected stores? ({0} stores selected)",
this.state.selectedItems.length
)}
</span>
}
onConfirm={() => this.deleteStores(this.state.selectedItems)}
/>
</span>
);
}
}
export const renderer = () =>
SpaRenderer.renderNavigationReact(<ImageStores />, document.getElementById("image-stores"));