eLabSDK2.Journal.Experiment.Section.ExperimentSection

Hierarchy

Methods

addSubMenuItem

Static addSubMenuItem(config, id, targetSectionType?): void

Add a custom menu item to the experiment section hamburger dropdown menu.

This adds a custom action button to the section dropdown menu (hamburger icon) that appears
in the top-right corner of each experiment section. You can target all sections or limit the
menu item to specific section types (e.g., PARAGRAPH, IMAGE, CHEMICAL). The action callback
is executed when the user clicks the menu item. Use this to add section-specific functionality
like custom transformations, exports, validations, or integrations.

Parameters

NameTypeDefault valueDescription
configExperimentSectionSubmenuItemundefined{ id: string, label: string, icon: string, action: () => void }
idstringundefinedString reference/identifier for this handler (used for removal with removeSubMenuItem).
targetSectionType?anynullOptional section type to limit this menu item to. Can be 'CANVAS', 'COMMENT', 'IMAGE', 'NOTES', 'FILES', 'OUTPUTSAMPLES', 'BASESAMPLES', 'PARAGRAPH', 'PROCEDURE', 'DATATABLE', 'SAMPLESIN', 'SAMPLESOUT', 'FILE', 'EXCEL', 'MARVINJS', 'CHEMICAL', or 'CUSTOM'. If not specified, appears in all section types.

Returns

void

Example

// Add menu item to all section types
eLabSDK2.Journal.Experiment.ExperimentSection.addSubMenuItem(
  {
    id: 'validate-section',
    label: 'Validate Section',
    action: () => {
      console.log('Validating section...');
      validateCurrentSection();
    },
    icon: 'fas fa-check-circle'
  },
  'validate-handler'
);

Example

// Add menu item only to PARAGRAPH sections
eLabSDK2.Journal.Experiment.ExperimentSection.addSubMenuItem(
  {
    id: 'export-text',
    label: 'Export Text',
    action: () => {
      exportSectionText();
    },
    icon: 'fas fa-file-export'
  },
  'export-text-handler',
  'PARAGRAPH'
);

Example

// Add menu item only to CHEMICAL sections
eLabSDK2.Journal.Experiment.ExperimentSection.addSubMenuItem(
  {
    id: 'analyze-structure',
    label: 'Analyze Structure',
    action: () => {
      analyzeChemicalStructure();
    },
    icon: 'fas fa-flask'
  },
  'analyze-chem-handler',
  'CHEMICAL'
);

removeSubMenuItem

Static removeSubMenuItem(id): void

Remove a custom menu item from experiment section hamburger dropdown menus.

This unsubscribes and removes a previously added custom menu item from all experiment section
dropdown menus (hamburger icon). Use the same ID that was passed as the second parameter when
adding the menu item with addSubMenuItem(). This is useful for cleaning up menu items when
they're no longer needed, such as when a feature is disabled or an add-on is deactivated.

Parameters

NameTypeDescription
idstringThe reference ID that was passed as the second parameter in the addSubMenuItem() call.

Returns

void

Example

// Remove a previously added menu item
eLabSDK2.Journal.Experiment.ExperimentSection.removeSubMenuItem('validate-handler');

Example

// Add and later remove menu item
// Add menu item
eLabSDK2.Journal.Experiment.ExperimentSection.addSubMenuItem(
  {
    id: 'temp-action',
    label: 'Temporary Action',
    action: () => { console.log('action'); },
    icon: 'fas fa-clock'
  },
  'temp-handler',
  'PARAGRAPH'
);

// Later, remove it
eLabSDK2.Journal.Experiment.ExperimentSection.removeSubMenuItem('temp-handler');

Example

// Conditionally remove menu item
function cleanupSectionMenuItems() {
  if (!window.featureEnabled) {
    eLabSDK2.Journal.Experiment.ExperimentSection.removeSubMenuItem('feature-handler');
  }
}

© 2023 eLabNext