Skip to content

Commit

Permalink
fetch count as per new count api for entity and user page and remove …
Browse files Browse the repository at this point in the history
…mentions tab from entity
  • Loading branch information
Ashish8689 committed Jan 27, 2024
1 parent d863a6a commit fe8e2ec
Show file tree
Hide file tree
Showing 30 changed files with 362 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
*/
import { Typography } from 'antd';
import { isEmpty } from 'lodash';
import React, { ReactNode, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import React, { ReactNode, useEffect, useState } from 'react';
import { ReactComponent as FeedEmptyIcon } from '../../../assets/svg/activity-feed-no-data-placeholder.svg';
import ErrorPlaceHolder from '../../../components/common/ErrorWithPlaceholder/ErrorPlaceHolder';
import Loader from '../../../components/Loader/Loader';
import { ERROR_PLACEHOLDER_TYPE, SIZE } from '../../../enums/common.enum';
import { Thread } from '../../../generated/entity/feed/thread';
import { getFeedListWithRelativeDays } from '../../../utils/FeedUtils';
import FeedPanelBodyV1 from '../ActivityFeedPanel/FeedPanelBodyV1';
import { ActivityFeedTabs } from '../ActivityFeedTab/ActivityFeedTab.interface';
import './activity-feed-list.less';

interface ActivityFeedListV1Props {
Expand All @@ -33,7 +31,6 @@ interface ActivityFeedListV1Props {
hidePopover: boolean;
isForFeedTab?: boolean;
emptyPlaceholderText: ReactNode;
tab: ActivityFeedTabs;
}

const ActivityFeedListV1 = ({
Expand All @@ -45,13 +42,9 @@ const ActivityFeedListV1 = ({
hidePopover = false,
isForFeedTab = false,
emptyPlaceholderText,
tab,
}: ActivityFeedListV1Props) => {
const { t } = useTranslation();
const [entityThread, setEntityThread] = useState<Thread[]>([]);

const isTaskTab = useMemo(() => tab === ActivityFeedTabs.TASKS, [tab]);

useEffect(() => {
const { updatedFeedList } = getFeedListWithRelativeDays(feedList);
setEntityThread(updatedFeedList);
Expand All @@ -78,11 +71,6 @@ const ActivityFeedListV1 = ({
<Typography.Paragraph
className="tw-max-w-md"
style={{ marginBottom: '0' }}>
{isTaskTab && (
<Typography.Text strong>
{t('message.no-open-tasks')} <br />
</Typography.Text>
)}
{emptyPlaceholderText}
</Typography.Paragraph>
</ErrorPlaceHolder>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* limitations under the License.
*/
import { Menu, Space, Typography } from 'antd';
import { AxiosError } from 'axios';
import classNames from 'classnames';
import { noop } from 'lodash';
import {
Expand All @@ -33,6 +34,7 @@ import {
ICON_DIMENSION,
ROUTES,
} from '../../../constants/constants';
import { FEED_COUNT_INITIAL_DATA } from '../../../constants/entity.constants';
import { observerOptions } from '../../../constants/Mydata.constants';
import { EntityTabs, EntityType } from '../../../enums/entity.enum';
import { FeedFilter } from '../../../enums/mydata.enum';
Expand All @@ -43,16 +45,19 @@ import {
} from '../../../generated/entity/feed/thread';
import { useAuth } from '../../../hooks/authHooks';
import { useElementInView } from '../../../hooks/useElementInView';
import { getAllFeeds, getFeedCount } from '../../../rest/feedsAPI';
import { FeedCounts } from '../../../interface/feed.interface';
import { getFeedCount } from '../../../rest/feedsAPI';
import {
getCountBadge,
getEntityDetailLink,
getFeedCounts,
Transi18next,
} from '../../../utils/CommonUtils';
import {
ENTITY_LINK_SEPARATOR,
getEntityFeedLink,
getEntityUserLink,
} from '../../../utils/EntityUtils';
import { showErrorToast } from '../../../utils/ToastUtils';
import { useAuthContext } from '../../Auth/AuthProviders/AuthProvider';
import Loader from '../../Loader/Loader';
import { TaskTab } from '../../Task/TaskTab/TaskTab.component';
Expand Down Expand Up @@ -89,8 +94,7 @@ export const ActivityFeedTab = ({
useParams<{ subTab: ActivityFeedTabs }>();
const { isAdminUser } = useAuth();
const [taskFilter, setTaskFilter] = useState<TaskFilter>('open');
const [allCount, setAllCount] = useState(0);
const [tasksCount, setTasksCount] = useState(0);
const [count, setCount] = useState<FeedCounts>(FEED_COUNT_INITIAL_DATA);

const {
postFeed,
Expand All @@ -99,7 +103,6 @@ export const ActivityFeedTab = ({
entityThread,
getFeedData,
loading,
userId,
entityPaging,
} = useActivityFeedProvider();

Expand Down Expand Up @@ -149,65 +152,44 @@ export const ActivityFeedTab = ({
}
}, [activeTab]);

const fetchFeedsCount = () => {
if (!isUserEntity) {
// To get conversation count
getFeedCount(
getEntityFeedLink(entityType, fqn),
ThreadType.Conversation
).then((res) => {
if (res) {
setAllCount(res.totalCount);
} else {
throw t('server.entity-feed-fetch-error');
}
});
const handleFeedCount = useCallback((data: FeedCounts) => {
setCount(data);
}, []);

// To get open tasks count
getFeedCount(getEntityFeedLink(entityType, fqn), ThreadType.Task).then(
(res) => {
if (res) {
setTasksCount(res.totalCount);
} else {
throw t('server.entity-feed-fetch-error');
}
}
);
const fetchFeedsCount = async () => {
if (isUserEntity) {
try {
const res = await getFeedCount(
getEntityUserLink(
isAdminUser ? currentUser?.fullyQualifiedName ?? '' : fqn
)
);
setCount({
conversationCount: res[0].conversationCount ?? 0,
totalTasksCount: res[0].totalTaskCount,
openTaskCount: res[0].openTaskCount ?? 0,
closedTaskCount: res[0].closedTaskCount ?? 0,
totalCount: res[0].conversationCount ?? 0 + res[0].totalTaskCount,
mentionCount: res[0].mentionCount ?? 0,
});
} catch (err) {
showErrorToast(err as AxiosError, t('server.entity-feed-fetch-error'));
}
} else {
// count for task on userProfile page
getAllFeeds(
undefined,
undefined,
ThreadType.Task,
isAdminUser ? undefined : FeedFilter.OWNER,
undefined,
userId
).then((res) => {
if (res) {
setTasksCount(res.paging.total);
} else {
throw t('server.entity-feed-fetch-error');
}
});

// count for all on userProfile page
getAllFeeds(
undefined,
undefined,
ThreadType.Conversation,
isAdminUser ? undefined : FeedFilter.OWNER,
undefined,
userId
).then((res) => {
if (res) {
setAllCount(res.paging.total);
} else {
throw t('server.entity-feed-fetch-error');
}
});
getFeedCounts(entityType, fqn, handleFeedCount);
}
};

const getThreadType = useCallback((activeTab) => {
if (activeTab === ActivityFeedTabs.TASKS) {
return ThreadType.Task;
} else if (activeTab === ActivityFeedTabs.ALL) {
return ThreadType.Conversation;
} else {
return;
}
}, []);

useEffect(() => {
if (fqn) {
fetchFeedsCount();
Expand All @@ -221,8 +203,7 @@ export const ActivityFeedTab = ({
const filter = isUserEntity ? currentFilter : undefined;

return {
threadType:
activeTab === 'tasks' ? ThreadType.Task : ThreadType.Conversation,
threadType: getThreadType(activeTab),
feedFilter: activeTab === 'mentions' ? FeedFilter.MENTIONS : filter,
};
}, [activeTab, isUserEntity, currentUser]);
Expand Down Expand Up @@ -323,7 +304,7 @@ export const ActivityFeedTab = ({

<span>
{getCountBadge(
allCount,
count.conversationCount,
'',
activeTab === ActivityFeedTabs.ALL
)}
Expand All @@ -332,15 +313,32 @@ export const ActivityFeedTab = ({
),
key: 'all',
},
{
label: (
<Space align="center" size="small">
<MentionIcon style={COMMON_ICON_STYLES} {...ICON_DIMENSION} />
<span>{t('label.mention-plural')}</span>
</Space>
),
key: 'mentions',
},
...(isUserEntity
? [
{
label: (
<div className="d-flex justify-between">
<Space align="center" size="small">
<MentionIcon
style={COMMON_ICON_STYLES}
{...ICON_DIMENSION}
/>
<span>{t('label.mention-plural')}</span>
</Space>

<span>
{getCountBadge(
count.mentionCount,
'',
activeTab === ActivityFeedTabs.MENTIONS
)}
</span>
</div>
),
key: 'mentions',
},
]
: []),
{
label: (
<div className="d-flex justify-between">
Expand All @@ -351,7 +349,9 @@ export const ActivityFeedTab = ({
/>
<span>{t('label.task-plural')}</span>
</Space>
<span>{getCountBadge(tasksCount, '', isTaskActiveTab)}</span>
<span>
{getCountBadge(count.totalTasksCount, '', isTaskActiveTab)}
</span>
</div>
),
key: 'tasks',
Expand Down Expand Up @@ -403,7 +403,6 @@ export const ActivityFeedTab = ({
isForFeedTab={isForFeedTab}
isLoading={false}
showThread={false}
tab={activeTab}
onFeedClick={handleFeedClick}
/>
{loader}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ import TableDescription from '../../components/TableDescription/TableDescription
import TableTags from '../../components/TableTags/TableTags.component';
import TabsLabel from '../../components/TabsLabel/TabsLabel.component';
import { getDashboardDetailsPath } from '../../constants/constants';
import { FEED_COUNT_INITIAL_DATA } from '../../constants/entity.constants';
import { EntityTabs, EntityType } from '../../enums/entity.enum';
import { Tag } from '../../generated/entity/classification/tag';
import { Dashboard } from '../../generated/entity/data/dashboard';
import { ThreadType } from '../../generated/entity/feed/thread';
import { TagSource } from '../../generated/type/schema';
import { TagLabel } from '../../generated/type/tagLabel';
import { useFqn } from '../../hooks/useFqn';
import { FeedCounts } from '../../interface/feed.interface';
import { restoreDashboard } from '../../rest/dashboardAPI';
import { getFeedCounts } from '../../utils/CommonUtils';
import { getEntityName } from '../../utils/EntityUtils';
import { getEntityFieldThreadCounts } from '../../utils/FeedUtils';
import { DEFAULT_ENTITY_PERMISSION } from '../../utils/PermissionsUtils';
import {
getAllTags,
Expand Down Expand Up @@ -102,7 +103,9 @@ const DashboardDetails = ({
chart: ChartType;
index: number;
}>();
const [feedCount, setFeedCount] = useState<number>(0);
const [feedCount, setFeedCount] = useState<FeedCounts>(
FEED_COUNT_INITIAL_DATA
);
const [threadLink, setThreadLink] = useState<string>('');

const [threadType, setThreadType] = useState<ThreadType>(
Expand Down Expand Up @@ -177,8 +180,12 @@ const DashboardDetails = ({
}
}, []);

const handleFeedCount = useCallback((data: FeedCounts) => {
setFeedCount(data);
}, []);

const getEntityFeedCount = () =>
getFeedCounts(EntityType.DASHBOARD, decodedDashboardFQN, setFeedCount);
getFeedCounts(EntityType.DASHBOARD, decodedDashboardFQN, handleFeedCount);

useEffect(() => {
getEntityFeedCount();
Expand Down Expand Up @@ -541,7 +548,6 @@ const DashboardDetails = ({
hasEditTagAccess,
handleUpdateChart,
handleChartTagSelection,
getEntityFieldThreadCounts,
]
);

Expand Down Expand Up @@ -640,7 +646,7 @@ const DashboardDetails = ({
{
label: (
<TabsLabel
count={feedCount}
count={feedCount.totalCount}
id={EntityTabs.ACTIVITY_FEED}
isActive={activeTab === EntityTabs.ACTIVITY_FEED}
name={t('label.activity-feed-and-task-plural')}
Expand Down Expand Up @@ -692,7 +698,7 @@ const DashboardDetails = ({
},
],
[
feedCount,
feedCount.totalCount,
activeTab,
isEdit,
tableColumn,
Expand All @@ -701,7 +707,6 @@ const DashboardDetails = ({
deleted,
entityName,
dashboardTags,
getEntityFieldThreadCounts,
onCancel,
onDescriptionEdit,
onDescriptionUpdate,
Expand Down Expand Up @@ -731,6 +736,7 @@ const DashboardDetails = ({
afterDomainUpdateAction={updateDashboardDetailsState}
dataAsset={dashboardDetails}
entityType={EntityType.DASHBOARD}
openTaskCount={feedCount.openTaskCount}
permissions={dashboardPermissions}
onDisplayNameUpdate={onUpdateDisplayName}
onFollowClick={followDashboard}
Expand Down
Loading

0 comments on commit fe8e2ec

Please sign in to comment.