Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ import { ResourceFilters, ResourceMetadata, GetDataViewRows } from './types';
import { useConsoleDataViewData } from './useConsoleDataViewData';
import { useConsoleDataViewFilters } from './useConsoleDataViewFilters';

export type ConsoleDataViewProps<TData, TCustomRowData, TFilters> = {
export const initialFiltersDefault: ResourceFilters = { name: '', label: '' };

export type ConsoleDataViewProps<
TData,
TCustomRowData = any,
TFilters extends ResourceFilters = ResourceFilters
> = {
label?: string;
data: TData[];
loaded: boolean;
loadError?: any;
columns: TableColumn<TData>[];
columnLayout?: ColumnLayout;
columnManagementID?: string;
initialFilters: TFilters;
initialFilters?: TFilters;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work to remove the useMemo in line 109?

Suggested change
initialFilters?: TFilters;
initialFilters?: TFilters = initialFilters;

additionalFilterNodes?: React.ReactNode[];
/**
* By default, `TData` is assumed to be assignable to `K8sResourceCommon` type.
Expand Down Expand Up @@ -86,7 +92,7 @@ export const ConsoleDataView = <
columns,
columnLayout,
columnManagementID,
initialFilters,
initialFilters = initialFiltersDefault as TFilters,
additionalFilterNodes,
getObjectMetadata,
matchesAdditionalFilters,
Expand Down Expand Up @@ -253,5 +259,3 @@ export const actionsCellProps = {
hasLeftBorder: true,
isActionCell: true,
};

export const initialFiltersDefault = { name: '', label: '' };
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type ConsoleDataViewRow = DataViewTd[];
/**
* Maps Console `RowProps` data to DataView compatible format.
*/
export type GetDataViewRows<TData, TCustomRowData> = (
export type GetDataViewRows<TData, TCustomRowData = any> = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using any instead of unknown for compatibility with existing RowProps signature

RowProps<D, R extends any = {}>

data: RowProps<TData, TCustomRowData>[],
columns: ConsoleDataViewColumn<TData>[],
) => ConsoleDataViewRow[];
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ const NodeList: React.FC<NodeListProps> = ({
[],
);

const initialFilters = React.useMemo<NodeFilters>(
() => ({ ...initialFiltersDefault, status: [], roles: [], architecture: [] }),
[],
);

// Create stable filter nodes with stable option references to prevent filter resets
const additionalFilterNodes = React.useMemo<React.ReactNode[]>(
() => [
Expand Down Expand Up @@ -622,9 +627,7 @@ const NodeList: React.FC<NodeListProps> = ({
columns={columns}
columnLayout={columnLayout}
columnManagementID={columnManagementID}
initialFilters={
{ ...initialFiltersDefault, status: [], roles: [], architecture: [] } as NodeFilters
}
initialFilters={initialFilters}
additionalFilterNodes={additionalFilterNodes}
matchesAdditionalFilters={matchesAdditionalFilters}
getDataViewRows={(rowData, tableColumns) =>
Expand Down
4 changes: 1 addition & 3 deletions frontend/packages/console-app/src/components/pdb/PDBList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
actionsCellProps,
cellIsStickyProps,
getNameCellProps,
initialFiltersDefault,
ConsoleDataView,
} from '@console/app/src/components/data-view/ConsoleDataView';
import { GetDataViewRows } from '@console/app/src/components/data-view/types';
Expand All @@ -31,7 +30,7 @@ export const tableColumnInfo = [
{ id: '' },
];

const getDataViewRows: GetDataViewRows<PodDisruptionBudgetKind, undefined> = (data, columns) => {
const getDataViewRows: GetDataViewRows<PodDisruptionBudgetKind> = (data, columns) => {
return data.map(({ obj: pdb }) => {
const { name, namespace } = pdb.metadata;
const resourceKind = referenceForModel(PodDisruptionBudgetModel);
Expand Down Expand Up @@ -155,7 +154,6 @@ const PodDisruptionBudgetList: React.FCC<PodDisruptionBudgetsListProps> = ({
data={data}
loaded={loaded}
columns={columns}
initialFilters={initialFiltersDefault}
getDataViewRows={getDataViewRows}
hideColumnManagement
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import {
ConsoleDataView,
initialFiltersDefault,
} from '@console/app/src/components/data-view/ConsoleDataView';
import { ConsoleDataView } from '@console/app/src/components/data-view/ConsoleDataView';
import { TableProps } from '@console/internal/components/factory';
import { LoadingBox } from '@console/internal/components/utils';
import { K8sResourceKind } from '@console/internal/module/k8s';
Expand All @@ -22,7 +19,6 @@ const HelmReleaseResourcesList: React.FC<TableProps> = (props) => {
loaded={props.loaded}
label={t('helm-plugin~Resources')}
columns={columns}
initialFilters={initialFiltersDefault}
getDataViewRows={getDataViewRows}
hideColumnManagement
data-test="helm-resources-list"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const HelmReleaseResourceStatus: React.FC<HelmReleaseResourceStatusProps>
);
};

export const getDataViewRows: GetDataViewRows<K8sResourceKind, undefined> = (data, columns) => {
export const getDataViewRows: GetDataViewRows<K8sResourceKind> = (data, columns) => {
return data.map(({ obj: resource }) => {
const kind = referenceFor(resource);
const rowCells = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getDataViewRows, HelmReleaseResourceStatus } from '../HelmReleaseResour

configure({ testIdAttribute: 'data-test' });

let testData: RowProps<K8sResourceKind, undefined>[];
let testData: RowProps<K8sResourceKind>[];
let testColumns: TableColumn<K8sResourceKind>[];

describe('getDataViewRows', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import {
ConsoleDataView,
initialFiltersDefault,
} from '@console/app/src/components/data-view/ConsoleDataView';
import { ConsoleDataView } from '@console/app/src/components/data-view/ConsoleDataView';
import { TableProps } from '@console/internal/components/factory';
import { LoadingBox } from '@console/internal/components/utils';
import { K8sResourceKind } from '@console/internal/module/k8s';
Expand All @@ -22,7 +19,6 @@ const HelmChartRepositoryList: React.FC<TableProps> = (props) => {
loaded={props.loaded}
label={t('helm-plugin~HelmChartRepositories')}
columns={columns}
initialFilters={initialFiltersDefault}
getDataViewRows={getDataViewRows}
hideColumnManagement
data-test="helm-chart-repositories-list"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const DisabledCell: React.FC<{ disabled?: boolean }> = ({ disabled }) => {
return <>{disabled ? t('helm-plugin~True') : t('helm-plugin~False')}</>;
};

export const getDataViewRows: GetDataViewRows<K8sResourceKind, undefined> = (data, columns) => {
export const getDataViewRows: GetDataViewRows<K8sResourceKind> = (data, columns) => {
return data.map(({ obj }) => {
const objReference = referenceFor(obj);
const context = { [objReference]: obj };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ const HelmReleaseList: React.FC = () => {
}));
}, []);

const initialFilters = React.useMemo(() => ({ ...initialFiltersDefault, status: [] }), []);

const additionalFilterNodes = React.useMemo<React.ReactNode[]>(
() => [
<DataViewCheckboxFilter
Expand Down Expand Up @@ -262,7 +264,7 @@ const HelmReleaseList: React.FC = () => {
loaded={isLoaded}
loadError={secretsLoadError || loadError}
columns={columns}
initialFilters={{ ...initialFiltersDefault, status: [] }}
initialFilters={initialFilters}
additionalFilterNodes={additionalFilterNodes}
getObjectMetadata={getObjectMetadata}
matchesAdditionalFilters={matchesAdditionalFilters}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import {
ConsoleDataView,
initialFiltersDefault,
} from '@console/app/src/components/data-view/ConsoleDataView';
import { ConsoleDataView } from '@console/app/src/components/data-view/ConsoleDataView';
import { TableProps } from '@console/internal/components/factory';
import { LoadingBox } from '@console/internal/components/utils';
import { K8sResourceKind } from '@console/internal/module/k8s';
Expand All @@ -22,7 +19,6 @@ const ProjectHelmChartRepositoryList: React.FC<TableProps> = (props) => {
loaded={props.loaded}
label={t('helm-plugin~HelmChartRepositories')}
columns={columns}
initialFilters={initialFiltersDefault}
getDataViewRows={getDataViewRows}
hideColumnManagement
data-test="project-helm-chart-repositories-list"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const DisabledCell: React.FC<{ disabled?: boolean }> = ({ disabled }) => {
return <>{disabled ? t('helm-plugin~True') : t('helm-plugin~False')}</>;
};

export const getDataViewRows: GetDataViewRows<K8sResourceKind, undefined> = (data, columns) => {
export const getDataViewRows: GetDataViewRows<K8sResourceKind> = (data, columns) => {
return data.map(({ obj }) => {
const objReference = referenceFor(obj);
const context = { [objReference]: obj };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import {
ConsoleDataView,
initialFiltersDefault,
} from '@console/app/src/components/data-view/ConsoleDataView';
import { ConsoleDataView } from '@console/app/src/components/data-view/ConsoleDataView';
import { TableProps } from '@console/internal/components/factory';
import { LoadingBox } from '@console/internal/components/utils';
import { K8sResourceKind } from '@console/internal/module/k8s';
Expand All @@ -22,7 +19,6 @@ const RepositoriesList: React.FC<TableProps> = (props) => {
loaded={props.loaded}
label={t('helm-plugin~HelmChartRepositories')}
columns={columns}
initialFilters={initialFiltersDefault}
getDataViewRows={getDataViewRows}
hideColumnManagement
data-test="repositories-list"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const DisabledCell: React.FC<{ disabled?: boolean }> = ({ disabled }) => {
return <>{disabled ? t('helm-plugin~True') : t('helm-plugin~False')}</>;
};

export const getDataViewRows: GetDataViewRows<K8sResourceKind, undefined> = (data, columns) => {
export const getDataViewRows: GetDataViewRows<K8sResourceKind> = (data, columns) => {
return data.map(({ obj }) => {
const objReference = referenceFor(obj);
const context = { [objReference]: obj };
Expand Down
6 changes: 4 additions & 2 deletions frontend/public/components/RBAC/bindings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const bindingType = (binding: BindingKind) => {
return binding.metadata.namespace ? 'namespace' : 'cluster';
};

const getDataViewRows: GetDataViewRows<BindingKind, undefined> = (data, columns) => {
const getDataViewRows: GetDataViewRows<BindingKind> = (data, columns) => {
return data.map(({ obj: binding }) => {
const rowCells = {
[tableColumnInfo[0].id]: {
Expand Down Expand Up @@ -266,6 +266,8 @@ export const BindingsList: React.FCC<BindingsListTableProps> = (props) => {
return options;
}, [hasCRBindings, t]);

const initialFilters = React.useMemo(() => ({ ...initialFiltersDefault, 'role-kind': [] }), []);

const additionalFilterNodes = React.useMemo<React.ReactNode[]>(
() => [
<DataViewCheckboxFilter
Expand Down Expand Up @@ -318,7 +320,7 @@ export const BindingsList: React.FCC<BindingsListTableProps> = (props) => {
loaded={loaded}
label={t('public~RoleBindings')}
columns={columns}
initialFilters={{ ...initialFiltersDefault, 'role-kind': [] }}
initialFilters={initialFilters}
additionalFilterNodes={additionalFilterNodes}
matchesAdditionalFilters={matchesAdditionalFilters}
getDataViewRows={getDataViewRows}
Expand Down
5 changes: 3 additions & 2 deletions frontend/public/components/RBAC/role.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ const BindingsListComponent = (props) => {
loaded={loaded}
label={t('public~RoleBindings')}
columns={columns}
initialFilters={initialFiltersDefault}
getDataViewRows={getBindingsDataViewRows}
hideColumnManagement={true}
/>
Expand Down Expand Up @@ -446,6 +445,8 @@ const RolesList = (props) => {
const columns = useRolesColumns();
const roleFilterOptions = useRoleFilterOptions();

const initialFilters = React.useMemo(() => ({ ...initialFiltersDefault, 'role-kind': [] }), []);

const additionalFilterNodes = React.useMemo(
() => [
<DataViewCheckboxFilter
Expand Down Expand Up @@ -480,7 +481,7 @@ const RolesList = (props) => {
label={t('public~Roles')}
columns={columns}
getDataViewRows={getDataViewRows}
initialFilters={{ ...initialFiltersDefault, 'role-kind': [] }}
initialFilters={initialFilters}
additionalFilterNodes={additionalFilterNodes}
matchesAdditionalFilters={matchesAdditionalFilters}
hideColumnManagement={true}
Expand Down
4 changes: 1 addition & 3 deletions frontend/public/components/alert-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { ListPage } from './factory/list-page';
import {
cellIsStickyProps,
getNameCellProps,
initialFiltersDefault,
ConsoleDataView,
} from '@console/app/src/components/data-view/ConsoleDataView';
import { GetDataViewRows } from '@console/app/src/components/data-view/types';
Expand Down Expand Up @@ -124,7 +123,7 @@ const tableColumnInfo = [
{ id: 'nodeSelector' },
];

const getDataViewRows: GetDataViewRows<K8sResourceKind, undefined> = (data, columns) => {
const getDataViewRows: GetDataViewRows<K8sResourceKind> = (data, columns) => {
return data.map(({ obj: alertManager }) => {
const { metadata, spec } = alertManager;

Expand Down Expand Up @@ -230,7 +229,6 @@ const AlertManagersList: React.FCC<AlertManagersListProps> = ({ data, loaded, ..
data={data}
loaded={loaded}
columns={columns}
initialFilters={initialFiltersDefault}
getDataViewRows={getDataViewRows}
hideColumnManagement={true}
/>
Expand Down
4 changes: 1 addition & 3 deletions frontend/public/components/build-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
actionsCellProps,
cellIsStickyProps,
getNameCellProps,
initialFiltersDefault,
ConsoleDataView,
} from '@console/app/src/components/data-view/ConsoleDataView';
import { GetDataViewRows } from '@console/app/src/components/data-view/types';
Expand Down Expand Up @@ -134,7 +133,7 @@ const tableColumnInfo = [
{ id: 'actions' },
];

const getDataViewRows: GetDataViewRows<BuildConfig, undefined> = (data, columns) => {
const getDataViewRows: GetDataViewRows<BuildConfig> = (data, columns) => {
return data.map(({ obj }) => {
const { name, namespace } = obj.metadata;
const latestBuild = obj?.latestBuild;
Expand Down Expand Up @@ -328,7 +327,6 @@ export const BuildConfigsList: React.FCC<BuildConfigsListProps> = ({ data, loade
data={buildResource}
loaded={loaded}
columns={columns}
initialFilters={initialFiltersDefault}
getDataViewRows={getDataViewRows}
hideColumnManagement={true}
/>
Expand Down
4 changes: 1 addition & 3 deletions frontend/public/components/build.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
actionsCellProps,
cellIsStickyProps,
getNameCellProps,
initialFiltersDefault,
ConsoleDataView,
} from '@console/app/src/components/data-view/ConsoleDataView';
import { GetDataViewRows } from '@console/app/src/components/data-view/types';
Expand Down Expand Up @@ -358,7 +357,7 @@ const tableColumnInfo = [
{ id: 'actions' },
];

const getDataViewRows: GetDataViewRows<K8sResourceKind, undefined> = (data, columns) => {
const getDataViewRows: GetDataViewRows<K8sResourceKind> = (data, columns) => {
return data.map(({ obj }) => {
const { name, namespace } = obj.metadata;
const kindReference = referenceFor(obj);
Expand Down Expand Up @@ -466,7 +465,6 @@ export const BuildsList: React.FCC<BuildsListProps> = ({ data, loaded, ...props
data={data}
loaded={loaded}
columns={columns}
initialFilters={initialFiltersDefault}
getDataViewRows={getDataViewRows}
hideColumnManagement={true}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export const ClusterOperatorList: React.FC<ClusterOperatorListProps> = ({
}) => {
const { t } = useTranslation();
const columns = useClusterOperatorColumns();

const clusterOperatorStatusFilterOptions = React.useMemo<DataViewFilterOption[]>(() => {
return [
{
Expand Down Expand Up @@ -213,6 +214,9 @@ export const ClusterOperatorList: React.FC<ClusterOperatorListProps> = ({
},
];
}, [t]);

const initialFilters = React.useMemo(() => ({ ...initialFiltersDefault, status: [] }), []);

const additionalFilterNodes = React.useMemo<React.ReactNode[]>(
() => [
<DataViewCheckboxFilter
Expand All @@ -225,6 +229,7 @@ export const ClusterOperatorList: React.FC<ClusterOperatorListProps> = ({
],
[t, clusterOperatorStatusFilterOptions],
);

const matchesAdditionalFilters = React.useCallback(
(resource: ClusterOperator, filters: ClusterOperatorFilters) =>
filters.status.length === 0 || filters.status.includes(getClusterOperatorStatus(resource)),
Expand All @@ -239,7 +244,7 @@ export const ClusterOperatorList: React.FC<ClusterOperatorListProps> = ({
data={data}
loaded={loaded}
columns={columns}
initialFilters={{ ...initialFiltersDefault, status: [] }}
initialFilters={initialFilters}
additionalFilterNodes={additionalFilterNodes}
matchesAdditionalFilters={matchesAdditionalFilters}
getDataViewRows={getClusterOperatorDataViewRows}
Expand Down
Loading