Documentation

Class: Helpers

Description: This class provides helper functions for handling file paths, navigating the application, and interacting with the Hub platform.

Methods


Method: isFile

Description: This method checks if the current path represents a file and if the file extension is supported by the Hub.

Parameters: None

Returns:

  • boolean: True if the path represents a supported file, false otherwise.

Example:

const isFileResult = isFile(); // Returns true if the current path is a supported file, false otherwise.

Method: processFile

Description: This method processes a file by launching a quickstart pipeline.

Parameters:

  • doc ({ running: boolean }): An object representing the document state, including a flag indicating whether the pipeline is currently running.
  • setDoc ((arg: any) => void): A function to update the document state.

Returns:

  • void

Throws:

  • Error: If there is an error launching the quickstart pipeline.

Example:

const doc = { running: false };
const setDoc = (newDoc) => { 
  // Update the document state
};

processFile(doc, setDoc); 

Method: parsePath

Description: This method parses the current URL path to extract information such as repository ID, branch, and file path.

Parameters: None

Returns:

  • { repoId: string | null, branch: string, file: string | null }: An object containing extracted information from the URL path.

Example:

const pathInfo = parsePath();
console.log(pathInfo.repoId); // Example: "my-repo-id"

Method: navigate

Description: This method handles navigation within the application, updating the URL based on provided repository ID, file path, and branch.

Parameters:

  • history (any): The browser history object.
  • repoId (string | null): The repository ID to navigate to.
  • filePath (string | null): The file path to navigate to.
  • hash (string | null): The branch hash to navigate to.

Returns:

  • void

Example:

const history = window.history;
const repoId = "my-repo-id";
const filePath = "path/to/file.txt";
const hash = "branch-hash";

navigate(history, repoId, filePath, hash); // Navigates to `/hub/my-repo-id/path/to/file.txt#branch-hash`