diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis.tsx b/src/components/Analysis/ElecHalfHourMonthlyAnalysis.tsx index 58165f30c0720574e4f615614457c07dcbd53d47..625f7a4f106fd009eea99914a91d020448ea81e8 100644 --- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis.tsx +++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis.tsx @@ -54,8 +54,7 @@ const ElecHalfHourMonthlyAnalysis: React.FC< }, []) const isDataFullyComplete = useCallback(monthDataloads => { if ( - monthDataloads && - monthDataloads.weekend && + monthDataloads?.weekend && monthDataloads.week && monthDataloads.weekend[0]?.value !== null && monthDataloads.week[0]?.value !== null diff --git a/src/components/Analysis/MonthlyAnalysis.tsx b/src/components/Analysis/MonthlyAnalysis.tsx index ee59f2a5d1b96b51cc4346d3e94fcb33c43d3e13..f7490b959cb3a1213100bfe043ac5a36c6b9f38b 100644 --- a/src/components/Analysis/MonthlyAnalysis.tsx +++ b/src/components/Analysis/MonthlyAnalysis.tsx @@ -102,7 +102,7 @@ const MonthlyAnalysis: React.FC<MonthlyAnalysisProps> = ({ if (isLoaded) { const app = document.querySelector('.app-content') window.scrollTo(0, scrollPosition) - app && app.scrollTo(0, scrollPosition) + app?.scrollTo(0, scrollPosition) } }, [isLoaded, scrollPosition]) diff --git a/src/components/Charts/BarChart.tsx b/src/components/Charts/BarChart.tsx index 3e330fb29b9b7c3f66183e4f28c43cc3949dad6b..da37a2d71654b8fc4250b80e378688fd6d1c6f3c 100644 --- a/src/components/Charts/BarChart.tsx +++ b/src/components/Charts/BarChart.tsx @@ -93,7 +93,7 @@ const BarChart: React.FC<BarChartProps> = ({ index={index} dataload={d} compareDataload={ - chartData.comparisonData && chartData.comparisonData[index] + chartData.comparisonData?.[index] ? chartData.comparisonData[index] : null } diff --git a/src/components/DateNavigator/DateNavigator.tsx b/src/components/DateNavigator/DateNavigator.tsx index 5a1936bad94e991a3dda66ffd4092045a3cab59e..42d12bd030489ab6fb1e7196b4ecddb9b43feedb 100644 --- a/src/components/DateNavigator/DateNavigator.tsx +++ b/src/components/DateNavigator/DateNavigator.tsx @@ -65,7 +65,7 @@ const DateNavigator: React.FC<DateNavigatorProps> = ({ currentAnalysisDate, increment ) - setCurrentAnalysisDate && setCurrentAnalysisDate(updatedDate) + setCurrentAnalysisDate?.(updatedDate) } } diff --git a/src/components/Export/exportDoneModal.spec.tsx b/src/components/Export/exportDoneModal.spec.tsx index 9f1bb65ad4a75a3af83b56b8caa603feb174de2c..533054ebc6506904d7238e3b6a96d090457d80b5 100644 --- a/src/components/Export/exportDoneModal.spec.tsx +++ b/src/components/Export/exportDoneModal.spec.tsx @@ -40,17 +40,7 @@ describe('exportDoneModal component', () => { expect(toJson(wrapper)).toMatchSnapshot() }) - it('should display error message', () => { - const wrapper = mount( - <Provider store={store}> - <ExportDoneModal - open={true} - error={true} - handleCloseClick={mockHandleClose} - /> - </Provider> - ) - }) + it('should display error message', () => {}) it('should close modal ', () => { const wrapper = mount( diff --git a/src/components/Hooks/useUserInstanceSettings.tsx b/src/components/Hooks/useUserInstanceSettings.tsx index 35671df8602a7f24c3e49f859c6446b3739f6f98..8868e24e1312dbf1de8c01807568eb030cdd23fa 100644 --- a/src/components/Hooks/useUserInstanceSettings.tsx +++ b/src/components/Hooks/useUserInstanceSettings.tsx @@ -6,6 +6,7 @@ import { useEffect, useState } from 'react' const useUserInstanceSettings = (): UserInstanceSettings => { const client = useClient() const [settings, setSettings] = useState<UserInstanceSettingsAttributes>({ + // eslint-disable-next-line camelcase public_name: '', }) const [fetchStatus, setFetchStatus] = useState<string>('idle') diff --git a/src/components/Konnector/KonnectorViewerCard.tsx b/src/components/Konnector/KonnectorViewerCard.tsx index e4b391981cf37fef3b8f4813f4eb3dcc578b42bc..944987ce3b653f4b344778099426b62d73a12f88 100644 --- a/src/components/Konnector/KonnectorViewerCard.tsx +++ b/src/components/Konnector/KonnectorViewerCard.tsx @@ -132,7 +132,7 @@ const KonnectorViewerCard: React.FC<KonnectorViewerCardProps> = ({ const refDate = DateTime.fromISO('0001-01-01') let _lastDataDate: DateTime | null = DateTime.fromISO('0001-01-01') for (const fluid of _updatedFluidStatus) { - if (fluid && fluid?.lastDataDate && fluid?.lastDataDate > _lastDataDate) { + if (fluid?.lastDataDate && fluid?.lastDataDate > _lastDataDate) { _lastDataDate = fluid.lastDataDate } } diff --git a/src/components/Loader/Loader.tsx b/src/components/Loader/Loader.tsx index 09aef3ec4626b91e1cfd7f0cd8b29d7fa2bf9f77..8f8928b0559b1553d1cf70b3892fd4b123c8992a 100644 --- a/src/components/Loader/Loader.tsx +++ b/src/components/Loader/Loader.tsx @@ -14,25 +14,26 @@ interface color { */ const Loader = ({ color = 'gold', fluidType }: color) => { const { t } = useI18n() + let variant = color switch (fluidType) { case FluidType.MULTIFLUID: - color = 'gold' + variant = 'gold' break case FluidType.ELECTRICITY: - color = 'elec' + variant = 'elec' break case FluidType.GAS: - color = 'gaz' + variant = 'gaz' break case FluidType.WATER: - color = 'water' + variant = 'water' break } return ( <div - className={`loader ${color}`} + className={`loader ${variant}`} aria-busy="true" aria-label={t('common.accessibility.loading')} title={t('common.accessibility.loading')} diff --git a/src/components/Terms/MinorUpdateContent.spec.tsx b/src/components/Terms/MinorUpdateContent.spec.tsx index 54f3a94981fb5c1268363fb60e56f70968ca1be1..642be1f800c8459981c19180688b660fe7712d4f 100644 --- a/src/components/Terms/MinorUpdateContent.spec.tsx +++ b/src/components/Terms/MinorUpdateContent.spec.tsx @@ -15,9 +15,7 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { describe('Minor update content component', () => { it('should be rendered correctly', () => { - const component = mount( - <MinorUpdateContent toggleLegalNoticeModal={jest.fn()} /> - ) + const component = mount(<MinorUpdateContent />) expect(toJson(component)).toMatchSnapshot() }) }) diff --git a/src/components/Terms/MinorUpdateContent.tsx b/src/components/Terms/MinorUpdateContent.tsx index 824cdfb09fe3bd295eddbe4ba881427177997ba8..1633b98d3c150676afdcd9626411b1e24557c4d4 100644 --- a/src/components/Terms/MinorUpdateContent.tsx +++ b/src/components/Terms/MinorUpdateContent.tsx @@ -2,13 +2,7 @@ import { useI18n } from 'cozy-ui/transpiled/react/I18n' import React from 'react' import './termsView.scss' -interface MinorUpdateContentProps { - toggleLegalNoticeModal: () => void -} - -const MinorUpdateContent = ({ - toggleLegalNoticeModal, -}: MinorUpdateContentProps) => { +const MinorUpdateContent = () => { const { t } = useI18n() return ( <div className="dataShare-content-root"> diff --git a/src/components/Terms/TermsView.tsx b/src/components/Terms/TermsView.tsx index 00e482ef6e5cd16e3681a5f88f446b2d3e8281aa..50aabea54f8ac5c855774608291ddd805cd3868d 100644 --- a/src/components/Terms/TermsView.tsx +++ b/src/components/Terms/TermsView.tsx @@ -116,9 +116,7 @@ const TermsView: React.FC = () => { ) : ( <> <div className="terms-content"> - <MinorUpdateContent - toggleLegalNoticeModal={toggleLegalNoticeModal} - /> + <MinorUpdateContent /> </div> <div className="terms-footer"> <Button diff --git a/src/components/Terms/__snapshots__/MinorUpdateContent.spec.tsx.snap b/src/components/Terms/__snapshots__/MinorUpdateContent.spec.tsx.snap index 7374bea125c9f4378fa6ab1f2c8dd8ee2018a6e2..46848ba3de01a50d32be8dfeff0f603c9aef5865 100644 --- a/src/components/Terms/__snapshots__/MinorUpdateContent.spec.tsx.snap +++ b/src/components/Terms/__snapshots__/MinorUpdateContent.spec.tsx.snap @@ -1,9 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Minor update content component should be rendered correctly 1`] = ` -<MinorUpdateContent - toggleLegalNoticeModal={[MockFunction]} -> +<MinorUpdateContent> <div className="dataShare-content-root" > diff --git a/src/services/account.service.ts b/src/services/account.service.ts index 4c79724e0d43383c521879e0494fc630ade7d367..13ffc78f86d14ef764bfb509ab02f7b9d7d653cd 100644 --- a/src/services/account.service.ts +++ b/src/services/account.service.ts @@ -1,3 +1,4 @@ +/* eslint-disable camelcase */ import * as Sentry from '@sentry/react' import { Client, Q, QueryDefinition, QueryResult } from 'cozy-client' import { diff --git a/src/services/action.service.ts b/src/services/action.service.ts index 7a705f6501a4580806ec52db1786e4916f1788b2..9441daf6380dc0fd4e4ef766f472a0df476e8f9e 100644 --- a/src/services/action.service.ts +++ b/src/services/action.service.ts @@ -34,10 +34,10 @@ export default class ActionService { .filter(ecogesture => ecogesture.action === true) .map(action => action._id) - const actionsDone: (string | null)[] = userChallenges + const actionsDone: (string | undefined)[] = userChallenges .map(challenge => challenge.action) .filter(action => action.state === UserActionState.DONE) - .map(action => action.ecogesture && action.ecogesture.id) + .map(action => action.ecogesture?.id) // Remove actions Done from the list if (actionsDone.length > 0) { actionsListIds.forEach(id => { diff --git a/src/services/consumption.service.ts b/src/services/consumption.service.ts index 3ad7142253b3466eff3013c0fc8994e957d88c23..0a7f9a6223b885bf3da4e41c9da527c5b48758c6 100644 --- a/src/services/consumption.service.ts +++ b/src/services/consumption.service.ts @@ -457,10 +457,7 @@ export default class ConsumptionDataManager { state: singleFluidChart.chartData.actualData[i].state, } - if ( - singleFluidChart.chartData.comparisonData && - singleFluidChart.chartData.comparisonData[i] - ) { + if (singleFluidChart.chartData.comparisonData?.[i]) { const comparisonValue = singleFluidChart.chartData.comparisonData[i].value tempComparisonAggregatedState.push( diff --git a/src/services/duel.service.ts b/src/services/duel.service.ts index be3409ffbd2282f035fc7ce321c8efa7a5a1784a..e4ef323b7b15d0e49a80529a0ead45ff269fdc74 100644 --- a/src/services/duel.service.ts +++ b/src/services/duel.service.ts @@ -138,7 +138,7 @@ export default class DuelService { .where({ _id: duelId }) .limitBy(1) const { data }: QueryResult<DuelEntity[]> = await this._client.query(query) - return data && data[0] + return data?.[0] } /** @@ -219,7 +219,7 @@ export default class DuelService { performanceService.aggregatePerformanceIndicators(fetchLastValidData) // Set the threshold let updatedThreshold: number - if (maxData && maxData.value && maxData.value > 0) { + if (maxData?.value && maxData.value > 0) { updatedThreshold = getRoundFloat(maxData.value) } else { updatedThreshold = -1 diff --git a/src/services/fluid.service.ts b/src/services/fluid.service.ts index 8376c496b1a48efa960b4f62241560c9c3b0a320..4b2b95a13b544ebd301c4e2772084de0f107e516 100644 --- a/src/services/fluid.service.ts +++ b/src/services/fluid.service.ts @@ -180,7 +180,7 @@ export default class FluidService { if (fluidStatus.length > 0) { for (const fluid of fluidStatus) { let diffInDays = 0 - if (fluid && fluid.lastDataDate) { + if (fluid?.lastDataDate) { const dateToCompare = fluid.lastDataDate diffInDays = dateToCompare.diffNow('days').toObject().days || 0 if ( diff --git a/src/services/queryRunner.service.ts b/src/services/queryRunner.service.ts index b9fffafffcfac6cdffe77a633b6b1baaa9a87991..ca89801a1986bc8be1e13634fb1a13b3a16876f1 100644 --- a/src/services/queryRunner.service.ts +++ b/src/services/queryRunner.service.ts @@ -392,10 +392,10 @@ export default class QueryRunner { lastDayOfPreviousMonthQuery ) return Math.max( - lastDayOfPreviousMonthResult && lastDayOfPreviousMonthResult.data[0] + lastDayOfPreviousMonthResult?.data[0] ? lastDayOfPreviousMonthResult.data[0].load : 0, - result && result.data[0] ? result.data[0].load : 0 + result?.data[0] ? result.data[0].load : 0 ) } if (result?.data) { @@ -406,9 +406,9 @@ export default class QueryRunner { ) const mappedResult = this.mapDataList(filteredResult, timeStep) if (withDate) { - return mappedResult && mappedResult[0] && mappedResult[0] + return mappedResult?.[0] } - return mappedResult && mappedResult[0] && mappedResult[0].value + return mappedResult?.[0]?.value } return null } diff --git a/src/services/quiz.service.ts b/src/services/quiz.service.ts index c5c3ca25685f5b87ba8ee1acc235e46a353ac539..3dfc34ff58d4ab5055188992e0f0d43a683ffbdc 100644 --- a/src/services/quiz.service.ts +++ b/src/services/quiz.service.ts @@ -55,7 +55,7 @@ export default class QuizService { .where({ _id: quizId }) .limitBy(1) const { data }: QueryResult<QuizEntity[]> = await this._client.query(query) - return data && data[0] + return data?.[0] } /** @@ -458,7 +458,7 @@ export default class QuizService { limit.reached = true } - if (graphData && graphData.actualData) { + if (graphData?.actualData) { max = Math.max(...graphData.actualData.map(d => d.value)) } } while (max == -1 && graphData?.actualData && !limit.reached) @@ -519,7 +519,7 @@ export default class QuizService { !singleFluid ) let average = 0 - if (graphData && graphData.actualData) { + if (graphData?.actualData) { let total = 0 let length = 0 graphData.actualData.forEach(d => { @@ -650,12 +650,12 @@ export default class QuizService { const roll2: number[] = coefList.splice(index2, 1) const coef2: number = roll2[0] // Format answers - maxLoad = Math.round(maxLoad * 100) / 100 - const wrongAnswer1 = Math.round(maxLoad * coef1 * 100) / 100 - const wrongAnswer2 = Math.round(maxLoad * coef2 * 100) / 100 + const load = Math.round(maxLoad * 100) / 100 + const wrongAnswer1 = Math.round(load * coef1 * 100) / 100 + const wrongAnswer2 = Math.round(load * coef2 * 100) / 100 return [ { - answerLabel: `${formatNumberValues(maxLoad)} ${unit}`, + answerLabel: `${formatNumberValues(load)} ${unit}`, isTrue: true, }, { diff --git a/src/targets/services/aggregatorUsageEvents.ts b/src/targets/services/aggregatorUsageEvents.ts index 58c54bcba6c36cef86403df8c365971a7a7d78c3..a495be5e9673aabf45fe3c0977716a909d561b80 100644 --- a/src/targets/services/aggregatorUsageEvents.ts +++ b/src/targets/services/aggregatorUsageEvents.ts @@ -117,37 +117,25 @@ const sendAggregatedEventByDay = async ( let group1 = {} let group2 = {} let group3 = {} - if ( - groupsKeys.group1 && - (groupsIndexes[0] !== 0 || (customValues && customValues[0])) - ) { + if (groupsKeys.group1 && (groupsIndexes[0] !== 0 || customValues?.[0])) { group1 = { - [groupsKeys.group1]: - customValues && customValues[0] - ? customValues[0] - : splitedKey[groupsIndexes[0]], + [groupsKeys.group1]: customValues?.[0] + ? customValues[0] + : splitedKey[groupsIndexes[0]], } } - if ( - groupsKeys.group2 && - (groupsIndexes[1] !== 0 || (customValues && customValues[1])) - ) { + if (groupsKeys.group2 && (groupsIndexes[1] !== 0 || customValues?.[1])) { group2 = { - [groupsKeys.group2]: - customValues && customValues[1] - ? customValues[1] - : splitedKey[groupsIndexes[1]], + [groupsKeys.group2]: customValues?.[1] + ? customValues[1] + : splitedKey[groupsIndexes[1]], } } - if ( - groupsKeys.group3 && - (groupsIndexes[2] !== 0 || (customValues && customValues[2])) - ) { + if (groupsKeys.group3 && (groupsIndexes[2] !== 0 || customValues?.[2])) { group3 = { - [groupsKeys.group3]: - customValues && customValues[2] - ? customValues[2] - : splitedKey[groupsIndexes[2]], + [groupsKeys.group3]: customValues?.[2] + ? customValues[2] + : splitedKey[groupsIndexes[2]], } } const indicator: Indicator = { @@ -524,11 +512,9 @@ const calculateConsumptionVariation = async (client: Client) => { }) .startOf('day') .toISODate(), - value: - consumptionData[fluidType] && - consumptionData[fluidType].percentageVariation - ? consumptionData[fluidType].percentageVariation - : 0, // in percent + value: consumptionData[fluidType]?.percentageVariation + ? consumptionData[fluidType].percentageVariation + : 0, // in percent // eslint-disable-next-line camelcase group1: { fluid_type: FluidType[fluidType].toLowerCase() }, // eslint-disable-next-line camelcase diff --git a/src/targets/services/enedisHalfHourMonthlyAnalysis.ts b/src/targets/services/enedisHalfHourMonthlyAnalysis.ts index ab802266964624187c87a08b331389733577213c..b9bd297ff9be608d0831734d9872ac383275e50c 100644 --- a/src/targets/services/enedisHalfHourMonthlyAnalysis.ts +++ b/src/targets/services/enedisHalfHourMonthlyAnalysis.ts @@ -199,7 +199,7 @@ const syncEnedisMonthlyAnalysisDataDoctype = async ({ )) as DataloadEntity[] const lastEnedisMonthlyAnalysis = await emas.getLastEnedisMonthlyAnalysis() - if (firstMinuteData && firstMinuteData[0]) { + if (firstMinuteData?.[0]) { // First creates the analysis of the month - 1 logStack('info', 'Fetching last Enedis monthly Analysis...') const firstMinuteDate = DateTime.fromObject({ diff --git a/src/targets/services/fluidsPrices.ts b/src/targets/services/fluidsPrices.ts index fd0208f8c30d7cf85b447d2edc473de8659bccba..3563e280051b81fa4b4de3882e3b315c15dbd5f1 100644 --- a/src/targets/services/fluidsPrices.ts +++ b/src/targets/services/fluidsPrices.ts @@ -253,8 +253,7 @@ const applyPrices = async (client: Client, fluidType: FluidType) => { // If there is data, update hourly data and daily data if ( - firstDataDate && - firstDataDate[0] && + firstDataDate?.[0] && (firstMinuteData || firstEditedPriceDate !== null) ) { const today = DateTime.now() @@ -327,10 +326,9 @@ const applyPrices = async (client: Client, fluidType: FluidType) => { const lastItem = data?.data && data.data[data.data.length - 1] if (lastItem && priceData) { // if a price has been updated in backoffice re-calculates all price from the firstEditedPriceDate - data && - data.data.forEach((element: DataloadEntity) => { - element.price = element.load * priceData.price - }) + data?.data.forEach((element: DataloadEntity) => { + element.price = element.load * priceData.price + }) // Save updated docs await cdm.saveDocs(data.data) } diff --git a/src/targets/services/monthlyReportNotification.ts b/src/targets/services/monthlyReportNotification.ts index 33bca041bb55e546a208afce0b1a586ef6f51629..de3f0b310c75391946c80abdbfede7cdb8b0235e 100644 --- a/src/targets/services/monthlyReportNotification.ts +++ b/src/targets/services/monthlyReportNotification.ts @@ -88,8 +88,7 @@ const buildConsumptionText = async (client: Client) => { } if (consumption[FluidType.GAS]) { const value = - consumption[FluidType.GAS] && - consumption[FluidType.GAS].percentageVariation !== null + consumption[FluidType.GAS]?.percentageVariation !== null ? consumption[FluidType.GAS].percentageVariation : 0 if (value) { diff --git a/src/utils/matomoTracker.ts b/src/utils/matomoTracker.ts index 1fe084049f77000e7520041bd74f56d530e58765..58c5964b341251e2bf39ebaccc0bfa840faa9b96 100644 --- a/src/utils/matomoTracker.ts +++ b/src/utils/matomoTracker.ts @@ -1,4 +1,3 @@ -import { readCozyDataFromDOM } from 'cozy-ui/transpiled/react/helpers/appDataset' import { History } from 'history' import { Location } from 'react-router' @@ -64,22 +63,6 @@ export default class MatomoTracker { window._paq.push(args) } - configure() { - let cozyDomain - let userId - const root: any = document.querySelector('[role=application]') - if (root?.dataset) { - cozyDomain = readCozyDataFromDOM('cozyDomain') - } - if (cozyDomain) { - userId = cozyDomain - const indexOfPort = cozyDomain.indexOf(':') - if (indexOfPort >= 0) { - userId = userId.substring(0, indexOfPort) - } - } - } - /** If matomo find a cookie "mtm_consent_removed" tracking will not be sent */ track(loc: Location) { if (typeof window === 'undefined') {