Skip to content

Commit 9d9ce02

Browse files
committed
Add reusable StatusBar component and migrate view and file item status messages to use it
- create 'StatusBar' component with icon, label, actions, etc. that consolidate various present components or their parts (it should be configurable enough to fully replace `packages/ui/src/components/editor/prompt/PromptAttachments/PromptAttachments.tsx` `packages/ui/src/components/editor/prompt/BrowserConnectionStatus/BrowserConnectionStatus.tsx` and be used in `packages/ui/src/components/editor/prompt/ResponsePreview/components/FileItem/FileItem.tsx` - when hovering status bar actions, change background like you did before [Changes] - before your edits, actions were sticking to right edge, now we have an undesired padding [Changes] - such margin [Pasted text] should be a part of status bar, not outside wrapper - status bar can be shown above or below, it determines whether border radius is on top or bottom corners. Should accept appropriate prop and set radius from within `packages/ui/src/components/editor/prompt/StatusBar/StatusBar.tsx` appropriately - status bar should accept description prop instead of such hacks [Fragment] - `packages/ui/src/components/editor/prompt/BrowserConnectionStatus/BrowserConnectionStatus.tsx` and `packages/ui/src/components/editor/prompt/PromptAttachments/PromptAttachments.tsx` are not ui components, should be placed in `apps/editor/src/views/prompt/frontend/Main/MainView/components` - hide `apps/editor/src/views/prompt/frontend/Main/MainView/components/BrowserConnectionStatus/BrowserConnectionStatus.tsx` when connected: once shown responses, when not connected: once showing responses - `apps/editor/src/views/prompt/frontend/Main/MainView/components/BrowserConnectionStatus/BrowserConnectionStatus.tsx` should reappear immediately while not connected and not having responses ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ └── frontend │ └── Main │ └── MainView │ ├── MainView.module.scss │ ├── MainView.tsx │ └── components │ ├── BrowserConnectionStatus │ │ ├── BrowserConnectionStatus.tsx │ │ └── index.ts │ ├── Header │ │ ├── Header.module.scss │ │ ├── Header.tsx │ │ ├── hooks │ │ │ └── use-keyboard-shortcuts.ts │ │ └── index.ts │ └── PromptAttachments │ ├── PromptAttachments.tsx │ └── index.ts └── packages └── ui └── src └── components └── editor └── prompt ├── BrowserConnectionStatus │ ├── BrowserConnectionStatus.module.scss │ ├── BrowserConnectionStatus.stories.tsx │ └── BrowserConnectionStatus.tsx ├── PromptAttachments │ ├── PromptAttachments.module.scss │ ├── PromptAttachments.stories.tsx │ └── PromptAttachments.tsx ├── ResponsePreview │ └── components │ └── FileItem │ ├── FileItem.module.scss │ ├── FileItem.tsx │ └── index.ts └── StatusBar ├── StatusBar.module.scss ├── StatusBar.tsx └── index.ts
1 parent dd2789e commit 9d9ce02

16 files changed

Lines changed: 383 additions & 485 deletions

File tree

‎apps/editor/src/views/prompt/frontend/Main/MainView/MainView.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styles from './MainView.module.scss'
22
import { Configurations as UiConfigurations } from '@ui/components/editor/prompt/Configurations'
33
import { PromptField as UiPromptField } from '@ui/components/editor/common/prompts/PromptField'
4-
import { PromptAttachments as UiPromptAttachments } from '@ui/components/editor/prompt/PromptAttachments'
4+
import { PromptAttachments as UiPromptAttachments } from './components/PromptAttachments'
55
import { Separator as UiSeparator } from '@ui/components/editor/prompt/Separator'
66
import { WebConfiguration } from '@shared/types/web-configuration'
77
import { Responses as UiResponses } from '@ui/components/editor/prompt/Responses'
@@ -10,7 +10,7 @@ import { EditFormat } from '@shared/types/edit-format'
1010
import { TARGET, Target } from '@shared/types/mode'
1111
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
1212
import { Scrollable as UiScrollable } from '@ui/components/editor/common/Scrollable'
13-
import { BrowserConnectionStatus as UiBrowserConnectionStatus } from '@ui/components/editor/prompt/BrowserConnectionStatus'
13+
import { BrowserConnectionStatus as UiBrowserConnectionStatus } from './components/BrowserConnectionStatus'
1414
import { ApiConfiguration } from '@/views/prompt/types/messages'
1515
import { use_last_choice_tooltip } from './hooks/use-last-choice-tooltip'
1616
import { Header } from './components/Header'
@@ -250,6 +250,7 @@ export const MainView: React.FC<Props> = (props) => {
250250
{props.target == TARGET.WEB && (
251251
<UiBrowserConnectionStatus
252252
is_connected={props.is_connected}
253+
has_responses={props.response_history.length > 0}
253254
on_install={props.on_install_browser_extension}
254255
translations={{
255256
connected: 'Connected!',
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React, { useEffect, useState } from 'react'
2+
import { StatusBar } from '@ui/components/editor/prompt/StatusBar'
3+
4+
type Props = {
5+
is_connected: boolean
6+
has_responses: boolean
7+
translations: {
8+
connected: string
9+
not_connected: string
10+
install: string
11+
hide: string
12+
}
13+
on_install: () => void
14+
}
15+
16+
export const BrowserConnectionStatus: React.FC<Props> = (props) => {
17+
const [is_closed, setIsClosed] = useState(false)
18+
19+
useEffect(() => {
20+
if (props.has_responses) {
21+
setIsClosed(true)
22+
} else if (!props.is_connected) {
23+
setIsClosed(false)
24+
}
25+
}, [props.has_responses, props.is_connected])
26+
27+
if (is_closed || props.has_responses) {
28+
return null
29+
}
30+
31+
const actions = []
32+
if (!props.is_connected) {
33+
actions.push({
34+
id: 'install',
35+
icon: 'codicon-desktop-download',
36+
label: props.translations.install,
37+
title: props.translations.install,
38+
on_click: props.on_install
39+
})
40+
} else {
41+
actions.push({
42+
id: 'hide',
43+
icon: 'codicon-close-small',
44+
label: props.translations.hide,
45+
title: props.translations.hide,
46+
on_click: () => setIsClosed(true)
47+
})
48+
}
49+
50+
return (
51+
<StatusBar
52+
placement="top"
53+
theme={props.is_connected ? 'success' : 'warning'}
54+
icon={
55+
props.is_connected
56+
? 'codicon-debug-connected'
57+
: 'codicon-debug-disconnect'
58+
}
59+
label={
60+
props.is_connected
61+
? props.translations.connected
62+
: props.translations.not_connected
63+
}
64+
actions={actions}
65+
/>
66+
)
67+
}

packages/ui/src/components/editor/prompt/BrowserConnectionStatus/index.ts renamed to apps/editor/src/views/prompt/frontend/Main/MainView/components/BrowserConnectionStatus/index.ts

File renamed without changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react'
2+
import { StatusBar } from '@ui/components/editor/prompt/StatusBar'
3+
import { display_token_count } from '@shared/utils/display-token-count'
4+
5+
type Props = {
6+
token_count?: number
7+
files_count?: number
8+
translations: {
9+
warning?: string
10+
attaching_files: string
11+
}
12+
}
13+
14+
export const PromptAttachments: React.FC<Props> = (props) => {
15+
if (!props.translations.warning && props.files_count === undefined) {
16+
return null
17+
}
18+
19+
return (
20+
<>
21+
{props.translations.warning && (
22+
<StatusBar
23+
placement="bottom"
24+
theme="warning"
25+
icon="codicon-warning"
26+
label={props.translations.warning}
27+
/>
28+
)}
29+
{props.files_count !== undefined && (
30+
<StatusBar
31+
placement="bottom"
32+
theme="default"
33+
icon="codicon-attach"
34+
label={props.translations.attaching_files.replace(
35+
'{files}',
36+
String(props.files_count)
37+
)}
38+
description={
39+
(props.token_count ?? 0) > 0
40+
? display_token_count(props.token_count ?? 0)
41+
: undefined
42+
}
43+
/>
44+
)}
45+
</>
46+
)
47+
}

packages/ui/src/components/editor/prompt/PromptAttachments/index.ts renamed to apps/editor/src/views/prompt/frontend/Main/MainView/components/PromptAttachments/index.ts

File renamed without changes.

‎packages/ui/src/components/editor/prompt/BrowserConnectionStatus/BrowserConnectionStatus.module.scss‎

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

‎packages/ui/src/components/editor/prompt/BrowserConnectionStatus/BrowserConnectionStatus.stories.tsx‎

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

‎packages/ui/src/components/editor/prompt/BrowserConnectionStatus/BrowserConnectionStatus.tsx‎

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

‎packages/ui/src/components/editor/prompt/PromptAttachments/PromptAttachments.module.scss‎

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

0 commit comments

Comments
 (0)