-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathModelHeader.tsx
More file actions
51 lines (46 loc) · 1.93 KB
/
ModelHeader.tsx
File metadata and controls
51 lines (46 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Flex, Heading, Link, Spacer, Text } from '@invoke-ai/ui-library';
import { useIsModelManagerEnabled } from 'features/modelManagerV2/hooks/useIsModelManagerEnabled';
import ModelImageUpload from 'features/modelManagerV2/subpanels/ModelPanel/Fields/ModelImageUpload';
import type { PropsWithChildren } from 'react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import type { AnyModelConfig } from 'services/api/types';
const isSafeUrl = (url: string): boolean => {
return url.startsWith('https://') || url.startsWith('http://');
};
type Props = PropsWithChildren<{
modelConfig: AnyModelConfig;
}>;
export const ModelHeader = memo(({ modelConfig, children }: Props) => {
const { t } = useTranslation();
const canManageModels = useIsModelManagerEnabled();
return (
<Flex alignItems="flex-start" gap={4}>
{canManageModels && <ModelImageUpload model_key={modelConfig.key} model_image={modelConfig.cover_image} />}
<Flex flexDir="column" gap={1} flexGrow={1} minW={0}>
<Flex gap={2}>
<Heading as="h2" fontSize="lg" noOfLines={1} wordBreak="break-all">
{modelConfig.name}
</Heading>
<Spacer />
{children}
</Flex>
{modelConfig.source && (
<Text variant="subtext" noOfLines={1} wordBreak="break-all">
{t('modelManager.source')}: {modelConfig.source}
</Text>
)}
{'source_url' in modelConfig && modelConfig.source_url && isSafeUrl(modelConfig.source_url) && (
<Text variant="subtext" noOfLines={1} wordBreak="break-all">
{t('modelManager.sourceUrl')}:{' '}
<Link href={modelConfig.source_url} isExternal color="invokeBlue.300">
{modelConfig.source_url}
</Link>
</Text>
)}
<Text noOfLines={3}>{modelConfig.description}</Text>
</Flex>
</Flex>
);
});
ModelHeader.displayName = 'ModelHeader';