Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(overlay-sandbox): improve UI navigation in Overlay Sandbox (Issue #3072) #3076

Merged
merged 7 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link';

export function BackToButton() {
return (
<Link href="/" className="button w-[300px]">
Back to select Overlay mode
</Link>
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client';

import { BackToButton } from './backToSelectOverlayMode';

import {
ChatOverlayManager,
ChatOverlayManagerOptions,
Expand All @@ -16,6 +18,7 @@ export const ChatOverlayManagerWrapper: React.FC<
const overlayManager = useRef<ChatOverlayManager | null>(null);
const dialogRef = useRef<HTMLDialogElement | null>(null);
const [dialogInfo, setDialogInfo] = useState('');
const [created, setCreated] = useState(false);
const [conversationIdInputValue, setConversationIdInputValue] = useState('');

const handleDisplayInformation = useCallback((textToShow: string) => {
Expand All @@ -31,9 +34,18 @@ export const ChatOverlayManagerWrapper: React.FC<
...overlayManagerOptions,
hostDomain: window.location.origin,
});
setCreated(true);
}
}, [overlayManagerOptions]);

useEffect(() => {
return () => {
if (overlayManager.current && created) {
overlayManager.current?.removeOverlay(overlayManagerOptions.id);
}
};
});

useEffect(() => {
overlayManager.current?.subscribe(
overlayManagerOptions.id,
Expand All @@ -59,7 +71,7 @@ export const ChatOverlayManagerWrapper: React.FC<
<dialog ref={dialogRef} className="rounded p-5">
<div className="flex justify-end">
<button
className="rounded bg-gray-200 p-2"
className="button"
autoFocus
onClick={() => dialogRef.current?.close()}
>
Expand All @@ -70,12 +82,13 @@ export const ChatOverlayManagerWrapper: React.FC<
</dialog>

<div className="flex max-w-[300px] flex-col gap-2">
<BackToButton />
<details>
<summary>Chat actions</summary>

<div className="flex flex-col gap-2">
<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={() => {
overlayManager.current?.sendMessage(
overlayManagerOptions.id,
Expand All @@ -87,7 +100,7 @@ export const ChatOverlayManagerWrapper: React.FC<
</button>

<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={() => {
overlayManager.current?.setSystemPrompt(
overlayManagerOptions.id,
Expand All @@ -99,7 +112,7 @@ export const ChatOverlayManagerWrapper: React.FC<
</button>

<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={async () => {
const messages = await overlayManager.current?.getMessages(
overlayManagerOptions.id,
Expand All @@ -112,7 +125,7 @@ export const ChatOverlayManagerWrapper: React.FC<
</button>

<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={async () => {
const conversations =
await overlayManager.current?.getConversations(
Expand All @@ -128,7 +141,7 @@ export const ChatOverlayManagerWrapper: React.FC<
</button>

<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={async () => {
const conversation =
await overlayManager.current?.createConversation(
Expand All @@ -142,7 +155,7 @@ export const ChatOverlayManagerWrapper: React.FC<
</button>

<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={async () => {
const conversation =
await overlayManager.current?.createConversation(
Expand All @@ -158,7 +171,7 @@ export const ChatOverlayManagerWrapper: React.FC<

<div className="flex flex-col gap-1 border p-1">
<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={async () => {
const conversation =
await overlayManager.current?.selectConversation(
Expand Down Expand Up @@ -187,7 +200,7 @@ export const ChatOverlayManagerWrapper: React.FC<

<div>
<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={() => {
const newOptions = {
...overlayManagerOptions,
Expand Down
24 changes: 12 additions & 12 deletions apps/overlay-sandbox/app/cases/components/chatOverlayWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client';

import { BackToButton } from './backToSelectOverlayMode';

import { ChatOverlay, ChatOverlayOptions } from '@epam/ai-dial-overlay';
import React, { useCallback, useEffect, useRef, useState } from 'react';

Expand Down Expand Up @@ -78,7 +80,7 @@ export const ChatOverlayWrapper: React.FC<ChatOverlayWrapperProps> = ({
<dialog ref={dialogRef} className="rounded p-5">
<div className="flex justify-end">
<button
className="rounded bg-gray-200 p-2"
className="button"
autoFocus
onClick={() => dialogRef.current?.close()}
>
Expand All @@ -97,12 +99,13 @@ export const ChatOverlayWrapper: React.FC<ChatOverlayWrapperProps> = ({
></div>

<div className="flex max-w-[300px] flex-col gap-2">
<BackToButton />
<details>
<summary>Chat actions</summary>

<div className="flex flex-col gap-2">
<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={() => {
overlay.current?.sendMessage('Hello');
}}
Expand All @@ -111,7 +114,7 @@ export const ChatOverlayWrapper: React.FC<ChatOverlayWrapperProps> = ({
</button>

<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={() => {
overlay.current?.setSystemPrompt(
'End each word with string "!?!?!"',
Expand All @@ -122,7 +125,7 @@ export const ChatOverlayWrapper: React.FC<ChatOverlayWrapperProps> = ({
</button>

<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={async () => {
const messages = await overlay.current?.getMessages();

Expand All @@ -133,7 +136,7 @@ export const ChatOverlayWrapper: React.FC<ChatOverlayWrapperProps> = ({
</button>

<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={async () => {
const conversations = await overlay.current?.getConversations();

Expand All @@ -146,7 +149,7 @@ export const ChatOverlayWrapper: React.FC<ChatOverlayWrapperProps> = ({
</button>

<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={async () => {
const conversation =
await overlay.current?.createConversation();
Expand All @@ -158,7 +161,7 @@ export const ChatOverlayWrapper: React.FC<ChatOverlayWrapperProps> = ({
</button>

<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={async () => {
const conversation =
await overlay.current?.createConversation(
Expand All @@ -172,10 +175,7 @@ export const ChatOverlayWrapper: React.FC<ChatOverlayWrapperProps> = ({
</button>

<div className="flex flex-col gap-1 border p-1">
<button
className="rounded bg-gray-200 p-2"
onClick={handleSelectConversation}
>
<button className="button" onClick={handleSelectConversation}>
Select conversation by ID
</button>
<textarea
Expand All @@ -192,7 +192,7 @@ export const ChatOverlayWrapper: React.FC<ChatOverlayWrapperProps> = ({

<div>
<button
className="rounded bg-gray-200 p-2"
className="button"
onClick={() => {
const newOptions = {
...overlayOptions,
Expand Down
1 change: 1 addition & 0 deletions apps/overlay-sandbox/app/cases/overlay-manager/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ChatOverlayManagerOptions, Feature } from '@epam/ai-dial-overlay';
const overlayOptions: Omit<ChatOverlayManagerOptions, 'hostDomain'> = {
id: 'test',
...commonOverlayProps,
domain: process.env.NEXT_PUBLIC_OVERLAY_HOST!,
theme: 'light',
modelId: 'gpt-4',
enabledFeatures: [
Expand Down
18 changes: 9 additions & 9 deletions apps/overlay-sandbox/app/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
@tailwind components;
@tailwind utilities;

.link-container {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}

@media (max-width: 768px) {
.link-container {
flex-direction: column;
@layer components {
.button {
@apply rounded border border-gray-800 bg-gray-300 p-2 text-center hover:border-gray-600 hover:bg-gray-200;
}
details {
cursor: pointer;
}
textarea {
padding: 5px 10px;
}
}
129 changes: 30 additions & 99 deletions apps/overlay-sandbox/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,106 +1,37 @@
import Link from 'next/link';

enum OverlayCases {
modelIdSetSandboxOverlay = '/cases/overlay/model-id-set-sandbox',
OverlayManager = '/cases/overlay-manager',
disabledHeaderOverlay = '/cases/overlay/disabled-header-sandbox',
enabledHeaderOverlay = '/cases/overlay/enabled-header-sandbox',
enabledOnlyHeaderOverlay = '/cases/overlay/enabled-only-header-sandbox',
enabledOnlyHeaderFooterOverlay = '/cases/overlay/enabled-only-header-footer-sandbox',
enabledOnlyFooterLinksAttachmentsOverlay = '/cases/overlay/enabled-only-footer-links-attachments-sandbox',
enabledOnlyHeaderConversationsSectionOverlay = '/cases/overlay/enabled-only-header-conversations-section-sandbox',
disableTopChatInfoOverlay = '/cases/overlay/disabled-top-chat-info-sandbox',
enableDisallowChangeAgentOverlay = '/cases/overlay/enabled-disallow-change-agent-sandbox',
enableHideTopContextMenuOverlay = '/cases/overlay/enabled-hide-top-context-menu-sandbox',
enableEmptyChatSettingsOverlay = '/cases/overlay/enabled-empty-chat-settings-sandbox',
enableInputFilesOverlay = '/cases/overlay/enabled-input-files-sandbox',
enableHideEmptyChangeAgentOverlay = '/cases/overlay/enabled-hide-empty-change-agent-sandbox',
disableAllFeaturesOverlay = '/cases/overlay/disabled-all-features-sandbox',
enableMarketplaceOverlay = '/cases/overlay/enabled-marketplace-sandbox',
disableMarketplaceOverlay = '/cases/overlay/disabled-marketplace-sandbox',
conversationIdSetOverlay = '/cases/overlay/overlay-conversation-id-set-sandbox',
}

export default async function Index() {
return (
<div>
<div className="link-container">
<span>
<Link href={'/cases/overlay/model-id-set-sandbox'}>
modelIdSetSandboxOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay-manager'}>OverlayManager</Link>
</span>
<span>
<Link href={'/cases/overlay/disabled-header-sandbox'}>
disabledHeaderOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/enabled-header-sandbox'}>
enabledHeaderOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/enabled-only-header-sandbox'}>
enabledOnlyHeaderOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/enabled-only-header-footer-sandbox'}>
enabledOnlyHeaderFooterOverlay
</Link>
</span>
<span>
<Link
href={
'/cases/overlay/enabled-only-footer-links-attachments-sandbox'
}
>
enabledOnlyFooterLinksAttachmentsOverlay
</Link>
</span>
<span>
<Link
href={
'/cases/overlay/enabled-only-header-conversations-section-sandbox'
}
>
enabledOnlyHeaderConversationsSectionOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/disabled-top-chat-info-sandbox'}>
disableTopChatInfoOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/enabled-disallow-change-agent-sandbox'}>
enableDisallowChangeAgentOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/enabled-hide-top-context-menu-sandbox'}>
enableHideTopContextMenuOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/enabled-empty-chat-settings-sandbox'}>
enableEmptyChatSettingsOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/enabled-input-files-sandbox'}>
enableInputFilesOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/enabled-hide-empty-change-agent-sandbox'}>
enableHideEmptyChangeAgentOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/disabled-all-features-sandbox'}>
disableAllFeaturesOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/enabled-marketplace-sandbox'}>
enableMarketplaceOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/disabled-marketplace-sandbox'}>
disableMarketplaceOverlay
</Link>
</span>
<span>
<Link href={'/cases/overlay/overlay-conversation-id-set-sandbox'}>
conversationIdSetOverlay
</Link>
</span>
</div>
<div className="flex flex-col gap-2 p-2">
<div className="font-semibold">Select mode/case for Overlay:</div>
<ul className="flex h-full flex-wrap gap-2">
{Object.entries(OverlayCases).map(([label, url]) => (
<li key={label} className="button w-[380px]">
<Link href={url}>{label}</Link>
</li>
))}
</ul>
</div>
);
}
Loading