Skip to content

Commit

Permalink
add loader nas páginas de busca e implementação da exportação para cvs
Browse files Browse the repository at this point in the history
  • Loading branch information
jesielviana committed Dec 7, 2023
1 parent eda0972 commit 11b6e01
Show file tree
Hide file tree
Showing 32 changed files with 482 additions and 86 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ INDEX_JOURNAL="release2-journal"
INDEX_PROGRAM="release2-program"
INDEX_PATENT="release2-patent"
INDEX_GROUP="release2-group"
INDEX_SOFTWARE="release2-software"
INDEX_SOFTWARE="release2-software"
DOWNLOAD_FOLDER_PATH="/tmp/brcris"
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
"deploy": "yarn && yarn build && pm2 start yarn --name 'brcris-nextjs' --interpreter bash -- start"
},
"dependencies": {
"@elastic/react-search-ui": "^1.18.1",
"@elastic/search-ui-elasticsearch-connector": "^1.18.1",
"@types/react-google-recaptcha": "^2.1.5",
"@types/react-tagcloud": "^1.1.7",
"bootstrap": "^5.2.2",
"chart.js": "^3.9.1",
"es7": "npm:@elastic/elasticsearch@7",
"i18next": "^22.4.14",
"js-cookie": "^3.0.5",
"json-2-csv": "^5.0.1",
"jszip": "^3.10.1",
"next": "12.3.1",
"next-i18next": "^13.2.2",
"node-fetch": "^3.3.1",
Expand All @@ -39,12 +37,16 @@
"swr": "^1.3.0"
},
"devDependencies": {
"@elastic/react-search-ui": "^1.18.1",
"@elastic/search-ui-elasticsearch-connector": "^1.18.1",
"@types/js-cookie": "^3.0.3",
"@types/node": "18.7.23",
"@types/nodemailer": "^6.4.7",
"@types/react": "18",
"@types/react-csv": "^1.1.3",
"@types/react-dom": "18",
"@types/react-google-recaptcha": "^2.1.5",
"@types/react-tagcloud": "^1.1.7",
"@types/vis": "^4.21.24",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"eslint": "8.24.0",
Expand Down
4 changes: 3 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"For example, if you want to search for publications on Computing in 2018, excluding master thesis: go to the ": "For example, if you want to search for publications on 'Computing' in 2018, excluding master thesis: go to the ",
"index page and use the query below": "index page and use the query below",
"See below for the full list of search fields that can be used for the index of": "See below for the full list of search fields that can be used for the index of",
"(all:Computing) AND (publicationDate:2018) AND NOT (type:master thesis)": "(all:Computing) AND (publicationDate:2018) AND NOT (type:master thesis)"
"(all:Computing) AND (publicationDate:2018) AND NOT (type:master thesis)": "(all:Computing) AND (publicationDate:2018) AND NOT (type:master thesis)",
"Download": "Download",
"Export csv": "Export csv"
}
4 changes: 3 additions & 1 deletion public/locales/pt-BR/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@
"For example, if you want to search for publications on Computing in 2018, excluding master thesis: go to the ": "Por exemplo, se você deseja buscar publicações sobre 'Computação' em 2018, excluindo dissertações: acesse a página do índice de ",
"index page and use the query below": "e use a query abaixo",
"See below for the full list of search fields that can be used for the index of": "Veja abaixo a lista completa dos campos de pesquisa que podem ser usados para o índice de",
"(all:Computing) AND (publicationDate:2018) AND NOT (type:master thesis)": "(all:Computação) AND (publicationDate:2018) AND NOT (type:master thesis)"
"(all:Computing) AND (publicationDate:2018) AND NOT (type:master thesis)": "(all:Computação) AND (publicationDate:2018) AND NOT (type:master thesis)",
"Download": "Baixar",
"Export csv": "Exportar para csv"
}
1 change: 0 additions & 1 deletion src/components/AllIndexVisNetwork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ function VisGraph() {
}, []);

useEffect(() => {
console.log('indexStat', indexesStats);
const newNodes: IndexNode[] = [];
const maxSizeOfNode = Math.max(...indexesStats.map((item) => item['docs.count']));
for (let i = 0; i < keysLanguage.length; i++) {
Expand Down
1 change: 0 additions & 1 deletion src/components/BasicSearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const BasicSearchBox = ({
const { t } = useTranslation('common');
const router = useRouter();
const [docsCount, setDocsCount] = useState(localStorage.getItem(indexName));
console.log('indexName', indexName);

useEffect(() => {
ElasticSearchStatsService(indexName)
Expand Down
79 changes: 79 additions & 0 deletions src/components/DownloadModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { SearchContext, withSearch } from '@elastic/react-search-ui';
import { useTranslation } from 'next-i18next';
import { useContext, useState } from 'react';
import { Button, Modal } from 'react-bootstrap';
import { FaFileExport } from 'react-icons/fa6';
import BulkDownloadService from '../services/BulkDownloadService';
import { CustomSearchQuery } from '../types/Entities';
import Loader from './Loader';
import { formatedQuery } from './indicators/query/Query';

type DownloadModalProps = {
filters?: any;
searchTerm?: any;
};

const DownloadModal = ({ filters, searchTerm }: DownloadModalProps) => {
const { t } = useTranslation('common');
const { driver } = useContext(SearchContext);
const [show, setShow] = useState(false);
const [downloadLink, setDownloadLink] = useState('');
const [isLoading, setLoading] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
const { search_fields, operator, index } = driver.searchQuery as CustomSearchQuery;
// @ts-ignore
const fields = Object.keys(search_fields);

async function handleDownload() {
try {
setLoading(true);
const query: QueryDslQueryContainer = formatedQuery(searchTerm, fields, operator, filters);
const response = await new BulkDownloadService().search(index, query);
const { file } = response;
console.log('download fim', file);
const nextDownloadLink = `/api/download?fileName=${file}`;
setDownloadLink(nextDownloadLink);
handleShow();
} finally {
setLoading(false);
}
}

return (
<>
<button
title={t('Export csv') || 'Export csv'}
className="btn-header btn btn-outline-secondary d-flex align-items-center flex-gap-8"
onClick={handleDownload}
>
<FaFileExport />
{t('csv')}
</button>
{isLoading ? <Loader /> : ''}
<Modal show={show} onHide={handleClose} size="lg">
<Modal.Header closeButton>
<Modal.Title>{t('Download')}</Modal.Title>
</Modal.Header>
<Modal.Body>
<a href={downloadLink} target="_blank" rel="noreferrer">
{t('Export csv')}
</a>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
{t('Close')}
</Button>
</Modal.Footer>
</Modal>
</>
);
};

export default withSearch(({ filters, searchTerm }) => ({
filters,
searchTerm,
}))(DownloadModal);
10 changes: 5 additions & 5 deletions src/components/indicators/GroupsIndicators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CustomSearchQuery, IndicatorType } from '../../types/Entities';
import { IndicatorsProps } from '../../types/Propos';
import IndicatorContext from '../context/CustomContext';
import { OptionsBar, OptionsPie } from './options/ChartsOptions';
import getFormatedQuery from './query/Query';
import { getAggregateQuery } from './query/Query';

ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement);
const INDEX_NAME = process.env.INDEX_GROUP || '';
Expand Down Expand Up @@ -67,7 +67,7 @@ function GroupsIndicators({ filters, searchTerm, isLoading }: IndicatorsProps) {
? ElasticSearchService(
[
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'creationYear',
searchTerm,
Expand All @@ -78,7 +78,7 @@ function GroupsIndicators({ filters, searchTerm, isLoading }: IndicatorsProps) {
})
),
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'researchLine',
searchTerm,
Expand All @@ -88,7 +88,7 @@ function GroupsIndicators({ filters, searchTerm, isLoading }: IndicatorsProps) {
})
),
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'knowledgeArea',
searchTerm,
Expand All @@ -98,7 +98,7 @@ function GroupsIndicators({ filters, searchTerm, isLoading }: IndicatorsProps) {
})
),
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'status',
searchTerm,
Expand Down
4 changes: 2 additions & 2 deletions src/components/indicators/JornalsIndicators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CustomSearchQuery, IndicatorType } from '../../types/Entities';
import { IndicatorsProps } from '../../types/Propos';
import IndicatorContext from '../context/CustomContext';
import { OptionsBar } from './options/ChartsOptions';
import getFormatedQuery from './query/Query';
import { getAggregateQuery } from './query/Query';

ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement);
const INDEX_NAME = process.env.INDEX_JOURNAL || '';
Expand Down Expand Up @@ -45,7 +45,7 @@ function JornalsIndicators({ filters, searchTerm, isLoading }: IndicatorsProps)
? ElasticSearchService(
[
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'qualis',
searchTerm,
Expand Down
6 changes: 3 additions & 3 deletions src/components/indicators/OrgUnitIndicators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CustomSearchQuery, IndicatorType } from '../../types/Entities';
import { IndicatorsProps } from '../../types/Propos';
import IndicatorContext from '../context/CustomContext';
import { OptionsBar } from './options/ChartsOptions';
import getFormatedQuery from './query/Query';
import { getAggregateQuery } from './query/Query';

ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement);
const INDEX_NAME = process.env.INDEX_ORGUNIT || '';
Expand Down Expand Up @@ -51,7 +51,7 @@ function OrgUnitIndicators({ filters, searchTerm, isLoading }: IndicatorsProps)
optionsState.plugins.title.text = t(optionsState.title);

const countryQuery = JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'country',
searchTerm,
Expand All @@ -61,7 +61,7 @@ function OrgUnitIndicators({ filters, searchTerm, isLoading }: IndicatorsProps)
})
);
const stateQuery = JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'state',
searchTerm,
Expand Down
10 changes: 5 additions & 5 deletions src/components/indicators/PatentsIndicators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CustomSearchQuery, IndicatorType } from '../../types/Entities';
import { IndicatorsProps } from '../../types/Propos';
import IndicatorContext from '../context/CustomContext';
import { OptionsBar, OptionsPie } from './options/ChartsOptions';
import getFormatedQuery from './query/Query';
import { getAggregateQuery } from './query/Query';

ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement);
const INDEX_NAME = process.env.INDEX_PATENT || '';
Expand Down Expand Up @@ -69,7 +69,7 @@ function PatentsIndicators({ filters, searchTerm, isLoading }: IndicatorsProps)
? ElasticSearchService(
[
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'depositDate',
searchTerm,
Expand All @@ -80,7 +80,7 @@ function PatentsIndicators({ filters, searchTerm, isLoading }: IndicatorsProps)
})
),
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'publicationDate',
searchTerm,
Expand All @@ -91,7 +91,7 @@ function PatentsIndicators({ filters, searchTerm, isLoading }: IndicatorsProps)
})
),
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'countryCode',
searchTerm,
Expand All @@ -101,7 +101,7 @@ function PatentsIndicators({ filters, searchTerm, isLoading }: IndicatorsProps)
})
),
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'kindCode',
searchTerm,
Expand Down
7 changes: 3 additions & 4 deletions src/components/indicators/PeopleIndicators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CustomSearchQuery, IndicatorType } from '../../types/Entities';
import { IndicatorsProps } from '../../types/Propos';
import IndicatorContext from '../context/CustomContext';
import { OptionsPie } from './options/ChartsOptions';
import getFormatedQuery from './query/Query';
import { getAggregateQuery } from './query/Query';

ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement);
const INDEX_NAME = process.env.INDEX_PERSON || '';
Expand All @@ -38,7 +38,6 @@ const headersResearchArea = [

function PeopleIndicators({ filters, searchTerm, isLoading }: IndicatorsProps) {
const { t } = useTranslation('common');

const { driver } = useContext(SearchContext);
const { indicators, setIndicatorsData, isEmpty } = useContext(IndicatorContext);

Expand All @@ -54,7 +53,7 @@ function PeopleIndicators({ filters, searchTerm, isLoading }: IndicatorsProps) {
? ElasticSearchService(
[
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'nationality',
searchTerm,
Expand All @@ -64,7 +63,7 @@ function PeopleIndicators({ filters, searchTerm, isLoading }: IndicatorsProps) {
})
),
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'researchArea',
searchTerm,
Expand Down
4 changes: 2 additions & 2 deletions src/components/indicators/ProgramsIndicators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CustomSearchQuery, IndicatorType } from '../../types/Entities';
import { IndicatorsProps } from '../../types/Propos';
import IndicatorContext from '../context/CustomContext';
import { OptionsBar } from './options/ChartsOptions';
import getFormatedQuery from './query/Query';
import { getAggregateQuery } from './query/Query';

ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement);
const INDEX_NAME = process.env.INDEX_PROGRAM || '';
Expand Down Expand Up @@ -45,7 +45,7 @@ function ProgramsIndicators({ filters, searchTerm, isLoading }: IndicatorsProps)
? ElasticSearchService(
[
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'orgunit.name',
searchTerm,
Expand Down
6 changes: 3 additions & 3 deletions src/components/indicators/PublicationsIndicators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CustomSearchQuery, IndicatorType } from '../../types/Entities';
import { IndicatorsProps } from '../../types/Propos';
import IndicatorContext from '../context/CustomContext';
import { OptionsBar, OptionsPie } from './options/ChartsOptions';
import getFormatedQuery from './query/Query';
import { getAggregateQuery } from './query/Query';

ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement);
const INDEX_NAME = process.env.INDEX_PUBLICATION || '';
Expand Down Expand Up @@ -50,7 +50,7 @@ function PublicationsIndicators({ filters, searchTerm, isLoading }: IndicatorsPr
optionsType.plugins.title.text = t(optionsType.title);
try {
const pdQuery = JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'publicationDate',
searchTerm,
Expand All @@ -61,7 +61,7 @@ function PublicationsIndicators({ filters, searchTerm, isLoading }: IndicatorsPr
})
);
const typeQuery = JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'type',
searchTerm,
Expand Down
6 changes: 3 additions & 3 deletions src/components/indicators/SoftwaresIndicators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CustomSearchQuery, IndicatorType } from '../../types/Entities';
import { IndicatorsProps } from '../../types/Propos';
import IndicatorContext from '../context/CustomContext';
import { OptionsBar, OptionsPie } from './options/ChartsOptions';
import getFormatedQuery from './query/Query';
import { getAggregateQuery } from './query/Query';

ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement);
const INDEX_NAME = process.env.INDEX_SOFTWARE || '';
Expand Down Expand Up @@ -54,7 +54,7 @@ function SoftwaresIndicators({ filters, searchTerm, isLoading }: IndicatorsProps
? ElasticSearchService(
[
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'releaseYear',
searchTerm,
Expand All @@ -65,7 +65,7 @@ function SoftwaresIndicators({ filters, searchTerm, isLoading }: IndicatorsProps
})
),
JSON.stringify(
getFormatedQuery({
getAggregateQuery({
size: 10,
indicadorName: 'knowledgeAreas',
searchTerm,
Expand Down
Loading

0 comments on commit 11b6e01

Please sign in to comment.