async handleEventClick()

in source/console/src/views/Client.tsx [970:1043]


  async handleEventClick(event: IEvent) {
    if (event.eventType && event.eventType.trim().toLowerCase() === 'automated') {
      LOGGER.warn('Automated events cannot be closed on the Client screen');
      return;
    }

    // Check if this event has sub events
    if (this.state.events.some(e => e.parentId === event.id)) {
      this.setState({ currentParentEventId: event.id! });
      return;
    }

    const promises = [];

    // If there's processing events, it won't publish messages for the event anymore.
    if (this.processingEvents.filter(processingEvent => processingEvent.id === event.id).length === 0) {
      const { selectedSite, selectedArea, selectedProcess, selectedStation, selectedDevice } = this.state;
      let issueToPublish: object;
      if (!event.isActive) {
        issueToPublish = {
          id: uuid.v1(),
          eventId: event.id,
          eventDescription: event.name,
          fullEventDescription: this.getFullEventDescription(event),
          eventType: event.eventType,
          priority: event.priority,
          siteName: selectedSite.name,
          areaName: selectedArea.name,
          processName: selectedProcess.name,
          stationName: selectedStation.name,
          deviceName: selectedDevice.name,
          created: addISOTimeOffset(new Date()),
          status: 'open',
          createdBy: this.username,
          issueSource: 'webClient'
        };

        promises.push(sendMetrics({ 'issue': 1 }));
      } else {
        let issueClosedTimestamp = addISOTimeOffset(new Date());
        let resolutionTime = Math.ceil((new Date(issueClosedTimestamp).valueOf() - new Date(event.createIssueTime as string).valueOf()) / 1000);
        issueToPublish = {
          id: event.activeIssueId,
          eventId: event.id,
          eventDescription: event.name,
          eventType: event.eventType,
          priority: event.priority,
          siteName: selectedSite.name,
          areaName: selectedArea.name,
          processName: selectedProcess.name,
          stationName: selectedStation.name,
          deviceName: selectedDevice.name,
          created: event.createIssueTime,
          closed: issueClosedTimestamp,
          resolutionTime: resolutionTime,
          status: 'closed',
          expectedVersion: event.updateIssueVersion,
          closedBy: this.username
        };
      }

      try {
        this.processingEvents.push(event);
        await PubSub.publish('ava/issues', issueToPublish);

        if (promises.length > 0) {
          await Promise.all(promises);
        }
      } catch (error) {
        this.processingEvents = this.processingEvents.filter(processingEvent => processingEvent.id !== event.id);
        LOGGER.error('Error occurred to publish an issue.', error);
      }
    }
  }