Skip to content

Commit

Permalink
Merge pull request #1229 from nyaruka/update-template-editor
Browse files Browse the repository at this point in the history
Update template editor for comps as list
  • Loading branch information
ericnewcomer authored Mar 29, 2024
2 parents 9f2a09b + bef327d commit 1199bc4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-react": "7.0.0",
"@nyaruka/temba-components": "0.75.0",
"@nyaruka/temba-components": "0.77.0",
"@testing-library/jest-dom": "4.0.0",
"@testing-library/react": "8.0.1",
"@types/common-tags": "^1.8.0",
Expand Down
13 changes: 6 additions & 7 deletions src/components/flow/actions/sendmsg/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { getActionUUID } from 'components/flow/actions/helpers';
import { SendMsgFormState } from 'components/flow/actions/sendmsg/SendMsgForm';
import { Types } from 'config/interfaces';
import { MsgTemplating, SendMsg } from 'flowTypes';
import { Component, MsgTemplating, SendMsg } from 'flowTypes';
import { FormEntry, NodeEditorSettings } from 'store/nodeEditor';
import { SelectOption } from 'components/form/select/SelectElement';
import { Attachment } from './attachments';
Expand All @@ -18,7 +18,6 @@ export const TOPIC_OPTIONS: SelectOption[] = [

export const initializeForm = (settings: NodeEditorSettings): SendMsgFormState => {
let template: FormEntry = { value: null };

if (settings.originalAction && settings.originalAction.type === Types.send_msg) {
const action = settings.originalAction as SendMsg;
const attachments: Attachment[] = [];
Expand Down Expand Up @@ -49,6 +48,7 @@ export const initializeForm = (settings: NodeEditorSettings): SendMsgFormState =
paramsByTemplate = {
[action.templating.template.uuid]: {}
};

action.templating.components.forEach((component: any) => {
paramsByTemplate[action.templating.template.uuid][component.name] = component.params;
});
Expand Down Expand Up @@ -101,15 +101,14 @@ export const stateToAction = (settings: NodeEditorSettings, state: SendMsgFormSt
: [];

if (state.templateTranslation) {
components = Object.keys(state.templateTranslation.components).map((key: string) => {
components = state.templateTranslation.components.map((comp: Component) => {
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
(component: any) => component.name === comp.name
);
if (originalComponent) {
uuid = originalComponent.uuid;
Expand All @@ -119,8 +118,8 @@ export const stateToAction = (settings: NodeEditorSettings, state: SendMsgFormSt

return {
uuid,
name: key,
params: state.paramsByTemplate[state.template.value.uuid][key]
name: comp.name,
params: state.paramsByTemplate[state.template.value.uuid][comp.name]
};
});
}
Expand Down
8 changes: 7 additions & 1 deletion src/flowTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,19 @@ export interface RecipientsAction extends Action {
legacy_vars?: string[];
}

export interface Component {
name: string;
params: string[];
content: string;
}

export interface TemplateTranslation {
channel: Channel;
content: string;
language: string;
status: string;
variable_count: number;
components: { [key: string]: { params: string[]; content: string } };
components: Component[];
}

export interface TemplateOptions {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1496,10 +1496,10 @@
"@nodelib/fs.scandir" "2.1.3"
fastq "^1.6.0"

"@nyaruka/temba-components@0.75.0":
version "0.75.0"
resolved "https://registry.yarnpkg.com/@nyaruka/temba-components/-/temba-components-0.75.0.tgz#3ff7b415c228f32d8b2d3c72f889e5889faf3fc1"
integrity sha512-7j4cJK/dy+t21rIGMjSw78zNA8aCmEdbZOjw8w9GThS/SLMSbh4m0DAsDSBSfQDrtjUrCxST+5eIf6XcNqW0xw==
"@nyaruka/temba-components@0.77.0":
version "0.77.0"
resolved "https://registry.yarnpkg.com/@nyaruka/temba-components/-/temba-components-0.77.0.tgz#f9209ef944d79c222f04aeb1b3a5dfa808ba4888"
integrity sha512-ppzvT6tVRQ9t/r8/I048Y0hWxNtI6ltXO5xKGbBm40i41BR1QIwr7/W+13slR9epPBCrWh4dTpDU9FFjnWiZcA==
dependencies:
"@lit/localize" "^0.11.4"
color-hash "^2.0.2"
Expand Down

0 comments on commit 1199bc4

Please sign in to comment.