Skip to content

Commit 9464517

Browse files
committed
Add workspace-specific notes tab and storage support
- on Home, user can create tasks. Implement similar feature 'notes' under a tab placed to the right of "Tasks": "Notes". Data structure-wise, notes are array of object with: 'title' and 'note' keys. UX-wise, notes are 2 items: a selector (note titles), and a textarea. To the right of selector there are 3 icon buttons: [edit title] (opens vsc native input box), [add] (opens vsc native input box), [delete] (asks for confirmation in modal notification). - don't use such inline styles, we have module file for styles [Pasted text] - simplify notes without caring about backwards compatibility: no titles, no multiple notes per root folder. - [Changes] make the textarea of notes auto-grow, enter should add new lines - [Changes] it's been reported the notes textarea needs double enter presses to create new lines, should need only one - [Changes] in task's textarea new lines are not preserved to tasks.json ├── apps │ └── editor │ └── src │ ├── i18n │ │ ├── index.ts │ │ └── translations │ │ └── views │ │ └── prompt │ │ └── handlers │ │ └── index.ts │ ├── utils │ │ └── global-workspace-storage.ts │ └── views │ ├── prompt │ │ ├── backend │ │ │ ├── message-handlers │ │ │ │ ├── handle-delete-task.ts │ │ │ │ ├── handle-get-notes.ts │ │ │ │ ├── handle-get-tasks.ts │ │ │ │ ├── handle-save-notes.ts │ │ │ │ ├── handle-save-tasks.ts │ │ │ │ └── index.ts │ │ │ └── prompt-view-provider.ts │ │ ├── frontend │ │ │ ├── Home │ │ │ │ ├── Home.module.scss │ │ │ │ ├── Home.tsx │ │ │ │ └── hooks │ │ │ │ ├── use-notes.ts │ │ │ │ └── use-tasks.ts │ │ │ └── i18n │ │ │ └── translations │ │ │ ├── home.ts │ │ │ └── index.ts │ │ └── types │ │ └── messages.ts │ └── settings │ └── frontend │ └── Home │ └── sections │ ├── ApiSection.tsx │ └── GeneralSection.tsx └── packages ├── shared │ └── src │ └── types │ └── task.ts └── ui └── src └── components └── editor ├── common │ ├── Dropdown │ │ ├── Dropdown.module.scss │ │ ├── Dropdown.tsx │ │ └── index.ts │ ├── DropdownMenu │ │ └── DropdownMenu.tsx │ ├── IconButton │ │ ├── IconButton.tsx │ │ └── index.ts │ ├── QuickPickButton │ │ ├── QuickPickButton.module.scss │ │ ├── QuickPickButton.tsx │ │ └── index.ts │ └── Textarea │ ├── Textarea.stories.tsx │ ├── Textarea.tsx │ └── index.ts └── prompt-view ├── Tabs │ ├── Tabs.tsx │ └── index.ts └── Tasks └── Tasks.tsx
1 parent c4f7f6c commit 9464517

11 files changed

Lines changed: 243 additions & 55 deletions

File tree

‎apps/editor/src/utils/global-workspace-storage.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ export const RangesStorage = new GlobalWorkspaceStorage<Record<string, string>>(
5656
'ranges.json'
5757
)
5858
export const TasksStorage = new GlobalWorkspaceStorage<Task[]>('tasks.json')
59+
export const NotesStorage = new GlobalWorkspaceStorage<string>('notes.json')
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
2+
import { NotesStorage } from '@/utils/global-workspace-storage'
3+
4+
export const handle_get_notes = async (
5+
prompt_view_provider: PromptViewProvider
6+
): Promise<void> => {
7+
const workspace_roots =
8+
prompt_view_provider.workspace_provider.get_workspace_roots()
9+
const all_data = NotesStorage.load_all(prompt_view_provider.extension_context)
10+
11+
const notes: Record<string, string> = {}
12+
13+
for (const root of workspace_roots) {
14+
notes[root] = all_data[root] || ''
15+
}
16+
17+
prompt_view_provider.send_message({
18+
command: 'NOTES',
19+
notes
20+
})
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
2+
import { SaveNotesMessage } from '@/views/prompt/types/messages'
3+
import { NotesStorage } from '@/utils/global-workspace-storage'
4+
5+
export const handle_save_notes = async (
6+
prompt_view_provider: PromptViewProvider,
7+
message: SaveNotesMessage
8+
): Promise<void> => {
9+
let all_data = NotesStorage.load_all(prompt_view_provider.extension_context)
10+
11+
all_data = {
12+
...all_data,
13+
...message.notes
14+
}
15+
16+
NotesStorage.save_all(prompt_view_provider.extension_context, all_data)
17+
}

‎apps/editor/src/views/prompt/backend/message-handlers/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ export * from './handle-show-accuracy-boost-info'
7171
export * from './handle-update-extension'
7272
export * from './handle-save-targets-order'
7373
export * from './handle-apply-from'
74+
export * from './handle-get-notes'
75+
export * from './handle-save-notes'

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
check_for_updates
5050
} from './utils'
5151
import * as path from 'path'
52-
import { TasksStorage } from '@/utils/global-workspace-storage'
52+
import { TasksStorage, NotesStorage } from '@/utils/global-workspace-storage'
5353

5454
export class PromptViewProvider implements vscode.WebviewViewProvider {
5555
public readonly extension_uri: vscode.Uri
@@ -317,12 +317,24 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
317317
tasks_watcher.onDidCreate(() => handlers.handle_get_tasks(this))
318318
tasks_watcher.onDidChange(() => handlers.handle_get_tasks(this))
319319
tasks_watcher.onDidDelete(() => handlers.handle_get_tasks(this))
320-
321320
this.extension_context.subscriptions.push(tasks_watcher)
322321

322+
const notes_file_path = NotesStorage.get_file_path(this.extension_context)
323+
const notes_watcher = vscode.workspace.createFileSystemWatcher(
324+
new vscode.RelativePattern(
325+
vscode.Uri.file(path.dirname(notes_file_path)),
326+
path.basename(notes_file_path)
327+
)
328+
)
329+
notes_watcher.onDidCreate(() => handlers.handle_get_notes(this))
330+
notes_watcher.onDidChange(() => handlers.handle_get_notes(this))
331+
notes_watcher.onDidDelete(() => handlers.handle_get_notes(this))
332+
this.extension_context.subscriptions.push(notes_watcher)
333+
323334
this.extension_context.subscriptions.push(
324335
vscode.workspace.onDidChangeWorkspaceFolders(() => {
325336
handlers.handle_get_tasks(this)
337+
handlers.handle_get_notes(this)
326338
handlers.handle_get_workspace_state(this)
327339
this.send_token_count()
328340
})
@@ -835,6 +847,10 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
835847
await handlers.handle_save_tasks(this, message)
836848
} else if (message.command === 'DELETE_TASK') {
837849
await handlers.handle_delete_task(this, message)
850+
} else if (message.command === 'GET_NOTES') {
851+
await handlers.handle_get_notes(this)
852+
} else if (message.command === 'SAVE_NOTES') {
853+
await handlers.handle_save_notes(this, message)
838854
} else if (message.command === 'PREVIEW_GENERATED_CODE') {
839855
await handlers.handle_preview_generated_code(message)
840856
} else if (message.command === 'CREATE_API_CONFIGURATION') {

‎apps/editor/src/views/prompt/frontend/Home/Home.module.scss‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@
176176
&__tasks {
177177
width: 100%;
178178
}
179+
180+
&__notes {
181+
width: 100%;
182+
display: flex;
183+
flex-direction: column;
184+
padding: 0 12px;
185+
186+
@include modern-ui {
187+
padding: 0 10px;
188+
}
189+
}
179190
}
180191

181192
.bottom {

‎apps/editor/src/views/prompt/frontend/Home/Home.tsx‎

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { Spacer as UiSpacer } from '@ui/components/editor/prompt-view/Spacer'
1212
import { Translation, use_translation } from '../i18n/use-translation'
1313
import { Tasks as UiTasks } from '@ui/components/editor/prompt-view/Tasks'
1414
import { use_tasks } from './hooks/use-tasks'
15+
import { use_notes } from './hooks/use-notes'
1516
import { use_has_scrolled_past_target_button } from './hooks/use-has-scrolled-past-mode-button'
17+
import { Textarea as UiTextarea } from '@ui/components/editor/common/Textarea'
1618
import { use_keyboard_shortcuts } from './hooks/use-keyboard-shortcuts'
1719
import {
1820
ApiPromptType,
@@ -45,6 +47,7 @@ export const Home: React.FC<Props> = (props) => {
4547
const { t } = use_translation()
4648
const is_landscape = use_is_landscape()
4749
const [active_workspace_root, set_active_workspace_root] = useState<string>()
50+
const [active_tab, set_active_tab] = useState<'tasks' | 'notes'>('tasks')
4851
const { has_scrolled_past_target_button, target_ref, handle_scroll } =
4952
use_has_scrolled_past_target_button(props.is_active)
5053

@@ -65,7 +68,11 @@ export const Home: React.FC<Props> = (props) => {
6568
handle_delete
6669
} = use_tasks(props.vscode)
6770

68-
const roots = Object.keys(tasks)
71+
const { notes, handle_note_change } = use_notes(props.vscode)
72+
73+
const roots = Array.from(
74+
new Set([...Object.keys(tasks), ...Object.keys(notes)])
75+
)
6976
const active_root =
7077
active_workspace_root && roots.includes(active_workspace_root)
7178
? active_workspace_root
@@ -242,12 +249,29 @@ export const Home: React.FC<Props> = (props) => {
242249
</div>
243250
)
244251

252+
const notes_for_root = notes[active_root] || ''
253+
254+
const notes_section = (
255+
<div className={styles.inner__notes}>
256+
<UiTextarea
257+
value={notes_for_root}
258+
on_change={(v) => handle_note_change(active_root, v)}
259+
placeholder={t('home.notes.placeholder')}
260+
min_rows={10}
261+
blur_on_enter={false}
262+
/>
263+
</div>
264+
)
265+
245266
const tasks_section = (
246267
<>
247268
<UiTabs
248-
tabs={[{ id: 'tasks', label: t('home.tasks') }]}
249-
active_tab="tasks"
250-
on_tab_change={() => {}}
269+
tabs={[
270+
{ id: 'tasks', label: t('home.tasks') },
271+
{ id: 'notes', label: t('home.notes') }
272+
]}
273+
active_tab={active_tab}
274+
on_tab_change={(id) => set_active_tab(id as any)}
251275
actions={
252276
<>
253277
{roots.length > 1 && (
@@ -286,33 +310,37 @@ export const Home: React.FC<Props> = (props) => {
286310

287311
<UiSpacer height={4} />
288312

289-
<div className={styles.inner__tasks}>
290-
<UiTasks
291-
tasks={tasks[active_root] || []}
292-
on_reorder={(new_tasks) => handle_reorder(active_root, new_tasks)}
293-
on_change={(updated_task) => {
294-
handle_change(active_root, tasks[active_root] || [], updated_task)
295-
}}
296-
on_add={(timestamp) => {
297-
handle_add(active_root, tasks[active_root] || [], timestamp)
298-
}}
299-
on_add_subtask={(parent_task, timestamp) => {
300-
handle_add_subtask(
301-
active_root,
302-
tasks[active_root] || [],
303-
parent_task,
304-
timestamp
305-
)
306-
}}
307-
on_delete={(timestamp) => {
308-
handle_delete(active_root, timestamp)
309-
}}
310-
translations={{
311-
placeholder: t('home.tasks.placeholder'),
312-
add_new: t('home.tasks.add-new')
313-
}}
314-
/>
315-
</div>
313+
{active_tab === 'tasks' && (
314+
<div className={styles.inner__tasks}>
315+
<UiTasks
316+
tasks={tasks[active_root] || []}
317+
on_reorder={(new_tasks) => handle_reorder(active_root, new_tasks)}
318+
on_change={(updated_task) => {
319+
handle_change(active_root, tasks[active_root] || [], updated_task)
320+
}}
321+
on_add={(timestamp) => {
322+
handle_add(active_root, tasks[active_root] || [], timestamp)
323+
}}
324+
on_add_subtask={(parent_task, timestamp) => {
325+
handle_add_subtask(
326+
active_root,
327+
tasks[active_root] || [],
328+
parent_task,
329+
timestamp
330+
)
331+
}}
332+
on_delete={(timestamp) => {
333+
handle_delete(active_root, timestamp)
334+
}}
335+
translations={{
336+
placeholder: t('home.tasks.placeholder'),
337+
add_new: t('home.tasks.add-new')
338+
}}
339+
/>
340+
</div>
341+
)}
342+
343+
{active_tab === 'notes' && notes_section}
316344
</>
317345
)
318346

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useState, useEffect } from 'react'
2+
import { BackendMessage } from '../../../types/messages'
3+
import { post_message } from '../../utils/post-message'
4+
5+
export const use_notes = (vscode: any) => {
6+
const [notes, set_notes] = useState<Record<string, string>>({})
7+
8+
useEffect(() => {
9+
const handle_message = (event: MessageEvent<BackendMessage>) => {
10+
const message = event.data
11+
if (message.command === 'NOTES') {
12+
set_notes(message.notes)
13+
}
14+
}
15+
16+
window.addEventListener('message', handle_message)
17+
post_message(vscode, { command: 'GET_NOTES' })
18+
19+
return () => window.removeEventListener('message', handle_message)
20+
}, [])
21+
22+
const handle_note_change = (root: string, note_text: string) => {
23+
const new_notes = { ...notes, [root]: note_text }
24+
set_notes(new_notes)
25+
post_message(vscode, {
26+
command: 'SAVE_NOTES',
27+
notes: new_notes
28+
})
29+
}
30+
31+
return {
32+
notes,
33+
handle_note_change
34+
}
35+
}

‎apps/editor/src/views/prompt/frontend/i18n/translations/home.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
11
export const home = {
2+
'home.notes': {
3+
en: 'Notes',
4+
pl: 'Notatki',
5+
'zh-cn': '笔记',
6+
ja: 'ノート',
7+
'zh-tw': '筆記',
8+
de: 'Notizen',
9+
es: 'Notas',
10+
fr: 'Notes',
11+
'pt-br': 'Notas',
12+
ru: 'Заметки',
13+
ko: '노트',
14+
it: 'Appunti',
15+
tr: 'Notlar',
16+
cs: 'Poznámky',
17+
hu: 'Jegyzetek',
18+
bg: 'Бележки'
19+
},
20+
'home.notes.placeholder': {
21+
en: 'Type your note here...',
22+
pl: 'Wpisz tutaj swoją notatkę...',
23+
'zh-cn': '在此输入您的笔记...',
24+
ja: 'ここにノートを入力...',
25+
'zh-tw': '在此輸入您的筆記...',
26+
de: 'Notiz hier eingeben...',
27+
es: 'Escribe tu nota aquí...',
28+
fr: 'Tapez votre note ici...',
29+
'pt-br': 'Digite sua nota aqui...',
30+
ru: 'Введите вашу заметку здесь...',
31+
ko: '여기에 노트를 입력하세요...',
32+
it: 'Digita qui la tua nota...',
33+
tr: 'Notunuzu buraya yazın...',
34+
cs: 'Zde zadejte svou poznámku...',
35+
hu: 'Írja ide a jegyzetét...',
36+
bg: 'Въведете вашата бележка тук...'
37+
},
238
'home.tasks': {
339
en: 'Tasks',
440
pl: 'Zadania',

‎apps/editor/src/views/prompt/types/messages.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,15 @@ export interface DeleteTaskMessage extends BaseMessage {
496496
timestamp: number
497497
}
498498

499+
export interface GetNotesMessage extends BaseMessage {
500+
command: 'GET_NOTES'
501+
}
502+
503+
export interface SaveNotesMessage extends BaseMessage {
504+
command: 'SAVE_NOTES'
505+
notes: Record<string, string>
506+
}
507+
499508
export interface UpdateFileProgressMessage extends BaseMessage {
500509
command: 'UPDATE_FILE_PROGRESS'
501510
file_path: string
@@ -764,6 +773,8 @@ export type FrontendMessage =
764773
| GetTasksMessage
765774
| SaveTasksMessage
766775
| DeleteTaskMessage
776+
| GetNotesMessage
777+
| SaveNotesMessage
767778
| PreviewGeneratedCodeMessage
768779
| CreateApiConfigurationMessage
769780
| DeleteApiConfigurationMessage
@@ -1081,6 +1092,11 @@ export interface TasksWorkspacePickedMessage extends BaseMessage {
10811092
root: string
10821093
}
10831094

1095+
export interface NotesMessage extends BaseMessage {
1096+
command: 'NOTES'
1097+
notes: Record<string, string>
1098+
}
1099+
10841100
export interface IsModernUiMessage extends BaseMessage {
10851101
command: 'IS_MODERN_UI'
10861102
is_modern_ui: boolean
@@ -1137,6 +1153,7 @@ export type BackendMessage =
11371153
| StartWebConfigurationCreationMessage
11381154
| StartApiConfigurationCreationMessage
11391155
| TasksWorkspacePickedMessage
1156+
| NotesMessage
11401157
| IsModernUiMessage
11411158
| AgentConfigurationsMessage
11421159
| AgentConfigurationUpdatedMessage

0 commit comments

Comments
 (0)