Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't update template variables if tab is never visited #1225

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 3 additions & 42 deletions src/components/flow/actions/sendmsg/SendMsgForm.module.scss
Original file line number Diff line number Diff line change
@@ -1,42 +1,3 @@
@import 'variables.module.scss';

.checkbox {
margin-top: 20px;
}

.quick_reply_summary {
margin-top: -20px;
position: relative;
}


.existing_quick_replies {
padding: 5px;
border-radius: 5px;
border: 1px solid $light_gray;

.existing_quick_reply {
margin: 2px;
display: inline-block;
}
}

.add_quick_replies {
margin-top: 10px;
}

.template_text {
margin-top: 10px;
padding: 10px;
background: $light_gray_2;
border-radius: 5px;
margin-bottom: 10px;
}

.variable {
margin-bottom: 6px;
}

temba-completion {
--textarea-height: 120px;
}
.message {
--textarea-height: 8em;
}
2 changes: 2 additions & 0 deletions src/components/flow/actions/sendmsg/SendMsgForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import i18n from 'config/i18n';
import { Trans } from 'react-i18next';
import { Attachment, renderAttachments } from './attachments';
import { TembaComponent } from 'temba/TembaComponent';
import styles from './SendMsgForm.module.scss';

export interface SendMsgFormState extends FormState {
message: StringEntry;
Expand Down Expand Up @@ -400,6 +401,7 @@ export default class SendMsgForm extends React.Component<ActionFormProps, SendMs
>
<TypeList __className="" initialType={typeConfig} onChange={this.props.onTypeChange} />
<TextInputElement
__className={styles.message}
name={i18n.t('forms.message', 'Message')}
showLabel={false}
counter=".sms-counter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ exports[`SendMsgForm render should render 1`] = `
onChange={[MockFunction]}
/>
<TextInputElement
__className="message"
autocomplete={true}
counter=".sms-counter"
entry={
Expand Down
48 changes: 29 additions & 19 deletions src/components/flow/actions/sendmsg/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,38 @@

let templating: MsgTemplating = null;
if (state.template && state.template.value) {
const components = Object.keys(state.templateTranslation.components).map((key: string) => {
let uuid = createUUID();

// try looking up the uuid from the original action
if (settings.originalAction && settings.originalAction.type === Types.send_msg) {
const originalAction = settings.originalAction as SendMsg;
if (originalAction.templating) {
const originalComponent = originalAction.templating.components.find(
(component: any) => component.name === key
);
if (originalComponent) {
uuid = originalComponent.uuid;
const originalAction =
settings.originalAction.type === Types.send_msg ? (settings.originalAction as SendMsg) : null;

let components =
originalAction.templating && originalAction.templating.components
? originalAction.templating.components
: [];

if (state.templateTranslation) {
components = Object.keys(state.templateTranslation.components).map((key: string) => {
let uuid = createUUID();

Check warning on line 105 in src/components/flow/actions/sendmsg/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/components/flow/actions/sendmsg/helpers.ts#L104-L105

Added lines #L104 - L105 were not covered by tests

// try looking up the uuid from the original action
if (settings.originalAction && settings.originalAction.type === Types.send_msg) {
const originalAction = settings.originalAction as SendMsg;

Check warning on line 109 in src/components/flow/actions/sendmsg/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/components/flow/actions/sendmsg/helpers.ts#L109

Added line #L109 was not covered by tests
if (originalAction.templating) {
const originalComponent = originalAction.templating.components.find(
(component: any) => component.name === key

Check warning on line 112 in src/components/flow/actions/sendmsg/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/components/flow/actions/sendmsg/helpers.ts#L111-L112

Added lines #L111 - L112 were not covered by tests
);
if (originalComponent) {
uuid = originalComponent.uuid;

Check warning on line 115 in src/components/flow/actions/sendmsg/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/components/flow/actions/sendmsg/helpers.ts#L115

Added line #L115 was not covered by tests
}
}
}
}

return {
uuid,
name: key,
params: state.paramsByTemplate[state.template.value.uuid][key]
};
});
return {

Check warning on line 120 in src/components/flow/actions/sendmsg/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/components/flow/actions/sendmsg/helpers.ts#L120

Added line #L120 was not covered by tests
uuid,
name: key,
params: state.paramsByTemplate[state.template.value.uuid][key]
};
});
}

templating = {
template: {
Expand Down
Loading