MINOR: fix the team profile call being made in activity feed (#20750)

* fix the team profile call being made in activity feed

* remove the function call from renderer and useMemo variable instead
This commit is contained in:
Ashish Gupta 2025-04-10 15:34:11 +05:30 committed by GitHub
parent e2a3eb823a
commit ec336bc026
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 83 additions and 70 deletions

View File

@ -12,19 +12,21 @@
*/ */
import { Col, Row, Typography } from 'antd'; import { Col, Row, Typography } from 'antd';
import classNames from 'classnames';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import React, { useMemo } from 'react'; import React, { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { ReactComponent as AddIcon } from '../../../../../assets/svg/added-icon.svg'; import { ReactComponent as AddIcon } from '../../../../../assets/svg/added-icon.svg';
import { ReactComponent as DeletedIcon } from '../../../../../assets/svg/deleted-icon.svg'; import { ReactComponent as DeletedIcon } from '../../../../../assets/svg/deleted-icon.svg';
import { useTranslation } from 'react-i18next';
import { import {
MAX_VISIBLE_OWNERS_FOR_FEED_CARD, MAX_VISIBLE_OWNERS_FOR_FEED_CARD,
MAX_VISIBLE_OWNERS_FOR_FEED_TAB, MAX_VISIBLE_OWNERS_FOR_FEED_TAB,
} from '../../../../../constants/constants'; } from '../../../../../constants/constants';
import { EntityType } from '../../../../../enums/entity.enum';
import { Owner } from '../../../../../generated/entity/feed/owner'; import { Owner } from '../../../../../generated/entity/feed/owner';
import { Thread } from '../../../../../generated/entity/feed/thread'; import { Thread } from '../../../../../generated/entity/feed/thread';
import { EntityReference } from '../../../../../generated/entity/type'; import { EntityReference } from '../../../../../generated/entity/type';
import { OwnerItem } from '../../../../common/OwnerItem/OwnerItem';
import { OwnerLabel } from '../../../../common/OwnerLabel/OwnerLabel.component'; import { OwnerLabel } from '../../../../common/OwnerLabel/OwnerLabel.component';
import UserPopOverCard from '../../../../common/PopOverCard/UserPopOverCard'; import UserPopOverCard from '../../../../common/PopOverCard/UserPopOverCard';
import ProfilePicture from '../../../../common/ProfilePicture/ProfilePicture'; import ProfilePicture from '../../../../common/ProfilePicture/ProfilePicture';
@ -50,31 +52,26 @@ function OwnersFeed({
}; };
}, [feed]); }, [feed]);
const maxVisibleOwners = isForFeedTab const maxVisibleOwners = useMemo(
() =>
isForFeedTab
? MAX_VISIBLE_OWNERS_FOR_FEED_TAB ? MAX_VISIBLE_OWNERS_FOR_FEED_TAB
: MAX_VISIBLE_OWNERS_FOR_FEED_CARD; : MAX_VISIBLE_OWNERS_FOR_FEED_CARD,
[isForFeedTab]
);
return ( const getOwnerItems = useCallback(
<Row gutter={[8, 8]}> (ownerList: EntityReference[]) => {
{!isEmpty(updatedOwner) && ( return ownerList.length <= maxVisibleOwners ? (
<Col span={24}>
<Row wrap align="middle"> <Row wrap align="middle">
<Row align="middle" gutter={[8, 8]}> {ownerList.map((owner: EntityReference, index: number) =>
<AddIcon className="text-success-hover" height={16} width={16} /> owner.type === EntityType.USER ? (
<Typography.Text className="owners-label">
{t('label.owner-plural-with-colon')}
</Typography.Text>
</Row>
<Col>
{updatedOwner.length <= maxVisibleOwners ? (
<Row wrap align="middle">
{updatedOwner.map((owner: EntityReference) => (
<UserPopOverCard key={owner.id} userName={owner.name ?? ''}> <UserPopOverCard key={owner.id} userName={owner.name ?? ''}>
<div <div
className={`owner-chip d-flex items-center ${ className={`owner-chip d-flex items-center ${
showThread && 'bg-white' showThread && 'bg-white'
}`}> }`}
key={owner.id}>
<ProfilePicture <ProfilePicture
displayName={owner.displayName} displayName={owner.displayName}
name={owner.name ?? ''} name={owner.name ?? ''}
@ -85,18 +82,59 @@ function OwnersFeed({
</Typography.Text> </Typography.Text>
</div> </div>
</UserPopOverCard> </UserPopOverCard>
))} ) : (
<div
className={classNames('owner-chip', {
'bg-white': showThread,
})}
key={owner.id}>
<OwnerItem
isCompactView
avatarSize={24}
className="owner-chip-text"
index={index}
owner={owner}
/>
</div>
)
)}
</Row> </Row>
) : ( ) : (
<OwnerLabel <OwnerLabel
avatarSize={24} avatarSize={24}
isCompactView={false} isCompactView={false}
maxVisibleOwners={maxVisibleOwners} maxVisibleOwners={maxVisibleOwners}
owners={updatedOwner} owners={ownerList}
showLabel={false} showLabel={false}
/> />
)} );
</Col> },
[maxVisibleOwners, showThread]
);
const renderUpdatedOwner = useMemo(
() => getOwnerItems(updatedOwner),
[updatedOwner, getOwnerItems]
);
const renderPreviousOwner = useMemo(
() => getOwnerItems(previousOwner),
[previousOwner, getOwnerItems]
);
return (
<Row gutter={[8, 8]}>
{!isEmpty(updatedOwner) && (
<Col span={24}>
<Row wrap align="middle">
<Row align="middle">
<AddIcon className="text-success-hover" height={16} width={16} />
<Typography.Text className="owners-label">
{t('label.owner-plural-with-colon')}
</Typography.Text>
</Row>
<Col>{renderUpdatedOwner}</Col>
</Row> </Row>
</Col> </Col>
)} )}
@ -104,44 +142,14 @@ function OwnersFeed({
<Col span={24}> <Col span={24}>
<Row wrap align="middle"> <Row wrap align="middle">
<Col> <Col>
<Row align="middle" gutter={[8, 8]}> <Row align="middle">
<DeletedIcon className="text-error" height={14} width={14} /> <DeletedIcon className="text-error" height={14} width={14} />
<Typography.Text className="owners-label"> <Typography.Text className="owners-label">
{t('label.owner-plural-with-colon')} {t('label.owner-plural-with-colon')}
</Typography.Text> </Typography.Text>
</Row> </Row>
</Col> </Col>
<Col> <Col>{renderPreviousOwner}</Col>
{previousOwner.length <= maxVisibleOwners ? (
<Row align="middle">
{previousOwner.map((owner: EntityReference) => (
<UserPopOverCard key={owner.id} userName={owner.name ?? ''}>
<div
className={`owner-chip d-flex items-center ${
showThread && 'bg-white'
}`}>
<ProfilePicture
displayName={owner.displayName}
name={owner.name ?? ''}
width="24"
/>
<Typography.Text className="owner-chip-text">
{owner.displayName}
</Typography.Text>
</div>
</UserPopOverCard>
))}
</Row>
) : (
<OwnerLabel
avatarSize={24}
isCompactView={false}
maxVisibleOwners={maxVisibleOwners}
owners={previousOwner}
showLabel={false}
/>
)}
</Col>
</Row> </Row>
</Col> </Col>
)} )}

View File

@ -590,6 +590,10 @@
padding: 4px 8px; padding: 4px 8px;
margin-right: @margin-xs; margin-right: @margin-xs;
border: 1px solid @grey-15; border: 1px solid @grey-15;
.owner-team-icon {
font-size: 24px !important;
}
} }
.owner-chip-text { .owner-chip-text {
@ -597,6 +601,7 @@
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
line-height: normal; line-height: normal;
font-size: 14px !important;
margin-left: @margin-xss; margin-left: @margin-xss;
} }