/** * Describes the context in which a Lime Web Component is running. * * The context provides information about the current business object (limetype and ID) * that the component is associated with. This allows components to load and interact * with the relevant data based on where they are displayed in the application. * * Contexts can be nested when components are embedded within other components, * allowing for hierarchical relationships between different views. * * @example * ```ts * import { LimeWebComponentContext } from '@limetech/lime-web-components'; * * // A component running in a customer detail view * const detailContext: LimeWebComponentContext = { * limetype: 'customer', * id: 123, * }; * * // A component on a list view, with no specific record * const listContext: LimeWebComponentContext = { * limetype: 'customer', * id: null, * }; * * // A contact list nested within a customer view * const nestedContext: LimeWebComponentContext = { * limetype: 'contact', * id: null, * parent: { * limetype: 'customer', * id: 123, * }, * }; * ``` * * @example Load related data based on the parent context * ```ts * import { Operator, PlatformServiceName } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.LimeObjectRepository); * * if (context.parent?.limetype === 'customer' && context.parent.id) { * const response = await repository.loadObjects('contact', { * filter: { * key: 'customer', * op: Operator.EQUALS, * exp: context.parent.id, * }, * }); * * const contacts = response.objects; * } * ``` * * @public * @group Core */ export interface LimeWebComponentContext { /** * The name of the {@link LimeType} for this context. * * This identifies what type of business object the component is working with * (e.g., 'customer', 'contact', 'deal', 'invoice'). Can be `null` if the * component is not associated with a specific limetype. * * @example * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * if (context.limetype === 'customer') { * // Load customer-specific data and features * const limetypes = platform.get(PlatformServiceName.LimeTypeRepository); * const customer = limetypes.getLimeType('customer'); * } * ``` */ limetype: string | null; /** * The ID of the specific limeobject (record) in this context. * * When set, indicates the component is viewing/editing a specific record. * When `null`, the component may be on a list view or creating a new record. * * @example * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.LimeObjectRepository); * * if (context.limetype && context.id) { * const limeObject = await repository.loadObject( * context.limetype, * context.id * ); * } * ``` */ id: number | null; /** * Optional parent context when this component is nested within another. * * Used when components are embedded in other components to maintain the * relationship hierarchy. For example, a contact list component shown * within a customer detail view would have the customer as its parent context. * * @example * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const loggerFactory = platform.get(PlatformServiceName.Logger); * const logger = loggerFactory.createLogger('my-component'); * * if (context.parent) { * logger.debug('Running in a nested context', { * current: context.limetype, * parent: context.parent.limetype, * }); * * // Load the record the parent context points at * if (context.parent.limetype && context.parent.id) { * const repository = platform.get( * PlatformServiceName.LimeObjectRepository * ); * * const parentObject = await repository.loadObject( * context.parent.limetype, * context.parent.id * ); * } * } * ``` */ parent?: LimeWebComponentContext; } /** * A {@link LimeWebComponentContext} bound to a specific Lime object. * * Narrows the context so that both `limetype` and `id` are required. * Use this anywhere the consumer needs guaranteed access to a single * record — for example property panels, detail views, or operations * that target one object. * * @public * @group Core */ export type LimeObjectContext = LimeWebComponentContext & { limetype: string; id: number; }; /** * A {@link LimeWebComponentContext} bound to a Lime type without * targeting a specific object. * * Narrows the context so that `limetype` is required while `id` may * still be `null`. Use this anywhere the consumer works with the * limetype as a whole — for example list views, type-level * configuration, or operations over a set of objects of one limetype. * * @public * @group Core */ export type LimeTypeContext = LimeWebComponentContext & { limetype: string; };