Skip to content

fix(widget): use welcomeBubbleDefault locale string when text is omitted - #630

Open
bhushan4work wants to merge 1 commit into
codercops:devfrom
bhushan4work:610
Open

bhushan4work wants to merge 1 commit into
codercops:devfrom
bhushan4work:610

Conversation

@bhushan4work

Copy link
Copy Markdown
Collaborator

What does this change?

Makes WidgetConfig.welcomeBubble.text optional, defaulting to the chat's welcomeBubbleDefault locale string ("Need help? Chat with us!" in English, or the active translation).

  • packages/widget/src/widget.ts: Made text optional in WidgetConfig.welcomeBubble. In createBubble(), fallback to this.locale.welcomeBubbleDefault when text is not provided (welcomeBubble: {} and welcomeBubble: { delay: 5000 } now display default text).
  • packages/widget/src/script-config.ts: Changed data-welcome-bubble attribute check so an empty attribute (data-welcome-bubble="" or bare data-welcome-bubble) enables the welcome bubble with default text, while a tag without the attribute still shows no bubble. The loader gzip size remains within budget (4.95 kB / 5 kB budget), so no script-tag work needed to be dropped.
  • website/src/content/docs/widget/configuration.mdx: Updated documentation for welcomeBubble to show text is optional defaulting to welcomeBubbleDefault, corrected "hover bubble" comment to "bubble", and updated the data-welcome-bubble row to reflect that an empty value enables the bubble with default text.
  • api/widget.api.md & api/react.api.md: Updated API snapshots via pnpm api.
  • Added minor changeset for @chatcops/widget noting the empty attribute behavior.

Tests added

  • packages/widget/tests/widget.test.ts: Added test initializing with welcomeBubble: {}, advancing past 3000 ms, and asserting .cc-bubble-trigger displays "Need help? Chat with us!" as well as the translated string when strings overrides are passed, plus verification for welcomeBubble: { delay: 5000 }.
  • packages/widget/tests/script-config.test.ts: Added test verifying data-welcome-bubble="" enables the bubble with default text, and tags without the attribute show no bubble.
  • packages/widget/tests/loader.test.ts: Added test verifying createLoader with loadLocale resolving { default: { welcomeBubbleDefault: 'Brauchen Sie Hilfe?' } } passes it through strings to the widget when the bubble is due.

Closes #610

How I tested this

Ran the required checks, all passing:

  • pnpm vitest run --project @chatcops/widget
  • pnpm test:coverage
  • pnpm lint
  • pnpm size (chatcops.min.js at 4.95 kB gzipped <= 5 kB limit)
  • pnpm docs:check

AI assistance

None

Checklist

  • This PR targets dev
  • I was assigned the linked issue
  • pnpm -r build, pnpm test and pnpm -r typecheck pass locally
  • Tests added or updated where it makes sense
  • For a bug fix: the new test fails without my change
  • Changeset added (pnpm changeset) if this changes core, widget or server
  • pnpm api run and api/ committed if an exported type or option changed
  • Docs updated if behavior or options changed

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show the translated welcomeBubbleDefault when welcomeBubble has no text

1 participant