Skip to content

Commit

Permalink
Merge pull request #46 from CybercentreCanada/hotfix/db_max_search
Browse files Browse the repository at this point in the history
hotfix/deb_max_search (dev)
  • Loading branch information
cccs-sgaron authored Mar 29, 2021
2 parents 2073d7d + 168d904 commit 8d8c191
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 15 deletions.
1 change: 0 additions & 1 deletion docker/config.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ ui:
email: dev@<YOUR_IP>.nip.io
enforce_quota: false
fqdn: <YOUR_IP>.nip.io
ui4_path: /next/
3 changes: 2 additions & 1 deletion src/components/routes/admin/error_viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DEFAULT_SUGGESTION } from 'components/visual/SearchBar/search-textfield
import SimpleSearchQuery from 'components/visual/SearchBar/simple-search-query';
import SearchPager from 'components/visual/SearchPager';
import ErrorsTable from 'components/visual/SearchResult/errors';
import { searchResultsDisplay } from 'helpers/utils';
import 'moment/locale/fr';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -288,7 +289,7 @@ export default function ErrorViewer() {
<span>{t('searching')}</span>
) : (
<span>
{errorResults.total}&nbsp;
{searchResultsDisplay(errorResults.total)}&nbsp;
{query.get('query')
? t(`filtered${errorResults.total === 1 ? '' : 's'}`)
: t(`total${errorResults.total === 1 ? '' : 's'}`)}
Expand Down
3 changes: 2 additions & 1 deletion src/components/routes/admin/users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { DEFAULT_SUGGESTION } from 'components/visual/SearchBar/search-textfield
import SimpleSearchQuery from 'components/visual/SearchBar/simple-search-query';
import SearchPager from 'components/visual/SearchPager';
import UsersTable from 'components/visual/SearchResult/users';
import { searchResultsDisplay } from 'helpers/utils';
import ChipInput from 'material-ui-chip-input';
import 'moment/locale/fr';
import React, { useEffect, useRef, useState } from 'react';
Expand Down Expand Up @@ -420,7 +421,7 @@ export default function Users() {
<span>{t('searching')}</span>
) : (
<span>
{userResults.total}&nbsp;
{searchResultsDisplay(userResults.total)}&nbsp;
{query.get('query')
? t(`filtered${userResults.total === 1 ? '' : 's'}`)
: t(`total${userResults.total === 1 ? '' : 's'}`)}
Expand Down
5 changes: 3 additions & 2 deletions src/components/routes/alerts/alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import InformativeAlert from 'components/visual/InformativeAlert';
import SearchBar from 'components/visual/SearchBar/search-bar';
import SearchQuery, { SearchQueryFilters } from 'components/visual/SearchBar/search-query';
import { DEFAULT_SUGGESTION } from 'components/visual/SearchBar/search-textfield';
import { searchResultsDisplay } from 'helpers/utils';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { BiNetworkChart } from 'react-icons/bi';
Expand Down Expand Up @@ -472,7 +473,7 @@ const SearchResultLarge = ({ searching, total, query, onApplyFilters }) => {
<div style={{ position: 'relative' }}>
<AlertsFiltersSelected searchQuery={query} onChange={onApplyFilters} hideQuery />
<div style={{ position: 'absolute', top: theme.spacing(0.5), right: theme.spacing(1) }}>
{searching ? '' : <span>{`${total} ${total > 1 ? t('results') : t('result')}`}</span>}
{searching ? '' : <span>{`${searchResultsDisplay(total)} ${total > 1 ? t('results') : t('result')}`}</span>}
</div>
</div>
);
Expand All @@ -490,7 +491,7 @@ const SearchResultSmall = ({ searching, total, query }) => {
<FiFilter style={{ marginRight: theme.spacing(1) }} />
</>
)}
{searching ? '' : `${total} ${total > 1 ? t('results') : t('result')}`}
{searching ? '' : `${searchResultsDisplay(total)} ${total > 1 ? t('results') : t('result')}`}
</div>
</>
);
Expand Down
3 changes: 2 additions & 1 deletion src/components/routes/manage/heuristics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DEFAULT_SUGGESTION } from 'components/visual/SearchBar/search-textfield
import SimpleSearchQuery from 'components/visual/SearchBar/simple-search-query';
import SearchPager from 'components/visual/SearchPager';
import HeuristicsTable from 'components/visual/SearchResult/heuristics';
import { searchResultsDisplay } from 'helpers/utils';
import 'moment/locale/fr';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -148,7 +149,7 @@ export default function Heuristics() {
<span>{t('searching')}</span>
) : (
<span>
{heuristicResults.total}&nbsp;
{searchResultsDisplay(heuristicResults.total)}&nbsp;
{query.get('query')
? t(`filtered${heuristicResults.total === 1 ? '' : 's'}`)
: t(`total${heuristicResults.total === 1 ? '' : 's'}`)}
Expand Down
3 changes: 2 additions & 1 deletion src/components/routes/manage/signatures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { DEFAULT_SUGGESTION } from 'components/visual/SearchBar/search-textfield
import SimpleSearchQuery from 'components/visual/SearchBar/simple-search-query';
import SearchPager from 'components/visual/SearchPager';
import SignaturesTable from 'components/visual/SearchResult/signatures';
import { searchResultsDisplay } from 'helpers/utils';
import 'moment/locale/fr';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -225,7 +226,7 @@ export default function Signatures() {
<span>{t('searching')}</span>
) : (
<span>
{signatureResults.total}&nbsp;
{searchResultsDisplay(signatureResults.total)}&nbsp;
{query.get('query')
? t(`filtered${signatureResults.total === 1 ? '' : 's'}`)
: t(`total${signatureResults.total === 1 ? '' : 's'}`)}
Expand Down
3 changes: 2 additions & 1 deletion src/components/routes/manage/workflows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { DEFAULT_SUGGESTION } from 'components/visual/SearchBar/search-textfield
import SimpleSearchQuery from 'components/visual/SearchBar/simple-search-query';
import SearchPager from 'components/visual/SearchPager';
import WorkflowTable from 'components/visual/SearchResult/workflow';
import { searchResultsDisplay } from 'helpers/utils';
import 'moment/locale/fr';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -210,7 +211,7 @@ export default function Workflows() {
<span>{t('searching')}</span>
) : (
<span>
{workflowResults.total}&nbsp;
{searchResultsDisplay(workflowResults.total)}&nbsp;
{query.get('query')
? t(`filtered${workflowResults.total === 1 ? '' : 's'}`)
: t(`total${workflowResults.total === 1 ? '' : 's'}`)}
Expand Down
28 changes: 22 additions & 6 deletions src/components/routes/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import FilesTable from 'components/visual/SearchResult/files';
import ResultsTable from 'components/visual/SearchResult/results';
import SignaturesTable from 'components/visual/SearchResult/signatures';
import SubmissionsTable from 'components/visual/SearchResult/submissions';
import { searchResultsDisplay } from 'helpers/utils';
import React, { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Link, useHistory, useLocation, useParams } from 'react-router-dom';
Expand Down Expand Up @@ -265,16 +266,29 @@ function Search({ index }: SearchProps) {
variant="scrollable"
>
<Tab
label={`${t('submission')} (${submissionResults ? submissionResults.total : '...'})`}
label={`${t('submission')} (${
submissionResults ? searchResultsDisplay(submissionResults.total) : '...'
})`}
value="submission"
/>
<Tab label={`${t('file')} (${fileResults ? fileResults.total : '...'})`} value="file" />
<Tab label={`${t('result')} (${resultResults ? resultResults.total : '...'})`} value="result" />
<Tab
label={`${t('signature')} (${signatureResults ? signatureResults.total : '...'})`}
label={`${t('file')} (${fileResults ? searchResultsDisplay(fileResults.total) : '...'})`}
value="file"
/>
<Tab
label={`${t('result')} (${resultResults ? searchResultsDisplay(resultResults.total) : '...'})`}
value="result"
/>
<Tab
label={`${t('signature')} (${
signatureResults ? searchResultsDisplay(signatureResults.total) : '...'
})`}
value="signature"
/>
<Tab label={`${t('alert')} (${alertResults ? alertResults.total : '...'})`} value="alert" />
<Tab
label={`${t('alert')} (${alertResults ? searchResultsDisplay(alertResults.total) : '...'})`}
value="alert"
/>
<TabSpacer />
<SpecialTab>
<Tooltip title={t('focus_search')}>
Expand All @@ -293,7 +307,9 @@ function Search({ index }: SearchProps) {
<div style={{ display: 'flex', flexDirection: 'row', flexWrap: 'wrap', marginBottom: theme.spacing(0.5) }}>
{resMap[tab] && resMap[tab].total !== 0 && (index || id) && (
<div className={classes.searchresult}>
{`${resMap[tab].total} ${t(resMap[tab].total === 1 ? 'matching_result' : 'matching_results')}`}
{`${searchResultsDisplay(resMap[tab].total)} ${t(
resMap[tab].total === 1 ? 'matching_result' : 'matching_results'
)}`}
</div>
)}
<div style={{ flexGrow: 1 }} />
Expand Down
3 changes: 2 additions & 1 deletion src/components/routes/submissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DEFAULT_SUGGESTION } from 'components/visual/SearchBar/search-textfield
import SimpleSearchQuery from 'components/visual/SearchBar/simple-search-query';
import SearchPager from 'components/visual/SearchPager';
import SubmissionsTable, { SubmissionResult } from 'components/visual/SearchResult/submissions';
import { searchResultsDisplay } from 'helpers/utils';
import 'moment/locale/fr';
import React, { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -153,7 +154,7 @@ export default function Submissions() {
<span>{t('searching')}</span>
) : (
<span>
{submissionResults.total}&nbsp;
{searchResultsDisplay(submissionResults.total)}&nbsp;
{query.get('query')
? t(`filtered${submissionResults.total === 1 ? '' : 's'}`)
: t(`total${submissionResults.total === 1 ? '' : 's'}`)}
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ export function getProvider() {
const params = new URLSearchParams(window.location.search);
return params.get('provider');
}

export function searchResultsDisplay(count, max = 10000) {
if (count >= max) {
return `${count}+`;
}

return `${count}`;
}

0 comments on commit 8d8c191

Please sign in to comment.