From 8796b68d955e02b4b1283f3a291eb2defbb44a0e Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Fri, 1 Nov 2024 13:25:23 +1100 Subject: [PATCH 01/13] chores --- next/components/molecules/DataInformationQuery.js | 11 ++++++----- next/public/locales/en/aboutUs.json | 6 +++--- next/public/locales/en/common.json | 4 ++-- next/public/locales/en/dataset.json | 6 +++--- next/public/locales/pt/dataset.json | 4 ++++ 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/next/components/molecules/DataInformationQuery.js b/next/components/molecules/DataInformationQuery.js index 84ac9326..67ed4ffe 100644 --- a/next/components/molecules/DataInformationQuery.js +++ b/next/components/molecules/DataInformationQuery.js @@ -46,6 +46,7 @@ import CheckIcon from "../../public/img/icons/checkIcon"; import Link from "../atoms/Link"; export function CodeHighlight({ language, children }) { + const { t } = useTranslation('dataset'); const textRef = useRef(null) const [isOverflowing, setIsOverflowing] = useState(false) const [isExpanded, setIsExpanded] = useState(true) @@ -117,17 +118,17 @@ export function CodeHighlight({ language, children }) { color:"#9D9FA3", }} > - {hasCopied ? "Copiado" : "Copiar"} + {hasCopied ? t('table.copied') : t('table.copy')} {hasCopied ? : - {isExpanded ? "Recolher" : "Expandir"} + {isExpanded ? t('table.collapse') : t('table.expand')} )} diff --git a/next/public/locales/en/aboutUs.json b/next/public/locales/en/aboutUs.json index 7f5e1eaf..37a88f57 100644 --- a/next/public/locales/en/aboutUs.json +++ b/next/public/locales/en/aboutUs.json @@ -1,9 +1,9 @@ { "pageTitle": "About Us – Data Basis", "pageDescription": "Get to know Data Basis. We facilitate access to data so that the distance between you and your analysis is just a good question. Learn more about the organization's history and the team behind our work.", - "heroTitle1": "We facilitate access to data", - "heroTitle2": "so that the distance between you and your analysis", - "heroTitle3": "will be", + "heroTitle1": "We facilitate access to data so that", + "heroTitle2": "the distance between you and an analysis", + "heroTitle3": "is", "heroTitle4": "just a good question", "usersCount": "+114 thousand", "usersText": "users on the platform", diff --git a/next/public/locales/en/common.json b/next/public/locales/en/common.json index 43347787..34016197 100644 --- a/next/public/locales/en/common.json +++ b/next/public/locales/en/common.json @@ -5,8 +5,8 @@ "search_by_theme": "Search by theme", "noDatasetsFound": ["No dataset with all selected themes was found.","Try unselecting some of the themes."], "products": { - "facilitation_text": "We make the work easier so that the distance", - "analysis_distance": "between you and your analysis is ", + "facilitation_text": "We facilitate access to data so that the distance", + "analysis_distance": "between you and an analysis is ", "good_question": "just a good question", "filters": "FILTERS", "search_as_you_want": "Search for data as you wish", diff --git a/next/public/locales/en/dataset.json b/next/public/locales/en/dataset.json index 52eb437a..898337f0 100644 --- a/next/public/locales/en/dataset.json +++ b/next/public/locales/en/dataset.json @@ -108,13 +108,13 @@ "translateTooltip": "For example, translate the code \"2927408\" to \"Salvador-BA\"", "generateQuery": "Generate query", "downloadTable": "Download table", - "bigQueryInstructions": "In the BigQuery query editor, enter the following instruction:", + "bigQueryInstructions": "In the BigQuery query editor, enter the following instructions:", "firstTimeBigQuery": "First time using BigQuery?", "followStepByStep": "Follow the step-by-step guide.", "accessBigQuery": "Access BigQuery", - "pythonInstructions": "In the Python terminal, enter the following instruction:", + "pythonInstructions": "In the Python terminal, enter the following instructions:", "firstTimePython": "First time using the Python package?", - "rInstructions": "In the R terminal, enter the following instruction:", + "rInstructions": "In the R terminal, enter the following instructions:", "firstTimeR": "First time using the R package?", "compareThePlans": "Compare the plans", "warningLargeTable": ["This complete table, with all columns, has ", ". Be careful not to exceed the ", "free processing limit", "of BigQuery."], diff --git a/next/public/locales/pt/dataset.json b/next/public/locales/pt/dataset.json index 6c56c1c7..e1052b63 100644 --- a/next/public/locales/pt/dataset.json +++ b/next/public/locales/pt/dataset.json @@ -108,6 +108,10 @@ "translateInstitutionalCodes": "Traduzir códigos institucionais", "translateTooltip": "Por exemplo, traduzir o código \"2927408\" por \"Salvador-BA\"", "generateQuery": "Gerar consulta", + "copy": "Copiar", + "copied": "Copiado", + "expand": "Expandir", + "collapse": "Recolher", "downloadTable": "Download da tabela", "bigQueryInstructions": "No editor de consultas do BigQuery, digite a seguinte instrução:", "firstTimeBigQuery": "Primeira vez usando o BigQuery?", From 5fe4a65d20214f08bb46fcbf880cd081389c28eb Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Fri, 1 Nov 2024 13:28:11 +1100 Subject: [PATCH 02/13] chores --- next/public/locales/en/dataset.json | 4 ++++ next/public/locales/es/dataset.json | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/next/public/locales/en/dataset.json b/next/public/locales/en/dataset.json index 898337f0..8f01f875 100644 --- a/next/public/locales/en/dataset.json +++ b/next/public/locales/en/dataset.json @@ -107,6 +107,10 @@ "translateInstitutionalCodes": "Translate institutional codes", "translateTooltip": "For example, translate the code \"2927408\" to \"Salvador-BA\"", "generateQuery": "Generate query", + "copy": "Copy", + "copied": "Copied", + "expand": "Expand", + "collapse": "Collapse", "downloadTable": "Download table", "bigQueryInstructions": "In the BigQuery query editor, enter the following instructions:", "firstTimeBigQuery": "First time using BigQuery?", diff --git a/next/public/locales/es/dataset.json b/next/public/locales/es/dataset.json index 3ff3b4c3..94319aee 100644 --- a/next/public/locales/es/dataset.json +++ b/next/public/locales/es/dataset.json @@ -107,6 +107,10 @@ "translateInstitutionalCodes": "Traducir códigos institucionales", "translateTooltip": "Por ejemplo, traducir el código \"2927408\" a \"Salvador-BA\"", "generateQuery": "Generar consulta", + "copy": "Copiar", + "copied": "Copiado", + "expand": "Expandir", + "collapse": "Contraer", "downloadTable": "Descargar tabla", "bigQueryInstructions": "En el editor de consultas de BigQuery, ingrese la siguiente instrucción:", "firstTimeBigQuery": "¿Es la primera vez que utiliza BigQuery?", From 887ea8744321395837554cd76bda889f0e741960 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Mon, 4 Nov 2024 11:50:28 +1100 Subject: [PATCH 03/13] feat: spatial coverage in search, card, dataset and table pages --- next/components/molecules/TableColumns.js | 4 +- next/components/molecules/ThemeCatalog.js | 4 +- .../{Dataset.js => DatasetSearchCard.js} | 62 +++++++- ...asetCard.js => DatasetThemeCatalogCard.js} | 0 next/components/organisms/TablePage.js | 104 +++++++++--- next/pages/api/areas/getArea.js | 45 ++++++ next/pages/api/areas/getAreas.js | 45 ++++++ next/pages/api/areas/getCountries.js | 50 ++++++ next/pages/api/datasets/getDataset.js | 3 +- next/pages/api/tables/getTable.js | 4 +- next/pages/api/tables/getTableColumns.js | 3 +- next/pages/dataset/[dataset].js | 149 ++++++++++++------ next/pages/search.js | 26 ++- next/public/locales/en/dataset.json | 8 +- next/public/locales/es/dataset.json | 7 +- next/public/locales/pt/dataset.json | 6 +- 16 files changed, 431 insertions(+), 89 deletions(-) rename next/components/organisms/{Dataset.js => DatasetSearchCard.js} (82%) rename next/components/organisms/{DatasetCard.js => DatasetThemeCatalogCard.js} (100%) create mode 100644 next/pages/api/areas/getArea.js create mode 100644 next/pages/api/areas/getAreas.js create mode 100644 next/pages/api/areas/getCountries.js diff --git a/next/components/molecules/TableColumns.js b/next/components/molecules/TableColumns.js index cc522e2e..89ff0d71 100644 --- a/next/components/molecules/TableColumns.js +++ b/next/components/molecules/TableColumns.js @@ -668,8 +668,8 @@ export default function TableColumns({ - {elm?.node?.coverage?.start && elm?.node?.coverage?.end ? - elm.node.coverage.start +" - "+ elm.node.coverage.end + {elm?.node?.temporalCoverage?.start && elm?.node?.temporalCoverage?.end ? + elm.node.temporalCoverage.start +" - "+ elm.node.temporalCoverage.end : t('column.notProvided') } diff --git a/next/components/molecules/ThemeCatalog.js b/next/components/molecules/ThemeCatalog.js index d5830062..e6e7360b 100644 --- a/next/components/molecules/ThemeCatalog.js +++ b/next/components/molecules/ThemeCatalog.js @@ -18,7 +18,7 @@ import { triggerGAEvent } from "../../utils"; import Carousel from "../atoms/Carousel"; import SectionText from "../atoms/SectionText"; -import DatasetCard from "../organisms/DatasetCard"; +import DatasetThemeCatalogCard from "../organisms/DatasetThemeCatalogCard"; import RemoveIcon from "../../public/img/icons/removeIcon"; import styles from "../../styles/themeCatalog.module.css"; @@ -249,7 +249,7 @@ function CardThemes ({ responsive, datasetsCards = [], loading, locale }) { )) : datasetsCards.map((elm, i) => ( - { + const fetchAreaNames = async () => { + if (!spatialCoverage) return; + + const coverageArray = Array.isArray(spatialCoverage) + ? spatialCoverage + : typeof spatialCoverage === 'string' + ? spatialCoverage.split(',').map(item => item.trim()) + : Object.values(spatialCoverage); + + const promises = coverageArray.map(slug => + axios.get(`/api/areas/getArea?slug=${slug}&locale=${locale}`) + ); + + try { + const responses = await Promise.all(promises); + const areaNames = responses + .map(res => res.data.resource[0]?.node[`name${capitalize(locale)}`] || res.data.resource[0]?.node.name) + .filter(Boolean) + .sort((a, b) => a.localeCompare(b, locale)); + setSpatialCoverageNames(areaNames); + } catch (error) { + console.error('Error fetching area names:', error); + } + }; + + fetchAreaNames(); + }, [spatialCoverage, locale]); const Tables = () => { let tablesNumber = tables.number @@ -261,7 +293,33 @@ export default function Dataset({ lineHeight="20px" color="#71757A" > - {temporalCoverageText ? temporalCoverageText : t('noCoverage')} + {temporalCoverageText ? temporalCoverageText : t('notProvided')} + + + + + + {t('spatialCoverage')}: + + + {spatialCoverageNames.length > 0 + ? spatialCoverageNames.join(', ') + : spatialCoverage ? spatialCoverage : t('notProvided')} diff --git a/next/components/organisms/DatasetCard.js b/next/components/organisms/DatasetThemeCatalogCard.js similarity index 100% rename from next/components/organisms/DatasetCard.js rename to next/components/organisms/DatasetThemeCatalogCard.js diff --git a/next/components/organisms/TablePage.js b/next/components/organisms/TablePage.js index 82895657..1f8c38be 100644 --- a/next/components/organisms/TablePage.js +++ b/next/components/organisms/TablePage.js @@ -27,6 +27,7 @@ import TwitterIcon from "../../public/img/icons/twitterIcon"; import InfoIcon from "../../public/img/icons/infoIcon"; import DownloadIcon from "../../public/img/icons/downloadIcon"; import RedirectIcon from "../../public/img/icons/redirectIcon"; +import axios from "axios"; export default function TablePage({ id }) { const { t } = useTranslation('dataset', 'prices'); @@ -35,17 +36,38 @@ export default function TablePage({ id }) { const [isLoading, setIsLoading] = useState(true) const [resource, setResource] = useState({}) const [isError, setIsError] = useState(false) + const [spatialCoverageNames, setSpatialCoverageNames] = useState([]); useEffect(() => { const fetchData = async () => { - setIsLoading(true) try { const response = await fetch(`/api/tables/getTable?id=${id}&locale=${locale}`, { method: "GET" }) const result = await response.json() if (result.success) { - setResource(result.resource) - setIsError(false) + let areaNames = []; + + if (result.resource?.spatialCoverage) { + const coverageArray = Array.isArray(result.resource.spatialCoverage) + ? result.resource.spatialCoverage + : typeof result.resource.spatialCoverage === 'string' + ? result.resource.spatialCoverage.split(',').map(item => item.trim()) + : Object.values(result.resource.spatialCoverage); + + const promises = coverageArray.map(slug => + axios.get(`/api/areas/getArea?slug=${slug}&locale=${locale}`) + ); + + const responses = await Promise.all(promises); + areaNames = responses + .map(res => res.data.resource[0]?.node[`name${capitalize(locale)}`] || res.data.resource[0]?.node.name) + .filter(Boolean) + .sort((a, b) => a.localeCompare(b, locale)); + } + + setResource(result.resource); + setSpatialCoverageNames(areaNames); + setIsError(false); } else { console.error(result.error) setIsError(true) @@ -58,7 +80,8 @@ export default function TablePage({ id }) { } } - fetchData() + setIsLoading(true); + fetchData(); }, [id, locale]) const TooltipText = ({ text, info, ...props }) => { @@ -232,8 +255,8 @@ export default function TablePage({ id }) { return formats[value] ? formats[value] : t('table.updateNotDefined') } - if(isError) return - + if (isError) return ; + return ( - - - {t('table.temporalCoverage')} - - + + + + + {t('table.temporalCoverage')} + + - - - + + + + + + + + + {t('table.spatialCoverage')} + + + + + + {spatialCoverageNames.length > 0 + ? spatialCoverageNames.join(', ') + : t('table.notProvided')} + + + + diff --git a/next/pages/api/areas/getArea.js b/next/pages/api/areas/getArea.js new file mode 100644 index 00000000..05874a93 --- /dev/null +++ b/next/pages/api/areas/getArea.js @@ -0,0 +1,45 @@ +import axios from "axios"; +import { capitalize } from 'lodash'; + +const API_URL = `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql`; + +async function getArea(slug, locale) { + try { + const res = await axios({ + url: API_URL, + method: "POST", + data: { + query: ` + query { + allArea (slug: "${slug}") { + edges { + node { + _id + slug + name + name${capitalize(locale)} + } + } + } + } + `, + variables: null + } + }); + const data = res?.data?.data?.allArea?.edges; + return data; + } catch (error) { + console.error(error); + return null; + } +} + +export default async function handler(req, res) { + const { slug, locale = 'pt' } = req.query; + const result = await getArea(slug, locale); + + if(result.errors) return res.status(500).json({error: result.errors, success: false}) + if(result === "err") return res.status(500).json({error: "err", success: false}) + + return res.status(200).json({resource: result, success: true}) +} \ No newline at end of file diff --git a/next/pages/api/areas/getAreas.js b/next/pages/api/areas/getAreas.js new file mode 100644 index 00000000..0e7ddfea --- /dev/null +++ b/next/pages/api/areas/getAreas.js @@ -0,0 +1,45 @@ +import axios from "axios"; +import { capitalize } from 'lodash'; + +const API_URL = `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql`; + +async function getAreas(locale = 'pt') { + try { + const res = await axios({ + url: API_URL, + method: "POST", + data: { + query: ` + query { + allArea { + edges { + node { + _id + slug + name + name${capitalize(locale)} + } + } + } + } + `, + variables: null + } + }); + const data = res?.data?.data?.allArea?.edges; + return data; + } catch (error) { + console.error(error); + return null; + } +} + +export default async function handler(req, res) { + const { locale } = req.query; + const result = await getAreas(locale); + + if(result.errors) return res.status(500).json({error: result.errors, success: false}) + if(result === "err") return res.status(500).json({error: "err", success: false}) + + return res.status(200).json({resource: result, success: true}) +} \ No newline at end of file diff --git a/next/pages/api/areas/getCountries.js b/next/pages/api/areas/getCountries.js new file mode 100644 index 00000000..f849a348 --- /dev/null +++ b/next/pages/api/areas/getCountries.js @@ -0,0 +1,50 @@ +import axios from "axios"; +import { capitalize } from 'lodash'; + +const API_URL = `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql`; + +async function getAreas(locale = 'pt') { + try { + const res = await axios({ + url: API_URL, + method: "POST", + data: { + query: ` + query { + allArea (administrativeLevel: A_0) { + edges { + node { + _id + slug + name + name${capitalize(locale)} + } + } + } + } + `, + variables: null + } + }); + const data = res?.data?.data?.allArea?.edges; + + return data; + } catch (error) { + console.error(error); + return null; + } +} + +export default async function handler(req, res) { + const { locale } = req.query; + console.log('API URL:', API_URL); + console.log('Locale:', locale); + + const result = await getAreas(locale); + console.log('Result:', result); + + if(result.errors) return res.status(500).json({error: result.errors, success: false}) + if(result === "err") return res.status(500).json({error: "err", success: false}) + + return res.status(200).json({resource: result, success: true}) +} \ No newline at end of file diff --git a/next/pages/api/datasets/getDataset.js b/next/pages/api/datasets/getDataset.js index 60e73e92..03406774 100644 --- a/next/pages/api/datasets/getDataset.js +++ b/next/pages/api/datasets/getDataset.js @@ -20,7 +20,8 @@ export default async function getDataset(id, locale = 'pt') { name${capitalize(locale)} description description${capitalize(locale)} - coverage + spatialCoverage + temporalCoverage themes { edges { node { diff --git a/next/pages/api/tables/getTable.js b/next/pages/api/tables/getTable.js index a921390d..d58fcad8 100644 --- a/next/pages/api/tables/getTable.js +++ b/next/pages/api/tables/getTable.js @@ -46,7 +46,9 @@ async function getTable(id, locale='pt') { } } version - fullCoverage + temporalCoverage + spatialCoverage + fullTemporalCoverage rawDataSource { edges { node { diff --git a/next/pages/api/tables/getTableColumns.js b/next/pages/api/tables/getTableColumns.js index 1c3f83fb..0cf44eae 100644 --- a/next/pages/api/tables/getTableColumns.js +++ b/next/pages/api/tables/getTableColumns.js @@ -55,7 +55,8 @@ async function getTableColumns(id, locale = 'pt') { bigqueryType { name } - coverage + spatialCoverage + temporalCoverage measurementUnit containsSensitiveData observations diff --git a/next/pages/dataset/[dataset].js b/next/pages/dataset/[dataset].js index f1019d18..bd4b2100 100644 --- a/next/pages/dataset/[dataset].js +++ b/next/pages/dataset/[dataset].js @@ -15,6 +15,7 @@ import Head from "next/head"; import { useTranslation } from 'next-i18next'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { capitalize } from 'lodash'; +import axios from "axios"; import BigTitle from "../../components/atoms/BigTitle"; import GreenTab from "../../components/atoms/GreenTab"; @@ -35,8 +36,36 @@ import { export async function getStaticProps(context) { const { locale, params } = context; let dataset = null; + let spatialCoverageNames = []; + try { dataset = await getDataset(params.dataset, locale || 'pt'); + + if (dataset?.spatialCoverage) { + const coverageArray = Array.isArray(dataset.spatialCoverage) + ? dataset.spatialCoverage + : typeof dataset.spatialCoverage === 'string' + ? dataset.spatialCoverage.split(',').map(item => item.trim()) + : Object.values(dataset.spatialCoverage); + + const promises = coverageArray.map(slug => { + const url = `${process.env.NEXT_PUBLIC_BASE_URL_FRONTEND}/api/areas/getArea?slug=${slug}&locale=${locale}`; + return axios.get(url).catch(error => { + console.error(`Error fetching ${url}:`, error.message); + return null; + }); + }); + + const responses = await Promise.all(promises); + spatialCoverageNames = responses + .filter(res => res !== null) + .map(res => { + const name = res.data.resource[0]?.node[`name${capitalize(locale)}`] || res.data.resource[0]?.node.name; + return name; + }) + .filter(Boolean) + .sort((a, b) => a.localeCompare(b, locale)); + } } catch (error) { console.error("Fetch error:", error.message); } @@ -45,6 +74,7 @@ export async function getStaticProps(context) { props: { ...(await serverSideTranslations(locale, ['dataset', 'common', 'menu', 'prices'])), dataset, + spatialCoverageNames, }, revalidate: 30, }; @@ -61,7 +91,7 @@ export async function getStaticPaths(context) { } } -export default function DatasetPage ({ dataset }) { +export default function DatasetPage ({ dataset, spatialCoverageNames }) { const { t } = useTranslation('dataset', 'common'); const router = useRouter() const { locale } = router @@ -70,11 +100,6 @@ export default function DatasetPage ({ dataset }) { const isDatasetEmpty = dataset === null || Object.keys(dataset).length === 0 - useEffect(() => { - if (router.query?.dataset === "mundo-kaggle-olimpiadas") return window.open(`${process.env.NEXT_PUBLIC_BASE_URL_FRONTEND}/dataset/62f8cb83-ac37-48be-874b-b94dd92d3e2b`, "_self") - if (isDatasetEmpty) return router.push(`${process.env.NEXT_PUBLIC_API_URL}/dataset_redirect?dataset=${query.dataset}`) - }, []) - if(isDatasetEmpty) return return ( @@ -163,53 +188,85 @@ export default function DatasetPage ({ dataset }) { - - - {t('temporalCoverage')} - - - {dataset.coverage || t('noCoverage')} - - + + + + {t('temporalCoverage')} + + + {dataset.temporalCoverage || t('notProvided')} + + - - - {t('organization')} - - + + {t('spatialCoverage')} + + - {dataset.organization?.[`name${capitalize(locale)}`] || dataset.organization?.name || t('noOrganization')} + {spatialCoverageNames.length > 0 + ? spatialCoverageNames.join(', ') + : t('notProvided')} - - + + + + + {t('organization')} + + + + {dataset.organization?.[`name${capitalize(locale)}`] || dataset.organization?.name || t('noOrganization')} + + + + diff --git a/next/pages/search.js b/next/pages/search.js index 034bc1b5..ed55ec5d 100644 --- a/next/pages/search.js +++ b/next/pages/search.js @@ -27,7 +27,7 @@ import { import { CheckboxFilterAccordion } from "../components/atoms/FilterAccordion"; import Checkbox from "../components/atoms/Checkbox"; import { TagFilter } from "../components/atoms/Tag"; -import Dataset from "../components/organisms/Dataset"; +import DatasetSearchCard from "../components/organisms/DatasetSearchCard"; import { MainPageTemplate } from "../components/templates/main"; import FilterIcon from "../public/img/icons/filterIcon"; @@ -43,6 +43,7 @@ export async function getStaticProps({ locale }) { export default function SearchDatasetPage() { const { t } = useTranslation('dataset') + const { locale } = useRouter() const router = useRouter() const query = router.query @@ -56,7 +57,6 @@ export default function SearchDatasetPage() { const [isLoading, setIsLoading] = useState(true) async function getDatasets({q, filters, page}) { - const { locale } = router const res = await getSearchDatasets({q, filter: filters, page, locale: locale || 'pt'}) if(res === undefined) return router.push({pathname:"500"}) if(res?.count === 0) setShowEmptyState(true) @@ -292,11 +292,14 @@ export default function SearchDatasetPage() { function DatasetCard({ data }) { return ( - coverage.slug) || []) + .sort((a, b) => a.localeCompare(b)) + .join(', ')} organization={data.organizations[0]} tables={{ id: data?.first_table_id, @@ -314,6 +317,7 @@ export default function SearchDatasetPage() { free: data?.contains_open_data, pro: data?.contains_closed_data }} + locale={locale} /> ) } @@ -660,6 +664,20 @@ export default function SearchDatasetPage() { + handleSelectFilter(["spatial_coverage",`${value}`])} + isLoading={!isLoading} + /> + + + Date: Mon, 4 Nov 2024 18:08:11 +1100 Subject: [PATCH 04/13] feat: observation_level table order working --- .../components/atoms/ObservationLevelTable.js | 23 +++++++++++++------ .../api/rawDataSources/getRawDataSource.js | 1 + next/pages/api/tables/getTable.js | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/next/components/atoms/ObservationLevelTable.js b/next/components/atoms/ObservationLevelTable.js index f1f04f21..8d2bda79 100644 --- a/next/components/atoms/ObservationLevelTable.js +++ b/next/components/atoms/ObservationLevelTable.js @@ -18,16 +18,25 @@ export default function ObservationLevel({ resource }) { const headers = [t('observationLevelTable.entityHeader'), t('observationLevelTable.columnsHeader')]; - let array = [] - const keys = Object.keys(resource?.observationLevels) + function sortElements(a, b) { + if (a.order < b.order) { + return -1; + } + if (a.order > b.order) { + return 1; + } + return 0; + } - keys.forEach((elm) => { - const value = resource?.observationLevels[elm] + let array = []; + const keys = Object.keys(resource?.observationLevels); + const sortedLevels = Object.values(resource?.observationLevels).sort(sortElements); + sortedLevels.forEach((value) => { const valueEntity = () => { - if(value.entity[`name${capitalize(locale)}`]) return value.entity[`name${capitalize(locale)}`] - if(value.entity.name) return value.entity.name - return t('observationLevelTable.notProvided') + if(value.entity[`name${capitalize(locale)}`]) return value.entity[`name${capitalize(locale)}`]; + if(value.entity.name) return value.entity.name; + return t('observationLevelTable.notProvided'); } const valueColumns = () => { diff --git a/next/pages/api/rawDataSources/getRawDataSource.js b/next/pages/api/rawDataSources/getRawDataSource.js index cadc8bdb..4b9fc868 100644 --- a/next/pages/api/rawDataSources/getRawDataSource.js +++ b/next/pages/api/rawDataSources/getRawDataSource.js @@ -61,6 +61,7 @@ async function getRawDataSource(id, locale = 'pt') { edges { node { _id + order columns { edges { node { diff --git a/next/pages/api/tables/getTable.js b/next/pages/api/tables/getTable.js index a921390d..83a369a1 100644 --- a/next/pages/api/tables/getTable.js +++ b/next/pages/api/tables/getTable.js @@ -105,6 +105,7 @@ async function getTable(id, locale='pt') { edges { node { _id + order columns { edges { node { From 1de746493d46c7bcadc7eaed7279bc78f473e5a3 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Tue, 5 Nov 2024 17:12:45 +1100 Subject: [PATCH 05/13] feat: many to many, keep organization[0] data --- next/components/molecules/ThemeCatalog.js | 2 +- .../components/organisms/DatasetSearchCard.js | 12 +-- .../organisms/DatasetThemeCatalogCard.js | 6 +- next/components/organisms/TablePage.js | 73 +++++++++++-------- next/pages/api/datasets/getDataset.js | 18 +++-- next/pages/api/tables/getTable.js | 16 ++-- next/pages/dataset/[dataset].js | 6 +- next/pages/search.js | 2 +- 8 files changed, 76 insertions(+), 59 deletions(-) diff --git a/next/components/molecules/ThemeCatalog.js b/next/components/molecules/ThemeCatalog.js index e6e7360b..42165eec 100644 --- a/next/components/molecules/ThemeCatalog.js +++ b/next/components/molecules/ThemeCatalog.js @@ -253,7 +253,7 @@ function CardThemes ({ responsive, datasetsCards = [], loading, locale }) { key={i} name={elm?.name} themes={elm?.themes} - organization={elm?.organizations?.[0]} + organizations={elm?.organizations} tags={elm?.tags} tables={{ id: elm?.first_table_id || elm?.first_closed_table_id, diff --git a/next/components/organisms/DatasetSearchCard.js b/next/components/organisms/DatasetSearchCard.js index ff607747..28d658a8 100644 --- a/next/components/organisms/DatasetSearchCard.js +++ b/next/components/organisms/DatasetSearchCard.js @@ -23,7 +23,7 @@ export default function Dataset({ name, spatialCoverage, temporalCoverageText, - organization, + organizations, tables, rawDataSources, informationRequests, @@ -187,8 +187,10 @@ export default function Dataset({ _hover={{ opacity: 0.9 }} > {organization[`name${capitalize(locale)}`] - {organization[`name${capitalize(locale)}`] || organization?.name} + {organizations[0]?.[`name${capitalize(locale)}`] || organizations[0]?.name} diff --git a/next/components/organisms/DatasetThemeCatalogCard.js b/next/components/organisms/DatasetThemeCatalogCard.js index 672a4579..cd7274b1 100644 --- a/next/components/organisms/DatasetThemeCatalogCard.js +++ b/next/components/organisms/DatasetThemeCatalogCard.js @@ -16,7 +16,7 @@ import { DatasetCardTag } from "../atoms/DatasetCardTag"; export default function DatasetCard({ name, themes = [], - organization, + organizations, tags = [], tables, rawDataSources, @@ -136,7 +136,7 @@ export default function DatasetCard({ {name} - + - {organization[`name${capitalize(locale)}`] || organization.name || organization.slug} + {organizations?.[0]?.[`name${capitalize(locale)}`] || organizations?.[0]?.name || organizations?.[0]?.slug} diff --git a/next/components/organisms/TablePage.js b/next/components/organisms/TablePage.js index 1f8c38be..e3138c67 100644 --- a/next/components/organisms/TablePage.js +++ b/next/components/organisms/TablePage.js @@ -167,38 +167,49 @@ export default function TablePage({ id }) { } const PublishedOrDataCleanedBy = ({ resource }) => { + if (!resource || typeof resource !== 'object' || Object.keys(resource).length === 0) { + return ( + + {t('table.notProvided')} + + ); + } + + const people = Object.values(resource); + return ( - - {resource?.firstName && resource?.lastName ? - - {`${resource.firstName} ${resource.lastName}`} - - : - - {t('table.notProvided')} - - } - {resource?.email && } - {resource?.github && } - {resource?.website && } - {resource?.twitter && } - - ) - } + + {people.map((person, index) => ( + + + {person?.firstName && person?.lastName + ? `${person.firstName} ${person.lastName}` + : t('table.notProvided') + } + + {person?.email && } + {person?.github && } + {person?.website && } + {person?.twitter && } + + ))} + + ); + }; const StackSkeleton = ({ children, ...props }) => { return ( diff --git a/next/pages/api/datasets/getDataset.js b/next/pages/api/datasets/getDataset.js index 03406774..a3dd182c 100644 --- a/next/pages/api/datasets/getDataset.js +++ b/next/pages/api/datasets/getDataset.js @@ -40,13 +40,17 @@ export default async function getDataset(id, locale = 'pt') { } } } - organization { - _id - slug - name - name${capitalize(locale)} - website - picture + organizations { + edges { + node { + _id + slug + name + name${capitalize(locale)} + website + picture + } + } } informationRequests { edges { diff --git a/next/pages/api/tables/getTable.js b/next/pages/api/tables/getTable.js index d58fcad8..daf68df4 100644 --- a/next/pages/api/tables/getTable.js +++ b/next/pages/api/tables/getTable.js @@ -25,14 +25,14 @@ async function getTable(id, locale='pt') { dataset { _id slug - organization { - _id - slug - name - name${capitalize(locale)} - area { - _id - slug + organizations { + edges { + node { + _id + slug + name + name${capitalize(locale)} + } } } } diff --git a/next/pages/dataset/[dataset].js b/next/pages/dataset/[dataset].js index bd4b2100..e5b824db 100644 --- a/next/pages/dataset/[dataset].js +++ b/next/pages/dataset/[dataset].js @@ -155,7 +155,7 @@ export default function DatasetPage ({ dataset, spatialCoverageNames }) { borderRadius="16px" > @@ -262,7 +262,7 @@ export default function DatasetPage ({ dataset, spatialCoverageNames }) { fontSize="14px" lineHeight="20px" > - {dataset.organization?.[`name${capitalize(locale)}`] || dataset.organization?.name || t('noOrganization')} + {dataset.organizations?.edges?.[0]?.node?.[`name${capitalize(locale)}`] || dataset.organizations?.edges?.[0]?.node?.name || t('noOrganization')} diff --git a/next/pages/search.js b/next/pages/search.js index ed55ec5d..9f144759 100644 --- a/next/pages/search.js +++ b/next/pages/search.js @@ -300,7 +300,7 @@ export default function SearchDatasetPage() { spatialCoverage={(data?.spatial_coverage?.map(coverage => coverage.slug) || []) .sort((a, b) => a.localeCompare(b)) .join(', ')} - organization={data.organizations[0]} + organizations={data.organizations} tables={{ id: data?.first_table_id, number: data?.n_tables From 8fefc8438556951ee4d91b8da572af4dc54b3cf4 Mon Sep 17 00:00:00 2001 From: aldemirLucas Date: Tue, 5 Nov 2024 17:36:09 -0300 Subject: [PATCH 06/13] fix: hide spatial_coverage components in Prod --- next/components/molecules/Footer.js | 7 +- .../components/organisms/DatasetSearchCard.js | 50 +++++---- next/components/organisms/TablePage.js | 98 ++++++++--------- next/pages/dataset/[dataset].js | 104 +++++++++--------- next/pages/search.js | 31 +++--- 5 files changed, 144 insertions(+), 146 deletions(-) diff --git a/next/components/molecules/Footer.js b/next/components/molecules/Footer.js index 97957372..e04142d4 100644 --- a/next/components/molecules/Footer.js +++ b/next/components/molecules/Footer.js @@ -93,25 +93,24 @@ export default function Footer({ template, ocult = false }) { if(template === "simple") return ( diff --git a/next/components/organisms/DatasetSearchCard.js b/next/components/organisms/DatasetSearchCard.js index 28d658a8..51c41ecd 100644 --- a/next/components/organisms/DatasetSearchCard.js +++ b/next/components/organisms/DatasetSearchCard.js @@ -299,31 +299,33 @@ export default function Dataset({ - - - {t('spatialCoverage')}: - - - {spatialCoverageNames.length > 0 - ? spatialCoverageNames.join(', ') - : spatialCoverage ? spatialCoverage : t('notProvided')} - - + + {t('spatialCoverage')}: + + + {spatialCoverageNames.length > 0 + ? spatialCoverageNames.join(', ') + : spatialCoverage ? spatialCoverage : t('notProvided')} + + + } - - - - - {t('table.temporalCoverage')} - - + + + {t('table.temporalCoverage')} + + - - - - + + + + - - - - {t('table.spatialCoverage')} - - + {process.env.NEXT_PUBLIC_BASE_URL_FRONTEND !== "https://basedosdados.org" && + + + + {t('table.spatialCoverage')} + + - + - - {spatialCoverageNames.length > 0 - ? spatialCoverageNames.join(', ') - : t('table.notProvided')} - - - - - + {spatialCoverageNames.length > 0 + ? spatialCoverageNames.join(', ') + : t('table.notProvided')} + + + + } diff --git a/next/pages/dataset/[dataset].js b/next/pages/dataset/[dataset].js index e5b824db..20147f63 100644 --- a/next/pages/dataset/[dataset].js +++ b/next/pages/dataset/[dataset].js @@ -142,7 +142,7 @@ export default function DatasetPage ({ dataset, spatialCoverageNames }) { spacing={0} > - + - + {dataset[`description${capitalize(locale)}`] || dataset.description || t('noDescription')} - - - - {t('temporalCoverage')} - + + + {t('organization')} + + - {dataset.temporalCoverage || t('notProvided')} + {dataset.organizations?.edges?.[0]?.node?.[`name${capitalize(locale)}`] || dataset.organizations?.edges?.[0]?.node?.name || t('noOrganization')} - + + + + + + {t('temporalCoverage')} + + + {dataset.temporalCoverage || t('notProvided')} + + - + {process.env.NEXT_PUBLIC_BASE_URL_FRONTEND !== "https://basedosdados.org" && + - - - - {t('organization')} - - - - {dataset.organizations?.edges?.[0]?.node?.[`name${capitalize(locale)}`] || dataset.organizations?.edges?.[0]?.node?.name || t('noOrganization')} - - - - + } diff --git a/next/pages/search.js b/next/pages/search.js index 9f144759..f9e6ed22 100644 --- a/next/pages/search.js +++ b/next/pages/search.js @@ -664,19 +664,24 @@ export default function SearchDatasetPage() { - handleSelectFilter(["spatial_coverage",`${value}`])} - isLoading={!isLoading} - /> - - + {process.env.NEXT_PUBLIC_BASE_URL_FRONTEND !== "https://basedosdados.org" ? + <> + handleSelectFilter(["spatial_coverage",`${value}`])} + isLoading={!isLoading} + /> + + + : + <> + } Date: Tue, 5 Nov 2024 17:44:59 -0300 Subject: [PATCH 07/13] chore: adjust image alignment with text --- next/pages/dataset/[dataset].js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/next/pages/dataset/[dataset].js b/next/pages/dataset/[dataset].js index 20147f63..905d8312 100644 --- a/next/pages/dataset/[dataset].js +++ b/next/pages/dataset/[dataset].js @@ -142,7 +142,7 @@ export default function DatasetPage ({ dataset, spatialCoverageNames }) { spacing={0} > From 5e6d6e9fb0a374a3b9e6245662af48aca1ea0b78 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Wed, 6 Nov 2024 15:41:52 +1100 Subject: [PATCH 08/13] feat: table.isDeprecated --- next/pages/api/tables/getTable.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/next/pages/api/tables/getTable.js b/next/pages/api/tables/getTable.js index 4352e55c..ead6eb75 100644 --- a/next/pages/api/tables/getTable.js +++ b/next/pages/api/tables/getTable.js @@ -46,6 +46,11 @@ async function getTable(id, locale='pt') { } } version + status { + _id + slug + } + isDeprecated temporalCoverage spatialCoverage fullTemporalCoverage From 675e29fec46cee3cb9c21a3bdeb58d04eaee1673 Mon Sep 17 00:00:00 2001 From: aldemirLucas Date: Wed, 6 Nov 2024 11:27:59 -0300 Subject: [PATCH 09/13] fix: separation of spatial_coverage feature into Prod and Staging --- next/components/organisms/DatasetResource.js | 83 ++++++++++++------- .../components/organisms/DatasetSearchCard.js | 7 +- next/components/organisms/TablePage.js | 45 +++++----- next/pages/api/areas/getCountries.js | 4 - next/pages/dataset/[dataset].js | 68 ++++++++------- next/pages/search.js | 4 +- next/public/locales/en/dataset.json | 1 + next/public/locales/es/dataset.json | 1 + next/public/locales/pt/dataset.json | 1 + 9 files changed, 130 insertions(+), 84 deletions(-) diff --git a/next/components/organisms/DatasetResource.js b/next/components/organisms/DatasetResource.js index 9bd37577..126d78b8 100644 --- a/next/components/organisms/DatasetResource.js +++ b/next/components/organisms/DatasetResource.js @@ -27,12 +27,12 @@ import ChevronIcon from "../../public/img/icons/chevronIcon"; export default function DatasetResource({ dataset }) { + const { t } = useTranslation('dataset'); const router = useRouter() const { query, locale } = router const [tables, setTables] = useState([]) const [rawDataSources, setRawDataSources] = useState([]) const [informationRequests, setInformationRequests] = useState([]) - const { t } = useTranslation('dataset'); const displayScreen = useBreakpointValue({ base: "mobile", lg: "desktop" }) const pushQuery = (key, value) => { @@ -55,7 +55,6 @@ export default function DatasetResource({ } useEffect(() => { - let dataset_tables = dataset?.tables?.edges.map((elm) => elm.node) .filter((elm) => elm?.status?.slug !== "under_review") .filter((elm) => elm?.slug !== "dicionario") @@ -194,10 +193,24 @@ export default function DatasetResource({ ) } - function SelectResource() { - const [widthScreen, setWidthScreen] = useState(0) + function SelectResource ({ selectedResource }) { + const { t } = useTranslation('dataset'); + const [widthScreen, setWidthScreen] = useState(0); + const [value, setValue] = useState("") + const {table, raw_data_source, information_request} = selectedResource; + + const findResourceName = (source, id) => { + const resource = source.find(item => item._id === id); + return resource ? resource[`name${capitalize(locale)}`] || resource.name : ""; + }; useEffect(() => { + setValue( + table ? findResourceName(tables, table) : + raw_data_source ? findResourceName(rawDataSources, raw_data_source) : + information_request ? findResourceName(informationRequests, information_request) : "" + ); + const updateWidthScreen = () => { setWidthScreen(window.innerWidth - 48) } @@ -209,35 +222,49 @@ export default function DatasetResource({ return () => { window.removeEventListener('resize', updateWidthScreen) } - }, []) + }, [table, raw_data_source, information_request]); return ( - - - Selecione uma tabela ou fonte original - - - + + {value} + + + + : - + } diff --git a/next/components/organisms/DatasetSearchCard.js b/next/components/organisms/DatasetSearchCard.js index 51c41ecd..c9a0abec 100644 --- a/next/components/organisms/DatasetSearchCard.js +++ b/next/components/organisms/DatasetSearchCard.js @@ -33,7 +33,12 @@ export default function Dataset({ const { t } = useTranslation('dataset'); const [spatialCoverageNames, setSpatialCoverageNames] = useState([]); + const allowedURLs = ["https://basedosdados.org", "https://staging.basedosdados.org"] + + useEffect(() => { + if(allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND)) return + const fetchAreaNames = async () => { if (!spatialCoverage) return; @@ -299,7 +304,7 @@ export default function Dataset({ - {process.env.NEXT_PUBLIC_BASE_URL_FRONTEND !== "https://basedosdados.org" && + {!allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND) && { const fetchData = async () => { try { @@ -45,28 +47,31 @@ export default function TablePage({ id }) { const result = await response.json() if (result.success) { - let areaNames = []; - - if (result.resource?.spatialCoverage) { - const coverageArray = Array.isArray(result.resource.spatialCoverage) - ? result.resource.spatialCoverage - : typeof result.resource.spatialCoverage === 'string' - ? result.resource.spatialCoverage.split(',').map(item => item.trim()) - : Object.values(result.resource.spatialCoverage); - - const promises = coverageArray.map(slug => - axios.get(`/api/areas/getArea?slug=${slug}&locale=${locale}`) - ); - - const responses = await Promise.all(promises); - areaNames = responses - .map(res => res.data.resource[0]?.node[`name${capitalize(locale)}`] || res.data.resource[0]?.node.name) - .filter(Boolean) - .sort((a, b) => a.localeCompare(b, locale)); + if(!allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND)) { + let areaNames = []; + + if (result.resource?.spatialCoverage) { + const coverageArray = Array.isArray(result.resource.spatialCoverage) + ? result.resource.spatialCoverage + : typeof result.resource.spatialCoverage === 'string' + ? result.resource.spatialCoverage.split(',').map(item => item.trim()) + : Object.values(result.resource.spatialCoverage); + + const promises = coverageArray.map(slug => + axios.get(`/api/areas/getArea?slug=${slug}&locale=${locale}`) + ); + + const responses = await Promise.all(promises); + areaNames = responses + .map(res => res.data.resource[0]?.node[`name${capitalize(locale)}`] || res.data.resource[0]?.node.name) + .filter(Boolean) + .sort((a, b) => a.localeCompare(b, locale)); + } + + setSpatialCoverageNames(areaNames); } setResource(result.resource); - setSpatialCoverageNames(areaNames); setIsError(false); } else { console.error(result.error) @@ -346,7 +351,7 @@ export default function TablePage({ id }) { - {process.env.NEXT_PUBLIC_BASE_URL_FRONTEND !== "https://basedosdados.org" && + {!allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND) && item.trim()) - : Object.values(dataset.spatialCoverage); - const promises = coverageArray.map(slug => { - const url = `${process.env.NEXT_PUBLIC_BASE_URL_FRONTEND}/api/areas/getArea?slug=${slug}&locale=${locale}`; - return axios.get(url).catch(error => { - console.error(`Error fetching ${url}:`, error.message); - return null; + if(!allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND)) { + if (dataset?.spatialCoverage) { + const coverageArray = Array.isArray(dataset.spatialCoverage) + ? dataset.spatialCoverage + : typeof dataset.spatialCoverage === 'string' + ? dataset.spatialCoverage.split(',').map(item => item.trim()) + : Object.values(dataset.spatialCoverage); + + const promises = coverageArray.map(slug => { + const url = `${process.env.NEXT_PUBLIC_BASE_URL_FRONTEND}/api/areas/getArea?slug=${slug}&locale=${locale}`; + return axios.get(url).catch(error => { + console.error(`Error fetching ${url}:`, error.message); + return null; + }); }); - }); - - const responses = await Promise.all(promises); - spatialCoverageNames = responses - .filter(res => res !== null) - .map(res => { - const name = res.data.resource[0]?.node[`name${capitalize(locale)}`] || res.data.resource[0]?.node.name; - return name; - }) - .filter(Boolean) - .sort((a, b) => a.localeCompare(b, locale)); + + const responses = await Promise.all(promises); + spatialCoverageNames = responses + .filter(res => res !== null) + .map(res => { + const name = res.data.resource[0]?.node[`name${capitalize(locale)}`] || res.data.resource[0]?.node.name; + return name; + }) + .filter(Boolean) + .sort((a, b) => a.localeCompare(b, locale)); + } } } catch (error) { console.error("Fetch error:", error.message); } + const props = { + ...(await serverSideTranslations(locale, ['dataset', 'common', 'menu', 'prices'])), + dataset, + ...(allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND) ? {} : { spatialCoverageNames }), + }; + return { - props: { - ...(await serverSideTranslations(locale, ['dataset', 'common', 'menu', 'prices'])), - dataset, - spatialCoverageNames, - }, + props, revalidate: 30, }; } @@ -91,13 +96,16 @@ export async function getStaticPaths(context) { } } -export default function DatasetPage ({ dataset, spatialCoverageNames }) { +export default function DatasetPage ({ dataset, spatialCoverageNames = [] }) { const { t } = useTranslation('dataset', 'common'); const router = useRouter() const { locale } = router const { query } = router const [tabIndex, setTabIndex] = useState(0) + const allowedURLs = ["https://basedosdados.org", "https://staging.basedosdados.org"] + + const isDatasetEmpty = dataset === null || Object.keys(dataset).length === 0 if(isDatasetEmpty) return @@ -236,7 +244,7 @@ export default function DatasetPage ({ dataset, spatialCoverageNames }) { - {process.env.NEXT_PUBLIC_BASE_URL_FRONTEND !== "https://basedosdados.org" && + {!allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND) && - {process.env.NEXT_PUBLIC_BASE_URL_FRONTEND !== "https://basedosdados.org" ? + {!allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND) ? <> Date: Thu, 7 Nov 2024 20:16:10 +1100 Subject: [PATCH 10/13] fix: remove calls to getArea --- .../components/organisms/DatasetSearchCard.js | 42 ++----------------- next/components/organisms/TablePage.js | 33 +++------------ next/pages/api/datasets/getDataset.js | 3 +- next/pages/api/tables/getTable.js | 1 + next/pages/api/tables/getTableColumns.js | 3 +- next/pages/dataset/[dataset].js | 37 +++------------- next/pages/search.js | 6 ++- 7 files changed, 22 insertions(+), 103 deletions(-) diff --git a/next/components/organisms/DatasetSearchCard.js b/next/components/organisms/DatasetSearchCard.js index c9a0abec..7acd9796 100644 --- a/next/components/organisms/DatasetSearchCard.js +++ b/next/components/organisms/DatasetSearchCard.js @@ -21,9 +21,9 @@ import { useState, useEffect } from "react"; export default function Dataset({ id, name, - spatialCoverage, - temporalCoverageText, organizations, + temporalCoverageText, + spatialCoverage, tables, rawDataSources, informationRequests, @@ -31,42 +31,8 @@ export default function Dataset({ locale }) { const { t } = useTranslation('dataset'); - const [spatialCoverageNames, setSpatialCoverageNames] = useState([]); - const allowedURLs = ["https://basedosdados.org", "https://staging.basedosdados.org"] - - useEffect(() => { - if(allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND)) return - - const fetchAreaNames = async () => { - if (!spatialCoverage) return; - - const coverageArray = Array.isArray(spatialCoverage) - ? spatialCoverage - : typeof spatialCoverage === 'string' - ? spatialCoverage.split(',').map(item => item.trim()) - : Object.values(spatialCoverage); - - const promises = coverageArray.map(slug => - axios.get(`/api/areas/getArea?slug=${slug}&locale=${locale}`) - ); - - try { - const responses = await Promise.all(promises); - const areaNames = responses - .map(res => res.data.resource[0]?.node[`name${capitalize(locale)}`] || res.data.resource[0]?.node.name) - .filter(Boolean) - .sort((a, b) => a.localeCompare(b, locale)); - setSpatialCoverageNames(areaNames); - } catch (error) { - console.error('Error fetching area names:', error); - } - }; - - fetchAreaNames(); - }, [spatialCoverage, locale]); - const Tables = () => { let tablesNumber = tables.number if(tables.number === undefined) tablesNumber = 0 @@ -325,9 +291,7 @@ export default function Dataset({ lineHeight="20px" color="#71757A" > - {spatialCoverageNames.length > 0 - ? spatialCoverageNames.join(', ') - : spatialCoverage ? spatialCoverage : t('notProvided')} + {spatialCoverage ? spatialCoverage : t('notProvided')} } diff --git a/next/components/organisms/TablePage.js b/next/components/organisms/TablePage.js index 2fa99eb4..42687473 100644 --- a/next/components/organisms/TablePage.js +++ b/next/components/organisms/TablePage.js @@ -36,7 +36,6 @@ export default function TablePage({ id }) { const [isLoading, setIsLoading] = useState(true) const [resource, setResource] = useState({}) const [isError, setIsError] = useState(false) - const [spatialCoverageNames, setSpatialCoverageNames] = useState([]); const allowedURLs = ["https://basedosdados.org", "https://staging.basedosdados.org"] @@ -47,30 +46,6 @@ export default function TablePage({ id }) { const result = await response.json() if (result.success) { - if(!allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND)) { - let areaNames = []; - - if (result.resource?.spatialCoverage) { - const coverageArray = Array.isArray(result.resource.spatialCoverage) - ? result.resource.spatialCoverage - : typeof result.resource.spatialCoverage === 'string' - ? result.resource.spatialCoverage.split(',').map(item => item.trim()) - : Object.values(result.resource.spatialCoverage); - - const promises = coverageArray.map(slug => - axios.get(`/api/areas/getArea?slug=${slug}&locale=${locale}`) - ); - - const responses = await Promise.all(promises); - areaNames = responses - .map(res => res.data.resource[0]?.node[`name${capitalize(locale)}`] || res.data.resource[0]?.node.name) - .filter(Boolean) - .sort((a, b) => a.localeCompare(b, locale)); - } - - setSpatialCoverageNames(areaNames); - } - setResource(result.resource); setIsError(false); } else { @@ -367,7 +342,7 @@ export default function TablePage({ id }) { - {spatialCoverageNames.length > 0 - ? spatialCoverageNames.join(', ') + {resource?.[`spatialCoverageName${capitalize(locale)}`] + ? Object.values(resource[`spatialCoverageName${capitalize(locale)}`]) + .sort((a, b) => a.localeCompare(b, locale)) + .join(', ') : t('table.notProvided')} diff --git a/next/pages/api/datasets/getDataset.js b/next/pages/api/datasets/getDataset.js index a3dd182c..482ca97a 100644 --- a/next/pages/api/datasets/getDataset.js +++ b/next/pages/api/datasets/getDataset.js @@ -20,8 +20,9 @@ export default async function getDataset(id, locale = 'pt') { name${capitalize(locale)} description description${capitalize(locale)} - spatialCoverage temporalCoverage + spatialCoverage + spatialCoverageName${capitalize(locale)} themes { edges { node { diff --git a/next/pages/api/tables/getTable.js b/next/pages/api/tables/getTable.js index ead6eb75..e012a7a1 100644 --- a/next/pages/api/tables/getTable.js +++ b/next/pages/api/tables/getTable.js @@ -53,6 +53,7 @@ async function getTable(id, locale='pt') { isDeprecated temporalCoverage spatialCoverage + spatialCoverageName${capitalize(locale)} fullTemporalCoverage rawDataSource { edges { diff --git a/next/pages/api/tables/getTableColumns.js b/next/pages/api/tables/getTableColumns.js index 0cf44eae..39b076b5 100644 --- a/next/pages/api/tables/getTableColumns.js +++ b/next/pages/api/tables/getTableColumns.js @@ -55,8 +55,9 @@ async function getTableColumns(id, locale = 'pt') { bigqueryType { name } - spatialCoverage temporalCoverage + spatialCoverage + spatialCoverageName${capitalize(locale)} measurementUnit containsSensitiveData observations diff --git a/next/pages/dataset/[dataset].js b/next/pages/dataset/[dataset].js index eb941706..4b63ebb8 100644 --- a/next/pages/dataset/[dataset].js +++ b/next/pages/dataset/[dataset].js @@ -36,39 +36,11 @@ import { export async function getStaticProps(context) { const { locale, params } = context; let dataset = null; - let spatialCoverageNames = []; const allowedURLs = ["https://basedosdados.org", "https://staging.basedosdados.org"] try { dataset = await getDataset(params.dataset, locale || 'pt'); - if(!allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND)) { - if (dataset?.spatialCoverage) { - const coverageArray = Array.isArray(dataset.spatialCoverage) - ? dataset.spatialCoverage - : typeof dataset.spatialCoverage === 'string' - ? dataset.spatialCoverage.split(',').map(item => item.trim()) - : Object.values(dataset.spatialCoverage); - - const promises = coverageArray.map(slug => { - const url = `${process.env.NEXT_PUBLIC_BASE_URL_FRONTEND}/api/areas/getArea?slug=${slug}&locale=${locale}`; - return axios.get(url).catch(error => { - console.error(`Error fetching ${url}:`, error.message); - return null; - }); - }); - - const responses = await Promise.all(promises); - spatialCoverageNames = responses - .filter(res => res !== null) - .map(res => { - const name = res.data.resource[0]?.node[`name${capitalize(locale)}`] || res.data.resource[0]?.node.name; - return name; - }) - .filter(Boolean) - .sort((a, b) => a.localeCompare(b, locale)); - } - } } catch (error) { console.error("Fetch error:", error.message); } @@ -76,7 +48,6 @@ export async function getStaticProps(context) { const props = { ...(await serverSideTranslations(locale, ['dataset', 'common', 'menu', 'prices'])), dataset, - ...(allowedURLs.includes(process.env.NEXT_PUBLIC_BASE_URL_FRONTEND) ? {} : { spatialCoverageNames }), }; return { @@ -96,7 +67,7 @@ export async function getStaticPaths(context) { } } -export default function DatasetPage ({ dataset, spatialCoverageNames = [] }) { +export default function DatasetPage ({ dataset }) { const { t } = useTranslation('dataset', 'common'); const router = useRouter() const { locale } = router @@ -263,8 +234,10 @@ export default function DatasetPage ({ dataset, spatialCoverageNames = [] }) { lineHeight="20px" color="#464A51" > - {spatialCoverageNames.length > 0 - ? spatialCoverageNames.join(', ') + {dataset?.[`spatialCoverageName${capitalize(locale)}`] + ? Object.values(dataset[`spatialCoverageName${capitalize(locale)}`]) + .sort((a, b) => a.localeCompare(b, locale)) + .join(', ') : t('notProvided')} diff --git a/next/pages/search.js b/next/pages/search.js index 66a3da33..9057cf2f 100644 --- a/next/pages/search.js +++ b/next/pages/search.js @@ -16,6 +16,7 @@ import { useEffect, useState } from "react"; import cookies from "js-cookie"; import { useTranslation } from 'next-i18next'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; +import capitalize from "lodash/capitalize"; import Link from "../components/atoms/Link"; import { isMobileMod, useCheckMobile } from "../hooks/useCheckMobile.hook"; import { triggerGAEvent } from "../utils"; @@ -299,8 +300,9 @@ export default function SearchDatasetPage() { themes={data?.themes} name={data?.name || t('noName')} temporalCoverageText={(data?.temporal_coverage && data.temporal_coverage[0]) || ""} - spatialCoverage={(data?.spatial_coverage?.map(coverage => coverage.slug) || []) - .sort((a, b) => a.localeCompare(b)) + spatialCoverage={data?.spatial_coverage + ?.map(coverage => coverage.name) + .sort((a, b) => a.localeCompare(b, locale)) .join(', ')} organizations={data.organizations} tables={{ From ef64b61b701f0bf997a7d6ef0d0254b4b5cbfbd4 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Thu, 7 Nov 2024 20:32:19 +1100 Subject: [PATCH 11/13] fix dependency --- next/pages/search.js | 1 - 1 file changed, 1 deletion(-) diff --git a/next/pages/search.js b/next/pages/search.js index 9057cf2f..1ea95799 100644 --- a/next/pages/search.js +++ b/next/pages/search.js @@ -16,7 +16,6 @@ import { useEffect, useState } from "react"; import cookies from "js-cookie"; import { useTranslation } from 'next-i18next'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; -import capitalize from "lodash/capitalize"; import Link from "../components/atoms/Link"; import { isMobileMod, useCheckMobile } from "../hooks/useCheckMobile.hook"; import { triggerGAEvent } from "../utils"; From aefbe42073277b197a24b32d722b762d077c8941 Mon Sep 17 00:00:00 2001 From: aldemirLucas Date: Thu, 7 Nov 2024 11:52:36 -0300 Subject: [PATCH 12/13] fix: fix text in dataUpdateFrequency --- next/components/organisms/TablePage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/next/components/organisms/TablePage.js b/next/components/organisms/TablePage.js index 2fa99eb4..0e85e721 100644 --- a/next/components/organisms/TablePage.js +++ b/next/components/organisms/TablePage.js @@ -490,7 +490,7 @@ export default function TablePage({ id }) { color="#464A51" > {resource?.rawDataSource?.[0]?.updates?.[0]?.latest ? - `${formatDate(resource.rawDataSource[0].updates[0].latest)}:` + `${formatDate(resource.rawDataSource[0].updates[0].latest)}` : t('table.notProvided') }: {t('table.lastUpdateRawDataSource')} @@ -543,7 +543,7 @@ export default function TablePage({ id }) { color="#464A51" > {resource?.rawDataSource?.[0]?.polls?.[0]?.latest ? - `${formatDate(resource.rawDataSource[0].polls[0].latest)}:` + `${formatDate(resource.rawDataSource[0].polls[0].latest)}` : t('table.notProvided') }: {t('table.lastCheckRawDataSource')} From 7a52f7688b27784e028e6891b4493f9586e112d6 Mon Sep 17 00:00:00 2001 From: aldemirLucas Date: Thu, 7 Nov 2024 11:59:32 -0300 Subject: [PATCH 13/13] fix: removing unused import and const --- next/components/organisms/TablePage.js | 1 - next/pages/dataset/[dataset].js | 1 - 2 files changed, 2 deletions(-) diff --git a/next/components/organisms/TablePage.js b/next/components/organisms/TablePage.js index 4a6451fd..642898ed 100644 --- a/next/components/organisms/TablePage.js +++ b/next/components/organisms/TablePage.js @@ -27,7 +27,6 @@ import TwitterIcon from "../../public/img/icons/twitterIcon"; import InfoIcon from "../../public/img/icons/infoIcon"; import DownloadIcon from "../../public/img/icons/downloadIcon"; import RedirectIcon from "../../public/img/icons/redirectIcon"; -import axios from "axios"; export default function TablePage({ id }) { const { t } = useTranslation('dataset', 'prices'); diff --git a/next/pages/dataset/[dataset].js b/next/pages/dataset/[dataset].js index 4b63ebb8..223dffa5 100644 --- a/next/pages/dataset/[dataset].js +++ b/next/pages/dataset/[dataset].js @@ -36,7 +36,6 @@ import { export async function getStaticProps(context) { const { locale, params } = context; let dataset = null; - const allowedURLs = ["https://basedosdados.org", "https://staging.basedosdados.org"] try { dataset = await getDataset(params.dataset, locale || 'pt');