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

Contentful/fix reply buttons #149

Merged
merged 2 commits into from
Aug 26, 2019
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
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