embed-app-modal.tsx


Overview

embed-app-modal.tsx defines a React functional component named EmbedAppModal that provides an interactive modal dialog interface for embedding an application via an iframe into external websites. The modal allows users to customize certain embed parameters such as hiding the user avatar and selecting the locale (language) for the embedded app. It dynamically generates the iframe embed code based on these settings and provides UI controls to copy the embed token for easy integration.

This component is designed to be used within a larger web application where embedding a mini app or widget is required, facilitating convenient sharing and localization.


Detailed Explanation

Component: EmbedAppModal

Purpose

EmbedAppModal renders a modal dialog that allows users to:

Props (IEmbedAppModalProps)

Prop Name

Type

Description

open

any

Controls the visibility state of the modal. Typically a boolean indicating if modal is open or closed.

url

string

Base URL path to be embedded inside the iframe.

token

string

Authentication or identification token for the embedded app.

from

string

A string indicating the source or context from where the embed is requested.

setOpen

(e: any) => void

Callback function to toggle the modal's open state.

tenantId

string

Tenant identifier used for multi-tenant environments.

beta

string (optional)

Optional beta feature flag or token passed as a query parameter.

State Variables

Hooks and Utilities Used

Main Functions / Methods

generateIframeSrc

Generates the iframe src URL with query parameters based on current modal state and props.

text (memoized)

Generates the full HTML iframe embed code snippet as a markdown string with triple backticks and HTML tag.

Example output:

<iframe
  src="https://example.com/embed?shared_id=token123&from=source&auth=beta&tenantId=tenant1&visible_avatar=1&locale=en"
  style="width: 100%; height: 100%; min-height: 600px"
  frameborder="0">
</iframe>

Usage Example

import EmbedAppModal from './embed-app-modal';

function ParentComponent() {
  const [modalOpen, setModalOpen] = useState(false);

  return (
    <>
      <button onClick={() => setModalOpen(true)}>Show Embed Modal</button>
      <EmbedAppModal
        open={modalOpen}
        setOpen={setModalOpen}
        url="/embed-app"
        token="abc123"
        from="dashboard"
        tenantId="tenant_001"
        beta="betaFeatureFlag"
      />
    </>
  );
}

UI Structure and Interaction


Important Implementation Details


Interaction with Other System Components

This component is likely invoked by a parent page or component responsible for managing app embedding workflows, passing necessary props such as token, url, and tenantId.


Mermaid Component Diagram

componentDiagram
    component EmbedAppModal {
      +props: IEmbedAppModalProps
      +state: hideAvatar:boolean, locale:string
      +generateIframeSrc(): string
      +render(): JSX.Element
    }
    EmbedAppModal --> Modal
    EmbedAppModal --> Switch
    EmbedAppModal --> RAGFlowSelect
    EmbedAppModal --> HightLightMarkdown
    EmbedAppModal --> useTranslate
    EmbedAppModal --> message

Summary

embed-app-modal.tsx provides a reusable, customizable modal component facilitating the embedding of an external app via iframe. It offers user-friendly controls to adjust embed parameters, automatically generates the embed code, and supports copying both the embed code and token for easy integration. The component leverages React hooks, custom UI components, and localization for a seamless user experience in multi-lingual environments.