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 @@ -23,7 +23,14 @@
import { Globe01, Package, Plus } from '@untitledui/icons';
import classNames from 'classnames';
import { isEmpty } from 'lodash';
import { FC, ReactNode, useCallback, useMemo, useState } from 'react';
import {
FC,
MouseEvent,
ReactNode,
useCallback,
useMemo,
useState,
} from 'react';
import { useTranslation } from 'react-i18next';
import { NO_DATA, ROUTES } from '../../constants/constants';
import { LEARNING_PAGE_IDS } from '../../constants/Learning.constants';
Expand Down Expand Up @@ -66,7 +73,7 @@

const DataProductListPage = ({
renderPageHeader,
}: DataProductListPageProps) => {

Check warning on line 76 in openmetadata-ui/src/main/resources/ui/src/components/DataProduct/DataProductListPage.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

{"message":"Function has a complexity of 12 which is greater than 10 authorized.","cost":2,"secondaryLocations":[{"line":76,"column":29,"endLine":76,"endColumn":31,"message":"+1"},{"line":83,"column":50,"endLine":83,"endColumn":52,"message":"+1"},{"line":131,"column":40,"endLine":131,"endColumn":41,"message":"+1"},{"line":138,"column":54,"endLine":138,"endColumn":56,"message":"+1"},{"line":142,"column":22,"endLine":142,"endColumn":23,"message":"+1"},{"line":396,"column":38,"endLine":396,"endColumn":40,"message":"+1"},{"line":396,"column":25,"endLine":396,"endColumn":27,"message":"+1"},{"line":400,"column":8,"endLine":400,"endColumn":9,"message":"+1"},{"line":402,"column":62,"endLine":402,"endColumn":64,"message":"+1"},{"line":413,"column":26,"endLine":413,"endColumn":27,"message":"+1"},{"line":419,"column":31,"endLine":419,"endColumn":33,"message":"+1"},{"line":420,"column":31,"endLine":420,"endColumn":33,"message":"+1"}]}
const dataProductListing = useDataProductListingData();
const { isMarketplace, dataProductBasePath } = useMarketplaceStore();
const { t } = useTranslation();
Expand Down Expand Up @@ -138,7 +145,7 @@
});

const { titleAndCount } = useTitleAndCount({
titleKey: 'label.data-product',

Check warning on line 148 in openmetadata-ui/src/main/resources/ui/src/components/DataProduct/DataProductListPage.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

Define a constant instead of duplicating this literal 4 times
count: dataProductListing.totalEntities,
loading: dataProductListing.loading,
});
Expand All @@ -159,7 +166,7 @@
);

const renderDataProductCell = useCallback(
(entity: DataProduct, columnId: string): ReactNode => {

Check warning on line 169 in openmetadata-ui/src/main/resources/ui/src/components/DataProduct/DataProductListPage.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

{"message":"Function has a complexity of 13 which is greater than 10 authorized.","cost":3,"secondaryLocations":[{"line":169,"column":55,"endLine":169,"endColumn":57,"message":"+1"},{"line":171,"column":8,"endLine":171,"endColumn":12,"message":"+1"},{"line":175,"column":24,"endLine":175,"endColumn":26,"message":"+1"},{"line":174,"column":31,"endLine":174,"endColumn":33,"message":"+1"},{"line":199,"column":26,"endLine":199,"endColumn":28,"message":"+1"},{"line":211,"column":8,"endLine":211,"endColumn":12,"message":"+1"},{"line":220,"column":8,"endLine":220,"endColumn":12,"message":"+1"},{"line":222,"column":8,"endLine":222,"endColumn":12,"message":"+1"},{"line":224,"column":10,"endLine":224,"endColumn":12,"message":"+1"},{"line":240,"column":39,"endLine":240,"endColumn":41,"message":"+1"},{"line":244,"column":36,"endLine":244,"endColumn":38,"message":"+1"},{"line":249,"column":8,"endLine":249,"endColumn":12,"message":"+1"},{"line":253,"column":8,"endLine":253,"endColumn":12,"message":"+1"}]}
switch (columnId) {
case 'name': {
const entityName = getEntityName(entity);
Expand All @@ -168,12 +175,18 @@
entity.name &&
entity.displayName !== entity.name;

const handleNameClick = (event: MouseEvent<HTMLDivElement>) => {
event.stopPropagation();
dataProductListing.actionHandlers.onEntityClick?.(entity);
};

return (
<Box
align="center"
className={NAME_CELL_CLIP_CLASS}
direction="row"
gap={3}>
gap={3}
onClick={handleNameClick}>
<Avatar size="md" {...getEntityAvatarProps(entity)} />
<Box className="tw:min-w-0" direction="col">
<Typography
Expand Down Expand Up @@ -250,7 +263,7 @@
return null;
}
},
[]
[dataProductListing.actionHandlers.onEntityClick]

Check warning on line 266 in openmetadata-ui/src/main/resources/ui/src/components/DataProduct/DataProductListPage.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useCallback has a missing dependency: 'dataProductListing.actionHandlers'. Either include it or remove the dependency array
);

const selectedDataProductEntities = useMemo(
Expand Down Expand Up @@ -360,7 +373,7 @@
/>
</>
);
}, [

Check warning on line 376 in openmetadata-ui/src/main/resources/ui/src/components/DataProduct/DataProductListPage.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useMemo has missing dependencies: 'dataProductColumns' and 'dataProductListing'. Either include them or remove the dependency array
dataProductListing.loading,
dataProductListing.entities,
dataProductListing.selectedEntities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import { useDomainCreateDrawer } from './hooks/useDomainCreateDrawer';
import { useDomainListingData } from './hooks/useDomainListingData';

const DomainListPage = ({ renderPageHeader }: DomainListPageProps) => {

Check warning on line 51 in openmetadata-ui/src/main/resources/ui/src/components/DomainListing/DomainListPage.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

{"message":"Function has a complexity of 13 which is greater than 10 authorized.","cost":3,"secondaryLocations":[{"line":51,"column":67,"endLine":51,"endColumn":69,"message":"+1"},{"line":60,"column":45,"endLine":60,"endColumn":47,"message":"+1"},{"line":107,"column":40,"endLine":107,"endColumn":41,"message":"+1"},{"line":114,"column":49,"endLine":114,"endColumn":51,"message":"+1"},{"line":119,"column":22,"endLine":119,"endColumn":23,"message":"+1"},{"line":283,"column":51,"endLine":283,"endColumn":53,"message":"+1"},{"line":286,"column":38,"endLine":286,"endColumn":40,"message":"+1"},{"line":286,"column":25,"endLine":286,"endColumn":27,"message":"+1"},{"line":290,"column":8,"endLine":290,"endColumn":9,"message":"+1"},{"line":292,"column":57,"endLine":292,"endColumn":59,"message":"+1"},{"line":303,"column":26,"endLine":303,"endColumn":27,"message":"+1"},{"line":309,"column":31,"endLine":309,"endColumn":33,"message":"+1"},{"line":310,"column":31,"endLine":310,"endColumn":33,"message":"+1"}]}
const domainListing = useDomainListingData();
const { isMarketplace, domainBasePath } = useMarketplaceStore();
const { t } = useTranslation();
Expand Down Expand Up @@ -122,7 +122,7 @@
});

const { titleAndCount } = useTitleAndCount({
titleKey: 'label.domain',

Check warning on line 125 in openmetadata-ui/src/main/resources/ui/src/components/DomainListing/DomainListPage.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

Define a constant instead of duplicating this literal 3 times
count: domainListing.totalEntities,
loading: domainListing.loading,
});
Expand All @@ -132,7 +132,9 @@
const { renderDomainCard } = useDomainCardTemplates();

const { columns: domainColumns, renderCell: renderDomainCell } =
useDomainTableColumns();
useDomainTableColumns({
onEntityClick: domainListing.actionHandlers.onEntityClick,
});

const selectedDomainEntities = useMemo(
() =>
Expand Down Expand Up @@ -252,7 +254,7 @@
/>
</>
);
}, [

Check warning on line 257 in openmetadata-ui/src/main/resources/ui/src/components/DomainListing/DomainListPage.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useMemo has missing dependencies: 'domainColumns' and 'domainListing'. Either include them or remove the dependency array
isTreeView,
domainListing.loading,
domainListing.entities,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { fireEvent, render, screen } from '@testing-library/react';
import { ReactNode } from 'react';
import { Domain } from '../../../../../generated/entity/domains/domain';
import { renderDomainNameCell } from './domainFieldRenderers';

jest.mock('@openmetadata/ui-core-components', () => ({
Avatar: () => <span data-testid="avatar" />,
Box: ({
children,
onClick,
}: {
children: ReactNode;
onClick?: () => void;
}) => (
<div data-testid="name-cell" onClick={onClick}>

Check warning on line 27 in openmetadata-ui/src/main/resources/ui/src/components/common/atoms/domain/ui/domainFieldRenderers.test.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

Avoid non-native interactive elements. If using native HTML is not possible, add an appropriate role and support for tabbing, mouse, keyboard, and touch inputs to an interactive content element

Check warning on line 27 in openmetadata-ui/src/main/resources/ui/src/components/common/atoms/domain/ui/domainFieldRenderers.test.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

Visible, non-interactive elements with click handlers must have at least one keyboard listener
{children}
</div>
),
Typography: ({ children }: { children: ReactNode }) => (
<span>{children}</span>
),
}));

jest.mock('../../../../../utils/TooltipUtils', () => ({
renderBreakableTooltip: (value: string) => value,
}));

const DOMAIN = {
id: 'domain-id',
name: 'engineering',
displayName: 'Engineering',
fullyQualifiedName: 'engineering',
} as Domain;

describe('renderDomainNameCell', () => {
it('navigates once when the name cell is clicked', () => {
const onClick = jest.fn();

render(<>{renderDomainNameCell(DOMAIN, onClick)}</>);
fireEvent.click(screen.getByText('Engineering'));

expect(onClick).toHaveBeenCalledTimes(1);
});

it('stops the click from bubbling to the row so navigation is not duplicated', () => {
const onClick = jest.fn();
const rowClick = jest.fn();

render(
<div onClick={rowClick}>{renderDomainNameCell(DOMAIN, onClick)}</div>
);
fireEvent.click(screen.getByText('Engineering'));

expect(onClick).toHaveBeenCalledTimes(1);
expect(rowClick).not.toHaveBeenCalled();
});

it('does not attach a click handler when no onClick is provided', () => {
const rowClick = jest.fn();

render(<div onClick={rowClick}>{renderDomainNameCell(DOMAIN)}</div>);
fireEvent.click(screen.getByText('Engineering'));

// With no cell handler the click falls through to the row unchanged.
expect(rowClick).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

import { Avatar, Box, Typography } from '@openmetadata/ui-core-components';
import { ReactNode } from 'react';
import { MouseEvent, ReactNode } from 'react';
import { NO_DATA } from '../../../../../constants/constants';
import { DataProduct } from '../../../../../generated/entity/domains/dataProduct';
import { Domain } from '../../../../../generated/entity/domains/domain';
Expand Down Expand Up @@ -69,16 +69,23 @@ export const LIST_EMPTY_STATE_CLASS =
'tw:flex tw:flex-1 tw:min-h-60 tw:items-center tw:justify-center';

export const renderDomainNameCell = (
entity: Domain | DataProduct
entity: Domain | DataProduct,
onClick?: () => void
): ReactNode => {
const entityName = getEntityName(entity);

const handleNameClick = (event: MouseEvent<HTMLDivElement>) => {
event.stopPropagation();
onClick?.();
};

return (
<Box
align="center"
className={NAME_CELL_CLIP_CLASS}
direction="row"
gap={3}>
gap={3}
onClick={onClick ? handleNameClick : undefined}>
<Avatar size="md" {...getEntityAvatarProps(entity)} />
<Typography
Comment thread
gitar-bot[bot] marked this conversation as resolved.
className={CLIPPED_NAME_CLASS}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { fireEvent, render, renderHook, screen } from '@testing-library/react';
import { ReactNode } from 'react';
import { Domain } from '../../../../../generated/entity/domains/domain';
import { useDomainTableColumns } from './useDomainTableColumns';

jest.mock('react-i18next', () => ({
useTranslation: () => ({ t: (key: string) => key }),
}));

jest.mock('@openmetadata/ui-core-components', () => ({
Avatar: () => <span data-testid="avatar" />,
Box: ({
children,
onClick,
}: {
children: ReactNode;
onClick?: () => void;
}) => (
<div data-testid="name-cell" onClick={onClick}>
{children}
</div>
),
Typography: ({ children }: { children: ReactNode }) => (
<span>{children}</span>
),
}));

jest.mock('../../../../../utils/TooltipUtils', () => ({
renderBreakableTooltip: (value: string) => value,
}));

const DOMAIN = {
id: 'domain-id',
name: 'engineering',
displayName: 'Engineering',
fullyQualifiedName: 'engineering',
} as Domain;

describe('useDomainTableColumns', () => {
it('routes a name-cell click to onEntityClick with the row entity', () => {
const onEntityClick = jest.fn();

const { result } = renderHook(() =>
useDomainTableColumns({ onEntityClick })
);

render(<>{result.current.renderCell(DOMAIN, 'name')}</>);
fireEvent.click(screen.getByText('Engineering'));

expect(onEntityClick).toHaveBeenCalledTimes(1);
expect(onEntityClick).toHaveBeenCalledWith(DOMAIN);
});

it('renders the name cell without a click handler when onEntityClick is omitted', () => {
const rowClick = jest.fn();

const { result } = renderHook(() => useDomainTableColumns());

render(
<div onClick={rowClick}>{result.current.renderCell(DOMAIN, 'name')}</div>
);
fireEvent.click(screen.getByText('Engineering'));

expect(rowClick).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import {
interface UseDomainTableColumnsOptions {
nameLabelKey?: string;
tagSize?: 'sm' | 'lg';
onEntityClick?: (entity: Domain) => void;
}

export const useDomainTableColumns = ({
nameLabelKey = 'label.domain',
tagSize = 'sm',
onEntityClick,
}: UseDomainTableColumnsOptions = {}) => {
const { t } = useTranslation();

Expand All @@ -49,7 +51,10 @@ export const useDomainTableColumns = ({
(entity: Domain, columnId: string): ReactNode => {
switch (columnId) {
case 'name':
return renderDomainNameCell(entity);
return renderDomainNameCell(
entity,
onEntityClick ? () => onEntityClick(entity) : undefined
);
case 'domainType':
return renderDomainTypeCell(entity);
case 'owners':
Expand All @@ -62,7 +67,7 @@ export const useDomainTableColumns = ({
return null;
}
},
[tagSize]
[tagSize, onEntityClick]
);

return { columns, renderCell };
Expand Down
Loading