| 1 |
import React from "react"; |
| 2 |
// PatternFly |
| 3 |
import { |
| 4 |
Button, |
| 5 |
Flex, |
| 6 |
FlexItem, |
| 7 |
PageSection, |
| 8 |
PaginationVariant, |
| 9 |
SelectOptionProps, |
| 10 |
ToolbarItemVariant, |
| 11 |
} from "@patternfly/react-core"; |
| 12 |
// PatternFly table |
| 13 |
import { |
| 14 |
InnerScrollContainer, |
| 15 |
OuterScrollContainer, |
| 16 |
} from "@patternfly/react-table"; |
| 17 |
// Data types |
| 18 |
import { AutomemberEntry } from "src/utils/datatypes/globalDataTypes"; |
| 19 |
// Redux |
| 20 |
import { useAppSelector } from "src/store/hooks"; |
| 21 |
// Layouts |
| 22 |
import TitleLayout from "src/components/layouts/TitleLayout"; |
| 23 |
import HelpTextWithIconLayout from "src/components/layouts/HelpTextWithIconLayout"; |
| 24 |
import SecondaryButton from "src/components/layouts/SecondaryButton"; |
| 25 |
import ToolbarLayout, { |
| 26 |
ToolbarItem, |
| 27 |
} from "src/components/layouts/ToolbarLayout"; |
| 28 |
import SearchInputLayout from "src/components/layouts/SearchInputLayout"; |
| 29 |
// Tables |
| 30 |
import MainTable from "../AutoMemUserRules/AutomemRulesTable"; |
| 31 |
// Components |
| 32 |
import PaginationLayout from "../../components/layouts/PaginationLayout"; |
| 33 |
import BulkSelectorPrep from "src/components/BulkSelectorPrep"; |
| 34 |
import TypeAheadSelect from "src/components/TypeAheadSelect"; |
| 35 |
import useApiError from "src/hooks/useApiError"; |
| 36 |
import GlobalErrors from "src/components/errors/GlobalErrors"; |
| 37 |
// RPC |
| 38 |
import { GenericPayload } from "src/services/rpc"; |
| 39 |
import { |
| 40 |
useSearchHostGroupRulesEntriesMutation, |
| 41 |
ChangeDefaultPayload, |
| 42 |
useChangeDefaultGroupMutation, |
| 43 |
} from "src/services/rpcAutomember"; |
| 44 |
// Redux |
| 45 |
import { useAppDispatch } from "src/store/hooks"; |
| 46 |
// Hooks |
| 47 |
import { addAlert } from "src/store/Global/alerts-slice"; |
| 48 |
import useUpdateRoute from "src/hooks/useUpdateRoute"; |
| 49 |
import useListPageSearchParams from "src/hooks/useListPageSearchParams"; |
| 50 |
import { useHostGroupsRulesData } from "src/hooks/useHostGroupRules"; |
| 51 |
// Utils |
| 52 |
import { |
| 53 |
API_VERSION_BACKUP, |
| 54 |
isAutomemberUserGroupSelectable, |
| 55 |
} from "src/utils/utils"; |
| 56 |
// Errors |
| 57 |
import { FetchBaseQueryError } from "@reduxjs/toolkit/query"; |
| 58 |
import { SerializedError } from "@reduxjs/toolkit"; |
| 59 |
// Modals |
| 60 |
import AddRule from "src/components/modals/Automember/AddRule"; |
| 61 |
import DeleteRule from "src/components/modals/Automember/DeleteRule"; |
| 62 |
import ConfirmationModal from "src/components/modals/ConfirmationModal"; |
| 63 |
|
| 64 |
// Automembership host group rules |
| 65 |
const AutoMemHostRules = () => { |
| 66 |
const dispatch = useAppDispatch(); |
| 67 |
|
| 68 |
// Update current route data to Redux and highlight the current page in the Nav bar |
| 69 |
const { browserTitle } = useUpdateRoute({ |
| 70 |
pathname: "host-group-rules", |
| 71 |
}); |
| 72 |
|
| 73 |
// Set the page title to be shown in the browser tab |
| 74 |
React.useEffect(() => { |
| 75 |
document.title = browserTitle; |
| 76 |
}, [browserTitle]); |
| 77 |
|
| 78 |
// Retrieve API version from environment data |
| 79 |
const apiVersion = useAppSelector( |
| 80 |
(state) => state.global.environment.api_version |
| 81 |
) as string; |
| 82 |
|
| 83 |
const NO_SELECTION = "No default group selected"; |
| 84 |
|
| 85 |
const [hostGroups, setHostGroups] = React.useState<string[]>([]); |
| 86 |
const [automemberRules, setAutomemberRules] = React.useState< |
| 87 |
AutomemberEntry[] |
| 88 |
>([]); |
| 89 |
const [defaultGroup, setDefaultGroup] = React.useState<string>(NO_SELECTION); |
| 90 |
const [errors, setErrors] = React.useState< |
| 91 |
Array<FetchBaseQueryError | SerializedError> |
| 92 |
>([]); |
| 93 |
// Options for the default host group selector |
| 94 |
const [hostGroupsOptions, setHostGroupsOptions] = React.useState< |
| 95 |
SelectOptionProps[] |
| 96 |
>([]); |
| 97 |
// Available elements ready to add |
| 98 |
const [groupsAvailableToAdd, setGroupsAvailableToAdd] = React.useState< |
| 99 |
string[] |
| 100 |
>([]); |
| 101 |
const [previousDefaultGroup, setPreviousDefaultGroup] = |
| 102 |
React.useState<string>(NO_SELECTION); |
| 103 |
|
| 104 |
// Handle API calls errors |
| 105 |
const globalErrors = useApiError([]); |
| 106 |
|
| 107 |
// URL parameters: page number, page size, search value |
| 108 |
const { page, setPage, perPage, setPerPage, searchValue, setSearchValue } = |
| 109 |
useListPageSearchParams(); |
| 110 |
|
| 111 |
const [totalCount, setTotalCount] = React.useState<number>(0); |
| 112 |
const [searchDisabled, setSearchIsDisabled] = React.useState<boolean>(false); |
| 113 |
|
| 114 |
// Page indexes |
| 115 |
const firstIdx = (page - 1) * perPage; |
| 116 |
const lastIdx = page * perPage; |
| 117 |
|
| 118 |
// API calls via custom hook |
| 119 |
const hostGroupRulesData = useHostGroupsRulesData(); |
| 120 |
const [changeDefaultGroup] = useChangeDefaultGroupMutation(); |
| 121 |
|
| 122 |
// Show table rows |
| 123 |
const [showTableRows, setShowTableRows] = React.useState( |
| 124 |
!hostGroupRulesData.isLoading |
| 125 |
); |
| 126 |
|
| 127 |
// Update table rows when the data is loaded |
| 128 |
React.useEffect(() => { |
| 129 |
if (showTableRows !== !hostGroupRulesData.isLoading) { |
| 130 |
setShowTableRows(!hostGroupRulesData.isLoading); |
| 131 |
} |
| 132 |
}, [hostGroupRulesData.isLoading]); |
| 133 |
|
| 134 |
// Main API call |
| 135 |
React.useEffect(() => { |
| 136 |
if (hostGroupRulesData.isFetching) { |
| 137 |
setShowTableRows(false); |
| 138 |
} else { |
| 139 |
if (hostGroupRulesData.errors && hostGroupRulesData.errors.length > 0) { |
| 140 |
setErrors(hostGroupRulesData.errors || []); |
| 141 |
} else { |
| 142 |
const fullAutomemberIds: AutomemberEntry[] = |
| 143 |
hostGroupRulesData.automembersIds; |
| 144 |
const totalAutomembersCount = fullAutomemberIds.length; |
| 145 |
// Paginate data based on first and last indexes |
| 146 |
const shownPaginatedRulesList: AutomemberEntry[] = []; |
| 147 |
if (hostGroupRulesData.automembersIds.length > 0) { |
| 148 |
const pagAutomemberIds = fullAutomemberIds.slice(firstIdx, lastIdx); |
| 149 |
shownPaginatedRulesList.push(...pagAutomemberIds); |
| 150 |
} |
| 151 |
// Update lists |
| 152 |
setHostGroups(hostGroupRulesData.hostGroups); |
| 153 |
setAutomemberRules(shownPaginatedRulesList); |
| 154 |
// If no default group is set, set it as 'No selection' |
| 155 |
if (hostGroupRulesData.defaultGroup === "") { |
| 156 |
setDefaultGroup(NO_SELECTION); |
| 157 |
setPreviousDefaultGroup(NO_SELECTION); |
| 158 |
} else { |
| 159 |
setDefaultGroup(hostGroupRulesData.defaultGroup); |
| 160 |
setPreviousDefaultGroup(hostGroupRulesData.defaultGroup); |
| 161 |
} |
| 162 |
|
| 163 |
// Set available host groups to add |
| 164 |
const allAutomemberIds = fullAutomemberIds.map( |
| 165 |
(item) => item.automemberRule |
| 166 |
); |
| 167 |
const availableItems = hostGroupRulesData.hostGroups.filter( |
| 168 |
(item) => !allAutomemberIds.includes(item) |
| 169 |
); |
| 170 |
setGroupsAvailableToAdd(availableItems); |
| 171 |
|
| 172 |
// Set table count |
| 173 |
setTotalCount(totalAutomembersCount); |
| 174 |
// Show table elements |
| 175 |
setShowTableRows(true); |
| 176 |
} |
| 177 |
} |
| 178 |
}, [ |
| 179 |
hostGroupRulesData.hostGroups, |
| 180 |
hostGroupRulesData.automembersIds, |
| 181 |
hostGroupRulesData.defaultGroup, |
| 182 |
]); |
| 183 |
|
| 184 |
// Parse host groups to be shown in the default host group selector |
| 185 |
React.useEffect(() => { |
| 186 |
if (hostGroups.length > 0) { |
| 187 |
// Add empty entry as an option |
| 188 |
const groupsToSelector = [ |
| 189 |
{ |
| 190 |
"data-cy": "typeahead-select-no-selection", |
| 191 |
value: NO_SELECTION, |
| 192 |
children: NO_SELECTION, |
| 193 |
}, |
| 194 |
]; |
| 195 |
|
| 196 |
// Add the rest of the data from hostgroups |
| 197 |
const tempGroupsToSelector = hostGroups.map((group) => ({ |
| 198 |
"data-cy": "typeahead-select-" + group, |
| 199 |
value: group, |
| 200 |
children: group, |
| 201 |
})); |
| 202 |
groupsToSelector.push(...tempGroupsToSelector); |
| 203 |
setHostGroupsOptions(groupsToSelector); |
| 204 |
} |
| 205 |
}, [hostGroups]); |
| 206 |
|
| 207 |
// On select default group |
| 208 |
const onSelectDefaultGroup = (group: string) => { |
| 209 |
const payload: ChangeDefaultPayload = { |
| 210 |
defaultGroup: group, |
| 211 |
type: "hostgroup", |
| 212 |
}; |
| 213 |
changeDefaultGroup(payload).then((result) => { |
| 214 |
if ("data" in result) { |
| 215 |
setDefaultGroup(group); |
| 216 |
setPreviousDefaultGroup(group); |
| 217 |
dispatch( |
| 218 |
addAlert({ |
| 219 |
name: "default-group-success", |
| 220 |
title: "Default group updated", |
| 221 |
variant: "success", |
| 222 |
}) |
| 223 |
); |
| 224 |
onCloseConfirmationModal(); |
| 225 |
} else { |
| 226 |
dispatch( |
| 227 |
addAlert({ |
| 228 |
name: "default-group-failure", |
| 229 |
title: "Default group not updated", |
| 230 |
variant: "danger", |
| 231 |
}) |
| 232 |
); |
| 233 |
} |
| 234 |
}); |
| 235 |
}; |
| 236 |
|
| 237 |
// If some entries' status has been updated, unselect selected rows |
| 238 |
const [isDisableEnableOp, setIsDisableEnableOp] = React.useState(false); |
| 239 |
|
| 240 |
const updateIsDisableEnableOp = (value: boolean) => { |
| 241 |
setIsDisableEnableOp(value); |
| 242 |
}; |
| 243 |
|
| 244 |
// Elements selected (per page) |
| 245 |
// - This will help to calculate the remaining elements on a specific page (bulk selector) |
| 246 |
const [selectedPerPage, setSelectedPerPage] = React.useState<number>(0); |
| 247 |
|
| 248 |
const updateSelectedPerPage = (selected: number) => { |
| 249 |
setSelectedPerPage(selected); |
| 250 |
}; |
| 251 |
|
| 252 |
// Pagination |
| 253 |
const updatePage = (newPage: number) => { |
| 254 |
setPage(newPage); |
| 255 |
}; |
| 256 |
|
| 257 |
const updatePerPage = (newSetPerPage: number) => { |
| 258 |
setPerPage(newSetPerPage); |
| 259 |
}; |
| 260 |
|
| 261 |
// Automembers displayed on the first page |
| 262 |
const updateShownAutomembersList = ( |
| 263 |
newShownAutomembersList: AutomemberEntry[] |
| 264 |
) => { |
| 265 |
setAutomemberRules(newShownAutomembersList); |
| 266 |
}; |
| 267 |
|
| 268 |
// Update search input valie |
| 269 |
const updateSearchValue = (value: string) => { |
| 270 |
setSearchValue(value); |
| 271 |
}; |
| 272 |
|
| 273 |
const [selectedAutomembers, setSelectedAutomembers] = React.useState< |
| 274 |
AutomemberEntry[] |
| 275 |
>([]); |
| 276 |
|
| 277 |
const clearSelectedRules = () => { |
| 278 |
const emptyList: AutomemberEntry[] = []; |
| 279 |
setSelectedAutomembers(emptyList); |
| 280 |
}; |
| 281 |
|
| 282 |
// Refresh button handling |
| 283 |
const refreshData = () => { |
| 284 |
setShowTableRows(false); |
| 285 |
setTotalCount(0); |
| 286 |
clearSelectedRules(); |
| 287 |
hostGroupRulesData.refetch(); |
| 288 |
}; |
| 289 |
|
| 290 |
const [retrieveAutomembers] = useSearchHostGroupRulesEntriesMutation({}); |
| 291 |
|
| 292 |
// Issue a search using a specific search value |
| 293 |
const submitSearchValue = () => { |
| 294 |
setShowTableRows(false); |
| 295 |
setSearchIsDisabled(true); |
| 296 |
setTotalCount(0); |
| 297 |
retrieveAutomembers({ |
| 298 |
searchValue: searchValue, |
| 299 |
sizeLimit: 0, |
| 300 |
apiVersion: apiVersion || API_VERSION_BACKUP, |
| 301 |
startIdx: firstIdx, |
| 302 |
stopIdx: lastIdx, |
| 303 |
} as GenericPayload).then((result) => { |
| 304 |
if ("data" in result) { |
| 305 |
const automembersListResult = result.data; |
| 306 |
setTotalCount(result.data?.length ?? 0); |
| 307 |
setAutomemberRules(automembersListResult || []); |
| 308 |
// Show table elements |
| 309 |
setShowTableRows(true); |
| 310 |
setSearchIsDisabled(false); |
| 311 |
} |
| 312 |
}); |
| 313 |
}; |
| 314 |
|
| 315 |
// Always refetch data when the component is loaded. |
| 316 |
// This ensures the data is always up-to-date. |
| 317 |
React.useEffect(() => { |
| 318 |
hostGroupRulesData.refetch(); |
| 319 |
}, [page, perPage]); |
| 320 |
|
| 321 |
// 'Delete' button state |
| 322 |
const [isDeleteButtonDisabled, setIsDeleteButtonDisabled] = |
| 323 |
React.useState<boolean>(true); |
| 324 |
|
| 325 |
const updateIsDeleteButtonDisabled = (value: boolean) => { |
| 326 |
setIsDeleteButtonDisabled(value); |
| 327 |
}; |
| 328 |
|
| 329 |
const [isDeletion, setIsDeletion] = React.useState(false); |
| 330 |
const updateIsDeletion = (value: boolean) => { |
| 331 |
setIsDeletion(value); |
| 332 |
}; |
| 333 |
|
| 334 |
// Table-related shared functionality |
| 335 |
// - Selectable checkboxes on table |
| 336 |
const selectableAutomembersTable = automemberRules.filter( |
| 337 |
isAutomemberUserGroupSelectable |
| 338 |
); // elements per Table |
| 339 |
|
| 340 |
const updateSelectedAutomembers = ( |
| 341 |
automembers: AutomemberEntry[], |
| 342 |
isSelected: boolean |
| 343 |
) => { |
| 344 |
let newSelectedAutomembers: AutomemberEntry[] = []; |
| 345 |
if (isSelected) { |
| 346 |
newSelectedAutomembers = JSON.parse(JSON.stringify(selectedAutomembers)); |
| 347 |
for (let i = 0; i < automembers.length; i++) { |
| 348 |
if ( |
| 349 |
selectedAutomembers.find( |
| 350 |
(selectedRule) => |
| 351 |
selectedRule.automemberRule === automembers[i].automemberRule |
| 352 |
) |
| 353 |
) { |
| 354 |
// Already in the list |
| 355 |
continue; |
| 356 |
} |
| 357 |
// Add rule to list |
| 358 |
newSelectedAutomembers.push(automembers[i]); |
| 359 |
} |
| 360 |
} else { |
| 361 |
// Remove rule |
| 362 |
for (let i = 0; i < selectedAutomembers.length; i++) { |
| 363 |
let found = false; |
| 364 |
for (let ii = 0; ii < automembers.length; ii++) { |
| 365 |
if ( |
| 366 |
selectedAutomembers[i].automemberRule === |
| 367 |
automembers[ii].automemberRule |
| 368 |
) { |
| 369 |
found = true; |
| 370 |
break; |
| 371 |
} |
| 372 |
} |
| 373 |
if (!found) { |
| 374 |
// Keep this valid selected entry |
| 375 |
newSelectedAutomembers.push(selectedAutomembers[i]); |
| 376 |
} |
| 377 |
} |
| 378 |
} |
| 379 |
setSelectedAutomembers(newSelectedAutomembers); |
| 380 |
setIsDeleteButtonDisabled(newSelectedAutomembers.length === 0); |
| 381 |
}; |
| 382 |
|
| 383 |
// - Helper method to set the selected entries from the table |
| 384 |
const setAutomembersSelected = ( |
| 385 |
automember: AutomemberEntry, |
| 386 |
isSelecting = true |
| 387 |
) => { |
| 388 |
if (isAutomemberUserGroupSelectable(automember)) { |
| 389 |
updateSelectedAutomembers([automember], isSelecting); |
| 390 |
} |
| 391 |
}; |
| 392 |
|
| 393 |
// Data wrappers |
| 394 |
// TODO: Better separation of concerts |
| 395 |
// - 'PaginationLayout' |
| 396 |
const paginationData = { |
| 397 |
page, |
| 398 |
perPage, |
| 399 |
updatePage, |
| 400 |
updatePerPage, |
| 401 |
updateSelectedPerPage, |
| 402 |
updateShownElementsList: updateShownAutomembersList, |
| 403 |
totalCount, |
| 404 |
}; |
| 405 |
|
| 406 |
// - 'BulkSelectorPrep' |
| 407 |
const automembersBulkSelectorData = { |
| 408 |
selected: selectedAutomembers, |
| 409 |
updateSelected: updateSelectedAutomembers, |
| 410 |
selectableTable: selectableAutomembersTable, |
| 411 |
nameAttr: "automemberRule", |
| 412 |
}; |
| 413 |
|
| 414 |
const buttonsData = { |
| 415 |
updateIsDeleteButtonDisabled, |
| 416 |
updateIsDisableEnableOp, |
| 417 |
}; |
| 418 |
|
| 419 |
const selectedPerPageData = { |
| 420 |
selectedPerPage, |
| 421 |
updateSelectedPerPage, |
| 422 |
}; |
| 423 |
|
| 424 |
// SearchInputLayout |
| 425 |
const searchValueData = { |
| 426 |
searchValue, |
| 427 |
updateSearchValue, |
| 428 |
submitSearchValue, |
| 429 |
}; |
| 430 |
|
| 431 |
// 'Table' |
| 432 |
const automembersTableData = { |
| 433 |
isElementSelectable: isAutomemberUserGroupSelectable, |
| 434 |
selectedElements: selectedAutomembers, |
| 435 |
selectableElementsTable: selectableAutomembersTable, |
| 436 |
setElementsSelected: setAutomembersSelected, |
| 437 |
clearSelectedElements: clearSelectedRules, |
| 438 |
}; |
| 439 |
|
| 440 |
const automembersTableButtonsData = { |
| 441 |
updateIsDeleteButtonDisabled, |
| 442 |
isDeletion, |
| 443 |
updateIsDeletion, |
| 444 |
isDisableEnableOp, |
| 445 |
updateIsDisableEnableOp, |
| 446 |
}; |
| 447 |
|
| 448 |
// Modals functionality |
| 449 |
const [showAddModal, setShowAddModal] = React.useState(false); |
| 450 |
const [showDeleteModal, setShowDeleteModal] = React.useState(false); |
| 451 |
const [showChangeConfirmationModal, setShowChangeConfirmationModal] = |
| 452 |
React.useState(false); |
| 453 |
|
| 454 |
const onOpenAddModal = () => { |
| 455 |
setShowAddModal(true); |
| 456 |
}; |
| 457 |
|
| 458 |
const onCloseAddModal = () => { |
| 459 |
setShowAddModal(false); |
| 460 |
}; |
| 461 |
|
| 462 |
const onAddModalToggle = () => { |
| 463 |
setShowAddModal(!showAddModal); |
| 464 |
}; |
| 465 |
|
| 466 |
const onOpenDeleteModal = () => { |
| 467 |
setShowDeleteModal(true); |
| 468 |
}; |
| 469 |
|
| 470 |
const onToggleDeleteModal = () => { |
| 471 |
setShowDeleteModal(!showDeleteModal); |
| 472 |
}; |
| 473 |
|
| 474 |
const onCloseConfirmationModal = () => { |
| 475 |
setShowChangeConfirmationModal(false); |
| 476 |
}; |
| 477 |
|
| 478 |
const onOpenConfirmationModal = () => { |
| 479 |
setShowChangeConfirmationModal(true); |
| 480 |
}; |
| 481 |
|
| 482 |
const onShowDefaultGroupOnModal = (group: string) => { |
| 483 |
setDefaultGroup(group); |
| 484 |
onOpenConfirmationModal(); |
| 485 |
}; |
| 486 |
|
| 487 |
const onCancelDefaultGroup = () => { |
| 488 |
setDefaultGroup(previousDefaultGroup); |
| 489 |
onCloseConfirmationModal(); |
| 490 |
}; |
| 491 |
|
| 492 |
// 'Delete automember rules data |
| 493 |
const deleteButtonsData = { |
| 494 |
updateIsDeleteButtonDisabled, |
| 495 |
updateIsDeletion, |
| 496 |
}; |
| 497 |
|
| 498 |
const selectedData = { |
| 499 |
selectedItems: selectedAutomembers, |
| 500 |
clearSelected: clearSelectedRules, |
| 501 |
}; |
| 502 |
|
| 503 |
// List of Toolbar items |
| 504 |
const toolbarItems: ToolbarItem[] = [ |
| 505 |
{ |
| 506 |
key: 0, |
| 507 |
element: ( |
| 508 |
<BulkSelectorPrep |
| 509 |
list={automemberRules} |
| 510 |
shownElementsList={automemberRules} |
| 511 |
elementData={automembersBulkSelectorData} |
| 512 |
buttonsData={buttonsData} |
| 513 |
selectedPerPageData={selectedPerPageData} |
| 514 |
/> |
| 515 |
), |
| 516 |
}, |
| 517 |
{ |
| 518 |
key: 1, |
| 519 |
element: ( |
| 520 |
<SearchInputLayout |
| 521 |
dataCy="search" |
| 522 |
name="search" |
| 523 |
ariaLabel="Search rules" |
| 524 |
placeholder="Search" |
| 525 |
searchValueData={searchValueData} |
| 526 |
isDisabled={searchDisabled} |
| 527 |
/> |
| 528 |
), |
| 529 |
toolbarItemVariant: ToolbarItemVariant.label, |
| 530 |
toolbarItemGap: { default: "gapMd" }, |
| 531 |
}, |
| 532 |
{ |
| 533 |
key: 2, |
| 534 |
element: ( |
| 535 |
<TypeAheadSelect |
| 536 |
id="host-group" |
| 537 |
dataCy="auto-member-host-rules-typeahead-select" |
| 538 |
options={hostGroupsOptions} |
| 539 |
selected={defaultGroup} |
| 540 |
placeholder="Default host group" |
| 541 |
onSelectedChange={onShowDefaultGroupOnModal} |
| 542 |
/> |
| 543 |
), |
| 544 |
}, |
| 545 |
{ |
| 546 |
key: 3, |
| 547 |
toolbarItemVariant: ToolbarItemVariant.separator, |
| 548 |
}, |
| 549 |
{ |
| 550 |
key: 4, |
| 551 |
element: ( |
| 552 |
<SecondaryButton |
| 553 |
dataCy="auto-member-host-rules-button-refresh" |
| 554 |
onClickHandler={refreshData} |
| 555 |
isDisabled={!showTableRows} |
| 556 |
> |
| 557 |
Refresh |
| 558 |
</SecondaryButton> |
| 559 |
), |
| 560 |
}, |
| 561 |
{ |
| 562 |
key: 5, |
| 563 |
element: ( |
| 564 |
<SecondaryButton |
| 565 |
dataCy="auto-member-host-rules-button-delete" |
| 566 |
isDisabled={isDeleteButtonDisabled || !showTableRows} |
| 567 |
onClickHandler={onOpenDeleteModal} |
| 568 |
> |
| 569 |
Delete |
| 570 |
</SecondaryButton> |
| 571 |
), |
| 572 |
}, |
| 573 |
{ |
| 574 |
key: 6, |
| 575 |
element: ( |
| 576 |
<SecondaryButton |
| 577 |
dataCy="auto-member-host-rules-button-add" |
| 578 |
isDisabled={!showTableRows} |
| 579 |
onClickHandler={onOpenAddModal} |
| 580 |
> |
| 581 |
Add |
| 582 |
</SecondaryButton> |
| 583 |
), |
| 584 |
}, |
| 585 |
{ |
| 586 |
key: 7, |
| 587 |
toolbarItemVariant: ToolbarItemVariant.separator, |
| 588 |
}, |
| 589 |
{ |
| 590 |
key: 8, |
| 591 |
element: <HelpTextWithIconLayout textContent="Help" />, |
| 592 |
}, |
| 593 |
{ |
| 594 |
key: 9, |
| 595 |
element: ( |
| 596 |
<PaginationLayout |
| 597 |
list={automemberRules} |
| 598 |
paginationData={paginationData} |
| 599 |
widgetId="pagination-options-menu-top" |
| 600 |
isCompact={true} |
| 601 |
/> |
| 602 |
), |
| 603 |
toolbarItemAlignment: { default: "alignEnd" }, |
| 604 |
}, |
| 605 |
]; |
| 606 |
|
| 607 |
return ( |
| 608 |
<div> |
| 609 |
<PageSection hasBodyWrapper={false}> |
| 610 |
<TitleLayout |
| 611 |
id="Automember host groups title" |
| 612 |
headingLevel="h1" |
| 613 |
text="Host group rules" |
| 614 |
/> |
| 615 |
</PageSection> |
| 616 |
<PageSection hasBodyWrapper={false} isFilled={false}> |
| 617 |
<Flex direction={{ default: "column" }}> |
| 618 |
<FlexItem> |
| 619 |
<ToolbarLayout toolbarItems={toolbarItems} /> |
| 620 |
</FlexItem> |
| 621 |
<FlexItem style={{ flex: "0 0 auto" }}> |
| 622 |
<OuterScrollContainer> |
| 623 |
<InnerScrollContainer |
| 624 |
style={{ height: "55vh", overflow: "auto" }} |
| 625 |
> |
| 626 |
{errors !== undefined && errors.length > 0 ? ( |
| 627 |
<GlobalErrors errors={globalErrors.getAll()} /> |
| 628 |
) : ( |
| 629 |
<MainTable |
| 630 |
shownElementsList={automemberRules} |
| 631 |
showTableRows={showTableRows} |
| 632 |
elementsData={automembersTableData} |
| 633 |
buttonsData={automembersTableButtonsData} |
| 634 |
paginationData={selectedPerPageData} |
| 635 |
searchValue={searchValue} |
| 636 |
automemberType="host-group" |
| 637 |
/> |
| 638 |
)} |
| 639 |
</InnerScrollContainer> |
| 640 |
</OuterScrollContainer> |
| 641 |
</FlexItem> |
| 642 |
<FlexItem style={{ flex: "0 0 auto", position: "sticky", bottom: 0 }}> |
| 643 |
<PaginationLayout |
| 644 |
list={automemberRules} |
| 645 |
paginationData={paginationData} |
| 646 |
variant={PaginationVariant.bottom} |
| 647 |
widgetId="pagination-options-menu-bottom" |
| 648 |
/> |
| 649 |
</FlexItem> |
| 650 |
</Flex> |
| 651 |
</PageSection> |
| 652 |
<AddRule |
| 653 |
show={showAddModal} |
| 654 |
handleModalToggle={onAddModalToggle} |
| 655 |
onOpenAddModal={onOpenAddModal} |
| 656 |
onCloseAddModal={onCloseAddModal} |
| 657 |
onRefresh={refreshData} |
| 658 |
groupsAvailableToAdd={groupsAvailableToAdd} |
| 659 |
ruleType="hostgroup" |
| 660 |
/> |
| 661 |
<DeleteRule |
| 662 |
show={showDeleteModal} |
| 663 |
handleModalToggle={onToggleDeleteModal} |
| 664 |
onRefresh={refreshData} |
| 665 |
buttonsData={deleteButtonsData} |
| 666 |
selectedData={selectedData} |
| 667 |
ruleType="hostgroup" |
| 668 |
/> |
| 669 |
<ConfirmationModal |
| 670 |
dataCy="auto-member-default-host-rules-modal" |
| 671 |
title="Default hostgroup" |
| 672 |
isOpen={showChangeConfirmationModal} |
| 673 |
onClose={onCloseConfirmationModal} |
| 674 |
actions={[ |
| 675 |
<Button |
| 676 |
data-cy="modal-button-ok" |
| 677 |
variant="primary" |
| 678 |
key="change-default" |
| 679 |
onClick={() => { |
| 680 |
onSelectDefaultGroup(defaultGroup); |
| 681 |
}} |
| 682 |
> |
| 683 |
OK |
| 684 |
</Button>, |
| 685 |
<SecondaryButton |
| 686 |
key="cancel" |
| 687 |
onClickHandler={onCancelDefaultGroup} |
| 688 |
dataCy="modal-button-cancel" |
| 689 |
> |
| 690 |
Cancel |
| 691 |
</SecondaryButton>, |
| 692 |
]} |
| 693 |
messageText="Are you sure you want to change default group?" |
| 694 |
messageObj={defaultGroup} |
| 695 |
/> |
| 696 |
</div> |
| 697 |
); |
| 698 |
}; |
| 699 |
|
| 700 |
export default AutoMemHostRules; |