| 1 |
import React, { useEffect, useState } from "react"; |
| 2 |
// PatternFly |
| 3 |
import { |
| 4 |
DropdownItem, |
| 5 |
Flex, |
| 6 |
FlexItem, |
| 7 |
PageSection, |
| 8 |
PaginationVariant, |
| 9 |
ToolbarItemVariant, |
| 10 |
} from "@patternfly/react-core"; |
| 11 |
import { |
| 12 |
InnerScrollContainer, |
| 13 |
OuterScrollContainer, |
| 14 |
} from "@patternfly/react-table"; |
| 15 |
// Layouts |
| 16 |
import DualListLayout from "src/components/layouts/DualListLayout"; |
| 17 |
import TitleLayout from "src/components/layouts/TitleLayout"; |
| 18 |
import KebabLayout from "src/components/layouts/KebabLayout"; |
| 19 |
import ToolbarLayout, { |
| 20 |
ToolbarItem, |
| 21 |
} from "src/components/layouts/ToolbarLayout"; |
| 22 |
import SearchInputLayout from "src/components/layouts/SearchInputLayout"; |
| 23 |
import SecondaryButton from "src/components/layouts/SecondaryButton"; |
| 24 |
import HelpTextWithIconLayout from "src/components/layouts/HelpTextWithIconLayout"; |
| 25 |
// Components |
| 26 |
import BulkSelectorPrep from "src/components/BulkSelectorPrep"; |
| 27 |
import PaginationLayout from "src/components/layouts/PaginationLayout"; |
| 28 |
// Tables |
| 29 |
import IDViewsTable from "src/pages/IDViews/IDViewsTable"; |
| 30 |
// Modal |
| 31 |
import AddIDViewModal from "src/components/modals/AddIDView"; |
| 32 |
import DeleteIDViewsModal from "src/components/modals/DeleteIDViews"; |
| 33 |
// Redux |
| 34 |
import { useAppSelector, useAppDispatch } from "src/store/hooks"; |
| 35 |
// Data types |
| 36 |
import { IDView } from "src/utils/datatypes/globalDataTypes"; |
| 37 |
// Utils |
| 38 |
import { API_VERSION_BACKUP, isViewSelectable } from "src/utils/utils"; |
| 39 |
// Hooks |
| 40 |
import { addAlert } from "src/store/Global/alerts-slice"; |
| 41 |
import useUpdateRoute from "src/hooks/useUpdateRoute"; |
| 42 |
import useListPageSearchParams from "src/hooks/useListPageSearchParams"; |
| 43 |
// Errors |
| 44 |
import { FetchBaseQueryError } from "@reduxjs/toolkit/query"; |
| 45 |
import { SerializedError } from "@reduxjs/toolkit"; |
| 46 |
import useApiError from "src/hooks/useApiError"; |
| 47 |
import GlobalErrors from "src/components/errors/GlobalErrors"; |
| 48 |
import ModalErrors from "src/components/errors/ModalErrors"; |
| 49 |
// RPC client |
| 50 |
import { |
| 51 |
ErrorResult, |
| 52 |
GenericPayload, |
| 53 |
useSearchEntriesMutation, |
| 54 |
} from "../../services/rpc"; |
| 55 |
import { |
| 56 |
useGettingIDViewsQuery, |
| 57 |
useUnapplyHostsMutation, |
| 58 |
useUnapplyHostgroupsMutation, |
| 59 |
} from "../../services/rpcIDViews"; |
| 60 |
|
| 61 |
const IDViews = () => { |
| 62 |
const dispatch = useAppDispatch(); |
| 63 |
|
| 64 |
// Update current route data to Redux and highlight the current page in the Nav bar |
| 65 |
const { browserTitle } = useUpdateRoute({ pathname: "id-views" }); |
| 66 |
|
| 67 |
// API |
| 68 |
const [executeUnapplyHosts] = useUnapplyHostsMutation(); |
| 69 |
const [executeUnapplyHostgroups] = useUnapplyHostgroupsMutation(); |
| 70 |
|
| 71 |
// Set the page title to be shown in the browser tab |
| 72 |
React.useEffect(() => { |
| 73 |
document.title = browserTitle; |
| 74 |
}, [browserTitle]); |
| 75 |
|
| 76 |
// Retrieve API version from environment data |
| 77 |
const apiVersion = useAppSelector( |
| 78 |
(state) => state.global.environment.api_version |
| 79 |
) as string; |
| 80 |
|
| 81 |
// Initialize views (Redux) |
| 82 |
const [viewsList, setViewsList] = useState<IDView[]>([]); |
| 83 |
|
| 84 |
// URL parameters: page number, page size, search value |
| 85 |
const { page, setPage, perPage, setPerPage, searchValue, setSearchValue } = |
| 86 |
useListPageSearchParams(); |
| 87 |
|
| 88 |
// Handle API calls errors |
| 89 |
const globalErrors = useApiError([]); |
| 90 |
const modalErrors = useApiError([]); |
| 91 |
|
| 92 |
// Table comps |
| 93 |
const [selectedPerPage, setSelectedPerPage] = useState<number>(0); |
| 94 |
const [totalCount, setViewsTotalCount] = useState<number>(0); |
| 95 |
const [searchDisabled, setSearchIsDisabled] = useState<boolean>(false); |
| 96 |
|
| 97 |
const updateSelectedPerPage = (selected: number) => { |
| 98 |
setSelectedPerPage(selected); |
| 99 |
}; |
| 100 |
const updatePage = (newPage: number) => { |
| 101 |
setPage(newPage); |
| 102 |
}; |
| 103 |
const updatePerPage = (newSetPerPage: number) => { |
| 104 |
setPerPage(newSetPerPage); |
| 105 |
}; |
| 106 |
|
| 107 |
// 'Delete' button state |
| 108 |
const [isDeleteButtonDisabled, setIsDeleteButtonDisabled] = |
| 109 |
useState<boolean>(true); |
| 110 |
|
| 111 |
const updateIsDeleteButtonDisabled = (value: boolean) => { |
| 112 |
setIsDeleteButtonDisabled(value); |
| 113 |
}; |
| 114 |
|
| 115 |
// If some entries have been deleted, restore the selected views list |
| 116 |
const [isDeletion, setIsDeletion] = useState(false); |
| 117 |
|
| 118 |
const updateIsDeletion = (value: boolean) => { |
| 119 |
setIsDeletion(value); |
| 120 |
}; |
| 121 |
|
| 122 |
const updateShownViewsList = (newShownViewsList: IDView[]) => { |
| 123 |
setViewsList(newShownViewsList); |
| 124 |
}; |
| 125 |
|
| 126 |
// Page indexes |
| 127 |
const firstIdx = (page - 1) * perPage; |
| 128 |
const lastIdx = page * perPage; |
| 129 |
|
| 130 |
// Derived states - what we get from API |
| 131 |
const viewsDataResponse = useGettingIDViewsQuery({ |
| 132 |
searchValue: "", |
| 133 |
sizeLimit: 0, |
| 134 |
apiVersion: apiVersion || API_VERSION_BACKUP, |
| 135 |
startIdx: firstIdx, |
| 136 |
stopIdx: lastIdx, |
| 137 |
} as GenericPayload); |
| 138 |
|
| 139 |
const { |
| 140 |
data: batchResponse, |
| 141 |
isLoading: isBatchLoading, |
| 142 |
error: batchError, |
| 143 |
} = viewsDataResponse; |
| 144 |
|
| 145 |
// Handle data when the API call is finished |
| 146 |
useEffect(() => { |
| 147 |
if (viewsDataResponse.isFetching) { |
| 148 |
setShowTableRows(false); |
| 149 |
// Reset selected ID views on refresh |
| 150 |
setViewsTotalCount(0); |
| 151 |
globalErrors.clear(); |
| 152 |
return; |
| 153 |
} |
| 154 |
|
| 155 |
// API response: Success |
| 156 |
if ( |
| 157 |
viewsDataResponse.isSuccess && |
| 158 |
viewsDataResponse.data && |
| 159 |
batchResponse !== undefined |
| 160 |
) { |
| 161 |
const viewsListResult = batchResponse.result.results; |
| 162 |
const totalCount = batchResponse.result.totalCount; |
| 163 |
const viewsListSize = batchResponse.result.count; |
| 164 |
const idViewsList: IDView[] = []; |
| 165 |
|
| 166 |
for (let i = 0; i < viewsListSize; i++) { |
| 167 |
idViewsList.push(viewsListResult[i].result); |
| 168 |
} |
| 169 |
|
| 170 |
setViewsList(idViewsList); |
| 171 |
setViewsTotalCount(totalCount); |
| 172 |
setIsKebabOpen(false); |
| 173 |
setShowTableRows(true); |
| 174 |
} |
| 175 |
|
| 176 |
// API response: Error |
| 177 |
if ( |
| 178 |
!viewsDataResponse.isLoading && |
| 179 |
viewsDataResponse.isError && |
| 180 |
viewsDataResponse.error !== undefined |
| 181 |
) { |
| 182 |
// This normally happens when the user is not authorized to view the data |
| 183 |
// So instead of adding an error, refresh page |
| 184 |
window.location.reload(); |
| 185 |
} |
| 186 |
}, [viewsDataResponse]); |
| 187 |
|
| 188 |
// Always refetch data when the component is loaded. |
| 189 |
// This ensures the data is always up-to-date. |
| 190 |
useEffect(() => { |
| 191 |
viewsDataResponse.refetch(); |
| 192 |
setIsKebabOpen(false); |
| 193 |
}, [page, perPage]); |
| 194 |
|
| 195 |
// Refresh button handling |
| 196 |
const refreshViewsData = () => { |
| 197 |
// Hide table |
| 198 |
setShowTableRows(false); |
| 199 |
|
| 200 |
// Reset selected views on refresh |
| 201 |
setViewsTotalCount(0); |
| 202 |
clearSelectedViews(); |
| 203 |
setPage(1); |
| 204 |
viewsDataResponse.refetch(); |
| 205 |
}; |
| 206 |
|
| 207 |
const updateSearchValue = (value: string) => { |
| 208 |
setSearchValue(value); |
| 209 |
}; |
| 210 |
|
| 211 |
const [selectedViews, setSelectedViewsList] = useState<IDView[]>([]); |
| 212 |
const clearSelectedViews = () => { |
| 213 |
const emptyList: IDView[] = []; |
| 214 |
setSelectedViewsList(emptyList); |
| 215 |
}; |
| 216 |
|
| 217 |
const [retrieveViews] = useSearchEntriesMutation({}); |
| 218 |
|
| 219 |
// Issue a search using a specific search value |
| 220 |
const submitSearchValue = () => { |
| 221 |
setShowTableRows(false); |
| 222 |
setViewsTotalCount(0); |
| 223 |
setSearchIsDisabled(true); |
| 224 |
retrieveViews({ |
| 225 |
searchValue: searchValue, |
| 226 |
sizeLimit: 0, |
| 227 |
apiVersion: apiVersion || API_VERSION_BACKUP, |
| 228 |
startIdx: firstIdx, |
| 229 |
stopIdx: lastIdx, |
| 230 |
entryType: "idview", |
| 231 |
} as GenericPayload).then((result) => { |
| 232 |
// Manage new response here |
| 233 |
if ("data" in result) { |
| 234 |
const searchError = result.data?.error as |
| 235 |
| FetchBaseQueryError |
| 236 |
| SerializedError; |
| 237 |
|
| 238 |
if (searchError) { |
| 239 |
// Error |
| 240 |
let error: string | undefined = ""; |
| 241 |
if ("error" in searchError) { |
| 242 |
error = searchError.error; |
| 243 |
} else if ("message" in searchError) { |
| 244 |
error = searchError.message; |
| 245 |
} |
| 246 |
dispatch( |
| 247 |
addAlert({ |
| 248 |
name: "submit-search-value-error", |
| 249 |
title: error || "Error when searching for ID views", |
| 250 |
variant: "danger", |
| 251 |
}) |
| 252 |
); |
| 253 |
} else { |
| 254 |
// Success |
| 255 |
const viewsListResult = result.data?.result.results || []; |
| 256 |
const viewsListSize = result.data?.result.count || 0; |
| 257 |
const totalCount = result.data?.result.totalCount || 0; |
| 258 |
const idViewsList: IDView[] = []; |
| 259 |
|
| 260 |
for (let i = 0; i < viewsListSize; i++) { |
| 261 |
idViewsList.push(viewsListResult[i].result); |
| 262 |
} |
| 263 |
|
| 264 |
setPage(1); |
| 265 |
setViewsList(idViewsList); |
| 266 |
setViewsTotalCount(totalCount); |
| 267 |
setIsKebabOpen(false); |
| 268 |
setShowTableRows(true); |
| 269 |
} |
| 270 |
setSearchIsDisabled(false); |
| 271 |
} |
| 272 |
}); |
| 273 |
}; |
| 274 |
|
| 275 |
// Show table rows |
| 276 |
const [showTableRows, setShowTableRows] = useState(!isBatchLoading); |
| 277 |
|
| 278 |
const updateSelectedViews = (views: IDView[], isSelected: boolean) => { |
| 279 |
let newSelectedViews: IDView[] = []; |
| 280 |
if (isSelected) { |
| 281 |
newSelectedViews = JSON.parse(JSON.stringify(selectedViews)); |
| 282 |
for (let i = 0; i < views.length; i++) { |
| 283 |
if ( |
| 284 |
selectedViews.find( |
| 285 |
(selectedView) => selectedView.cn[0] === views[i].cn[0] |
| 286 |
) |
| 287 |
) { |
| 288 |
// Already in the list |
| 289 |
continue; |
| 290 |
} |
| 291 |
// Add view to list |
| 292 |
newSelectedViews.push(views[i]); |
| 293 |
} |
| 294 |
} else { |
| 295 |
// Remove view |
| 296 |
for (let i = 0; i < selectedViews.length; i++) { |
| 297 |
let found = false; |
| 298 |
for (let ii = 0; ii < views.length; ii++) { |
| 299 |
if (selectedViews[i].cn[0] === views[ii].cn[0]) { |
| 300 |
found = true; |
| 301 |
break; |
| 302 |
} |
| 303 |
} |
| 304 |
if (!found) { |
| 305 |
// Keep this valid selected entry |
| 306 |
newSelectedViews.push(selectedViews[i]); |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
setIsKebabOpen(false); |
| 311 |
setSelectedViewsList(newSelectedViews); |
| 312 |
setIsDeleteButtonDisabled(newSelectedViews.length === 0); |
| 313 |
}; |
| 314 |
|
| 315 |
// - Helper method to set the selected views from the table |
| 316 |
const setViewSelected = (view: IDView, isSelecting = true) => { |
| 317 |
if (isViewSelectable(view)) { |
| 318 |
updateSelectedViews([view], isSelecting); |
| 319 |
} |
| 320 |
}; |
| 321 |
|
| 322 |
// Show table rows only when data is fully retrieved |
| 323 |
useEffect(() => { |
| 324 |
if (showTableRows !== !isBatchLoading) { |
| 325 |
setShowTableRows(!isBatchLoading); |
| 326 |
} |
| 327 |
}, [isBatchLoading]); |
| 328 |
|
| 329 |
// Modals functionality |
| 330 |
const [showAddModal, setShowAddModal] = useState(false); |
| 331 |
const [showDeleteModal, setShowDeleteModal] = useState(false); |
| 332 |
|
| 333 |
const onAddClickHandler = () => { |
| 334 |
setIsKebabOpen(false); |
| 335 |
setShowAddModal(true); |
| 336 |
}; |
| 337 |
const onCloseAddModal = () => { |
| 338 |
setShowAddModal(false); |
| 339 |
}; |
| 340 |
const onAddModalToggle = () => { |
| 341 |
setShowAddModal(!showAddModal); |
| 342 |
}; |
| 343 |
|
| 344 |
const onDeleteHandler = () => { |
| 345 |
setIsKebabOpen(false); |
| 346 |
setShowDeleteModal(true); |
| 347 |
}; |
| 348 |
const onDeleteModalToggle = () => { |
| 349 |
setShowDeleteModal(!showDeleteModal); |
| 350 |
}; |
| 351 |
|
| 352 |
// Unapply functions |
| 353 |
const [showHostModal, setShowHostModal] = useState(false); |
| 354 |
const [showHostgroupModal, setShowHostgroupModal] = useState(false); |
| 355 |
const [unapplySpinning, setUnapplySpinning] = useState(false); |
| 356 |
const openUnapplyHostModal = () => { |
| 357 |
setShowHostModal(true); |
| 358 |
}; |
| 359 |
const closeUnapplyHostModal = () => { |
| 360 |
setShowHostModal(false); |
| 361 |
}; |
| 362 |
const openUnapplyHostgroupModal = () => { |
| 363 |
setShowHostgroupModal(true); |
| 364 |
}; |
| 365 |
const closeUnapplyHostgroupModal = () => { |
| 366 |
setShowHostgroupModal(false); |
| 367 |
}; |
| 368 |
|
| 369 |
const onUnapplyHosts = (selectedHosts: string[]) => { |
| 370 |
setUnapplySpinning(true); |
| 371 |
|
| 372 |
// unapply views from hosts |
| 373 |
executeUnapplyHosts(selectedHosts).then((response) => { |
| 374 |
if ("data" in response) { |
| 375 |
if (response.data?.result) { |
| 376 |
dispatch( |
| 377 |
addAlert({ |
| 378 |
name: "unapply-id-views-hosts-success", |
| 379 |
title: |
| 380 |
"ID views unapplied from " + |
| 381 |
response.data.result["completed"] + |
| 382 |
" hosts", |
| 383 |
variant: "success", |
| 384 |
}) |
| 385 |
); |
| 386 |
// Refresh data |
| 387 |
refreshViewsData(); |
| 388 |
} else if (response.data?.error) { |
| 389 |
// Show toast notification: error |
| 390 |
const errorMessage = response.data.error as ErrorResult; |
| 391 |
dispatch( |
| 392 |
addAlert({ |
| 393 |
name: "unapply-id-views-hosts-error", |
| 394 |
title: |
| 395 |
"ID views unapplied from hosts failed: " + errorMessage.message, |
| 396 |
variant: "danger", |
| 397 |
}) |
| 398 |
); |
| 399 |
} |
| 400 |
} |
| 401 |
setIsKebabOpen(false); |
| 402 |
setUnapplySpinning(false); |
| 403 |
closeUnapplyHostModal(); |
| 404 |
}); |
| 405 |
}; |
| 406 |
|
| 407 |
const onUnapplyHostgroups = (selectedHostgroups: string[]) => { |
| 408 |
setUnapplySpinning(true); |
| 409 |
|
| 410 |
// unapply views from host groups |
| 411 |
executeUnapplyHostgroups(selectedHostgroups).then((response) => { |
| 412 |
if ("data" in response) { |
| 413 |
if (response.data?.result) { |
| 414 |
dispatch( |
| 415 |
addAlert({ |
| 416 |
name: "unapply-id-views-hosts-success", |
| 417 |
title: |
| 418 |
"ID views unapplied from " + |
| 419 |
response.data.result["completed"] + |
| 420 |
" hosts", |
| 421 |
variant: "success", |
| 422 |
}) |
| 423 |
); |
| 424 |
// Refresh data |
| 425 |
refreshViewsData(); |
| 426 |
} else if (response.data?.error) { |
| 427 |
// Show toast notification: error |
| 428 |
const errorMessage = response.data.error as ErrorResult; |
| 429 |
dispatch( |
| 430 |
addAlert({ |
| 431 |
name: "unapply-id-views-hosts-error", |
| 432 |
title: |
| 433 |
"ID views unapplied from host groups failed: " + |
| 434 |
errorMessage.message, |
| 435 |
variant: "danger", |
| 436 |
}) |
| 437 |
); |
| 438 |
} |
| 439 |
} |
| 440 |
setIsKebabOpen(false); |
| 441 |
setUnapplySpinning(false); |
| 442 |
closeUnapplyHostgroupModal(); |
| 443 |
}); |
| 444 |
}; |
| 445 |
|
| 446 |
// Table-related shared functionality |
| 447 |
// - Selectable checkboxes on table |
| 448 |
const selectableViewsTable = viewsList.filter(isViewSelectable); // elements per Table |
| 449 |
|
| 450 |
// Data wrappers |
| 451 |
// - 'PaginationLayout' |
| 452 |
const paginationData = { |
| 453 |
page, |
| 454 |
perPage, |
| 455 |
updatePage, |
| 456 |
updatePerPage, |
| 457 |
updateSelectedPerPage, |
| 458 |
updateShownElementsList: updateShownViewsList, |
| 459 |
totalCount, |
| 460 |
}; |
| 461 |
|
| 462 |
// - 'BulkSelectorIDViewPrep' |
| 463 |
const viewsBulkSelectorData = { |
| 464 |
selected: selectedViews, |
| 465 |
updateSelected: updateSelectedViews, |
| 466 |
selectableTable: selectableViewsTable, |
| 467 |
nameAttr: "cn", |
| 468 |
}; |
| 469 |
|
| 470 |
const buttonsData = { |
| 471 |
updateIsDeleteButtonDisabled, |
| 472 |
}; |
| 473 |
|
| 474 |
const selectedPerPageData = { |
| 475 |
selectedPerPage, |
| 476 |
updateSelectedPerPage, |
| 477 |
}; |
| 478 |
|
| 479 |
// - 'Delete Views' |
| 480 |
const deleteViewsButtonsData = { |
| 481 |
updateIsDeleteButtonDisabled, |
| 482 |
updateIsDeletion, |
| 483 |
}; |
| 484 |
|
| 485 |
const selectedViewsData = { |
| 486 |
selectedViews, |
| 487 |
clearSelectedViews, |
| 488 |
}; |
| 489 |
|
| 490 |
// - 'Views Table' |
| 491 |
const viewsTableData = { |
| 492 |
isViewSelectable, |
| 493 |
selectedViews, |
| 494 |
selectableViewsTable, |
| 495 |
setViewSelected, |
| 496 |
clearSelectedViews, |
| 497 |
}; |
| 498 |
|
| 499 |
const viewsTableButtonsData = { |
| 500 |
updateIsDeleteButtonDisabled, |
| 501 |
isDeletion, |
| 502 |
updateIsDeletion, |
| 503 |
}; |
| 504 |
|
| 505 |
// - 'SearchInputLayout' |
| 506 |
const searchValueData = { |
| 507 |
searchValue, |
| 508 |
updateSearchValue, |
| 509 |
submitSearchValue, |
| 510 |
}; |
| 511 |
|
| 512 |
// Keybob for un-apply actions |
| 513 |
const [isKebabOpen, setIsKebabOpen] = React.useState(false); |
| 514 |
const onKebabToggle = () => { |
| 515 |
setIsKebabOpen(!isKebabOpen); |
| 516 |
}; |
| 517 |
const onKebabSelect = ( |
| 518 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 519 |
_event: React.MouseEvent<Element, MouseEvent> | undefined |
| 520 |
) => { |
| 521 |
setIsKebabOpen(!isKebabOpen); |
| 522 |
}; |
| 523 |
const dropdownItems = [ |
| 524 |
<DropdownItem |
| 525 |
data-cy="id-views-kebab-unapply-hosts" |
| 526 |
key="unapply-hosts" |
| 527 |
onClick={openUnapplyHostModal} |
| 528 |
isDisabled={!showTableRows || totalCount === 0} |
| 529 |
> |
| 530 |
Unapply from hosts |
| 531 |
</DropdownItem>, |
| 532 |
<DropdownItem |
| 533 |
data-cy="id-views-kebab-unapply-hostgroups" |
| 534 |
key="unapply-hostgroups" |
| 535 |
onClick={openUnapplyHostgroupModal} |
| 536 |
isDisabled={!showTableRows || totalCount === 0} |
| 537 |
> |
| 538 |
Unapply from host groups |
| 539 |
</DropdownItem>, |
| 540 |
]; |
| 541 |
|
| 542 |
// List of toolbar items |
| 543 |
const toolbarItems: ToolbarItem[] = [ |
| 544 |
{ |
| 545 |
key: 0, |
| 546 |
element: ( |
| 547 |
<BulkSelectorPrep |
| 548 |
list={viewsList} |
| 549 |
shownElementsList={viewsList} |
| 550 |
elementData={viewsBulkSelectorData} |
| 551 |
buttonsData={buttonsData} |
| 552 |
selectedPerPageData={selectedPerPageData} |
| 553 |
/> |
| 554 |
), |
| 555 |
}, |
| 556 |
{ |
| 557 |
key: 1, |
| 558 |
element: ( |
| 559 |
<SearchInputLayout |
| 560 |
dataCy="search" |
| 561 |
name="search" |
| 562 |
ariaLabel="Search ID views" |
| 563 |
placeholder="Search" |
| 564 |
searchValueData={searchValueData} |
| 565 |
isDisabled={searchDisabled} |
| 566 |
/> |
| 567 |
), |
| 568 |
toolbarItemVariant: ToolbarItemVariant.label, |
| 569 |
toolbarItemGap: { default: "gapMd" }, |
| 570 |
}, |
| 571 |
{ |
| 572 |
key: 2, |
| 573 |
toolbarItemVariant: ToolbarItemVariant.separator, |
| 574 |
}, |
| 575 |
{ |
| 576 |
key: 3, |
| 577 |
element: ( |
| 578 |
<SecondaryButton |
| 579 |
dataCy="id-views-button-refresh" |
| 580 |
onClickHandler={refreshViewsData} |
| 581 |
isDisabled={!showTableRows} |
| 582 |
> |
| 583 |
Refresh |
| 584 |
</SecondaryButton> |
| 585 |
), |
| 586 |
}, |
| 587 |
{ |
| 588 |
key: 4, |
| 589 |
element: ( |
| 590 |
<SecondaryButton |
| 591 |
dataCy="id-views-button-delete" |
| 592 |
isDisabled={isDeleteButtonDisabled || !showTableRows} |
| 593 |
onClickHandler={onDeleteHandler} |
| 594 |
> |
| 595 |
Delete |
| 596 |
</SecondaryButton> |
| 597 |
), |
| 598 |
}, |
| 599 |
{ |
| 600 |
key: 5, |
| 601 |
element: ( |
| 602 |
<SecondaryButton |
| 603 |
dataCy="id-views-button-add" |
| 604 |
onClickHandler={onAddClickHandler} |
| 605 |
isDisabled={!showTableRows} |
| 606 |
> |
| 607 |
Add |
| 608 |
</SecondaryButton> |
| 609 |
), |
| 610 |
}, |
| 611 |
{ |
| 612 |
key: 6, |
| 613 |
element: ( |
| 614 |
<KebabLayout |
| 615 |
dataCy="id-views-kebab" |
| 616 |
onDropdownSelect={onKebabSelect} |
| 617 |
onKebabToggle={onKebabToggle} |
| 618 |
idKebab="toggle-action-buttons" |
| 619 |
isKebabOpen={isKebabOpen} |
| 620 |
dropdownItems={dropdownItems} |
| 621 |
isDisabled={!showTableRows} |
| 622 |
/> |
| 623 |
), |
| 624 |
}, |
| 625 |
{ |
| 626 |
key: 7, |
| 627 |
toolbarItemVariant: ToolbarItemVariant.separator, |
| 628 |
}, |
| 629 |
{ |
| 630 |
key: 8, |
| 631 |
element: <HelpTextWithIconLayout textContent="Help" />, |
| 632 |
}, |
| 633 |
{ |
| 634 |
key: 9, |
| 635 |
element: ( |
| 636 |
<PaginationLayout |
| 637 |
list={viewsList} |
| 638 |
paginationData={paginationData} |
| 639 |
widgetId="pagination-options-menu-top" |
| 640 |
isCompact={true} |
| 641 |
/> |
| 642 |
), |
| 643 |
toolbarItemAlignment: { default: "alignEnd" }, |
| 644 |
}, |
| 645 |
]; |
| 646 |
|
| 647 |
return ( |
| 648 |
<div> |
| 649 |
<PageSection hasBodyWrapper={false}> |
| 650 |
<TitleLayout id="Views title" headingLevel="h1" text="ID views" /> |
| 651 |
</PageSection> |
| 652 |
<PageSection hasBodyWrapper={false} isFilled={false}> |
| 653 |
<Flex direction={{ default: "column" }}> |
| 654 |
<FlexItem> |
| 655 |
<ToolbarLayout toolbarItems={toolbarItems} /> |
| 656 |
</FlexItem> |
| 657 |
<FlexItem style={{ flex: "0 0 auto" }}> |
| 658 |
<OuterScrollContainer> |
| 659 |
<InnerScrollContainer |
| 660 |
style={{ height: "60vh", overflow: "auto" }} |
| 661 |
> |
| 662 |
{batchError !== undefined && batchError ? ( |
| 663 |
<GlobalErrors errors={globalErrors.getAll()} /> |
| 664 |
) : ( |
| 665 |
<IDViewsTable |
| 666 |
elementsList={viewsList} |
| 667 |
shownElementsList={viewsList} |
| 668 |
showTableRows={showTableRows} |
| 669 |
idViewsData={viewsTableData} |
| 670 |
buttonsData={viewsTableButtonsData} |
| 671 |
paginationData={selectedPerPageData} |
| 672 |
searchValue={searchValue} |
| 673 |
/> |
| 674 |
)} |
| 675 |
</InnerScrollContainer> |
| 676 |
</OuterScrollContainer> |
| 677 |
</FlexItem> |
| 678 |
<FlexItem style={{ flex: "0 0 auto", position: "sticky", bottom: 0 }}> |
| 679 |
<PaginationLayout |
| 680 |
list={viewsList} |
| 681 |
paginationData={paginationData} |
| 682 |
variant={PaginationVariant.bottom} |
| 683 |
widgetId="pagination-options-menu-bottom" |
| 684 |
/> |
| 685 |
</FlexItem> |
| 686 |
</Flex> |
| 687 |
</PageSection> |
| 688 |
<ModalErrors |
| 689 |
errors={modalErrors.getAll()} |
| 690 |
dataCy="id-views-modal-error" |
| 691 |
/> |
| 692 |
<AddIDViewModal |
| 693 |
show={showAddModal} |
| 694 |
handleModalToggle={onAddModalToggle} |
| 695 |
onOpenAddModal={onAddClickHandler} |
| 696 |
onCloseAddModal={onCloseAddModal} |
| 697 |
onRefresh={refreshViewsData} |
| 698 |
/> |
| 699 |
<DeleteIDViewsModal |
| 700 |
show={showDeleteModal} |
| 701 |
handleModalToggle={onDeleteModalToggle} |
| 702 |
selectedViewsData={selectedViewsData} |
| 703 |
buttonsData={deleteViewsButtonsData} |
| 704 |
onRefresh={refreshViewsData} |
| 705 |
/> |
| 706 |
<DualListLayout |
| 707 |
entry={""} |
| 708 |
target={"host"} |
| 709 |
showModal={showHostModal} |
| 710 |
onCloseModal={closeUnapplyHostModal} |
| 711 |
onOpenModal={openUnapplyHostModal} |
| 712 |
tableElementsList={[]} |
| 713 |
action={onUnapplyHosts} |
| 714 |
title={"Unapply ID views from hosts"} |
| 715 |
spinning={unapplySpinning} |
| 716 |
addBtnName="Unapply" |
| 717 |
addSpinningBtnName="Unappling" |
| 718 |
/> |
| 719 |
<DualListLayout |
| 720 |
entry={""} |
| 721 |
target={"hostgroup"} |
| 722 |
showModal={showHostgroupModal} |
| 723 |
onCloseModal={closeUnapplyHostgroupModal} |
| 724 |
onOpenModal={openUnapplyHostgroupModal} |
| 725 |
tableElementsList={[]} |
| 726 |
action={onUnapplyHostgroups} |
| 727 |
title={"Unapply ID views from host groups"} |
| 728 |
spinning={unapplySpinning} |
| 729 |
addBtnName="Unapply" |
| 730 |
addSpinningBtnName="Unapplying" |
| 731 |
/> |
| 732 |
</div> |
| 733 |
); |
| 734 |
}; |
| 735 |
|
| 736 |
export default IDViews; |