Skip to content

Commit 9644124

Browse files
committed
Centralize validation translations and enable prompt preview when actions are disabled
- 'Preview' action should not be dimmed, but should display appropriate information message (e.g. Context cannot be empty.) - place common translations used by `apps/editor/src/views/prompt/backend/message-handlers/handle-preview-prompt.ts` in `apps/editor/src/i18n/translations/views/common/handlers/common.ts` ├── apps │ └── editor │ └── src │ ├── i18n │ │ └── translations │ │ └── views │ │ ├── common │ │ │ └── handlers │ │ │ └── common.ts │ │ └── prompt │ │ └── handlers │ │ └── handle-make-api-call.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-make-api-call.ts │ │ │ └── handle-preview-prompt.ts │ │ └── prompt-view-provider.ts │ ├── frontend │ │ ├── Main │ │ │ └── MainView │ │ │ └── MainView.tsx │ │ └── hooks │ │ └── use-prompt │ │ └── use-prompt.ts │ └── types │ └── messages.ts └── packages └── ui └── src └── components └── editor └── common ├── DropdownMenu │ ├── DropdownMenu.module.scss │ └── DropdownMenu.tsx └── prompts └── PromptField └── PromptField.tsx
1 parent 76fdc58 commit 9644124

5 files changed

Lines changed: 60 additions & 44 deletions

File tree

‎apps/editor/src/i18n/translations/views/common/handlers/common.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
11
export const translations = {
2+
'views.common.handlers.common.instructions-cannot-be-empty': {
3+
en: 'Instructions cannot be empty.',
4+
pl: 'Instrukcje nie mogą być puste.',
5+
'zh-cn': '指令不能为空。',
6+
ja: '指示を空にすることはできません。',
7+
'zh-tw': '指令不能為空。',
8+
de: 'Anweisungen dürfen nicht leer sein.',
9+
es: 'Las instrucciones no pueden estar vacías.',
10+
fr: 'Les instructions ne pin peuvent pas être vides.',
11+
'pt-br': 'As instruções não podem estar vazias.',
12+
ru: 'Инструкции не могут быть пустыми.',
13+
ko: '지침은 비워 둘 수 없습니다.',
14+
it: 'Le istruzioni non possono essere vuote.',
15+
tr: 'Talimatlar boş olamaz.',
16+
cs: 'Instrukce nemohou být prázdné.',
17+
hu: 'Az utasítások nem lehetnek üresek.',
18+
bg: 'Инструкциите не могат да бъдат празни.'
19+
},
20+
'views.common.handlers.common.context-cannot-be-empty': {
21+
en: 'Context cannot be empty.',
22+
pl: 'Kontekst nie może być pusty.',
23+
'zh-cn': '上下文不能为空。',
24+
ja: 'コンテキストを空にすることはできません。',
25+
'zh-tw': '上下文不能為空。',
26+
de: 'Kontext darf nicht leer sein.',
27+
es: 'El contexto no puede estar vacío.',
28+
fr: 'Le contexte ne peut pas être vide.',
29+
'pt-br': 'O contexto não pode estar vazio.',
30+
ru: 'Контекст не может быть пустым.',
31+
ko: '컨텍스트는 비워 둘 수 없습니다.',
32+
it: 'Il contesto non può essere vuoto.',
33+
tr: 'Bağlam boş olamaz.',
34+
cs: 'Kontext nemůže být prázdný.',
35+
hu: 'A kontextus nem lehet üres.',
36+
bg: 'Контекстът не може да бъде празен.'
37+
},
238
'views.common.handlers.common.confirm-discard-unsaved-changes': {
339
en: 'Discard unsaved changes to the {item type}?',
440
pl: 'Odrzucić niezapisane zmiany w {item type}?',

‎apps/editor/src/i18n/translations/views/prompt/handlers/handle-make-api-call.ts‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,4 @@
11
export const translations = {
2-
'views.prompt.handlers.handle-make-api-call.instructions-cannot-be-empty': {
3-
en: 'Instructions cannot be empty.',
4-
pl: 'Instrukcje nie mogą być puste.',
5-
'zh-cn': '指令不能为空。',
6-
ja: '指示を空にすることはできません。',
7-
'zh-tw': '指令不能為空。',
8-
de: 'Anweisungen dürfen nicht leer sein.',
9-
es: 'Las instrucciones no pueden estar vacías.',
10-
fr: 'Les instructions ne peuvent pas être vides.',
11-
'pt-br': 'As instruções não podem estar vazias.',
12-
ru: 'Инструкции не могут быть пустыми.',
13-
ko: '지침은 비워 둘 수 없습니다.',
14-
it: 'Le istruzioni non possono essere vuote.',
15-
tr: 'Talimatlar boş olamaz.',
16-
cs: 'Instrukce nemohou být prázdné.',
17-
hu: 'Az utasítások nem lehetnek üresek.',
18-
bg: 'Инструкциите не могат да бъдат празни.'
19-
},
20-
'views.prompt.handlers.handle-make-api-call.context-cannot-be-empty': {
21-
en: 'Context cannot be empty.',
22-
pl: 'Kontekst nie może być pusty.',
23-
'zh-cn': '上下文不能为空。',
24-
ja: 'コンテキストを空にすることはできません。',
25-
'zh-tw': '上下文不能為空。',
26-
de: 'Kontext darf nicht leer sein.',
27-
es: 'El contexto no puede estar vacío.',
28-
fr: 'Le contexte ne peut pas être vide.',
29-
'pt-br': 'O contexto não pode estar vazio.',
30-
ru: 'Контекст не может быть пустым.',
31-
ko: '컨텍스트는 비워 둘 수 없습니다.',
32-
it: 'Il contesto non può essere vuoto.',
33-
tr: 'Bağlam boş olamaz.',
34-
cs: 'Kontext nemůže být prázdný.',
35-
hu: 'A kontextus nem lehet üres.',
36-
bg: 'Контекстът не може да бъде празен.'
37-
},
382
'views.prompt.handlers.handle-make-api-call.select-code-at-cursor-api-configuration':
393
{
404
en: 'Select code at cursor API configuration',

‎apps/editor/src/views/prompt/backend/message-handlers/handle-make-api-call.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ export const handle_make_api_call = async (
158158

159159
if (!current_instructions) {
160160
vscode.window.showInformationMessage(
161-
t(
162-
'views.prompt.handlers.handle-make-api-call.instructions-cannot-be-empty'
163-
)
161+
t('views.common.handlers.common.instructions-cannot-be-empty')
164162
)
165163
return
166164
}
@@ -177,7 +175,7 @@ export const handle_make_api_call = async (
177175

178176
if (!collected_files) {
179177
vscode.window.showInformationMessage(
180-
t('views.prompt.handlers.handle-make-api-call.context-cannot-be-empty')
178+
t('views.common.handlers.common.context-cannot-be-empty')
181179
)
182180
return
183181
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,40 @@ import {
88
} from '@/constants/edit-format-instructions'
99
import { PromptBuilder } from '@/utils/prompt-builder'
1010
import { preview_text_in_temp_file } from '../utils/preview-text-in-temp-file'
11+
import * as vscode from 'vscode'
12+
import { t } from '@/i18n'
1113

1214
export const handle_preview_prompt = async (params: {
1315
prompt_view_provider: PromptViewProvider
1416
}): Promise<void> => {
17+
const current_instructions =
18+
params.prompt_view_provider.current_instructions.trim()
19+
20+
if (!current_instructions) {
21+
vscode.window.showInformationMessage(
22+
t('views.common.handlers.common.instructions-cannot-be-empty')
23+
)
24+
return
25+
}
26+
1527
const {
1628
other_files,
1729
recent_files,
30+
collected_files,
1831
processed_instructions,
1932
skill_definitions
2033
} = await build_prompt_payload({
2134
prompt_view_provider: params.prompt_view_provider,
2235
remove_images: true
2336
})
2437

38+
if (!collected_files) {
39+
vscode.window.showInformationMessage(
40+
t('views.common.handlers.common.context-cannot-be-empty')
41+
)
42+
return
43+
}
44+
2545
let formatted_system_instructions = ''
2646
const user_instructions = processed_instructions
2747

‎packages/ui/src/components/editor/common/prompts/PromptField/PromptField.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
380380
on_click: () => {
381381
props.on_preview_prompt?.()
382382
close_dropdown()
383-
},
384-
is_disabled: props.is_action_disabled
383+
}
385384
}
386385
].filter((item) => !(!has_content && item.is_disabled))
387386

@@ -416,8 +415,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
416415
on_click: () => {
417416
props.on_preview_prompt?.()
418417
close_dropdown()
419-
},
420-
is_disabled: props.is_action_disabled
418+
}
421419
}
422420
].filter((item) => !(!has_content && item.is_disabled))
423421

0 commit comments

Comments
 (0)