mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-03 21:03:48 +00:00
fix(ui): overflow for frequently joined table widget (#21623)
(cherry picked from commit b0f82aa0ef5f98384bebca74e6d837ffbd231222)
This commit is contained in:
parent
d0fe6f401d
commit
7040e02cfb
@ -10,13 +10,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Space, Typography } from 'antd';
|
||||
import { Button, Typography } from 'antd';
|
||||
import { isEmpty } from 'lodash';
|
||||
import React, { useEffect, useMemo } from 'react';
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link } from 'react-router-dom';
|
||||
import ExpandableCard from '../../../components/common/ExpandableCard/ExpandableCard';
|
||||
import { useGenericContext } from '../../../components/Customization/GenericProvider/GenericProvider';
|
||||
import { LIST_SIZE } from '../../../constants/constants';
|
||||
import { DetailPageWidgetKeys } from '../../../enums/CustomizeDetailPage.enum';
|
||||
import { EntityType } from '../../../enums/entity.enum';
|
||||
import { JoinedWith, Table } from '../../../generated/entity/data/table';
|
||||
@ -36,6 +37,7 @@ export const FrequentlyJoinedTables = ({
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const { data, filterWidgets } = useGenericContext<Table>();
|
||||
const [visibleCount, setVisibleCount] = useState(LIST_SIZE);
|
||||
|
||||
const joinedTables = useMemo(
|
||||
() => getJoinsFromTableJoins(data?.joins),
|
||||
@ -48,34 +50,64 @@ export const FrequentlyJoinedTables = ({
|
||||
}
|
||||
}, [joinedTables]);
|
||||
|
||||
const hasMoreElement = useMemo(
|
||||
() => LIST_SIZE < joinedTables.length,
|
||||
[joinedTables]
|
||||
);
|
||||
|
||||
const handleShowMore = useCallback(() => {
|
||||
setVisibleCount(
|
||||
visibleCount === joinedTables.length ? LIST_SIZE : joinedTables.length
|
||||
);
|
||||
}, [joinedTables, visibleCount]);
|
||||
|
||||
const content = useMemo(() => {
|
||||
return joinedTables.slice(0, visibleCount).map((table) => (
|
||||
<div
|
||||
className="frequently-joint-data"
|
||||
data-testid="related-tables-data"
|
||||
key={table.name}>
|
||||
<Link
|
||||
to={getEntityDetailsPath(EntityType.TABLE, table.fullyQualifiedName)}>
|
||||
<Typography.Text
|
||||
className="frequently-joint-name"
|
||||
ellipsis={{ tooltip: true }}>
|
||||
{table.name}
|
||||
</Typography.Text>
|
||||
</Link>
|
||||
{getCountBadge(table.joinCount, '', false)}
|
||||
</div>
|
||||
));
|
||||
}, [joinedTables, visibleCount]);
|
||||
|
||||
if (isEmpty(joinedTables)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const content = joinedTables.map((table) => (
|
||||
<Space
|
||||
className="w-full frequently-joint-data justify-between m-t-xss"
|
||||
data-testid="related-tables-data"
|
||||
key={table.name}
|
||||
size={4}>
|
||||
<Link
|
||||
to={getEntityDetailsPath(EntityType.TABLE, table.fullyQualifiedName)}>
|
||||
<Typography.Text className="frequently-joint-name">
|
||||
{table.name}
|
||||
</Typography.Text>
|
||||
</Link>
|
||||
{getCountBadge(table.joinCount, '', false)}
|
||||
</Space>
|
||||
));
|
||||
|
||||
return renderAsExpandableCard ? (
|
||||
<ExpandableCard
|
||||
cardProps={{
|
||||
title: t('label.frequently-joined-table-plural'),
|
||||
className: 'frequently-joint-data-container',
|
||||
}}
|
||||
dataTestId="frequently-joint-data-container"
|
||||
isExpandDisabled={isEmpty(joinedTables)}>
|
||||
{content}
|
||||
|
||||
{hasMoreElement ? (
|
||||
<Button
|
||||
className="show-more-tags-button"
|
||||
data-testid="read-button"
|
||||
size="small"
|
||||
type="link"
|
||||
onClick={handleShowMore}>
|
||||
{visibleCount === joinedTables.length
|
||||
? t('label.less')
|
||||
: t('label.plus-count-more', {
|
||||
count: joinedTables.length - visibleCount,
|
||||
})}
|
||||
</Button>
|
||||
) : null}
|
||||
</ExpandableCard>
|
||||
) : (
|
||||
<>{content}</>
|
||||
|
@ -10,15 +10,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@import url('../../../styles/variables.less');
|
||||
@import (reference) url('../../../styles/variables.less');
|
||||
|
||||
.frequently-joint-data-container {
|
||||
max-height: 200px;
|
||||
overflow-y: scroll;
|
||||
|
||||
.frequently-joint-data {
|
||||
.frequently-joint-name {
|
||||
font-weight: 300;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
|
||||
> a {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user