diff --git a/src/managers/gist-properties-manager.ts b/src/managers/gist-properties-manager.ts index eec8667..5fb8e1a 100644 --- a/src/managers/gist-properties-manager.ts +++ b/src/managers/gist-properties-manager.ts @@ -1,4 +1,4 @@ -import type { GistMessage, ResolvedMessageProperties } from '../types'; +import type { GistMessage, ResolvedMessageProperties, StepDisplayConfig } from '../types'; export const MESSAGE_PROPERTY_DEFAULTS: ResolvedMessageProperties = { isEmbedded: false, @@ -19,6 +19,35 @@ export const MESSAGE_PROPERTY_DEFAULTS: ResolvedMessageProperties = { hasCustomWidth: false, }; +function resolveMessageTooltipColor(message: GistMessage): string { + let tooltipColor = MESSAGE_PROPERTY_DEFAULTS.tooltipArrowColor; + + if ((message?.properties?.gist?.tooltipArrowColor?.length ?? 0) > 0) { + tooltipColor = message!.properties!.gist!.tooltipArrowColor!; + } else { + if (!Array.isArray(message?.displaySettings) || message.displaySettings.length === 0) { + return tooltipColor; + } + + // Try to match savedStepName, otherwise use first step + let step: StepDisplayConfig = message.displaySettings[0]; + if (message.savedStepName) { + const matchedStep = message.displaySettings.find( + (s: StepDisplayConfig) => s?.stepName === message.savedStepName && s.displaySettings + ); + if (matchedStep) { + step = matchedStep; + } + } + + if (step?.displaySettings?.tooltipArrowColor) { + tooltipColor = step.displaySettings.tooltipArrowColor; + } + } + + return tooltipColor; +} + export function resolveMessageProperties(message: GistMessage): ResolvedMessageProperties { const defaults = MESSAGE_PROPERTY_DEFAULTS; @@ -34,7 +63,7 @@ export function resolveMessageProperties(message: GistMessage): ResolvedMessageP hasPosition: !!gist.position, tooltipPosition: gist.tooltipPosition || '', hasTooltipPosition: !!gist.tooltipPosition, - tooltipArrowColor: gist.tooltipArrowColor || defaults.tooltipArrowColor, + tooltipArrowColor: resolveMessageTooltipColor(message), shouldScale: !!gist.scale, campaignId: gist.campaignId ?? null, messageWidth: