-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from refly-ai/fix/selection-context-issues
Fix/selection context issues
- Loading branch information
Showing
32 changed files
with
268 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...e-common/src/components/canvas/launchpad/context-manager/components/selection-preview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useCallback } from 'react'; | ||
import { useReactFlow } from '@xyflow/react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { IContextItem } from '@refly-packages/ai-workspace-common/stores/context-panel'; | ||
import { IconQuote } from '@refly-packages/ai-workspace-common/components/common/icon'; | ||
import { getContextItemIcon } from '@refly-packages/ai-workspace-common/components/canvas/launchpad/context-manager/utils/icon'; | ||
import { LuChevronRight } from 'react-icons/lu'; | ||
import { useNodePosition } from '@refly-packages/ai-workspace-common/hooks/canvas/use-node-position'; | ||
import { useNodeSelection } from '@refly-packages/ai-workspace-common/hooks/canvas/use-node-selection'; | ||
import { CanvasNode } from '@refly-packages/ai-workspace-common/components/canvas/nodes'; | ||
|
||
interface SelectionPreviewProps { | ||
item: IContextItem; | ||
} | ||
|
||
export const SelectionPreview: React.FC<SelectionPreviewProps> = ({ item }) => { | ||
const { t } = useTranslation(); | ||
const { selection } = item; | ||
const { getNodes } = useReactFlow(); | ||
const { setNodeCenter } = useNodePosition(); | ||
const { setSelectedNode } = useNodeSelection(); | ||
|
||
const handleSourceClick = useCallback(async () => { | ||
const node = getNodes().find((node) => node.data?.entityId === selection?.sourceEntityId); | ||
|
||
if (!node) { | ||
return; | ||
} | ||
|
||
setNodeCenter(node.id); | ||
setSelectedNode(node as CanvasNode<any>); | ||
}, [selection, setNodeCenter, setSelectedNode]); | ||
|
||
return ( | ||
<div className="w-64 p-3 rounded-lg max-h-[400px] overflow-y-auto flex flex-col gap-3"> | ||
<div className="flex items-center gap-2"> | ||
<div className="w-6 h-6 rounded bg-gray-700 shadow-lg flex items-center justify-center flex-shrink-0"> | ||
<IconQuote className="w-4 h-4 text-white" /> | ||
</div> | ||
<span className="text-sm font-medium leading-normal truncate">{t('copilot.contextItem.quote')}</span> | ||
</div> | ||
<div | ||
className=" | ||
px-2 | ||
py-1 | ||
text-xs | ||
text-gray-500 | ||
border | ||
border-solid | ||
border-gray-200 | ||
rounded-lg | ||
flex | ||
justify-between | ||
items-center | ||
gap-2 | ||
cursor-pointer | ||
hover:bg-gray-50 | ||
" | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
handleSourceClick(); | ||
}} | ||
> | ||
<div className="flex items-center gap-2"> | ||
{getContextItemIcon(selection?.sourceEntityType)} | ||
<span className="text-gray-500">{selection?.sourceTitle}</span> | ||
</div> | ||
<LuChevronRight className="w-4 h-4 text-gray-300" /> | ||
</div> | ||
<div className="text-xs">{selection?.content}</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 14 additions & 6 deletions
20
packages/ai-workspace-common/src/components/canvas/launchpad/context-manager/utils/icon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.