mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-24 21:36:06 +00:00
fix(web): show page component icon on plugin cards (#2345)
Co-authored-by: dadachann <dadachann@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
import {
|
||||||
|
AppWindow,
|
||||||
|
AudioWaveform,
|
||||||
|
Book,
|
||||||
|
FileText,
|
||||||
|
Hash,
|
||||||
|
Wrench,
|
||||||
|
type LucideIcon,
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
|
export const pluginComponentIconMap: Record<string, LucideIcon> = {
|
||||||
|
Tool: Wrench,
|
||||||
|
EventListener: AudioWaveform,
|
||||||
|
Command: Hash,
|
||||||
|
KnowledgeEngine: Book,
|
||||||
|
Parser: FileText,
|
||||||
|
Page: AppWindow,
|
||||||
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Fragment } from 'react';
|
import { Fragment } from 'react';
|
||||||
import { TFunction } from 'i18next';
|
import { TFunction } from 'i18next';
|
||||||
import { Wrench, AudioWaveform, Hash, Book, FileText } from 'lucide-react';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { pluginComponentIconMap } from './PluginComponentIcons';
|
||||||
|
|
||||||
export default function PluginComponentList({
|
export default function PluginComponentList({
|
||||||
components,
|
components,
|
||||||
@@ -18,14 +18,6 @@ export default function PluginComponentList({
|
|||||||
t: TFunction;
|
t: TFunction;
|
||||||
responsive?: boolean;
|
responsive?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const kindIconMap: Record<string, React.ReactNode> = {
|
|
||||||
Tool: <Wrench className="w-5 h-5" />,
|
|
||||||
EventListener: <AudioWaveform className="w-5 h-5" />,
|
|
||||||
Command: <Hash className="w-5 h-5" />,
|
|
||||||
KnowledgeEngine: <Book className="w-5 h-5" />,
|
|
||||||
Parser: <FileText className="w-5 h-5" />,
|
|
||||||
};
|
|
||||||
|
|
||||||
const componentKindList = Object.keys(components || {});
|
const componentKindList = Object.keys(components || {});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -34,11 +26,12 @@ export default function PluginComponentList({
|
|||||||
{componentKindList.length > 0 && (
|
{componentKindList.length > 0 && (
|
||||||
<>
|
<>
|
||||||
{componentKindList.map((kind) => {
|
{componentKindList.map((kind) => {
|
||||||
|
const ComponentIcon = pluginComponentIconMap[kind];
|
||||||
return (
|
return (
|
||||||
<Fragment key={kind}>
|
<Fragment key={kind}>
|
||||||
{useBadge && (
|
{useBadge && (
|
||||||
<Badge variant="outline" className="flex items-center gap-1">
|
<Badge variant="outline" className="flex items-center gap-1">
|
||||||
{kindIconMap[kind]}
|
{ComponentIcon && <ComponentIcon className="w-5 h-5" />}
|
||||||
{responsive ? (
|
{responsive ? (
|
||||||
<span className="hidden md:inline">
|
<span className="hidden md:inline">
|
||||||
{t('market.componentName.' + kind)}
|
{t('market.componentName.' + kind)}
|
||||||
@@ -52,7 +45,7 @@ export default function PluginComponentList({
|
|||||||
|
|
||||||
{!useBadge && (
|
{!useBadge && (
|
||||||
<div className="flex flex-row items-center justify-start gap-[0.2rem]">
|
<div className="flex flex-row items-center justify-start gap-[0.2rem]">
|
||||||
{kindIconMap[kind]}
|
{ComponentIcon && <ComponentIcon className="w-5 h-5" />}
|
||||||
{responsive ? (
|
{responsive ? (
|
||||||
<span className="hidden md:inline">
|
<span className="hidden md:inline">
|
||||||
{t('market.componentName.' + kind)}
|
{t('market.componentName.' + kind)}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import test from 'node:test';
|
||||||
|
import { createRequire } from 'node:module';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import ts from 'typescript';
|
||||||
|
|
||||||
|
const currentDirectory = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
const sourcePath = path.resolve(
|
||||||
|
currentDirectory,
|
||||||
|
'../../src/app/home/plugins/components/plugin-market/PluginComponentIcons.ts',
|
||||||
|
);
|
||||||
|
const source = fs.readFileSync(sourcePath, 'utf8');
|
||||||
|
const compiled = ts.transpileModule(source, {
|
||||||
|
compilerOptions: { module: ts.ModuleKind.CommonJS },
|
||||||
|
}).outputText;
|
||||||
|
const sourceRequire = createRequire(sourcePath);
|
||||||
|
const loadedModule = { exports: {} };
|
||||||
|
new Function('require', 'module', 'exports', compiled)(
|
||||||
|
sourceRequire,
|
||||||
|
loadedModule,
|
||||||
|
loadedModule.exports,
|
||||||
|
);
|
||||||
|
|
||||||
|
const { AppWindow } = sourceRequire('lucide-react');
|
||||||
|
const { pluginComponentIconMap } = loadedModule.exports;
|
||||||
|
|
||||||
|
test('maps the Page plugin component to the AppWindow icon', () => {
|
||||||
|
assert.equal(pluginComponentIconMap.Page, AppWindow);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user