Fixed #388 Show the document count in explore page next to tabs and also in services tabs (#399)

This commit is contained in:
Sachin Chaurasiya 2021-09-03 20:54:29 +05:30 committed by GitHub
parent dbe60628f8
commit 13c6342c90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 14 deletions

View File

@ -44,6 +44,7 @@ import { usePrevious } from '../../hooks/usePrevious';
import useToastContext from '../../hooks/useToastContext'; import useToastContext from '../../hooks/useToastContext';
import { getAggregationList } from '../../utils/AggregationUtils'; import { getAggregationList } from '../../utils/AggregationUtils';
import { formatDataResponse } from '../../utils/APIUtils'; import { formatDataResponse } from '../../utils/APIUtils';
import { getCountBadge } from '../../utils/CommonUtils';
import { getFilterString } from '../../utils/FilterUtils'; import { getFilterString } from '../../utils/FilterUtils';
import { dropdownIcon as DropDownIcon } from '../../utils/svgconstant'; import { dropdownIcon as DropDownIcon } from '../../utils/svgconstant';
import { getAggrWithDefaultValue } from './explore.constants'; import { getAggrWithDefaultValue } from './explore.constants';
@ -92,10 +93,13 @@ const ExplorePage: React.FC = (): React.ReactElement => {
const [sortOrder, setSortOrder] = useState<string>('desc'); const [sortOrder, setSortOrder] = useState<string>('desc');
const [searchIndex, setSearchIndex] = useState<string>(SearchIndex.TABLE); const [searchIndex, setSearchIndex] = useState<string>(SearchIndex.TABLE);
const [currentTab, setCurrentTab] = useState<number>(1); const [currentTab, setCurrentTab] = useState<number>(1);
const [tableCount, setTableCount] = useState<number>(0);
const [topicCount, setTopicCount] = useState<number>(0);
const [fieldList, setFieldList] = const [fieldList, setFieldList] =
useState<Array<{ name: string; value: string }>>(tableSortingFields); useState<Array<{ name: string; value: string }>>(tableSortingFields);
const isMounting = useRef(true); const isMounting = useRef(true);
const previsouIndex = usePrevious(searchIndex); const previsouIndex = usePrevious(searchIndex);
const handleSelectedFilter = ( const handleSelectedFilter = (
checked: boolean, checked: boolean,
selectedFilter: string, selectedFilter: string,
@ -174,6 +178,40 @@ const ExplorePage: React.FC = (): React.ReactElement => {
} }
}; };
const fetchCounts = () => {
const emptyValue = '';
const tableCount = searchData(
searchText,
0,
0,
getFilterString(filters),
emptyValue,
emptyValue,
SearchIndex.TABLE
);
const topicCount = searchData(
searchText,
0,
0,
getFilterString(filters),
emptyValue,
emptyValue,
SearchIndex.TOPIC
);
Promise.all([tableCount, topicCount])
.then(([table, topic]: Array<SearchResponse>) => {
setTableCount(table.data.hits.total.value);
setTopicCount(topic.data.hits.total.value);
})
.catch((err: AxiosError) => {
setError(ERROR404);
showToast({
variant: 'error',
body: err.response?.data?.responseMessage ?? ERROR500,
});
});
};
const fetchTableData = (forceSetAgg: boolean) => { const fetchTableData = (forceSetAgg: boolean) => {
setIsLoading(true); setIsLoading(true);
@ -358,6 +396,7 @@ const ExplorePage: React.FC = (): React.ReactElement => {
resetFilters(); resetFilters();
}}> }}>
Tables Tables
{getCountBadge(tableCount)}
</button> </button>
<button <button
className={`tw-pb-2 tw-px-4 tw-gh-tabs ${getActiveTabClass(2)}`} className={`tw-pb-2 tw-px-4 tw-gh-tabs ${getActiveTabClass(2)}`}
@ -370,6 +409,7 @@ const ExplorePage: React.FC = (): React.ReactElement => {
resetFilters(); resetFilters();
}}> }}>
Topics Topics
{getCountBadge(topicCount)}
</button> </button>
</div> </div>
{getSortingElements()} {getSortingElements()}
@ -400,6 +440,10 @@ const ExplorePage: React.FC = (): React.ReactElement => {
} }
}, [currentPage, filters, sortField, sortOrder]); }, [currentPage, filters, sortField, sortOrder]);
useEffect(() => {
fetchCounts();
}, [searchText, filters]);
// alwyas Keep this useEffect at the end... // alwyas Keep this useEffect at the end...
useEffect(() => { useEffect(() => {
isMounting.current = false; isMounting.current = false;

View File

@ -49,7 +49,7 @@ import {
servicesDisplayName, servicesDisplayName,
} from '../../constants/services.const'; } from '../../constants/services.const';
import { ServiceCategory } from '../../enums/service.enum'; import { ServiceCategory } from '../../enums/service.enum';
import { getTabClasses } from '../../utils/CommonUtils'; import { getCountBadge, getTabClasses } from '../../utils/CommonUtils';
import { getFrequencyTime, serviceTypeLogo } from '../../utils/ServiceUtils'; import { getFrequencyTime, serviceTypeLogo } from '../../utils/ServiceUtils';
import SVGIcons from '../../utils/SvgUtils'; import SVGIcons from '../../utils/SvgUtils';
@ -281,6 +281,7 @@ const ServicesPage = () => {
setServiceList(services[tab.name]); setServiceList(services[tab.name]);
}}> }}>
{tab.displayName} {tab.displayName}
{getCountBadge(services[tab.name].length)}
</button> </button>
))} ))}
</nav> </nav>

View File

@ -37,7 +37,7 @@ import Loader from '../../components/Loader/Loader';
import FormModal from '../../components/Modals/FormModal'; import FormModal from '../../components/Modals/FormModal';
import { ModalWithMarkdownEditor } from '../../components/Modals/ModalWithMarkdownEditor/ModalWithMarkdownEditor'; import { ModalWithMarkdownEditor } from '../../components/Modals/ModalWithMarkdownEditor/ModalWithMarkdownEditor';
import { ERROR404 } from '../../constants/constants'; import { ERROR404 } from '../../constants/constants';
import { countBackground } from '../../utils/styleconstant'; import { getCountBadge } from '../../utils/CommonUtils';
import SVGIcons from '../../utils/SvgUtils'; import SVGIcons from '../../utils/SvgUtils';
import AddUsersModal from './AddUsersModal'; import AddUsersModal from './AddUsersModal';
import Form from './Form'; import Form from './Form';
@ -143,16 +143,6 @@ const TeamsPage = () => {
return tab === currentTab ? 'active' : ''; return tab === currentTab ? 'active' : '';
}; };
const getCount = (count = 0) => {
return (
<span
className=" tw-py-0.5 tw-px-1 tw-ml-1 tw-border tw-rounded tw-text-xs"
style={{ background: countBackground }}>
<span data-testid="filter-count">{count}</span>
</span>
);
};
const getTabs = () => { const getTabs = () => {
return ( return (
<div className="tw-mb-3 "> <div className="tw-mb-3 ">
@ -163,7 +153,7 @@ const TeamsPage = () => {
setCurrentTab(1); setCurrentTab(1);
}}> }}>
Users Users
{getCount(currentTeam?.users.length)} {getCountBadge(currentTeam?.users.length)}
</button> </button>
<button <button
className={`tw-pb-2 tw-px-4 tw-gh-tabs ${getActiveTabClass(2)}`} className={`tw-pb-2 tw-px-4 tw-gh-tabs ${getActiveTabClass(2)}`}
@ -171,7 +161,7 @@ const TeamsPage = () => {
setCurrentTab(2); setCurrentTab(2);
}}> }}>
Assets Assets
{getCount(currentTeam?.owns.length)} {getCountBadge(currentTeam?.owns.length)}
</button> </button>
</nav> </nav>
</div> </div>

View File

@ -24,3 +24,4 @@ declare module 'react-draft-wysiwyg';
declare module 'markdown-draft-js'; declare module 'markdown-draft-js';
declare module 'react-syntax-highlighter'; declare module 'react-syntax-highlighter';
declare module 'rehype-raw'; declare module 'rehype-raw';
declare module 'react-codemirror2';

View File

@ -1,6 +1,8 @@
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { UserTeam } from 'Models'; import { UserTeam } from 'Models';
import React from 'react';
import AppState from '../AppState'; import AppState from '../AppState';
import { countBackground } from './styleconstant';
export const arraySorterByKey = ( export const arraySorterByKey = (
key: string, key: string,
@ -91,3 +93,13 @@ export const getTabClasses = (
) => { ) => {
return 'tw-gh-tabs' + (activeTab === tab ? ' active' : ''); return 'tw-gh-tabs' + (activeTab === tab ? ' active' : '');
}; };
export const getCountBadge = (count = 0) => {
return (
<span
className=" tw-py-0.5 tw-px-1 tw-ml-1 tw-border tw-rounded tw-text-xs"
style={{ background: countBackground }}>
<span data-testid="filter-count">{count}</span>
</span>
);
};