Skip to content

Commit b09abe1

Browse files
committed
Refactor SortableList component to remove header extra support and restore top insertion index handling
- adding template by using the 'add' icon in upper header, creates it at the bottom but should at the top. - make 'on add' on `packages/ui/src/components/editor/settings/SortableList/SortableList.tsx` a required prop - remove 'header extra' - these items should not touch each other [Image] ├── apps │ └── editor │ └── src │ └── views │ ├── prompt │ │ └── frontend │ │ └── Home │ │ └── Home.tsx │ └── settings │ ├── backend │ │ └── message-handlers │ │ ├── handle-create-template.ts │ │ ├── handle-delete-template.ts │ │ ├── handle-get-templates.ts │ │ └── handle-update-templates.ts │ └── frontend │ ├── Home │ │ ├── Home.tsx │ │ └── sections │ │ ├── ApiConfigurationsSection.tsx │ │ ├── GeneralSection.tsx │ │ ├── ModelProvidersSection.tsx │ │ └── WebConfigurationsSection.tsx │ ├── Settings.tsx │ ├── forms │ │ └── EditTemplateForm │ │ ├── EditTemplateForm.module.scss │ │ ├── EditTemplateForm.tsx │ │ └── index.ts │ └── i18n │ └── translations │ └── edit-template-form.ts └── packages └── ui └── src └── components └── editor ├── prompt │ └── Tasks │ ├── Tasks.stories.tsx │ ├── Tasks.tsx │ └── components │ └── TaskGroup.tsx └── settings ├── Notice │ ├── Notice.module.scss │ └── Notice.tsx ├── SortableList │ ├── SortableList.module.scss │ ├── SortableList.stories.tsx │ ├── SortableList.tsx │ └── index.ts └── Templates ├── Templates.module.scss ├── Templates.tsx └── index.ts
1 parent b6252d2 commit b09abe1

4 files changed

Lines changed: 14 additions & 26 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ export const WebConfigurationsSection = forwardRef<HTMLDivElement, Props>(
108108
title={t('chatbots.title')}
109109
subtitle={t('chatbots.subtitle')}
110110
>
111-
<UiNotice type="info">{t('chatbots.notice')}</UiNotice>
112-
{props.web_configurations.length == 0 && (
113-
<UiNotice type="warning">{t('chatbots.notice.missing')}</UiNotice>
114-
)}
111+
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
112+
<UiNotice type="info">{t('chatbots.notice')}</UiNotice>
113+
{props.web_configurations.length == 0 && (
114+
<UiNotice type="warning">{t('chatbots.notice.missing')}</UiNotice>
115+
)}
116+
</div>
115117
<div
116118
ref={(el) =>
117119
props.set_section_ref(

‎packages/ui/src/components/editor/settings/Notice/Notice.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ export const Notice: React.FC<Props> = ({ children, type }) => {
1111
return (
1212
<div
1313
className={cn(styles.container, {
14-
[styles['container--info']]: type === 'info',
15-
[styles['container--warning']]: type === 'warning'
14+
[styles['container--info']]: type == 'info',
15+
[styles['container--warning']]: type == 'warning'
1616
})}
1717
>
1818
<span
1919
className={cn(
2020
'codicon',
21-
type === 'info' ? 'codicon-info' : 'codicon-warning'
21+
type == 'info' ? 'codicon-info' : 'codicon-warning'
2222
)}
2323
/>
2424
<span>{children}</span>

‎packages/ui/src/components/editor/settings/SortableList/SortableList.stories.tsx‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useState } from 'react'
22
import { SortableList } from './SortableList'
33
import { Radio } from '../../common/Radio'
44
import { IconButton } from '../../common/IconButton'
5-
import { TextButton } from '../../common/TextButton'
65

76
export default {
87
component: SortableList
@@ -43,18 +42,13 @@ const initial_configurations: Configuration[] = [
4342

4443
export const Configurations = () => {
4544
const [configurations, set_configurations] = useState(initial_configurations)
46-
const has_default = configurations.some((c) => c.is_default)
4745

4846
const handle_set_default = (id: string) => {
4947
set_configurations(
5048
configurations.map((c) => ({ ...c, is_default: c.id == id }))
5149
)
5250
}
5351

54-
const handle_unset_default = () => {
55-
set_configurations(configurations.map((c) => ({ ...c, is_default: false })))
56-
}
57-
5852
return (
5953
<div
6054
style={{
@@ -74,14 +68,6 @@ export const Configurations = () => {
7468
item_text: 'config',
7569
items_text: 'configs'
7670
}}
77-
header_extra={
78-
has_default ? (
79-
<>
80-
<span>·</span>
81-
<TextButton on_click={handle_unset_default}>Unset</TextButton>
82-
</>
83-
) : undefined
84-
}
8571
render_content={(config) => (
8672
<>
8773
<Radio

‎packages/ui/src/components/editor/settings/SortableList/SortableList.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ export namespace SortableList {
1818
export type Props<T extends Item> = {
1919
items: T[]
2020
on_reorder: (items: T[]) => void
21-
on_add?: (params?: { insertion_index?: number }) => void
21+
on_add: (params?: { insertion_index?: number }) => void
2222
hide_add_button?: boolean
2323
render_content: (item: T, index: number) => React.ReactNode
2424
render_actions?: (item: T, index: number) => React.ReactNode
25-
header_extra?: React.ReactNode
2625
translations: Translations
2726
}
2827
}
@@ -67,13 +66,14 @@ export function SortableList<T extends SortableList.Item>(
6766
return props.translations.items_text
6867
})()}
6968
</div>
70-
{props.header_extra}
7169
</div>
72-
{!props.hide_add_button && props.on_add && (
70+
{!props.hide_add_button && (
7371
<IconButton
7472
codicon_icon="add"
7573
title={props.translations.add_title}
76-
on_click={() => props.on_add?.()}
74+
on_click={() =>
75+
props.on_add(is_top ? { insertion_index: 0 } : undefined)
76+
}
7777
/>
7878
)}
7979
</div>

0 commit comments

Comments
 (0)