{"action":"created","comment":{"url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/comments/86979242","pull_request_review_id":7608863,"id":86979242,"diff_hunk":"@@ -0,0 +1,107 @@\n+'use strict';\n+\n+const _ = require('lodash');\n+\n+module.exports = class Helpers {\n+  /**\n+   * Utility function which returns the\n+   * name of the step a field is present on\n+   * @param {String} field - id of the field\n+   * @param {Object} steps - steps config object\n+   * @returns {String} - the key of the step where field is found\n+   */\n+  static getStepFromFieldName(field, steps) {\n+    return _.findKey(steps, step => step.fields && step.fields.indexOf(field) > -1);\n+  }\n+\n+  /**\n+   * Alternative 'falsy' check which doesn't\n+   * return false for 0 or false\n+   * @param {any} value - the value to check\n+   * @returns {Boolean} - if the value is 'empty'\n+   */\n+  static isEmptyValue(value) {\n+    return value === undefined || value === null || value === '';\n+  }\n+\n+  /**\n+   * Utility function which returns true\n+   * if a field type has associated options\n+   * @param {String} mixin - the name of the mixin\n+   * @returns {Boolean} - if the mixin has associated options\n+   */\n+  static hasOptions(mixin) {\n+    return mixin === 'radio-group' || mixin === 'checkbox-group' || mixin === 'select';\n+  }\n+\n+  /**\n+   * helper function for looking up values in\n+   * fields that have options\n+   * @param {Function} translate - translate function\n+   * @param {String} field - the id of the field\n+   * @param {any} value - the value of the field\n+   * @returns {any} the translation of the label if found,\n+   * the raw value if not\n+   */\n+   static getValue(translate, field, value) {\n+     let key = `fields.${field}.options.${value}.label`;\n+     let result = translate(key);\n+     if (result !== key) {\n+       return result;\n+     }\n+     return value;\n+  }\n+\n+  /**\n+   * utility function which returns undefined on\n+   * failed translations instead of returning the key\n+   * @param {Function} translate - the translate funtion\n+   * @param {String} key - the key to translate\n+   * @returns {String|undefined} the string result if successful, undefined if not\n+   */\n+   static conditionalTranslate(translate, key) {\n+     let result = translate(key);\n+     if (result !== key) {\n+       return result;\n+     }\n+   }\n+\n+  /**\n+   * Utility function which looks up translations with fallback values\n+   * If the translation is for a field, it will first try fields.key.summary\n+   * If this fails it will try fields.key.label, if this fails it will try\n+   * fields.key.legend (radio-group and checkbox-group).\n+   *\n+   * If the translation is not for a field it will first try pages.key.summary,\n+   * if this fails it will fallback to pages.keys.header.\n+   * @param {Function} translate - translate function\n+   * @param {String} key - the key of the field/page\n+   * @param {Boolean} isField - if the translation is for a field\n+   * @return {String} the result of the translation\n+   */\n+  static getTranslation(translate, key, isField) {\n+    const base = isField ? 'fields' : 'pages';\n+    let path = `${base}.${key}.summary`;\n+    let result = translate(path);\n+    if (result === path) {\n+      if (isField) {\n+        path = `${base}.${key}.label`;\n+        result = translate(path);\n+        if (result === path) {\n+          path = `${base}.${key}.legend`;\n+          result = translate(path);\n+          if (result === path) {\n+            return key;\n+          }\n+        }\n+      } else {\n+        path = `${base}.${key}.header`;\n+        result = translate(path);\n+        if (result === path) {\n+          return key;\n+        }\n+      }","path":"lib/util/helpers.js","position":103,"original_position":103,"commit_id":"a60609529192beee0abf68d190ba7a7a1c475dbc","original_commit_id":"a60609529192beee0abf68d190ba7a7a1c475dbc","user":{"login":"joefitter","id":3604142,"avatar_url":"https://avatars.githubusercontent.com/u/3604142?v=3","gravatar_id":"","url":"https://api.github.com/users/joefitter","html_url":"https://github.com/joefitter","followers_url":"https://api.github.com/users/joefitter/followers","following_url":"https://api.github.com/users/joefitter/following{/other_user}","gists_url":"https://api.github.com/users/joefitter/gists{/gist_id}","starred_url":"https://api.github.com/users/joefitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joefitter/subscriptions","organizations_url":"https://api.github.com/users/joefitter/orgs","repos_url":"https://api.github.com/users/joefitter/repos","events_url":"https://api.github.com/users/joefitter/events{/privacy}","received_events_url":"https://api.github.com/users/joefitter/received_events","type":"User","site_admin":false},"body":"@danielepolencic I haven't updated this yet as up to my eyeballs in project work, but there is a potentially nicer solution used elsewhere in the architecture - i18n-lookup (one of Lenny's packages) - pass in an array of keys and it returns the first one found","created_at":"2016-11-08T12:34:37Z","updated_at":"2016-11-08T12:34:37Z","html_url":"https://github.com/UKHomeOfficeForms/hof-controllers/pull/89#discussion_r86979242","pull_request_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/89","_links":{"self":{"href":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/comments/86979242"},"html":{"href":"https://github.com/UKHomeOfficeForms/hof-controllers/pull/89#discussion_r86979242"},"pull_request":{"href":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/89"}}},"pull_request":{"url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/89","id":92126530,"html_url":"https://github.com/UKHomeOfficeForms/hof-controllers/pull/89","diff_url":"https://github.com/UKHomeOfficeForms/hof-controllers/pull/89.diff","patch_url":"https://github.com/UKHomeOfficeForms/hof-controllers/pull/89.patch","issue_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/issues/89","number":89,"state":"open","locked":false,"title":"Patch so master to master","user":{"login":"joefitter","id":3604142,"avatar_url":"https://avatars.githubusercontent.com/u/3604142?v=3","gravatar_id":"","url":"https://api.github.com/users/joefitter","html_url":"https://github.com/joefitter","followers_url":"https://api.github.com/users/joefitter/followers","following_url":"https://api.github.com/users/joefitter/following{/other_user}","gists_url":"https://api.github.com/users/joefitter/gists{/gist_id}","starred_url":"https://api.github.com/users/joefitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joefitter/subscriptions","organizations_url":"https://api.github.com/users/joefitter/orgs","repos_url":"https://api.github.com/users/joefitter/repos","events_url":"https://api.github.com/users/joefitter/events{/privacy}","received_events_url":"https://api.github.com/users/joefitter/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-11-03T10:31:02Z","updated_at":"2016-11-08T12:34:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a05a77893ceba6c0af0b0265df9ca302c2a3b01","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/89/commits","review_comments_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/89/comments","review_comment_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/comments{/number}","comments_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/issues/89/comments","statuses_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/statuses/a60609529192beee0abf68d190ba7a7a1c475dbc","head":{"label":"UKHomeOfficeForms:patch-so-master-to-master","ref":"patch-so-master-to-master","sha":"a60609529192beee0abf68d190ba7a7a1c475dbc","user":{"login":"UKHomeOfficeForms","id":23336489,"avatar_url":"https://avatars.githubusercontent.com/u/23336489?v=3","gravatar_id":"","url":"https://api.github.com/users/UKHomeOfficeForms","html_url":"https://github.com/UKHomeOfficeForms","followers_url":"https://api.github.com/users/UKHomeOfficeForms/followers","following_url":"https://api.github.com/users/UKHomeOfficeForms/following{/other_user}","gists_url":"https://api.github.com/users/UKHomeOfficeForms/gists{/gist_id}","starred_url":"https://api.github.com/users/UKHomeOfficeForms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UKHomeOfficeForms/subscriptions","organizations_url":"https://api.github.com/users/UKHomeOfficeForms/orgs","repos_url":"https://api.github.com/users/UKHomeOfficeForms/repos","events_url":"https://api.github.com/users/UKHomeOfficeForms/events{/privacy}","received_events_url":"https://api.github.com/users/UKHomeOfficeForms/received_events","type":"Organization","site_admin":false},"repo":{"id":45553140,"name":"hof-controllers","full_name":"UKHomeOfficeForms/hof-controllers","owner":{"login":"UKHomeOfficeForms","id":23336489,"avatar_url":"https://avatars.githubusercontent.com/u/23336489?v=3","gravatar_id":"","url":"https://api.github.com/users/UKHomeOfficeForms","html_url":"https://github.com/UKHomeOfficeForms","followers_url":"https://api.github.com/users/UKHomeOfficeForms/followers","following_url":"https://api.github.com/users/UKHomeOfficeForms/following{/other_user}","gists_url":"https://api.github.com/users/UKHomeOfficeForms/gists{/gist_id}","starred_url":"https://api.github.com/users/UKHomeOfficeForms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UKHomeOfficeForms/subscriptions","organizations_url":"https://api.github.com/users/UKHomeOfficeForms/orgs","repos_url":"https://api.github.com/users/UKHomeOfficeForms/repos","events_url":"https://api.github.com/users/UKHomeOfficeForms/events{/privacy}","received_events_url":"https://api.github.com/users/UKHomeOfficeForms/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/UKHomeOfficeForms/hof-controllers","description":"A collection of controllers commonly used in HOF","fork":false,"url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers","forks_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/forks","keys_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/teams","hooks_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/hooks","issue_events_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/issues/events{/number}","events_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/events","assignees_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/assignees{/user}","branches_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/branches{/branch}","tags_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/tags","blobs_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/git/refs{/sha}","trees_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/statuses/{sha}","languages_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/languages","stargazers_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/stargazers","contributors_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/contributors","subscribers_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/subscribers","subscription_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/subscription","commits_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/commits{/sha}","git_commits_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/git/commits{/sha}","comments_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/comments{/number}","issue_comment_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/issues/comments{/number}","contents_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/contents/{+path}","compare_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/merges","archive_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/downloads","issues_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/issues{/number}","pulls_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls{/number}","milestones_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/milestones{/number}","notifications_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/labels{/name}","releases_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/releases{/id}","deployments_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/deployments","created_at":"2015-11-04T16:48:58Z","updated_at":"2016-11-08T12:31:59Z","pushed_at":"2016-11-03T13:17:19Z","git_url":"git://github.com/UKHomeOfficeForms/hof-controllers.git","ssh_url":"git@github.com:UKHomeOfficeForms/hof-controllers.git","clone_url":"https://github.com/UKHomeOfficeForms/hof-controllers.git","svn_url":"https://github.com/UKHomeOfficeForms/hof-controllers","homepage":null,"size":171,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":14,"forks":4,"open_issues":14,"watchers":1,"default_branch":"master"}},"base":{"label":"UKHomeOfficeForms:master","ref":"master","sha":"a4225b7eb81c526c2250bc8afd984d92efca4b51","user":{"login":"UKHomeOfficeForms","id":23336489,"avatar_url":"https://avatars.githubusercontent.com/u/23336489?v=3","gravatar_id":"","url":"https://api.github.com/users/UKHomeOfficeForms","html_url":"https://github.com/UKHomeOfficeForms","followers_url":"https://api.github.com/users/UKHomeOfficeForms/followers","following_url":"https://api.github.com/users/UKHomeOfficeForms/following{/other_user}","gists_url":"https://api.github.com/users/UKHomeOfficeForms/gists{/gist_id}","starred_url":"https://api.github.com/users/UKHomeOfficeForms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UKHomeOfficeForms/subscriptions","organizations_url":"https://api.github.com/users/UKHomeOfficeForms/orgs","repos_url":"https://api.github.com/users/UKHomeOfficeForms/repos","events_url":"https://api.github.com/users/UKHomeOfficeForms/events{/privacy}","received_events_url":"https://api.github.com/users/UKHomeOfficeForms/received_events","type":"Organization","site_admin":false},"repo":{"id":45553140,"name":"hof-controllers","full_name":"UKHomeOfficeForms/hof-controllers","owner":{"login":"UKHomeOfficeForms","id":23336489,"avatar_url":"https://avatars.githubusercontent.com/u/23336489?v=3","gravatar_id":"","url":"https://api.github.com/users/UKHomeOfficeForms","html_url":"https://github.com/UKHomeOfficeForms","followers_url":"https://api.github.com/users/UKHomeOfficeForms/followers","following_url":"https://api.github.com/users/UKHomeOfficeForms/following{/other_user}","gists_url":"https://api.github.com/users/UKHomeOfficeForms/gists{/gist_id}","starred_url":"https://api.github.com/users/UKHomeOfficeForms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UKHomeOfficeForms/subscriptions","organizations_url":"https://api.github.com/users/UKHomeOfficeForms/orgs","repos_url":"https://api.github.com/users/UKHomeOfficeForms/repos","events_url":"https://api.github.com/users/UKHomeOfficeForms/events{/privacy}","received_events_url":"https://api.github.com/users/UKHomeOfficeForms/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/UKHomeOfficeForms/hof-controllers","description":"A collection of controllers commonly used in HOF","fork":false,"url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers","forks_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/forks","keys_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/teams","hooks_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/hooks","issue_events_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/issues/events{/number}","events_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/events","assignees_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/assignees{/user}","branches_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/branches{/branch}","tags_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/tags","blobs_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/git/refs{/sha}","trees_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/statuses/{sha}","languages_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/languages","stargazers_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/stargazers","contributors_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/contributors","subscribers_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/subscribers","subscription_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/subscription","commits_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/commits{/sha}","git_commits_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/git/commits{/sha}","comments_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/comments{/number}","issue_comment_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/issues/comments{/number}","contents_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/contents/{+path}","compare_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/merges","archive_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/downloads","issues_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/issues{/number}","pulls_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls{/number}","milestones_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/milestones{/number}","notifications_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/labels{/name}","releases_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/releases{/id}","deployments_url":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/deployments","created_at":"2015-11-04T16:48:58Z","updated_at":"2016-11-08T12:31:59Z","pushed_at":"2016-11-03T13:17:19Z","git_url":"git://github.com/UKHomeOfficeForms/hof-controllers.git","ssh_url":"git@github.com:UKHomeOfficeForms/hof-controllers.git","clone_url":"https://github.com/UKHomeOfficeForms/hof-controllers.git","svn_url":"https://github.com/UKHomeOfficeForms/hof-controllers","homepage":null,"size":171,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":14,"forks":4,"open_issues":14,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/89"},"html":{"href":"https://github.com/UKHomeOfficeForms/hof-controllers/pull/89"},"issue":{"href":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/issues/89"},"comments":{"href":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/issues/89/comments"},"review_comments":{"href":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/89/comments"},"review_comment":{"href":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/pulls/89/commits"},"statuses":{"href":"https://api.github.com/repos/UKHomeOfficeForms/hof-controllers/statuses/a60609529192beee0abf68d190ba7a7a1c475dbc"}}}}
{"actor":{"display_login":"joefitter"}}