refactor(core): ai input images display & max images count (#12395)
### TL;DR * refactor: use horizontal scrolling to display images * refactor: change max images to 9 * test: add test cases for validating the maximum number of uploadable images > CLOSE AI-6  <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a notification to inform users when attempting to upload more images than allowed in the AI chat input. - **Bug Fixes** - Prevented uploading more than 9 images at once in the AI chat input. - **Style** - Improved image preview grid layout to display images in a single horizontally scrollable row. - **Tests** - Added an end-to-end test to verify that an error message appears when too many images are uploaded. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { toast } from '@affine/component';
|
||||||
import { stopPropagation } from '@affine/core/utils';
|
import { stopPropagation } from '@affine/core/utils';
|
||||||
import type { CopilotSessionType } from '@affine/graphql';
|
import type { CopilotSessionType } from '@affine/graphql';
|
||||||
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
|
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
|
||||||
@@ -531,6 +532,10 @@ export class AIChatInput extends SignalWatcher(WithDisposable(LitElement)) {
|
|||||||
multiple: true,
|
multiple: true,
|
||||||
});
|
});
|
||||||
if (!images) return;
|
if (!images) return;
|
||||||
|
if (this.chatContextValue.images.length + images.length > MAX_IMAGE_COUNT) {
|
||||||
|
toast(`You can only upload up to ${MAX_IMAGE_COUNT} images`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.addImages(images);
|
this.addImages(images);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export const MAX_IMAGE_COUNT = 32;
|
export const MAX_IMAGE_COUNT = 9;
|
||||||
|
|||||||
@@ -7,16 +7,19 @@ import { repeat } from 'lit/directives/repeat.js';
|
|||||||
export class ImagePreviewGrid extends LitElement {
|
export class ImagePreviewGrid extends LitElement {
|
||||||
static override styles = css`
|
static override styles = css`
|
||||||
.image-preview-wrapper {
|
.image-preview-wrapper {
|
||||||
overflow: hidden scroll;
|
overflow-x: auto;
|
||||||
max-height: 128px;
|
overflow-y: hidden;
|
||||||
|
max-height: 80px;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
${scrollbarStyle('.image-preview-wrapper')}
|
${scrollbarStyle('.image-preview-wrapper')}
|
||||||
|
|
||||||
.images-container {
|
.images-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
flex-wrap: wrap;
|
flex-wrap: nowrap;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +34,7 @@ export class ImagePreviewGrid extends LitElement {
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-container img {
|
.image-container img {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -236,10 +236,9 @@ export class ChatPanelUtils {
|
|||||||
await this.makeChat(page, text);
|
await this.makeChat(page, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async chatWithImages(
|
public static async uploadImages(
|
||||||
page: Page,
|
page: Page,
|
||||||
images: { name: string; mimeType: string; buffer: Buffer }[],
|
images: { name: string; mimeType: string; buffer: Buffer }[]
|
||||||
text: string
|
|
||||||
) {
|
) {
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
delete window.showOpenFilePicker;
|
delete window.showOpenFilePicker;
|
||||||
@@ -251,6 +250,14 @@ export class ChatPanelUtils {
|
|||||||
|
|
||||||
const fileChooser = await fileChooserPromise;
|
const fileChooser = await fileChooserPromise;
|
||||||
await fileChooser.setFiles(images);
|
await fileChooser.setFiles(images);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async chatWithImages(
|
||||||
|
page: Page,
|
||||||
|
images: { name: string; mimeType: string; buffer: Buffer }[],
|
||||||
|
text: string
|
||||||
|
) {
|
||||||
|
await this.uploadImages(page, images);
|
||||||
|
|
||||||
await page.waitForSelector('ai-chat-input img');
|
await page.waitForSelector('ai-chat-input img');
|
||||||
await this.makeChat(page, text);
|
await this.makeChat(page, text);
|
||||||
|
|||||||
Reference in New Issue
Block a user