import { useTable, useExpanded, useSortBy, useFilters } from 'react-table'; import { useRowSelectColumn } from '@lineup-lite/hooks'; import _ from 'lodash'; import { Environment } from '@/portainer/environments/types'; import { AMTDevicesDatatable } from '@/edge/EdgeDevices/EdgeDevicesView/AMTDevicesDatatable/AMTDevicesDatatable'; import { EnvironmentGroup } from '@/portainer/environment-groups/types'; import { PaginationControls } from '@@/PaginationControls'; import { Table, TableActions, TableContainer, TableHeaderRow, TableRow, TableSettingsMenu, TableTitle, TableTitleActions, } from '@@/datatables'; import { multiple } from '@@/datatables/filter-types'; import { useTableSettings } from '@@/datatables/useTableSettings'; import { ColumnVisibilityMenu } from '@@/datatables/ColumnVisibilityMenu'; import { SearchBar } from '@@/datatables/SearchBar'; import { useRowSelect } from '@@/datatables/useRowSelect'; import { TableFooter } from '@@/datatables/TableFooter'; import { SelectedRowsCount } from '@@/datatables/SelectedRowsCount'; import { TextTip } from '@@/Tip/TextTip'; import { EdgeDevicesDatatableActions } from './EdgeDevicesDatatableActions'; import { EdgeDevicesDatatableSettings } from './EdgeDevicesDatatableSettings'; import { RowProvider } from './columns/RowContext'; import { useColumns } from './columns'; import styles from './EdgeDevicesDatatable.module.css'; import { EdgeDeviceTableSettings, Pagination } from './types'; export interface EdgeDevicesTableProps { storageKey: string; isFdoEnabled: boolean; isOpenAmtEnabled: boolean; showWaitingRoomLink: boolean; mpsServer: string; dataset: Environment[]; groups: EnvironmentGroup[]; setLoadingMessage(message: string): void; pagination: Pagination; onChangePagination(pagination: Partial): void; totalCount: number; search: string; onChangeSearch(search: string): void; } export function EdgeDevicesDatatable({ isFdoEnabled, isOpenAmtEnabled, showWaitingRoomLink, mpsServer, dataset, onChangeSearch, search, groups, setLoadingMessage, pagination, onChangePagination, totalCount, }: EdgeDevicesTableProps) { const { settings, setTableSettings } = useTableSettings(); const columns = useColumns(); const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow, selectedFlatRows, allColumns, setHiddenColumns, } = useTable( { defaultCanFilter: false, columns, data: dataset, filterTypes: { multiple }, initialState: { hiddenColumns: settings.hiddenColumns, sortBy: [settings.sortBy], }, isRowSelectable() { return true; }, autoResetExpanded: false, autoResetSelectedRows: false, getRowId(originalRow: Environment) { return originalRow.Id.toString(); }, selectColumnWidth: 5, }, useFilters, useSortBy, useExpanded, useRowSelect, useRowSelectColumn ); const columnsToHide = allColumns.filter((colInstance) => { const columnDef = columns.find((c) => c.id === colInstance.id); return columnDef?.canHide; }); const tableProps = getTableProps(); const tbodyProps = getTableBodyProps(); const someDeviceHasAMTActivated = dataset.some( (environment) => environment.AMTDeviceGUID && environment.AMTDeviceGUID !== '' ); const groupsById = _.groupBy(groups, 'Id'); return (
row.original)} isFDOEnabled={isFdoEnabled} isOpenAMTEnabled={isOpenAmtEnabled} setLoadingMessage={setLoadingMessage} showWaitingRoomLink={showWaitingRoomLink} /> columns={columnsToHide} onChange={handleChangeColumnsVisibility} value={settings.hiddenColumns} /> {isOpenAmtEnabled && someDeviceHasAMTActivated && (
For the KVM function to work you need to have the MPS server added to your trusted site list, browse to this{' '} site and add to your trusted site list
)} {headerGroups.map((headerGroup) => { const { key, className, role, style } = headerGroup.getHeaderGroupProps(); return ( key={key} className={className} role={role} style={style} headers={headerGroup.headers} onSortChange={handleSortChange} /> ); })} { const group = groupsById[row.original.GroupId]; return ( cells={row.cells} key={key} className={className} role={role} style={style} /> {row.isExpanded && ( )} ); }} />
gotoPage(p)} totalCount={totalCount} onPageLimitChange={handlePageSizeChange} />
); function gotoPage(pageIndex: number) { onChangePagination({ page: pageIndex }); } function setPageSize(pageSize: number) { onChangePagination({ pageLimit: pageSize }); } function handlePageSizeChange(pageSize: number) { setPageSize(pageSize); setTableSettings((settings) => ({ ...settings, pageSize })); } function handleChangeColumnsVisibility(hiddenColumns: string[]) { setHiddenColumns(hiddenColumns); setTableSettings((settings) => ({ ...settings, hiddenColumns })); } function handleSearchBarChange(value: string) { onChangeSearch(value); } function handleSortChange(id: string, desc: boolean) { setTableSettings((settings) => ({ ...settings, sortBy: { id, desc }, })); } }