Skip to main content

Activity Timeline

  

1. Overview

The PCF Calendar Control is a custom PowerApps component that displays activities in a calendar-like view. It supports multiple views (monthly, weekly, yearly, daily), allows users to expand/collapse records for each date, and provides a scrollable interface for better usability. The control is built using TypeScript and CSS, adhering to best practices for type safety and maintainability.

2. Features

View Modes:

  • Monthly View: Groups activities by month.

  • Weekly View: Groups activities by week.

  • Yearly View: Groups activities by year.

  • Daily View: Displays activities for individual days.

Expand/Collapse Functionality:

  • Users can click on a date to expand or collapse its associated records.

  • Smooth animations enhance the user experience.

Scrollable Container:

  • A scrollable container ensures that large datasets are manageable.

Responsive Design:

  • The control adjusts its layout for smaller screens.

Type Safety:

  • The code uses TypeScript interfaces to avoid the use of any and ensure type safety.

Status Indicators:

  • Activities are color-coded based on their status (e.g., Completed, In Progress, Canceled).

3. Prerequisites

To build and deploy the PCF Calendar Control, you need the following tools and dependencies:

3.1 Tools:

  • Node.js: Install Node.js from https://nodejs.org/.

  • Power Platform CLI: Install the Power Platform CLI using the command:

    npm install -g @microsoft/powerplatform-cli
  • Visual Studio Code: Download and install VS Code from https://code.visualstudio.com/.

3.2 Dependencies:

  • Install project dependencies by running:

    npm install

4. Project Structure

The project consists of the following files and folders:

4.1 Files:

  • ActivityTimelineControl.ts:

    • Contains the main logic for the calendar control.

    • Handles data grouping, view modes, and UI interactions.

  • style.css:

    • Defines the styles for the calendar control.

    • Includes animations, responsive design, and hover effects.

  • ControlManifest.Input.xml:

    • Defines metadata for the control, including properties, resources, and dataset bindings.

4.2 Folders:

  • generated: Contains auto-generated TypeScript types for the control's inputs and outputs.

  • out: Stores the compiled output after running the build process.

5. Implementation Details

5.1 TypeScript File (ActivityTimelineControl.ts)

This file contains the core logic for the calendar control. Below is a breakdown of its key components:

5.1.1 Interfaces

interface Record {
    getFormattedValue(fieldName: string): string | undefined;
    getValue(fieldName: string): number | undefined;
}

Defines the structure of the dataset records.

5.1.2 Grouping Logic

Activities are grouped based on the selected view mode:

private groupRecordsByViewMode(): { [key: string]: Record[] } {
    const groupedRecords: { [key: string]: Record[] } = {};

    this.activityDataset.sortedRecordIds.forEach((id) => {
        const record = this.activityDataset.records[id];
        const startDate = record.getFormattedValue("scheduledstart") || "No Start Date";

        let groupKey: string;

        switch (this.currentViewMode) {
            case "monthly":
                groupKey = this.formatMonth(startDate);
                break;
            case "weekly":
                groupKey = this.formatWeek(startDate);
                break;
            case "yearly":
                groupKey = this.formatYear(startDate);
                break;
            case "daily":
                groupKey = this.formatDate(startDate);
                break;
            default:
                groupKey = this.formatMonth(startDate);
        }

        if (!groupedRecords[groupKey]) {
            groupedRecords[groupKey] = [];
        }
        groupedRecords[groupKey].push(record);
    });

    return groupedRecords;
}

5.1.3 Expand/Collapse Functionality

Clicking on a date toggles the visibility of its associated records:

header.addEventListener('click', (event) => {
    const target = event.target as HTMLElement;
    const groupKey = target.getAttribute('data-group');
    const itemsContainer = document.querySelector(`[data-items-for="${groupKey}"]`) as HTMLElement;

    const toggleIcon = target.querySelector('.toggle-icon');
    if (!toggleIcon) return;

    if (itemsContainer.style.maxHeight === "0px" || itemsContainer.style.maxHeight === "") {
        itemsContainer.style.maxHeight = `${itemsContainer.scrollHeight}px`;
        toggleIcon.textContent = "▲";
    } else {
        itemsContainer.style.maxHeight = "0px";
        toggleIcon.textContent = "▼";
    }
});

6. Build and Deployment

6.1 Build the Control

Run the following command to compile the control:

npm run build

6.2 Test Locally

Use the Power Platform CLI to test the control locally:

pac pcf start

6.3 Deploy to Power Apps

Deploy the control to your Power Apps environment:

pac pcf push --publisher-prefix yourprefix
Uploading: 30661 of 30661 bytes uploaded.







7. Usage Instructions

7.1 Adding the Control to a Form

  • Open the form editor in Power Apps.

  • Add the PCF Calendar Control to the form.

  • Bind the control to a dataset containing activity records.

7.2 Configuring the Control

  • Set the view mode (monthly, weekly, yearly, daily) using the provided buttons.

  • Interact with the calendar by clicking on dates to expand/collapse records.

8. Troubleshooting

8.1 Common Errors

ESLint Validation Errors:

  • Ensure all any types are replaced with specific types.

    const groupedRecords: { [key: string]: Record[] } = {};

Build Failures:

  • Verify that all dependencies are installed (npm install).

  • Check for syntax errors in the TypeScript file.

Deployment Issues:

  • Ensure the publisher prefix matches the one used during deployment.

9. Conclusion

The PCF Calendar Control is a versatile and user-friendly tool for displaying activities in a calendar format. By following the steps outlined in this document, you can successfully build, test, and deploy the control to your Power Apps environment.

If you have further questions or need additional assistance, feel free to reach out!

Comments

Popular posts from this blog

Contacts View PCF Control

  1. Overview The ContactsControl component is a custom PowerApps control that displays a searchable and sortable table of contact records. It provides an interactive UI for filtering and selecting records. 2. Functionalities Search Feature: Allows users to filter records by entering text. Sorting: Clickable column headers enable ascending/descending sorting. Record Selection: Users can select a record to trigger a modal alert. Dynamic Rendering: Updates view dynamically based on search and sort input. Custom Styling: Uses external CSS for styling. 3. Component Structure Main Container ( HTMLDivElement ) : Holds the search bar and table. Search Input ( HTMLInputElement ) : Enables real-time search. Table ( HTMLTableElement ) : Displays the records with sortable headers. Modal Alert ( HTMLDivElement ) : Displays selected record details. 4. Implementation Details 4.1 Initialization ( init Method) Sets up the main container. Loads external styles. Creates...

Attachment PCF

Overview The AttachmentControl component is a PowerApps Component Framework (PCF) control designed for handling file uploads. It supports multiple file uploads, drag-and-drop functionality, file previews, and base64 encoding for easy data handling. Features Supports multiple file uploads Drag-and-drop functionality File type and size validation Base64 conversion for uploaded files Preview support for images, PDFs, and text files File removal functionality Code Breakdown Importing Dependencies import { IInputs, IOutputs } from "./generated/ManifestTypes"; The component imports IInputs and IOutputs from the generated manifest file to define the control's input and output types. Component Definition export class AttachmentControl implements ComponentFramework.StandardControl<IInputs, IOutputs> { Defines the AttachmentControl class, implementing the StandardControl interface from PCF. Class Variables private container: HTMLDivElement; private fileInput: HTMLInputEl...

Trigger JavaScript on Click of Button PCF Control

  Overview The TriggerJavascript control is a custom PCF (PowerApps Component Framework) control that renders a button with customizable label, icon, and on-click script execution. The control allows users to dynamically trigger JavaScript code upon clicking the button. Dependencies IInputs, IOutputs from ./generated/ManifestTypes (Auto-generated types from PowerApps) CSS styling from ./CSS/TriggerJavascript.css Class: TriggerJavascript This class implements ComponentFramework.StandardControl<IInputs, IOutputs> and manages rendering a button inside a container, dynamically executing JavaScript code on button click. Properties Private Properties _container: HTMLDivElement - A reference to the container element where the button will be rendered. Methods constructor() Initializes a new instance of the TriggerJavascript control. init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container: HTMLD...