diff --git a/public/interfaces/eventHubInterface.ts b/public/interfaces/eventHubInterface.ts index 3a9316ae..87b2dc6d 100644 --- a/public/interfaces/eventHubInterface.ts +++ b/public/interfaces/eventHubInterface.ts @@ -6,7 +6,6 @@ export interface StartEventHubMonitoringParameters { deviceId: string; moduleId: string; consumerGroup: string; - startTime: string; customEventHubConnectionString?: string; hubConnectionString?: string; } diff --git a/src/app/api/parameters/deviceParameters.ts b/src/app/api/parameters/deviceParameters.ts index e3455262..66a2c3fe 100644 --- a/src/app/api/parameters/deviceParameters.ts +++ b/src/app/api/parameters/deviceParameters.ts @@ -31,7 +31,6 @@ export interface MonitorEventsParameters { consumerGroup: string; customEventHubConnectionString?: string; hubConnectionString?: string; - startTime?: Date; decoderPrototype?: Type; } diff --git a/src/app/api/services/devicesService.ts b/src/app/api/services/devicesService.ts index f3a1c105..7b32dd79 100644 --- a/src/app/api/services/devicesService.ts +++ b/src/app/api/services/devicesService.ts @@ -252,16 +252,13 @@ export const deleteDevices = async (parameters: DeleteDevicesParameters) => { }; export const monitorEvents = async (parameters: MonitorEventsParameters): Promise => { - let requestParameters = { - ...parameters, - startTime: parameters.startTime && parameters.startTime.toISOString() - }; + let requestParameters = parameters; // if no custom event hub info is provided, use default hub connection string to connect to event hub if (!parameters.customEventHubConnectionString) { const connectionInfo = await dataPlaneConnectionHelper(); requestParameters = { - ...requestParameters, + ...parameters, hubConnectionString: connectionInfo.connectionString }; } diff --git a/src/app/devices/deviceEvents/components/__snapshots__/deviceEvents.spec.tsx.snap b/src/app/devices/deviceEvents/components/__snapshots__/deviceEvents.spec.tsx.snap index 524c5d7c..952e7155 100644 --- a/src/app/devices/deviceEvents/components/__snapshots__/deviceEvents.spec.tsx.snap +++ b/src/app/devices/deviceEvents/components/__snapshots__/deviceEvents.spec.tsx.snap @@ -31,13 +31,6 @@ exports[`deviceEvents matches snapshot after loaded 1`] = ` setConsumerGroup={[Function]} /> -
diff --git a/src/app/devices/deviceEvents/components/__snapshots__/startTime.spec.tsx.snap b/src/app/devices/deviceEvents/components/__snapshots__/startTime.spec.tsx.snap deleted file mode 100644 index 3028011f..00000000 --- a/src/app/devices/deviceEvents/components/__snapshots__/startTime.spec.tsx.snap +++ /dev/null @@ -1,40 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`startTime matches snapshot 1`] = ` - - - deviceEvents.toggleSpecifyStartingTime.label - - } - offText="deviceEvents.toggleSpecifyStartingTime.off" - onChange={[Function]} - onText="deviceEvents.toggleSpecifyStartingTime.on" - /> -
- -
-
-`; diff --git a/src/app/devices/deviceEvents/components/deviceEvents.tsx b/src/app/devices/deviceEvents/components/deviceEvents.tsx index 75ab1100..126c008f 100644 --- a/src/app/devices/deviceEvents/components/deviceEvents.tsx +++ b/src/app/devices/deviceEvents/components/deviceEvents.tsx @@ -18,7 +18,6 @@ import { DeviceSimulationPanel } from './deviceSimulationPanel'; import { Commands } from './commands'; import { CustomEventHub } from './customEventHub'; import { ConsumerGroup } from './consumerGroup'; -import { StartTime } from './startTime'; import { DeviceContentTypePanel } from './deviceContentTypePanel'; import { Loader } from './loader'; import { EventsContent } from './eventsContent'; @@ -35,8 +34,6 @@ export const DeviceEvents: React.FC = () => { // event hub settings const [consumerGroup, setConsumerGroup] = React.useState(DEFAULT_CONSUMER_GROUP); - const [specifyStartTime, setSpecifyStartTime] = React.useState(false); - const [startTime, setStartTime] = React.useState(); const [useBuiltInEventHub, setUseBuiltInEventHub] = React.useState(true); const [customEventHubConnectionString, setCustomEventHubConnectionString] = React.useState(undefined); const [showSystemProperties, setShowSystemProperties] = React.useState(false); @@ -85,8 +82,6 @@ export const DeviceEvents: React.FC = () => { React.useEffect( // tslint:disable-next-line: cyclomatic-complexity () => { if (state.formMode === 'updating' || - // when specifying start time, valid time need to be provided - (specifyStartTime && (!startTime || hasError)) || // when using custom event hub, both valid connection string and name need to be provided (!useBuiltInEventHub && (!customEventHubConnectionString || hasError))) { setStartDisabled(true); @@ -95,7 +90,7 @@ export const DeviceEvents: React.FC = () => { setStartDisabled(false); } }, - [hasError, state.formMode, useBuiltInEventHub, customEventHubConnectionString, specifyStartTime, startTime]); + [hasError, state.formMode, useBuiltInEventHub, customEventHubConnectionString]); const onSystemPropertyCheckBoxChange = (ev?: React.FormEvent, checked?: boolean) => { setShowSystemProperties(!!checked); @@ -131,19 +126,6 @@ export const DeviceEvents: React.FC = () => { ); }; - const renderStartTimePicker = () => { - return ( - - ); - }; - const renderCustomEventHub = () => { return (
@@ -170,8 +152,7 @@ export const DeviceEvents: React.FC = () => { consumerGroup, decoderPrototype, deviceId, - moduleId, - startTime + moduleId }; if (!useBuiltInEventHub) { @@ -203,7 +184,6 @@ export const DeviceEvents: React.FC = () => { tooltip={ResourceKeys.deviceEvents.tooltip} /> {renderConsumerGroup()} - {renderStartTimePicker()} {renderCustomEventHub()} ({ - useHistory: () => ({ push: jest.fn() }), - useLocation: () => ({ search, pathname, push: jest.fn() }) -})); - -describe('startTime', () => { - it('matches snapshot', () => { - expect(shallow( - )).toMatchSnapshot(); - }); - - it('specifies start time string', () => { - const mockSetSpecifyStartTime = jest.fn(); - const mockSetStartTime = jest.fn(); - const MockSetHasError = jest.fn(); - const wrapper = mount( - ); - - act(() => wrapper.find(Toggle).first().props().onChange?.(undefined as any, false)); - wrapper.update(); - expect(mockSetSpecifyStartTime).toBeCalledWith(false); - - act(() => wrapper.find(TextField).props().onChange?.(undefined as any, '2020/12/16/12/58/00')); - wrapper.update(); - expect(mockSetStartTime).toBeCalledTimes(2); - expect(mockSetStartTime.mock.calls[1][0]).toEqual(new Date(2020, 11, 16, 12, 58, 0)); - expect(MockSetHasError).toBeCalledWith(false); - }); -}); diff --git a/src/app/devices/deviceEvents/components/startTime.tsx b/src/app/devices/deviceEvents/components/startTime.tsx deleted file mode 100644 index 25de8a42..00000000 --- a/src/app/devices/deviceEvents/components/startTime.tsx +++ /dev/null @@ -1,95 +0,0 @@ -/*********************************************************** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License - **********************************************************/ -import * as React from 'react'; -import { useTranslation } from 'react-i18next'; -import { TextField, Toggle, Stack } from '@fluentui/react'; -import { ResourceKeys } from '../../../../localization/resourceKeys'; -import { LabelWithTooltip } from '../../../shared/components/labelWithTooltip'; -import './deviceEvents.scss'; - -export interface StartTimeProps { - monitoringData: boolean; - specifyStartTime: boolean; - startTime: Date; - setSpecifyStartTime: (specifyStartTime: boolean) => void; - setStartTime: (date: Date) => void; - setHasError: (hasError: boolean) => void; -} - -export const StartTime: React.FC = ({monitoringData, specifyStartTime, startTime, setSpecifyStartTime, setStartTime, setHasError}) => { - - const { t } = useTranslation(); - const [ error, setError ] = React.useState(); - const [ startTimeString, setStartTimeString ] = React.useState(); - - React.useEffect(() => { - setStartTimeString(startTime && - `${startTime.getFullYear()}/${startTime.getMonth() + 1}/${startTime.getDate()}/${startTime.getHours()}/${startTime.getMinutes()}/${startTime.getSeconds()}`); - }, [startTime]); - - React.useEffect(() => { - const pattern = new RegExp('^[0-9]{4}\/(0?[1-9]|1[0-2])\/(0?[1-9]|[12][0-9]|3[01])\/(00|[0-9]|1[0-9]|2[0-3])\/([0-9]|[0-5][0-9])\/([0-9]|[0-5][0-9])$'); - if (pattern.test(startTimeString)) { - const dateStringSplit = startTimeString.split('/'); - const dateSplit = dateStringSplit.map(date => parseInt(date)); // tslint:disable-line:radix - // with the regex check, the date is guaranteed to be in yyyy/mm/dd/hh/mm/ss format - setStartTime(new Date(dateSplit[0], dateSplit[1] - 1, dateSplit[2], dateSplit[3], dateSplit[4], dateSplit[5])); // tslint:disable-line:no-magic-numbers - setError(''); - setHasError(false); - } - else { - setError(t(ResourceKeys.deviceEvents.startTime.error)); - setHasError(true); - } - }, [startTimeString]); - - const toggleChange = () => { - setSpecifyStartTime(!specifyStartTime); - }; - - const renderToggleLabel = () => ( - - {t(ResourceKeys.deviceEvents.toggleSpecifyStartingTime.label)} - - ); - - const startTimeChange = (event: React.FormEvent, newValue?: string) => { - setStartTimeString(newValue); - }; - - return ( - - -
- {specifyStartTime && - - } -
-
- ); -}; diff --git a/src/app/devices/deviceEvents/reducer.spec.ts b/src/app/devices/deviceEvents/reducer.spec.ts index 1f49a098..afaca306 100644 --- a/src/app/devices/deviceEvents/reducer.spec.ts +++ b/src/app/devices/deviceEvents/reducer.spec.ts @@ -12,7 +12,7 @@ import { Type } from 'protobufjs'; describe('deviceEventsReducer', () => { const deviceId = 'testDeviceId'; - const params = {consumerGroup: DEFAULT_CONSUMER_GROUP, deviceId, moduleId:'', startTime: new Date()}; + const params = {consumerGroup: DEFAULT_CONSUMER_GROUP, deviceId, moduleId:''}; const events = [{ body: { humid: '123' // intentionally set a value which type is double diff --git a/src/localization/locales/en.json b/src/localization/locales/en.json index 1da18dc2..0afacd18 100644 --- a/src/localization/locales/en.json +++ b/src/localization/locales/en.json @@ -593,11 +593,6 @@ "label": "Consumer group", "tooltip": "Consumer groups are used by applications to pull data from the IoT Hub. To change the current consumer group, stop monitoring telemetry." }, - "startTime": { - "error": "Please enter datetime format in yyyy/mm/dd/hh/mm/ss", - "label": "Start time", - "tooltip": "Indicates the local enqueue time that should be used to read messages from the event hub. If not specified, the enqueue time would be the moment you click on the 'Start' button." - }, "customEventHub": { "connectionString": { "label": "Custom event hub connection string", diff --git a/src/localization/resourceKeys.ts b/src/localization/resourceKeys.ts index f173c6c6..dabbfef7 100644 --- a/src/localization/resourceKeys.ts +++ b/src/localization/resourceKeys.ts @@ -419,11 +419,6 @@ export class ResourceKeys { tooltiop : "deviceEvents.simulation.prerequisite.tooltiop", }, }, - startTime : { - error : "deviceEvents.startTime.error", - label : "deviceEvents.startTime.label", - tooltip : "deviceEvents.startTime.tooltip", - }, toggleShowRawData : { label : "deviceEvents.toggleShowRawData.label", off : "deviceEvents.toggleShowRawData.off", diff --git a/src/server/serverBase.ts b/src/server/serverBase.ts index a7d58514..e9b3ece6 100644 --- a/src/server/serverBase.ts +++ b/src/server/serverBase.ts @@ -10,7 +10,7 @@ import * as express from 'express'; import * as bodyParser from 'body-parser'; import * as cors from 'cors'; import fetch from 'node-fetch'; -import { EventHubConsumerClient, Subscription, ReceivedEventData } from '@azure/event-hubs'; +import { EventHubConsumerClient, Subscription, ReceivedEventData, earliestEventPosition } from '@azure/event-hubs'; import { generateDataPlaneRequestBody, generateDataPlaneResponse } from './dataPlaneHelper'; import { convertIotHubToEventHubsConnectionString } from './eventHubHelper'; import { fetchDirectories, fetchDrivesOnWindows, findMatchingFile, readFileFromLocal } from './utils'; @@ -230,8 +230,10 @@ const initializeEventHubClient = async (params: any) => { }, processError: async (err) => { console.log(err); - } + }, + }, + {startPosition: earliestEventPosition} ); timerId = setInterval(() => {