mirror of https://github.com/portainer/portainer
fix(edge): only show expand row for Edge Devices with AMT activated [EE-2489] (#6519)
parent
37ca62eb06
commit
2bffba7371
|
@ -206,6 +206,7 @@ export function EdgeDevicesDatatable({
|
||||||
<RowProvider
|
<RowProvider
|
||||||
key={key}
|
key={key}
|
||||||
disableTrustOnFirstConnect={disableTrustOnFirstConnect}
|
disableTrustOnFirstConnect={disableTrustOnFirstConnect}
|
||||||
|
isOpenAmtEnabled={isOpenAmtEnabled}
|
||||||
>
|
>
|
||||||
<TableRow<Environment>
|
<TableRow<Environment>
|
||||||
cells={row.cells}
|
cells={row.cells}
|
||||||
|
|
|
@ -2,21 +2,24 @@ import { createContext, useContext, useMemo, PropsWithChildren } from 'react';
|
||||||
|
|
||||||
interface RowContextState {
|
interface RowContextState {
|
||||||
disableTrustOnFirstConnect: boolean;
|
disableTrustOnFirstConnect: boolean;
|
||||||
|
isOpenAmtEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RowContext = createContext<RowContextState | null>(null);
|
const RowContext = createContext<RowContextState | null>(null);
|
||||||
|
|
||||||
export interface RowProviderProps {
|
export interface RowProviderProps {
|
||||||
disableTrustOnFirstConnect: boolean;
|
disableTrustOnFirstConnect: boolean;
|
||||||
|
isOpenAmtEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RowProvider({
|
export function RowProvider({
|
||||||
disableTrustOnFirstConnect,
|
disableTrustOnFirstConnect,
|
||||||
|
isOpenAmtEnabled,
|
||||||
children,
|
children,
|
||||||
}: PropsWithChildren<RowProviderProps>) {
|
}: PropsWithChildren<RowProviderProps>) {
|
||||||
const state = useMemo(
|
const state = useMemo(
|
||||||
() => ({ disableTrustOnFirstConnect }),
|
() => ({ disableTrustOnFirstConnect, isOpenAmtEnabled }),
|
||||||
[disableTrustOnFirstConnect]
|
[disableTrustOnFirstConnect, isOpenAmtEnabled]
|
||||||
);
|
);
|
||||||
|
|
||||||
return <RowContext.Provider value={state}>{children}</RowContext.Provider>;
|
return <RowContext.Provider value={state}>{children}</RowContext.Provider>;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { CellProps, Column, TableInstance } from 'react-table';
|
import { CellProps, Column } from 'react-table';
|
||||||
|
|
||||||
import { Environment } from '@/portainer/environments/types';
|
import { Environment } from '@/portainer/environments/types';
|
||||||
import { Link } from '@/portainer/components/Link';
|
import { Link } from '@/portainer/components/Link';
|
||||||
import { ExpandingCell } from '@/portainer/components/datatables/components/ExpandingCell';
|
import { ExpandingCell } from '@/portainer/components/datatables/components/ExpandingCell';
|
||||||
|
import { useRowContext } from '@/edge/devices/components/EdgeDevicesDatatable/columns/RowContext';
|
||||||
|
|
||||||
export const name: Column<Environment> = {
|
export const name: Column<Environment> = {
|
||||||
Header: 'Name',
|
Header: 'Name',
|
||||||
|
@ -15,9 +16,15 @@ export const name: Column<Environment> = {
|
||||||
sortType: 'string',
|
sortType: 'string',
|
||||||
};
|
};
|
||||||
|
|
||||||
export function NameCell({ value: name, row }: CellProps<TableInstance>) {
|
export function NameCell({ value: name, row }: CellProps<Environment>) {
|
||||||
|
const { isOpenAmtEnabled } = useRowContext();
|
||||||
|
const showExpandedRow = !!(
|
||||||
|
isOpenAmtEnabled &&
|
||||||
|
row.original.AMTDeviceGUID &&
|
||||||
|
row.original.AMTDeviceGUID.length > 0
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<ExpandingCell row={row}>
|
<ExpandingCell row={row} showExpandArrow={showExpandedRow}>
|
||||||
<Link
|
<Link
|
||||||
to="portainer.endpoints.endpoint"
|
to="portainer.endpoints.endpoint"
|
||||||
params={{ id: row.original.Id }}
|
params={{ id: row.original.Id }}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
.expand-button {
|
||||||
|
background: none;
|
||||||
|
color: inherit;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
font: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
outline: inherit;
|
||||||
|
}
|
|
@ -1,20 +1,30 @@
|
||||||
import { PropsWithChildren } from 'react';
|
import { PropsWithChildren } from 'react';
|
||||||
import { Row, TableInstance } from 'react-table';
|
import { Row } from 'react-table';
|
||||||
|
|
||||||
interface Props {
|
import styles from './ExpandingCell.module.css';
|
||||||
row: Row<TableInstance>;
|
|
||||||
|
interface Props<D extends Record<string, unknown> = Record<string, unknown>> {
|
||||||
|
row: Row<D>;
|
||||||
|
showExpandArrow: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ExpandingCell({ children, row }: PropsWithChildren<Props>) {
|
export function ExpandingCell<
|
||||||
|
D extends Record<string, unknown> = Record<string, unknown>
|
||||||
|
>({ row, showExpandArrow, children }: PropsWithChildren<Props<D>>) {
|
||||||
return (
|
return (
|
||||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
<>
|
||||||
<div {...row.getToggleRowExpandedProps()}>
|
{showExpandArrow && (
|
||||||
|
<button type="button" className={styles.expandButton}>
|
||||||
<i
|
<i
|
||||||
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||||
|
{...row.getToggleRowExpandedProps()}
|
||||||
className={`fas ${arrowClass(row.isExpanded)} space-right`}
|
className={`fas ${arrowClass(row.isExpanded)} space-right`}
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
function arrowClass(isExpanded: boolean) {
|
function arrowClass(isExpanded: boolean) {
|
||||||
|
|
Loading…
Reference in New Issue