Skip to content

Commit

Permalink
Linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
majakomel committed Apr 15, 2024
1 parent 1fa3724 commit ee4dc9f
Show file tree
Hide file tree
Showing 59 changed files with 239 additions and 164 deletions.
2 changes: 1 addition & 1 deletion components/Flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types'
import React from 'react'
import styled from 'styled-components'

var supportedCountryCodes = [
const supportedCountryCodes = [
'ad',
'ae',
'af',
Expand Down
2 changes: 1 addition & 1 deletion components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Header = () => {
const { asPath, locale, defaultLocale } = useRouter()

const lang = locale === defaultLocale ? '' : `/${locale}`
const canonical = 'https://explorer.ooni.org' + lang + asPath.split('?')[0]
const canonical = `https://explorer.ooni.org${lang}${asPath.split('?')[0]}`

const intl = useIntl()
const description = intl.formatMessage({ id: 'Home.Meta.Description' })
Expand Down
4 changes: 2 additions & 2 deletions components/MATChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ const MATChart = ({ query, showFilters = true }) => {
<>
{data?.data?.result?.length > 0 ? (
<Box>
{data && data.data.dimension_count == 0 && (
{data && data.data.dimension_count === 0 && (
<FunnelChart data={data.data.result} />
)}
{data && data.data.dimension_count == 1 && (
{data && data.data.dimension_count === 1 && (
<StackedBarChart data={data.data.result} query={query} />
)}
{data && data.data.dimension_count > 1 && (
Expand Down
1 change: 1 addition & 0 deletions components/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const NavBar = ({ color }) => {
logout()
}

// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
setShowMenu(false)
}, [pathname])
Expand Down
1 change: 1 addition & 0 deletions components/ThirdPartyDataChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const ThirdPartyDataChart = ({ since, until, country, asn, ...props }) => {
return [from, to]
}, [since, until])

// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
const cloudflareData = useEffect(() => {
if (!since && !until) return

Expand Down
5 changes: 4 additions & 1 deletion components/aggregation/Debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ export const Debug = ({ query, children, ...rest }) => {
</Bold>
</Box>
<Box>
<button onClick={() => updateNoOpState(performance.now())}>
<button
type="button"
onClick={() => updateNoOpState(performance.now())}
>
refresh
</button>

Expand Down
5 changes: 3 additions & 2 deletions components/aggregation/DebugContext.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, {
useState,
createContext,
useContext,
useCallback,
useContext,
useEffect,
useRef,
useState,
} from 'react'

export const DebugContext = createContext()
Expand Down Expand Up @@ -58,6 +58,7 @@ export const DebugProvider = ({ children }) => {
scrollStartRef.current = timestamp
}, [])

// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
// when API query is initiated, reset timestamps
console.debug('Query changed. Resetting timers')
Expand Down
18 changes: 9 additions & 9 deletions components/aggregation/mat/ChartHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Box, Flex, Heading, Text } from 'ooni-components'
import OONILogo from 'ooni-components/svgs/logos/OONI-HorizontalMonochrome.svg'
import { useIntl } from 'react-intl'

import { testGroups, testNames } from '/components/test-info'
import CountryNameLabel from './CountryNameLabel'
import { useMATContext } from './MATContext'
import { colorMap } from './colorMap'
import { testGroups, testNames } from '/components/test-info'

const Legend = ({ label, color }) => {
return (
Expand All @@ -29,9 +29,9 @@ const getTestNameGroupName = (testNameArray) => {
return [testNames[testNameArray[0]]?.id || testNameArray[0]]

const testGroup = new Set()
testNameArray.forEach((t) => {
for (const t of testNameArray) {
testNames[t]?.group && testGroup.add(testNames[t]?.group)
})
}
// if all test names belong to a single group, show group name
if (testGroup.size === 1) {
const testGroupName = testGroups[[...testGroup][0]].id
Expand All @@ -50,9 +50,9 @@ export const SubtitleStr = ({ query }) => {
? query.test_name
: [query.test_name]
const testNames = getTestNameGroupName(testNameQuery)
testNames.forEach((testName) => {
for (const testName of testNames) {
params.add(intl.formatMessage({ id: testName, defaultMessage: '' }))
})
}
}
if (query.domain) {
params.add(query.domain.split(',').join(', '))
Expand Down Expand Up @@ -104,25 +104,25 @@ export const ChartHeader = ({ options = {} }) => {
<Flex justifyContent="center" my={2} flexWrap="wrap">
<Legend
label={intl.formatMessage({ id: 'MAT.Table.Header.ok_count' })}
color={colorMap['ok_count']}
color={colorMap.ok_count}
/>
<Legend
label={intl.formatMessage({
id: 'MAT.Table.Header.confirmed_count',
})}
color={colorMap['confirmed_count']}
color={colorMap.confirmed_count}
/>
<Legend
label={intl.formatMessage({
id: 'MAT.Table.Header.anomaly_count',
})}
color={colorMap['anomaly_count']}
color={colorMap.anomaly_count}
/>
<Legend
label={intl.formatMessage({
id: 'MAT.Table.Header.failure_count',
})}
color={colorMap['failure_count']}
color={colorMap.failure_count}
/>
</Flex>
)}
Expand Down
2 changes: 1 addition & 1 deletion components/aggregation/mat/CustomTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const generateSearchQuery = (data, query) => {
if (query.time_grain !== 'hour') {
untilFilter = untilFilter.split('T')[0]
} else {
untilFilter = untilFilter.split('.')[0] + 'Z'
untilFilter = `${untilFilter.split('.')[0]}Z`
}
}

Expand Down
5 changes: 4 additions & 1 deletion components/aggregation/mat/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ const Filters = ({ data = [], tableData, setDataForCharts, query }) => {
])

useEffect(() => {
if (state.globalFilter == undefined && resetTableRef.current === true) {
if (state.globalFilter === undefined && resetTableRef.current === true) {
resetTableRef.current = false
toggleAllRowsSelected(false)
}
Expand Down Expand Up @@ -387,10 +387,12 @@ const Filters = ({ data = [], tableData, setDataForCharts, query }) => {
<Table {...getTableProps()}>
<TableHeader>
{headerGroups.map((headerGroup, i) => (
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
<TableRow key={i} {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((column, i) => {
return (
<Cell
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
key={i}
{...column.getHeaderProps([
{
Expand Down Expand Up @@ -457,6 +459,7 @@ const Filters = ({ data = [], tableData, setDataForCharts, query }) => {
{row.cells.map((cell, i) => {
return (
<Cell
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
key={i}
{...cell.getCellProps([
{
Expand Down
28 changes: 18 additions & 10 deletions components/aggregation/mat/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const filterAxisOptions = (
.map(([option]) => option)
}

// biome-ignore lint/style/useDefaultParameterLast: <explanation>
function isValidFilterForTestname(testName = 'XX', arrayWithMapping) {
// whether the dependent filter is valid to show along with `testName`
return arrayWithMapping.includes(testName)
Expand Down Expand Up @@ -138,17 +139,17 @@ export const Form = ({ onSubmit, query }) => {
}
}, [defaultValues, reset, router.isReady])

const [since, setSince] = useState(defaultValues['since'])
const [until, setUntil] = useState(defaultValues['until'])
const [countryValue, setCountryValue] = useState(defaultValues['probe_cc'])
const [testNameValue, setTestNameValue] = useState(defaultValues['test_name'])
const [since, setSince] = useState(defaultValues.since)
const [until, setUntil] = useState(defaultValues.until)
const [countryValue, setCountryValue] = useState(defaultValues.probe_cc)
const [testNameValue, setTestNameValue] = useState(defaultValues.test_name)

useEffect(() => {
const subscription = watch((value, { name, type }) => {
if (name === 'since') setSince(value['since'])
if (name === 'until') setUntil(value['until'])
if (name === 'probe_cc') setCountryValue(value['probe_cc'])
if (name === 'test_name') setTestNameValue(value['test_name'])
if (name === 'since') setSince(value.since)
if (name === 'until') setUntil(value.until)
if (name === 'probe_cc') setCountryValue(value.probe_cc)
if (name === 'test_name') setTestNameValue(value.test_name)
})
return () => subscription.unsubscribe()
}, [watch])
Expand Down Expand Up @@ -258,12 +259,14 @@ export const Form = ({ onSubmit, query }) => {
if (!availableValues.includes(getValues('time_grain')))
setValue('time_grain', 'hour')
return availableValues
} else if (diff >= 8 && diff < 31) {
}
if (diff >= 8 && diff < 31) {
const availableValues = ['day', 'week']
if (!availableValues.includes(getValues('time_grain')))
setValue('time_grain', 'day')
return availableValues
} else if (diff >= 31) {
}
if (diff >= 31) {
const availableValues = ['day', 'week', 'month']
if (!availableValues.includes(getValues('time_grain')))
setValue('time_grain', 'day')
Expand Down Expand Up @@ -296,6 +299,7 @@ export const Form = ({ onSubmit, query }) => {
{intl.formatMessage({ id: 'MAT.Form.AllCountries' })}
</option>
{sortedCountries.map((c, idx) => (
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
<option key={idx} value={c.iso3166_alpha2}>
{c.localisedCountryName}
</option>
Expand Down Expand Up @@ -372,6 +376,7 @@ export const Form = ({ onSubmit, query }) => {
width={1}
>
{timeGrainOptions.map((option, idx) => (
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
<option key={idx} value={option}>
{intl.formatMessage(messages[option])}
</option>
Expand All @@ -391,6 +396,7 @@ export const Form = ({ onSubmit, query }) => {
width={1}
>
{xAxisOptionsFiltered.map((option, idx) => (
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
<option key={idx} value={option}>
{option.length > 0
? intl.formatMessage(messages[option])
Expand All @@ -412,6 +418,7 @@ export const Form = ({ onSubmit, query }) => {
width={1}
>
{yAxisOptionsFiltered.map((option, idx) => (
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
<option key={idx} value={option}>
{option.length > 0
? intl.formatMessage(messages[option])
Expand Down Expand Up @@ -484,6 +491,7 @@ export const Form = ({ onSubmit, query }) => {
{categoryCodes
.sort((a, b) => (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0))
.map(([code, label], idx) => (
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
<option key={idx} value={code}>
{intl.formatMessage({
id: `CategoryCode.${code}.Name`,
Expand Down
4 changes: 2 additions & 2 deletions components/aggregation/mat/GridChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const prepareDataForGridChart = (data, query, locale) => {
const rowLabels = {}
const reshapedData = {}

data.forEach((item) => {
for (const item of data) {
// Convert non-string keys (e.g `probe_asn`) to string
// because they get casted to strings during Object transformations
const key = String(item[query.axis_y])
Expand All @@ -56,7 +56,7 @@ export const prepareDataForGridChart = (data, query, locale) => {
reshapedData[key] = [item]
rowLabels[key] = getRowLabel(key, query.axis_y, locale)
}
})
}

const reshapedDataWithoutHoles = fillDataHoles(reshapedData, query)

Expand Down
5 changes: 3 additions & 2 deletions components/aggregation/mat/HeatMapChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,21 @@ const CustomHeatMapCell = ({
let prevHeight = 0

return (
// biome-ignore lint/a11y/useKeyWithMouseEvents: <explanation>
<g
transform={`translate(${x}, ${y}) scale(1, -1)`}
onMouseOver={onHover}
onMouseLeave={onLeave}
>
{value !== undefined &&
barsData.map(([barLabel, barColor], index) => {
const barHeight =
height * (value[barLabel] / value['measurement_count']) // ((index + 1) / 10)
const barHeight = height * (value[barLabel] / value.measurement_count) // ((index + 1) / 10)
const barY =
prevHeight === 0 ? height * -0.5 : height * -0.5 + prevHeight
prevHeight = prevHeight + barHeight
return (
<rect
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
key={index}
x={width * -0.5}
y={barY}
Expand Down
1 change: 1 addition & 0 deletions components/aggregation/mat/MATContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const MATContextProvider = ({
[initialContext],
)

// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
stateReducer(MATquery)
}, [MATquery])
Expand Down
8 changes: 4 additions & 4 deletions components/aggregation/mat/TableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const prepareDataforTable = (data, query, locale) => {
measurement_count: 0,
}

rowData.forEach((d) => {
countKeys.forEach((countKey) => {
for (const d of rowData) {
for (const countKey of countKeys) {
row[countKey] = row[countKey] + d[countKey]
})
})
}
}

table.push(row)
}
Expand Down
2 changes: 1 addition & 1 deletion components/aggregation/mat/XAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const XAxis = ({ data }) => {

return (
<StyledFlex>
<Box width={2 / 16}></Box>
<Box width={2 / 16} />
<Box className="xAxis" sx={{ width: '100%', height: '62px' }}>
<ResponsiveBar
data={data}
Expand Down
8 changes: 4 additions & 4 deletions components/aggregation/mat/computations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const categoryCodesMap = getCategoryCodesMap()

export function getDatesBetween(startDate, endDate, timeGrain) {
const dateSet = new Set()
var currentDate = startDate
let currentDate = startDate
while (currentDate < endDate) {
if (timeGrain === 'hour') {
let startOfDay = dayjs(currentDate).utc().startOf('day')
const nextDay = startOfDay.add(1, 'day')
while (startOfDay.toDate() < nextDay.toDate()) {
dateSet.add(startOfDay.toISOString().split('.')[0] + 'Z')
dateSet.add(`${startOfDay.toISOString().split('.')[0]}Z`)
startOfDay = startOfDay.utc().add(1, 'hours')
}
currentDate = dayjs(currentDate).utc().add(1, 'day')
Expand Down Expand Up @@ -63,7 +63,7 @@ export function fillRowHoles(data, query, locale) {
const sampleDataPoint = { ...newData[0] }

// Add empty datapoints for columns where measurements are not available
missingCols.forEach((col) => {
for (const col of missingCols) {
// use any (first) column data to popuplate yAxis value e.g `input` | `probe_cc`
// and then overwrite with zero-data for that missing date
newData.splice([...domain].indexOf(col), 0, {
Expand All @@ -75,7 +75,7 @@ export function fillRowHoles(data, query, locale) {
measurement_count: 0,
ok_count: 0,
})
})
}

return newData
}
Expand Down
Loading

0 comments on commit ee4dc9f

Please sign in to comment.