diff --git a/src/components/ContainerComponents/IndicatorsContainer/IndicatorContainerSwitcher.tsx b/src/components/ContainerComponents/IndicatorsContainer/IndicatorContainerSwitcher.tsx index 835686a75b160d8ac678411a5d47cd8751cf1a3a..7d9db61d6ad733531ea89f0fcf114a68b42079ad 100644 --- a/src/components/ContainerComponents/IndicatorsContainer/IndicatorContainerSwitcher.tsx +++ b/src/components/ContainerComponents/IndicatorsContainer/IndicatorContainerSwitcher.tsx @@ -6,7 +6,7 @@ import { ITimePeriod, } from 'services/dataConsumptionContracts' import { convertDateByTimeStep } from 'utils/date' -import FluidConfigService from 'services/fluidConfigService' +import FluidConfigService from 'services/fluidConfig.service' import FluidPerformanceIndicator from 'components/ContentComponents/PerformanceIndicator/FluidPerformanceIndicator' import KonnectorViewer from 'components/ContentComponents/KonnectorViewer/KonnectorViewer' diff --git a/src/components/ContainerComponents/KonnectorViewerContainer/KonnectorViewerContainer.tsx b/src/components/ContainerComponents/KonnectorViewerContainer/KonnectorViewerContainer.tsx index e9931fbc60acc4fc9f0f454878c96570312bea0f..e3fe6d0205cdde9e7491412d062b96080da841f0 100644 --- a/src/components/ContainerComponents/KonnectorViewerContainer/KonnectorViewerContainer.tsx +++ b/src/components/ContainerComponents/KonnectorViewerContainer/KonnectorViewerContainer.tsx @@ -1,7 +1,7 @@ import React from 'react' import { translate } from 'cozy-ui/react/I18n' -import FluidConfigService from 'services/fluidConfigService' -import IFluidConfig from 'services/fluidConfigService' +import FluidConfigService from 'services/fluidConfig.service' +import { FluidConfig } from 'models' import KonnectorViewerList from 'components/ContentComponents/KonnectorViewer/KonnectorViewerList' interface KonnectorViewerContainerProps { @@ -13,7 +13,7 @@ const KonnectorViewerContainer: React.FC<KonnectorViewerContainerProps> = ({ isParam = false, t, }: KonnectorViewerContainerProps) => { - const fluidConfigs: IFluidConfig[] = new FluidConfigService().getFluidConfig() + const fluidConfigs: FluidConfig[] = new FluidConfigService().getFluidConfig() return ( <div className="kv-root"> <div className="kv-content"> diff --git a/src/components/ContentComponents/Konnector/KonnectorForm.tsx b/src/components/ContentComponents/Konnector/KonnectorForm.tsx index b27c1c8454e93df080bbcbf93105488223368674..3faeff9ed0139e0a2b913313934ec9d147d1eb23 100644 --- a/src/components/ContentComponents/Konnector/KonnectorForm.tsx +++ b/src/components/ContentComponents/Konnector/KonnectorForm.tsx @@ -1,14 +1,13 @@ import React from 'react' import { translate } from 'cozy-ui/react/I18n' -import IFluidConfig from 'services/fluidConfigService' -import { Konnector, Trigger } from 'doctypes' +import { Konnector, Trigger, FluidConfig } from 'models' import KonnectorLoginForm from 'components/ContentComponents/Konnector/KonnectorLoginForm' import KonnectorOAuthForm from 'components/ContentComponents/Konnector/KonnectorOAuthForm' interface KonnectorFormProps { - fluidConfig: IFluidConfig + fluidConfig: FluidConfig konnector: Konnector account: Account | null trigger: Trigger | null diff --git a/src/components/ContentComponents/Konnector/KonnectorLoginForm.tsx b/src/components/ContentComponents/Konnector/KonnectorLoginForm.tsx index 8ab2a128204917ec6b6dcf1636fbc0e2e7205488..80b296cb3c64fd1f02139263d4e79cbc067d0f04 100644 --- a/src/components/ContentComponents/Konnector/KonnectorLoginForm.tsx +++ b/src/components/ContentComponents/Konnector/KonnectorLoginForm.tsx @@ -2,10 +2,9 @@ import React, { useState, useEffect } from 'react' import { withClient, Client } from 'cozy-client' import { translate } from 'cozy-ui/react/I18n' -import { Account, AccountAuthData, Trigger } from 'models' +import { Account, AccountAuthData, Trigger, FluidConfig } from 'models' import AccountService from 'services/account.service' import ConnectionService from 'services/connection.service' -import IFluidConfig from 'services/fluidConfigService' import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton' import StyledButton from 'components/CommonKit/Button/StyledButton' @@ -17,7 +16,7 @@ import StyledAuthButton from 'components/CommonKit/Button/StyledAuthButton' import StyledIcon from 'components/CommonKit/Icon/StyledIcon' interface KonnectorLoginFormProps { - fluidConfig: IFluidConfig + fluidConfig: FluidConfig onSuccess: Function account: Account trigger: Trigger diff --git a/src/components/ContentComponents/KonnectorViewer/KonnectorViewer.tsx b/src/components/ContentComponents/KonnectorViewer/KonnectorViewer.tsx index e11cabe09ae1eac9f99ba9b9a4cd39e112990304..9d0d191dad44a411d47979cfca031b37582cd755 100644 --- a/src/components/ContentComponents/KonnectorViewer/KonnectorViewer.tsx +++ b/src/components/ContentComponents/KonnectorViewer/KonnectorViewer.tsx @@ -1,14 +1,13 @@ import React, { useState, useEffect } from 'react' import { withClient, Client } from 'cozy-client' -import { Konnector } from 'models' +import { Konnector, FluidConfig } from 'models' import KonnectorService from 'services/konnector.service' import KonnectorViewerCard from 'components/ContentComponents/KonnectorViewer/KonnectorViewerCard' -import IFluidConfig from 'services/fluidConfigService' export interface KonnectorViewerProps { - fluidConfig: IFluidConfig + fluidConfig: FluidConfig client: Client isParam: boolean } diff --git a/src/components/ContentComponents/KonnectorViewer/KonnectorViewerCard.tsx b/src/components/ContentComponents/KonnectorViewer/KonnectorViewerCard.tsx index 98e5e6c6f756f3e46c072f05b71f6c114237a178..f949248f06629527f21ba185b33809a5b767cfc3 100644 --- a/src/components/ContentComponents/KonnectorViewer/KonnectorViewerCard.tsx +++ b/src/components/ContentComponents/KonnectorViewer/KonnectorViewerCard.tsx @@ -14,20 +14,19 @@ import StyledIcon from 'components/CommonKit/Icon/StyledIcon' import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton' import failurePicto from 'assets/png/picto/picto-failure.png' -import IFluidConfig from 'services/fluidConfigService' import KonnectorNotFound from 'components/ContentComponents/Konnector/KonnectorNotFound' import KonnectorForm from 'components/ContentComponents/Konnector/KonnectorForm' import KonnectorResult from 'components/ContentComponents/Konnector/KonnectorResult' import KonnectorLaunch from 'components/ContentComponents/Konnector/KonnectorLaunch' -import { Konnector, Trigger, TriggerState } from 'models' +import { Konnector, Trigger, TriggerState, FluidConfig } from 'models' import AccountService from 'services/account.service' import TriggerService from 'services/triggers.service' import { JobState } from 'enum/jobState.enum' interface KonnectorViewerCardProps { - fluidConfig: IFluidConfig + fluidConfig: FluidConfig konnector: Konnector client: Client isParam: boolean diff --git a/src/components/ContentComponents/KonnectorViewer/KonnectorViewerList.tsx b/src/components/ContentComponents/KonnectorViewer/KonnectorViewerList.tsx index dbfe1e7dd87501b05b3993664599063067395c9d..3cf5f4893f4a8777e859d455155a52331771cbaf 100644 --- a/src/components/ContentComponents/KonnectorViewer/KonnectorViewerList.tsx +++ b/src/components/ContentComponents/KonnectorViewer/KonnectorViewerList.tsx @@ -1,11 +1,11 @@ import React, { useContext } from 'react' import KonnectorViewer from 'components/ContentComponents/KonnectorViewer/KonnectorViewer' -import IFluidConfig from 'services/fluidConfigService' +import { FluidConfig } from 'models' import { AppContext } from 'components/Contexts/AppContextProvider' export interface KonnectorViewerListProps { isParam: boolean - fluidConfigs: IFluidConfig[] + fluidConfigs: FluidConfig[] } const KonnectorViewerList: React.FC<KonnectorViewerListProps> = ({ @@ -15,12 +15,12 @@ const KonnectorViewerList: React.FC<KonnectorViewerListProps> = ({ const { fluidTypes } = useContext(AppContext) return ( <div> - {fluidConfigs.map((item: IFluidConfig, index: number) => { + {fluidConfigs.map((item: FluidConfig, index: number) => { return fluidTypes.includes(item.fluidTypeId) ? ( <KonnectorViewer isParam={isParam} key={index} fluidConfig={item} /> ) : null })} - {fluidConfigs.map((item: IFluidConfig, index: number) => { + {fluidConfigs.map((item: FluidConfig, index: number) => { return fluidTypes.includes(item.fluidTypeId) ? null : ( <KonnectorViewer isParam={isParam} key={index} fluidConfig={item} /> ) diff --git a/src/services/IFluidConfig.ts b/src/models/fluidConfig.model.ts similarity index 69% rename from src/services/IFluidConfig.ts rename to src/models/fluidConfig.model.ts index 9147fe93e0769d6e6c99ac5170e40d1e828a1c24..95fa4101b9fdc1e5f7fcd86760126c4d870ca130 100644 --- a/src/services/IFluidConfig.ts +++ b/src/models/fluidConfig.model.ts @@ -6,8 +6,7 @@ interface KonnectorConfig { cron?: string } -// eslint-disable-next-line @typescript-eslint/interface-name-prefix -export default interface IFluidConfig { +export interface FluidConfig { fluidTypeId: number name: string coefficient: number diff --git a/src/models/index.ts b/src/models/index.ts index e5120970cb241c4e51c54e3c24c0b0a9dffb5f53..8ee5577c61c8993bd1a1a0599ff1b160900954d8 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,4 +1,5 @@ export * from './account.model' +export * from './fluidConfig.model' export * from './konnector.model' export * from './trigger.model' export * from './userProfile.model' diff --git a/src/services/consumptionPeriodSelectorService.ts b/src/services/consumptionPeriodSelectorService.ts index 3ce691190d57b3cc28ac05a9669c0b5215085c31..21f0d294b5a9200afe8613cc77775ff669c81013 100644 --- a/src/services/consumptionPeriodSelectorService.ts +++ b/src/services/consumptionPeriodSelectorService.ts @@ -2,10 +2,10 @@ import { DateTime } from 'luxon' import { FluidType } from 'enum/fluid.enum' import { ITimePeriod, TimeStep } from './dataConsumptionContracts' import Config from '../../config.json' -import IFluidConfig from 'services/fluidConfigService' +import { FluidConfig } from 'models' export default class ConsumptionPeriodSelector { - private readonly _dataDelayOffsetConfig: IFluidConfig[] + private readonly _dataDelayOffsetConfig: FluidConfig[] constructor() { this._dataDelayOffsetConfig = Config.fluidConfig @@ -108,7 +108,9 @@ export default class ConsumptionPeriodSelector { .minus({ days: 1 }) case TimeStep.MONTH: - return DateTime.local(date.year, date.month, 1).minus({ days: 1 }) + return DateTime.local(date.year, date.month, 1).minus({ + days: 1, + }) case TimeStep.YEAR: return DateTime.local(date.year, 1, 1).minus({ days: 1 }) @@ -166,7 +168,9 @@ export default class ConsumptionPeriodSelector { switch (timeStep) { case TimeStep.HALF_AN_HOUR || TimeStep.HOUR: comparisonTimePeriodStartDate = timePeriod.startDate.minus({ days: 1 }) - comparisonTimePeriodEndDate = timePeriod.endDate.minus({ days: 1 }) + comparisonTimePeriodEndDate = timePeriod.endDate.minus({ + days: 1, + }) break case TimeStep.DAY: diff --git a/src/services/fluid.service.ts b/src/services/fluid.service.ts index e527df36d886c943f907999a50d2a1edd830e255..93e22c863c59f31bf9ab1f453ff6b3c3aae6d5e2 100644 --- a/src/services/fluid.service.ts +++ b/src/services/fluid.service.ts @@ -1,7 +1,7 @@ import { FluidType } from 'enum/fluid.enum' import { Client } from 'cozy-client' import { DateTime } from 'luxon' -import FluidConfigService from 'services/fluidConfigService' +import FluidConfigService from 'services/fluidConfig.service' import KonnectorService from 'services/konnector.service' import ConsumptionDataManager from 'services/consumptionDataManagerService' import AccountService from 'services/account.service' diff --git a/src/services/fluidConfig.service.ts b/src/services/fluidConfig.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..adb4de006b2aa652673adcc4a9ea0d1f7de72417 --- /dev/null +++ b/src/services/fluidConfig.service.ts @@ -0,0 +1,25 @@ +import Config from '../../config.json' +import { FluidConfig } from 'models' + +export default class FluidConfigService { + private readonly _fluidConfig: FluidConfig[] + + constructor() { + this._fluidConfig = Config.fluidConfig + } + + public getFluidConfig(): FluidConfig[] { + return this._fluidConfig + } + + /** + * + * @param min Minimum hour for cron + * @param max Maximum hour for cron + */ + public getCronArgs(min = 8, max = 9): string { + const randomHour = Math.floor(Math.random() * (max - min + 1) + min) + const randomMinutes = Math.floor(Math.random() * 59) + return `0 ${randomMinutes} ${randomHour} * * *` + } +} diff --git a/src/services/fluidConfigService.ts b/src/services/fluidConfigService.ts deleted file mode 100644 index a5c60c4aa27f8922ff6467fdbe68d5ae1ae1c1a0..0000000000000000000000000000000000000000 --- a/src/services/fluidConfigService.ts +++ /dev/null @@ -1,42 +0,0 @@ -import Config from '../../config.json' - -interface KonnectorConfig { - name: string - type: string - oauth: boolean - slug: string - cron?: string -} - -// eslint-disable-next-line @typescript-eslint/interface-name-prefix -export default interface IFluidConfig { - fluidTypeId: number - name: string - coefficient: number - dataDelayOffset: number - konnectorConfig: KonnectorConfig - siteLink: string -} - -export default class FluidConfig { - private readonly _fluidConfig: IFluidConfig[] - - constructor() { - this._fluidConfig = Config.fluidConfig - } - - public getFluidConfig(): IFluidConfig[] { - return this._fluidConfig - } - - /** - * - * @param min Minimum hour for cron - * @param max Maximum hour for cron - */ - public getCronArgs(min = 8, max = 9): string { - const randomHour = Math.floor(Math.random() * (max - min + 1) + min) - const randomMinutes = Math.floor(Math.random() * 59) - return `0 ${randomMinutes} ${randomHour} * * *` - } -} diff --git a/src/services/konnectorStatusService.ts b/src/services/konnectorStatusService.ts index d8229dc6279efcb2d54f7a7d49fca6aab0f33d91..823c77dccb082ba1436f7dc2b28edee538bd35af 100644 --- a/src/services/konnectorStatusService.ts +++ b/src/services/konnectorStatusService.ts @@ -1,5 +1,5 @@ import { Client } from 'cozy-client' -import FluidConfigService from 'services/fluidConfigService' +import FluidConfigService from 'services/fluidConfig.service' import AccountService from 'services/account.service' import { FluidType } from 'enum/fluid.enum' diff --git a/src/services/loadToCurrencyConverterService.ts b/src/services/loadToCurrencyConverterService.ts index 6299d808108168ffa898f8b14d180021c4231d3e..fd7506204ad85b4c2d3570bb212dc1a7f1e11031 100644 --- a/src/services/loadToCurrencyConverterService.ts +++ b/src/services/loadToCurrencyConverterService.ts @@ -1,9 +1,9 @@ import { FluidType } from 'enum/fluid.enum' import Config from '../../config.json' -import IFluidConfig from 'services/fluidConfigService' +import { FluidConfig } from 'models' export default class LoadToCurrencyConverter { - private readonly _fluidConfig: IFluidConfig[] + private readonly _fluidConfig: FluidConfig[] constructor() { this._fluidConfig = Config.fluidConfig diff --git a/src/services/triggers.service.ts b/src/services/triggers.service.ts index 453db69080140c11f5f67dd1a5843ac44c724422..ed4ba5d5f2610bbe095463a3793cac974e1849ce 100644 --- a/src/services/triggers.service.ts +++ b/src/services/triggers.service.ts @@ -8,7 +8,7 @@ import { } from 'models' import { buildAttributes } from 'cozy-harvest-lib/dist/helpers/triggers' import triggersMutations from 'cozy-harvest-lib/dist/connections/triggers' -import FluidConfig from 'services/fluidConfigService' +import FluidConfigService from 'services/fluidConfig.service' export default class TriggerService { private _client: Client @@ -18,7 +18,7 @@ export default class TriggerService { } private createTriggerAttributes(account: Account, konnector: Konnector) { - const fluidConfigService = new FluidConfig() + const fluidConfigService = new FluidConfigService() const cronArgs = fluidConfigService.getCronArgs() const triggerAttributes: TriggerAttributes = buildAttributes({ account: account,