From 74a6c6a184e0b540298080c61a2e55f0178c6a7d Mon Sep 17 00:00:00 2001 From: TJ Date: Fri, 12 Mar 2021 21:11:02 -0700 Subject: [PATCH 1/2] fix: Remove Attachment Lg template when they are deleted in the Response Editor --- .../modalityEditors/AttachmentArrayEditor.tsx | 12 ++- .../AttachmentModalityEditor.tsx | 2 + .../lg/modalityEditors/StringArrayItem.tsx | 97 ++++++++++++------- 3 files changed, 70 insertions(+), 41 deletions(-) diff --git a/Composer/packages/lib/code-editor/src/lg/modalityEditors/AttachmentArrayEditor.tsx b/Composer/packages/lib/code-editor/src/lg/modalityEditors/AttachmentArrayEditor.tsx index 0a2d61f295..c76db86a65 100644 --- a/Composer/packages/lib/code-editor/src/lg/modalityEditors/AttachmentArrayEditor.tsx +++ b/Composer/packages/lib/code-editor/src/lg/modalityEditors/AttachmentArrayEditor.tsx @@ -67,6 +67,7 @@ type AttachmentArrayEditorProps = { memoryVariables?: readonly string[]; lgOption?: LGOption; onChange: (items: string[]) => void; + onRemoveTemplate: (templateId: string) => void; onTemplateChange: (templateId: string, body?: string) => void; telemetryClient: TelemetryClient; codeEditorSettings?: Partial; @@ -80,6 +81,7 @@ export const AttachmentArrayEditor = React.memo( memoryVariables, onChange, onTemplateChange, + onRemoveTemplate, telemetryClient, codeEditorSettings, }: AttachmentArrayEditorProps) => { @@ -108,11 +110,12 @@ export const AttachmentArrayEditor = React.memo( ); const onRemove = React.useCallback( - (index: number) => () => { - const newItems = items.filter((_, idx) => idx !== index); + (templateId: string) => () => { + const newItems = items.filter((id) => id !== templateId); onChange(newItems); + onRemoveTemplate(templateId); }, - [items, onChange] + [items, onChange, onRemoveTemplate] ); const onAddTemplateClick = React.useCallback( @@ -239,11 +242,12 @@ export const AttachmentArrayEditor = React.memo( lgTemplates={lgTemplates} memoryVariables={memoryVariables} mode={idx === currentIndex ? 'edit' : 'view'} + removeTooltipTextContent={formatMessage('Remove attachment')} telemetryClient={telemetryClient} value={body} onFocus={onFocus(idx)} onLgChange={onLgCodeChange(name)} - onRemove={onRemove(idx)} + onRemove={onRemove(name)} onRenderDisplayText={onRenderDisplayText(idx)} /> ))} diff --git a/Composer/packages/lib/code-editor/src/lg/modalityEditors/AttachmentModalityEditor.tsx b/Composer/packages/lib/code-editor/src/lg/modalityEditors/AttachmentModalityEditor.tsx index a622f61eb9..2d4548c11c 100644 --- a/Composer/packages/lib/code-editor/src/lg/modalityEditors/AttachmentModalityEditor.tsx +++ b/Composer/packages/lib/code-editor/src/lg/modalityEditors/AttachmentModalityEditor.tsx @@ -33,6 +33,7 @@ const AttachmentModalityEditor = React.memo( onAttachmentLayoutChange, onUpdateResponseTemplate, onRemoveModality, + onRemoveTemplate, onTemplateChange, telemetryClient, editorSettings, @@ -108,6 +109,7 @@ const AttachmentModalityEditor = React.memo( selectedKey="text" telemetryClient={telemetryClient} onChange={handleChange} + onRemoveTemplate={onRemoveTemplate} onTemplateChange={onTemplateChange} /> diff --git a/Composer/packages/lib/code-editor/src/lg/modalityEditors/StringArrayItem.tsx b/Composer/packages/lib/code-editor/src/lg/modalityEditors/StringArrayItem.tsx index 69546f4cf4..c71589a3c5 100644 --- a/Composer/packages/lib/code-editor/src/lg/modalityEditors/StringArrayItem.tsx +++ b/Composer/packages/lib/code-editor/src/lg/modalityEditors/StringArrayItem.tsx @@ -100,6 +100,7 @@ type Props = { value: string; codeEditorSettings?: Partial; telemetryClient: TelemetryClient; + removeTooltipTextContent?: string; onRenderDisplayText?: () => React.ReactNode; onBlur?: () => void; onJumpTo?: (direction: 'next' | 'previous') => void; @@ -110,47 +111,62 @@ type Props = { onShowCallout?: (target: HTMLInputElement) => void; }; -type TextViewItemProps = Pick; +type TextViewItemProps = Pick< + Props, + 'value' | 'onRemove' | 'onFocus' | 'onRenderDisplayText' | 'codeEditorSettings' | 'removeTooltipTextContent' +>; -const TextViewItem = React.memo(({ value, onRemove, onFocus, onRenderDisplayText }: TextViewItemProps) => { - const remove = useCallback( - (e: React.MouseEvent) => { - e.stopPropagation(); - e.preventDefault(); - onRemove(); - }, - [onRemove] - ); +const TextViewItem = React.memo( + ({ removeTooltipTextContent, value, onRemove, onFocus, onRenderDisplayText }: TextViewItemProps) => { + const remove = useCallback( + (e: React.MouseEvent) => { + e.stopPropagation(); + e.preventDefault(); + onRemove(); + }, + [onRemove] + ); - const focus = React.useCallback( - (e: React.FocusEvent) => { - e.stopPropagation(); - onFocus(); - }, - [onFocus] - ); + const focus = React.useCallback( + (e: React.FocusEvent) => { + e.stopPropagation(); + onFocus(); + }, + [onFocus] + ); - const click = React.useCallback( - (e: React.MouseEvent) => { - e.stopPropagation(); - onFocus(); - }, - [onFocus] - ); + const click = React.useCallback( + (e: React.MouseEvent) => { + e.stopPropagation(); + onFocus(); + }, + [onFocus] + ); - const RemoveIcon = React.useMemo(() => withTooltip({ content: formatMessage('Remove variation') }, IconButton), []); + const RemoveIcon = React.useMemo( + () => withTooltip({ content: removeTooltipTextContent ?? formatMessage('Remove variation') }, IconButton), + [removeTooltipTextContent] + ); - return ( - - - - {onRenderDisplayText?.() ?? value} - - - - - ); -}); + return ( + + + + {onRenderDisplayText?.() ?? value} + + + + + ); + } +); type TextFieldItemProps = Omit; @@ -225,6 +241,7 @@ export const StringArrayItem = (props: Props) => { value, telemetryClient, codeEditorSettings, + removeTooltipTextContent, } = props; const onEditorDidMount = React.useCallback( @@ -258,7 +275,13 @@ export const StringArrayItem = (props: Props) => { ) ) : ( - + )} ); From 1d35c7d73e050c5387c1d73787cc8e8942d8caa0 Mon Sep 17 00:00:00 2001 From: Soroush Date: Fri, 12 Mar 2021 20:41:08 -0800 Subject: [PATCH 2/2] strings --- Composer/packages/server/src/locales/en-US.json | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Composer/packages/server/src/locales/en-US.json b/Composer/packages/server/src/locales/en-US.json index 4f8cfc963f..9bbb489103 100644 --- a/Composer/packages/server/src/locales/en-US.json +++ b/Composer/packages/server/src/locales/en-US.json @@ -1568,9 +1568,6 @@ "getting_template_910a4116": { "message": "Getting template" }, - "getting_yeoman_environment_4f50aae3": { - "message": "Getting Yeoman environment" - }, "go_to_qna_all_up_view_page_d475333d": { "message": "Go to QnA all-up view page." }, @@ -1721,12 +1718,6 @@ "install_the_update_and_restart_composer_fac30a61": { "message": "Install the update and restart Composer." }, - "installing_yeoman_template_38cf1e48": { - "message": "Installing Yeoman template" - }, - "instantiating_yeoman_template_5acf7e3f": { - "message": "Instantiating Yeoman template" - }, "integer_7f378275": { "message": "integer" }, @@ -2711,6 +2702,9 @@ "remove_all_text_responses_77592d1a": { "message": "Remove all text responses" }, + "remove_attachment_81f30aa3": { + "message": "Remove attachment" + }, "remove_f47dc62a": { "message": "Remove" },