Skip to content

ScheduledMaintenanceComponent JavaScript

Ethan Dunzer edited this page May 22, 2024 · 2 revisions

Overview

The ScheduledMaintenanceComponent is a Lightning Web Component (LWC) that manages and displays scheduled maintenance alerts within a Salesforce application. This component interacts with Apex methods to fetch maintenance data and handles the display logic, including modals and navigation.

Properties

  • @track scheduledMaintenances: Tracks the state of maintenance records.
  • @track appId: Stores the App ID for navigation.
  • @track isModalOpen: Controls the visibility of the modal.
  • @track isDismissible: Determines if the modal can be dismissed.
  • @track isSystemMaintenance: Indicates if there's an active system-wide maintenance.
  • @track isInMaintenance: Indicates if one of the records is in the maintenance window.
  • @track isFullLock: Indicates if the application is fully locked due to maintenance.
  • @api title: Public property for the modal title, default is 'Scheduled Maintenance Alert'.
  • @api currentAppContext: Public property for application context.
  • @track activeSectionName: Stores the name of the active section in the accordion.

Methods

  • connectedCallback: Lifecycle hook that's called after the component is inserted into the DOM. It initiates fetching of the App ID and scheduled maintenances, and sets up intervals for periodic data fetching.

  • disconnectedCallback: Lifecycle hook that's called when the component is removed from the DOM. Clears any active intervals.

  • fetchScheduledMaintenances: Fetches scheduled maintenances from the Apex method getActiveScheduledMaintenances. Logs the fetch time and processes the fetched data.

  • processScheduledMaintenances: Processes the fetched scheduled maintenances by filtering, formatting, and setting properties for display. Updates maintenance status indicators and modal visibility based on the processed data.

  • setupIntervals: Sets up intervals to periodically fetch scheduled maintenance data. The intervals adjust based on elapsed time to balance data freshness and performance.

  • updateDismissibleStatus: Updates the dismissible status of the modal based on current maintenance conditions and system admin rights.

  • calculateDismissible: Determines if a maintenance record is dismissible based on its start and end times relative to the current time.

  • fetchAppId: Fetches the App ID using the Apex method getAppIdByDeveloperName for navigation purposes.

  • navigateToApp: Navigates to another app based on the fetched App ID. Logs an error if the App ID is not found.

  • dismissAllRecords: Dismisses all maintenance records by updating their last dismissed date in local storage and closing the modal.

  • shouldShowAlert: Determines if an alert should be shown based on its timing and dismissibility status.

  • frequencyAllowsAlert: Checks if a maintenance alert should be repeated based on its alert frequency and the last dismissal date.

  • formatDateTime: Formats date and time strings for display in the component.

Clone this wiki locally