Skip to content

Commit 318aa1d

Browse files
committed
Replace ConfigurationsList and ModelProviders with a generic SortableList component for settings lists
1 parent 2f83893 commit 318aa1d

14 files changed

Lines changed: 598 additions & 672 deletions

File tree

‎apps/editor/src/views/i18n/settings.ts‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export const settings = {
289289
},
290290
'settings.action.model-providers': {
291291
en: 'model providers',
292-
pl: 'dostawców modelu',
292+
pl: 'dostawcy modelu',
293293
'zh-cn': '模型提供商',
294294
ja: 'モデルプロバイダー',
295295
'zh-tw': '模型供應商',
@@ -305,6 +305,24 @@ export const settings = {
305305
hu: 'modell szolgáltatók',
306306
bg: 'доставчици на модели'
307307
},
308+
'settings.action.model-providers-many': {
309+
en: 'model providers',
310+
pl: 'dostawców modelu',
311+
'zh-cn': '模型提供商',
312+
ja: 'モデルプロバイダー',
313+
'zh-tw': '模型供應商',
314+
de: 'Modellanbieter',
315+
es: 'proveedores de modelos',
316+
fr: 'fournisseurs de modèles',
317+
'pt-br': 'provedores de modelos',
318+
ru: 'провайдеров модели',
319+
ko: '모델 제공자',
320+
it: 'fornitori di modelli',
321+
tr: 'model sağlayıcılar',
322+
cs: 'poskytovatelů modelu',
323+
hu: 'modell szolgáltatók',
324+
bg: 'доставчици на модели'
325+
},
308326
'settings.action.insert-configuration': {
309327
en: 'Insert a new configuration below/above',
310328
pl: 'Wstaw nową konfigurację poniżej/powyżej',
@@ -431,6 +449,24 @@ export const settings = {
431449
hu: 'konfigurációk',
432450
bg: 'конфигурации'
433451
},
452+
'settings.action.configurations-many': {
453+
en: 'configurations',
454+
pl: 'konfiguracji',
455+
'zh-cn': '配置',
456+
ja: '設定',
457+
'zh-tw': '設定',
458+
de: 'Konfigurationen',
459+
es: 'configuraciones',
460+
fr: 'configurations',
461+
'pt-br': 'configurações',
462+
ru: 'конфигураций',
463+
ko: '구성',
464+
it: 'configurazioni',
465+
tr: 'yapılandırmalar',
466+
cs: 'konfigurací',
467+
hu: 'konfigurációk',
468+
bg: 'конфигурации'
469+
},
434470
'settings.message.missing-configuration': {
435471
en: 'Missing configuration.',
436472
pl: 'Brak konfiguracji.',

‎apps/editor/src/views/settings/frontend/Home/sections/ApiToolConfigurationSection.tsx‎

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { ConfigurationForClient } from '@/views/settings/types/messages'
2-
import { ConfigurationsList as UiConfigurationsList } from '@ui/components/editor/settings/ConfigurationsList'
2+
import { SortableList } from '@ui/components/editor/settings/SortableList'
3+
import { Radio } from '@ui/components/editor/common/Radio'
4+
import { IconButton } from '@ui/components/editor/common/IconButton'
5+
import { TextButton } from '@ui/components/editor/settings/TextButton'
36
import { use_translation } from '@/views/i18n/use-translation'
47

58
type ToolName =
@@ -32,31 +35,85 @@ export const ApiToolConfigurationSection: React.FC<
3235
const { configurations, set_configurations } = props
3336
const { t } = use_translation()
3437

38+
const has_default = configurations?.some((c) => c.is_default) ?? false
39+
3540
return (
3641
<>
3742
{configurations && (
38-
<UiConfigurationsList
39-
translations={{
40-
add_title: t('settings.action.add-new'),
41-
insert_title: t('settings.action.insert-configuration'),
42-
edit_title: t('settings.action.edit-configuration'),
43-
delete_title: t('settings.action.delete-configuration'),
44-
set_default_title: t('settings.action.set-default'),
45-
unset_default_text: t('settings.action.unset-default'),
46-
configuration_text: t('settings.action.configuration'),
47-
configurations_text: t('settings.action.configurations')
48-
}}
49-
configurations={configurations}
50-
on_add={props.on_add}
43+
<SortableList
44+
items={configurations}
5145
on_reorder={(reordered) => {
5246
set_configurations(reordered)
5347
props.on_reorder(reordered)
5448
}}
55-
on_edit={props.on_edit}
56-
on_delete={props.on_delete}
57-
on_set_default={props.on_set_default}
58-
on_unset_default={props.on_unset_default}
59-
radio_group_name={`default_configuration_${props.tool_name.toLowerCase()}`}
49+
on_add={props.on_add}
50+
translations={{
51+
add_title: t('settings.action.add-new'),
52+
insert_title: t('settings.action.insert-configuration'),
53+
item_text: t('settings.action.configuration'),
54+
items_text: t('settings.action.configurations'),
55+
items_text_many: t('settings.action.configurations-many')
56+
}}
57+
header_extra={
58+
props.on_unset_default && has_default ? (
59+
<>
60+
<span>·</span>
61+
<TextButton on_click={props.on_unset_default}>
62+
{t('settings.action.unset-default')}
63+
</TextButton>
64+
</>
65+
) : undefined
66+
}
67+
render_content={(config) => (
68+
<>
69+
{props.on_set_default && (
70+
<Radio
71+
name={`default_configuration_${props.tool_name.toLowerCase()}`}
72+
checked={!!config.is_default}
73+
title={t('settings.action.set-default')}
74+
on_change={() => props.on_set_default!(config.id)}
75+
/>
76+
)}
77+
<div
78+
style={{
79+
flex: 1,
80+
overflow: 'hidden',
81+
whiteSpace: 'nowrap',
82+
textOverflow: 'ellipsis',
83+
cursor: props.on_set_default ? 'pointer' : undefined
84+
}}
85+
onClick={() => props.on_set_default?.(config.id)}
86+
>
87+
<span>{config.model}</span>
88+
<span
89+
style={{
90+
marginLeft: '0.5em',
91+
opacity: 0.7,
92+
fontSize: '0.9em'
93+
}}
94+
>
95+
{config.description}
96+
</span>
97+
</div>
98+
</>
99+
)}
100+
render_actions={(config) => (
101+
<>
102+
<IconButton
103+
codicon_icon="edit"
104+
title={t('settings.action.edit-configuration')}
105+
on_click={() => props.on_edit(config.id)}
106+
/>
107+
<IconButton
108+
codicon_icon="trash"
109+
title={t('settings.action.delete-configuration')}
110+
on_click={(e) => {
111+
e.stopPropagation()
112+
props.on_delete(config.id)
113+
}}
114+
/>
115+
</>
116+
)}
60117
/>
61118
)}
62119
</>
Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ProviderForClient } from '@/views/settings/types/messages'
2-
import { ModelProviders as UiModelProviders } from '@ui/components/editor/settings/ModelProviders'
2+
import { SortableList } from '@ui/components/editor/settings/SortableList'
3+
import { IconButton } from '@ui/components/editor/common/IconButton'
34
import { use_translation } from '@/views/i18n/use-translation'
45

56
type ModelProvidersSectionProps = {
@@ -18,27 +19,79 @@ export const ModelProvidersSection: React.FC<ModelProvidersSectionProps> = (
1819
) => {
1920
const { t } = use_translation()
2021

22+
if (!props.providers) return null
23+
24+
const items = props.providers.map((p) => ({ ...p, id: p.name }))
25+
2126
return (
22-
<>
23-
{props.providers && (
24-
<UiModelProviders
25-
translations={{
26-
add_title: t('settings.action.add-new'),
27-
insert_title: t('settings.action.insert-provider'),
28-
edit_title: t('settings.action.edit-provider'),
29-
change_api_key_title: t('settings.action.change-api-key'),
30-
delete_title: t('settings.action.delete-provider'),
31-
provider_text: t('settings.action.model-provider'),
32-
providers_text: t('settings.action.model-providers')
33-
}}
34-
providers={props.providers}
35-
on_reorder={props.on_reorder}
36-
on_add_provider={props.on_add_provider}
37-
on_delete_provider={props.on_delete_provider}
38-
on_edit_provider={props.on_edit_provider}
39-
on_change_api_key={props.on_change_api_key}
40-
/>
27+
<SortableList
28+
items={items}
29+
on_reorder={(reordered) => {
30+
props.on_reorder(reordered.map(({ id: _id, ...rest }) => rest))
31+
}}
32+
on_add={props.on_add_provider}
33+
translations={{
34+
add_title: t('settings.action.add-new'),
35+
insert_title: t('settings.action.insert-provider'),
36+
item_text: t('settings.action.model-provider'),
37+
items_text: t('settings.action.model-providers')
38+
}}
39+
render_content={(provider) => (
40+
<>
41+
<div
42+
style={{
43+
width: 90,
44+
whiteSpace: 'nowrap',
45+
overflow: 'hidden',
46+
textOverflow: 'ellipsis'
47+
}}
48+
>
49+
{provider.name}
50+
</div>
51+
<div
52+
style={{
53+
width: 50,
54+
whiteSpace: 'nowrap',
55+
overflow: 'hidden',
56+
textOverflow: 'ellipsis'
57+
}}
58+
>
59+
{provider.apiKeyMask}
60+
</div>
61+
<div
62+
style={{
63+
flex: 1,
64+
whiteSpace: 'nowrap',
65+
overflow: 'hidden',
66+
textOverflow: 'ellipsis'
67+
}}
68+
>
69+
{provider.baseUrl}
70+
</div>
71+
</>
72+
)}
73+
render_actions={(provider) => (
74+
<>
75+
{provider.type == 'custom' ? (
76+
<IconButton
77+
codicon_icon="edit"
78+
title={t('settings.action.edit-provider')}
79+
on_click={() => props.on_edit_provider(provider.name)}
80+
/>
81+
) : (
82+
<IconButton
83+
codicon_icon="key"
84+
title={t('settings.action.change-api-key')}
85+
on_click={() => props.on_change_api_key(provider.name)}
86+
/>
87+
)}
88+
<IconButton
89+
codicon_icon="trash"
90+
title={t('settings.action.delete-provider')}
91+
on_click={() => props.on_delete_provider(provider.name)}
92+
/>
93+
</>
4194
)}
42-
</>
95+
/>
4396
)
4497
}

‎packages/ui/src/components/editor/settings/ConfigurationsList/ConfigurationsList.module.scss‎

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)