Skip to content

Commit

Permalink
Contentful/fix reply buttons (#149)
Browse files Browse the repository at this point in the history
* fix(contentful): replies format was different than expected by botonic react

* chore(contentful): improvements in eslint config
  • Loading branch information
dpinol authored Aug 26, 2019
1 parent 0259c57 commit d1a7071
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
23 changes: 19 additions & 4 deletions packages/botonic-plugin-contentful/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ module.exports = {
rules: {
// style. Soon a precommit githook will fix prettier errors
"prettier/prettier": "error",
"filenames/match-regex": [2, "^[a-z-.]+$", true],

"filenames/match-regex": ["warn", "^[a-z-.]+$", true],

// In typescript we must use obj.field when we have the types, and obj['field'] when we don't
// Not set to warn because Webstorm cannot fix eslint rules with --quiet https://youtrack.jetbrains.com/issue/WEB-39246
"dot-notation": "off",

"no-console" :"off",
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
"node/no-unsupported-features/es-syntax": "off", //babel will take care of ES compatibility
"unicorn/no-abusive-eslint-disable" : "off",
"@typescript-eslint/camelcase" : "warn",

// special for TYPESCRIPT
"@typescript-eslint/explicit-function-return-type": "off", // annoying for tests
Expand All @@ -51,13 +51,28 @@ module.exports = {
// allow public functions/classes to call private functions/classes declared below.
// otoh, variables (typically constants) should be declared at the top
"@typescript-eslint/no-use-before-define": ["error", { "variables": true, "functions": false, "classes": false }],
"@typescript-eslint/no-useless-constructor": "warn",
"@typescript-eslint/require-await": "error",
"no-empty-pattern" : "off",
"no-null/no-null": "warn", // fields declared with ? are undefined, not null (be aware that React uses null)
"unicorn/prevent-abbreviations" : "off", // the plugin removes removes type annotations from typescript code :-(
"unicorn/filename-case" : "off", // React convention is in CamelCase
"valid-jsdoc": "off", // function comments hide code complexity (and typescript already have type specifications),

},
"overrides": [
{
"files": [
"tests/**/*.ts" // to be able to skip required fields when not used in a particular test
],
"rules": {
"@typescript-eslint/no-object-literal-type-assertion" : "off",
}
}
],
settings: {
react: {
version: "detect" // Tells eslint-plugin-react to automatically detect the version of React to use
}
},
env: {
jest: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-plugin-contentful/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/botonic-plugin-contentful/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"build": "rm -rf lib && tsc",
"build_with_tests": "tsc -b tests/tsconfig.json",
"test": "jest",
"lint": "node_modules/.bin/eslint --fix --quiet 'src/**/*.ts*' 'tests/**/*.ts*'",
"lint": "node_modules/.bin/eslint --cache --fix --quiet 'src/**/*.ts*' 'tests/**/*.ts*'",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
"version": "git add -A src tests",
"postversion": "git push && git push --tags"
},
"name": "@botonic/plugin-contentful",
"version": "0.9.11",
"version": "0.9.12",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"dependencies": {
Expand Down
17 changes: 10 additions & 7 deletions packages/botonic-plugin-contentful/src/render/botonic-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ export class BotonicMsgConverter {
: this.options.maxQuickReplies;
cmsButtons = cmsButtons.slice(0, maxButtons);
return cmsButtons.map(cmsButton => {
return {
props: {
payload: cmsButton.callback.payload,
url: cmsButton.callback.url,
title: cmsButton.text
}
};
const msgButton = {
payload: cmsButton.callback.payload,
url: cmsButton.callback.url
} as any;
if (style == ButtonStyle.BUTTON) {
msgButton['title'] = cmsButton.text;
} else {
msgButton['text'] = cmsButton.text;
}
return msgButton;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ test('TEST: contentful text with URL button with followup', async () => {
);
expect(text.buttons).toHaveLength(1);
expect(text.buttons[0].text).toEqual('Acceda a su cuenta');
expect(text.buttons[0].callback.url).toEqual(
'https://shop.com/es/'
);
expect(text.buttons[0].callback.url).toEqual('https://shop.com/es/');
expect(text.followUp).not.toBeUndefined();
});

Expand Down

0 comments on commit d1a7071

Please sign in to comment.