From cf6f7a08a8f538f546b291cc40ef03ddb57ef0c4 Mon Sep 17 00:00:00 2001 From: laixingyou Date: Mon, 26 Feb 2024 17:12:02 +0800 Subject: [PATCH] feat: add contributor search Signed-off-by: laixingyou --- apps/web/i18n | 2 +- .../ContributorTable/ContributorDropdown.tsx | 48 +++++++++++++++++++ .../ContributorTable/index.tsx | 32 +++++++++---- apps/web/src/styles/antd.scss | 5 +- 4 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/ContributorDropdown.tsx diff --git a/apps/web/i18n b/apps/web/i18n index 3a9f4ed8..b1ae5306 160000 --- a/apps/web/i18n +++ b/apps/web/i18n @@ -1 +1 @@ -Subproject commit 3a9f4ed8f4c9e0ed258180931ff4f72a35f81e32 +Subproject commit b1ae5306b3852206a8a5febc0ff5cc947d79fba3 diff --git a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/ContributorDropdown.tsx b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/ContributorDropdown.tsx new file mode 100644 index 00000000..7bd547e0 --- /dev/null +++ b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/ContributorDropdown.tsx @@ -0,0 +1,48 @@ +import React, { useState } from 'react'; +// import { AiOutlineSearch } from 'react-icons/ai'; +import { Button, Input } from 'antd'; +import { useTranslation } from 'next-i18next'; + +const ContributorDropdown = ({ selectedKeys, setSelectedKeys, confirm }) => { + const { t } = useTranslation(); + const [contributor, setContributor] = useState(selectedKeys); + + const handleSearch = () => { + setSelectedKeys(contributor); + confirm(); + }; + const handleReset = () => { + setContributor([]); + }; + return ( +
e.stopPropagation()}> + setContributor([e.target.value])} + onPressEnter={() => handleSearch()} + style={{ marginBottom: 8, display: 'block' }} + /> +
+ + +
+
+ ); +}; + +export default ContributorDropdown; diff --git a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/index.tsx b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/index.tsx index c99df7f7..192e6403 100644 --- a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/index.tsx +++ b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/index.tsx @@ -17,17 +17,19 @@ import { getMaxDomain } from '../utils'; import { getContributorPolling, getContributorExport } from './tableDownload'; import DomainPersona from './DomainPersona'; import ContributorName from './ContributorName'; +import ContributorDropdown from './ContributorDropdown'; import { useTranslation } from 'next-i18next'; import Download from '@common/components/Table/Download'; import { useRouter } from 'next/router'; import { useHandleQueryParams } from '@modules/analyze/hooks/useHandleQueryParams'; import Dialog from '@common/components/Dialog'; import Tooltip from '@common/components/Tooltip'; -import { FiEdit } from 'react-icons/fi'; -import { GrClose } from 'react-icons/gr'; import ManageOrgEdit from '@common/components/OrgEdit/ManageOrgEdit'; import useVerifyDetailRange from '@modules/analyze/hooks/useVerifyDetailRange'; import { useIsCurrentUser } from '@modules/analyze/hooks/useIsCurrentUser'; +import { FiEdit } from 'react-icons/fi'; +import { GrClose } from 'react-icons/gr'; +import { AiOutlineSearch } from 'react-icons/ai'; import type { ColumnsType, TablePaginationConfig } from 'antd/es/table'; import type { FilterValue, SorterResult } from 'antd/es/table/interface'; @@ -90,13 +92,12 @@ const MetricTable: React.FC<{ return `${t('analyze:total_people', { total })} `; }, }, - filterOpts: filterOpts, sortOpts: defaultSortOpts, }); const query = { page: tableParams.pagination.current, per: tableParams.pagination.pageSize, - filterOpts: [...tableParams.filterOpts, mileageFilter], + filterOpts: [...filterOpts, mileageFilter], sortOpts: tableParams.sortOpts, label, level, @@ -113,7 +114,7 @@ const MetricTable: React.FC<{ { onSuccess: (data) => { const items = data.contributorsDetailList.items; - const hasTypeFilter = tableParams.filterOpts.find( + const hasTypeFilter = filterOpts.find( (i) => i.type === 'contribution_type' ); if (hasTypeFilter) { @@ -149,7 +150,7 @@ const MetricTable: React.FC<{ for (const key in filters) { if (filters.hasOwnProperty(key)) { const transformedObj = { - type: filterMap[key], + type: filterMap[key] || key, values: filters[key] as string[], }; filters[key] && filterOpts.push(transformedObj); @@ -180,7 +181,6 @@ const MetricTable: React.FC<{ ...pagination, }, sortOpts, - filterOpts, }); }; @@ -190,11 +190,27 @@ const MetricTable: React.FC<{ dataIndex: 'contributor', align: 'left', width: '200px', - sorter: true, fixed: 'left', render: (name) => { return ; }, + filterIcon: (filtered: boolean) => ( + + ), + defaultFilteredValue: + defaultFilterOpts.find((i) => i.type === 'contributor')?.values || null, + filterDropdown: ({ selectedKeys, setSelectedKeys, confirm }) => { + return ( + + ); + }, }, { title: t('analyze:metric_detail:role_persona'), diff --git a/apps/web/src/styles/antd.scss b/apps/web/src/styles/antd.scss index de02d82f..238f6b3c 100644 --- a/apps/web/src/styles/antd.scss +++ b/apps/web/src/styles/antd.scss @@ -1,6 +1,9 @@ -.ant-table-filter-dropdown-btns { +.ant-table-filter-dropdown { .ant-btn-primary { background-color: #1677ff !important; + // :hover { + // background-color: #4096ff !important; + // } } } .ant-progress-bg {