Skip to content

Commit b3dde6b

Browse files
authored
fix: unify icon display for new builder (refly-ai#1604)
* fix: remove content selection - Eliminated unnecessary context and selection logic from ActionStepCard, CollaborativeEditor, ResourceContent, and related components to streamline functionality and improve performance. - Removed buildContextItem and getSourceNode functions that were not utilized, enhancing code clarity. - Updated components to ensure proper handling of potentially undefined values using optional chaining and nullish coalescing. - Ensured adherence to Tailwind CSS for consistent styling across components. * refactor(icon): streamline file handling and icon rendering in various components - Removed unnecessary resource type and metadata handling in FileItem, ContextItem, and other components to simplify file rendering. - Updated NodeIcon usage to directly accept filename for better clarity and performance. - Enhanced mention handling in MentionNodeView and related components to utilize new class names for consistent styling. - Ensured adherence to Tailwind CSS for styling and optimized component rendering with React.memo. - Applied optional chaining and nullish coalescing for safer property access throughout the codebase. * fix: enable type check and remove type errors - Updated the rsbuild.config.ts to enable type checking based on environment variables for better development practices. - Removed the useCanvasInitialActions hook to simplify the canvas component logic and improve performance. - Cleaned up imports in the canvas index file and adjusted the ChatBox component to eliminate unnecessary properties. - Ensured adherence to best practices for property access and component structure, including the use of optional chaining and nullish coalescing. * fix: further fix build errors and remove deprecated components - Removed FollowingActions component from MediaActionContainer and refactored the component to streamline its logic. - Eliminated unnecessary context items and model info preparation, enhancing performance and maintainability. - Ensured adherence to best practices for property access using optional chaining and nullish coalescing. - Updated ResourceNodePreview and ActionContainer to remove FollowingActions, improving overall component clarity and performance. - Applied Tailwind CSS for consistent styling across components.
1 parent 68a72f0 commit b3dde6b

File tree

45 files changed

+116
-2710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+116
-2710
lines changed

apps/web/rsbuild.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const isProduction = process.env.NODE_ENV === 'production';
1818
export default defineConfig({
1919
plugins: [
2020
pluginTypeCheck({
21-
enable: false,
22-
// process.env.NODE_ENV === 'development' || process.env.VITE_ENFORCE_TYPE_CHECK === 'true',
21+
enable:
22+
process.env.NODE_ENV === 'development' || process.env.VITE_ENFORCE_TYPE_CHECK === 'true',
2323
}),
2424
pluginReact(),
2525
pluginSvgr(),

packages/ai-workspace-common/src/components/canvas/canvas-resources/file-list/file-item.tsx

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
44
import { cn } from '@refly/utils/cn';
55
import { FileItemAction } from '../share/file-item-action';
66
import { NodeIcon } from '@refly-packages/ai-workspace-common/components/canvas/nodes/shared/node-icon';
7-
import type { DriveFile, ResourceType } from '@refly/openapi-schema';
7+
import type { DriveFile } from '@refly/openapi-schema';
88
import { useCanvasContext } from '@refly-packages/ai-workspace-common/context/canvas';
99

1010
const { Text } = Typography;
@@ -15,20 +15,6 @@ export interface FileItemProps {
1515
onSelect: (resource: DriveFile, beforeParsed: boolean) => void;
1616
}
1717

18-
// Convert DriveFile type to ResourceType
19-
const getResourceType = (fileType: string): ResourceType => {
20-
const typeMap: Record<string, ResourceType> = {
21-
'text/plain': 'file',
22-
'application/pdf': 'document',
23-
'image/jpeg': 'image',
24-
'image/png': 'image',
25-
'image/gif': 'image',
26-
'video/mp4': 'video',
27-
'audio/mpeg': 'audio',
28-
};
29-
return typeMap[fileType] || 'file';
30-
};
31-
3218
/**
3319
* Render a single file item.
3420
*/
@@ -48,13 +34,7 @@ export const FileItem = memo(({ file, isActive, onSelect }: FileItemProps) => {
4834
onClick={() => onSelect(file, beforeParsed)}
4935
>
5036
<div className="flex items-center gap-2 flex-1 min-w-0">
51-
<NodeIcon
52-
type="resource"
53-
resourceType={getResourceType(file.type)}
54-
resourceMeta={{ contentType: file.type }}
55-
filled={false}
56-
small
57-
/>
37+
<NodeIcon type="file" filename={file.name} filled={false} small />
5838

5939
<Text
6040
ellipsis={{ tooltip: { placement: 'left' } }}

packages/ai-workspace-common/src/components/canvas/common/label-display/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const LabelItem = memo(
3030
onMouseEnter={onMouseEnter}
3131
onMouseLeave={onMouseLeave}
3232
>
33-
{icon && icon}
33+
{icon}
3434
<Paragraph
3535
className="text-xs text-refly-text-0 max-w-[100px] leading-4 !m-0"
3636
ellipsis={{

packages/ai-workspace-common/src/components/canvas/copilot/chat-box.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ export const ChatBox = memo(({ canvasId, query, setQuery, onSendMessage }: ChatB
8282
{
8383
query,
8484
resultId,
85-
selectedSkill: undefined,
8685
modelInfo: null,
87-
tplConfig: {},
88-
runtimeConfig: {},
8986
agentMode: 'copilot_agent',
9087
copilotSessionId: sessionId,
9188
},

packages/ai-workspace-common/src/components/canvas/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import {
6060
nodeOperationsEmitter,
6161
} from '@refly-packages/ai-workspace-common/events/nodeOperations';
6262
import { WorkflowRun } from './workflow-run';
63-
import { useCanvasInitialActions } from '@refly-packages/ai-workspace-common/hooks/use-canvas-initial-actions';
6463
import { CanvasDrive, CanvasResourcesWidescreenModal } from './canvas-resources';
6564
import { ToolbarButtons } from './top-toolbar/toolbar-buttons';
6665
import { CanvasControlButtons } from './top-toolbar/canvas-control-buttons';
@@ -136,8 +135,6 @@ const Flow = memo(({ canvasId, copilotWidth, setCopilotWidth, maxPanelWidth }: F
136135

137136
useHandleOrphanNode();
138137

139-
useCanvasInitialActions(canvasId);
140-
141138
const { addNode } = useAddNode();
142139
const { nodes, edges } = useStore(
143140
useShallow((state) => ({

packages/ai-workspace-common/src/components/canvas/launchpad/context-manager/components/base-mark-context-selector/home.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ export function Home({
3434
item?.onItemClick?.(item.data);
3535
}}
3636
>
37-
<NodeIcon
38-
type={item.type}
39-
resourceType={item?.data?.metadata?.resourceType}
40-
resourceMeta={item?.data?.metadata?.resourceMeta}
41-
filled={false}
42-
iconSize={14}
43-
/>
37+
<NodeIcon type={item.type} filename={item?.data?.title} filled={false} iconSize={14} />
4438
<div className="search-res-container">
4539
<p
4640
className="search-res-title dark:!text-gray-200"

packages/ai-workspace-common/src/components/canvas/launchpad/context-manager/context-item.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ export const ContextItem = ({
151151
type={type}
152152
small
153153
url={node?.data?.metadata?.imageUrl as string}
154-
resourceType={node?.data?.metadata?.resourceType ?? item.metadata?.resourceType}
155-
resourceMeta={node?.data?.metadata?.resourceMeta ?? item.metadata?.resourceMeta}
154+
filename={node?.data?.title ?? item.title}
156155
iconSize={16}
157156
iconColor={NODE_COLORS[type]}
158157
filled={false}

packages/ai-workspace-common/src/components/canvas/launchpad/rich-chat-input/mention-node-view.tsx

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,31 @@
11
import React from 'react';
2+
import { cn } from '@refly/utils';
23
import { NodeViewWrapper } from '@tiptap/react';
34
import type { NodeViewProps } from '@tiptap/react';
45
import { NodeIcon } from '@refly-packages/ai-workspace-common/components/canvas/nodes/shared/node-icon';
5-
import { getVariableIcon } from '@refly-packages/ai-workspace-common/components/canvas/launchpad/variable/getVariableIcon';
6+
import { X } from 'refly-icons';
67
import type { CanvasNodeType } from '@refly/openapi-schema';
78
import { ToolsetIcon } from '@refly-packages/ai-workspace-common/components/canvas/common/toolset-icon';
9+
import { MentionItemSource } from './const';
10+
import { AGENT_CONFIG_KEY_CLASSNAMES } from '@refly-packages/ai-workspace-common/components/canvas/nodes/shared/colors';
811

912
const TOOLSET_ICON_CONFIG = {
1013
size: 14,
1114
className: 'flex-shrink-0',
1215
builtinClassName: '!w-3.5 !h-3.5',
1316
} as const;
1417

15-
function renderNodeIcon(source: string, variableType: string, nodeAttrs: any) {
18+
function renderNodeIcon(source: MentionItemSource, variableType: string, nodeAttrs: any) {
1619
if (source === 'variables') {
17-
return getVariableIcon(variableType);
20+
return <X size={12} className="flex-shrink-0" />;
1821
}
19-
if (source === 'stepRecord') {
20-
return (
21-
<NodeIcon
22-
type={'skillResponse' as CanvasNodeType}
23-
small
24-
filled={false}
25-
className="!w-3.5 !h-3.5"
26-
/>
27-
);
22+
if (source === 'agents') {
23+
return <NodeIcon type="skillResponse" small filled={false} className="!w-3.5 !h-3.5" />;
2824
}
29-
if (source === 'resultRecord' || source === 'myUpload') {
30-
const nodeType = variableType || 'document';
25+
if (source === 'files' || source === 'products') {
26+
const filename = nodeAttrs?.label as string;
3127
return (
32-
<NodeIcon
33-
type={nodeType as CanvasNodeType}
34-
small
35-
filled={false}
36-
url={nodeType === 'image' ? (nodeAttrs?.url ?? undefined) : undefined}
37-
resourceType={nodeAttrs?.resourceType}
38-
resourceMeta={nodeAttrs?.resourceMeta}
39-
className="!w-3.5 !h-3.5"
40-
/>
28+
<NodeIcon type="file" small filled={false} filename={filename} className="!w-3.5 !h-3.5" />
4129
);
4230
}
4331
if (source === 'toolsets' || source === 'tools') {
@@ -55,16 +43,32 @@ function renderNodeIcon(source: string, variableType: string, nodeAttrs: any) {
5543
);
5644
}
5745

46+
const getMentionClassName = (source: MentionItemSource) => {
47+
if (source === 'variables') {
48+
return AGENT_CONFIG_KEY_CLASSNAMES.inputs;
49+
}
50+
if (source === 'toolsets' || source === 'tools') {
51+
return AGENT_CONFIG_KEY_CLASSNAMES.tools;
52+
}
53+
if (source === 'files' || source === 'products') {
54+
return AGENT_CONFIG_KEY_CLASSNAMES.files;
55+
}
56+
if (source === 'agents') {
57+
return AGENT_CONFIG_KEY_CLASSNAMES.agents;
58+
}
59+
return '';
60+
};
61+
5862
function MentionNodeViewBase(props: NodeViewProps) {
5963
const { node } = props;
6064
const labelText = (node?.attrs?.label as string) ?? (node?.attrs?.id as string) ?? '';
61-
const source = (node?.attrs?.source as string) ?? '';
62-
const variableType = (node?.attrs?.variableType as string) ?? source ?? '';
65+
const source = node?.attrs?.source as MentionItemSource;
66+
const variableType = node?.attrs?.variableType as string;
6367

6468
return (
6569
<NodeViewWrapper
6670
as="span"
67-
className="mention"
71+
className={cn('mention', getMentionClassName(source))}
6872
contentEditable={false}
6973
draggable={false}
7074
data-mention="true"

packages/ai-workspace-common/src/components/canvas/launchpad/rich-chat-input/mentionList.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,9 @@ export const MentionList = ({
487487
},
488488
files: {
489489
nodeIconProps: (item: MentionItem) => ({
490-
type: item.variableType as CanvasNodeType,
490+
type: 'file' as const,
491491
small: true,
492-
url: item.variableType === 'image' ? item.metadata?.imageUrl : undefined,
493-
resourceType: item.metadata?.resourceType,
494-
resourceMeta: item.metadata?.resourceMeta,
492+
filename: item.name,
495493
}),
496494
emptyStateKey: 'noFiles',
497495
},

packages/ai-workspace-common/src/components/canvas/launchpad/variable/mention-style.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export const mentionStyles = `
4343
}
4444
4545
[data-cy="rich-chat-input"] .mention {
46-
background-color: var(--refly-tertiary-default);
4746
border-radius: 4px;
4847
padding: 2px 4px 2px;
4948
border: 1px solid var(--refly-Card-Border);

0 commit comments

Comments
 (0)