{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/pontoon/pulls/comments/175424185","pull_request_review_id":104948613,"id":175424185,"diff_hunk":"@@ -0,0 +1,85 @@\n+\n+import React from 'react';\n+\n+import {ajax} from 'utils/ajax';\n+\n+\n+export class DataManager {\n+\n+    constructor (state) {\n+        this.state = state;\n+    }\n+\n+    get data () {\n+        return this.state.data;\n+    }\n+\n+    get errors () {\n+        return this.state.errors;\n+    }\n+}\n+\n+\n+export function dataManager(WrappedComponent, Manager, data) {\n+\n+    return class Wrapper extends React.Component {\n+\n+        constructor(props) {\n+            super(props);\n+            this.state = {errors: {}, data: data};\n+        }\n+\n+        get api () {\n+            return this.props.api;\n+        }\n+\n+        get requestMethod () {\n+            return this.props.requestMethod || 'get';\n+        }\n+\n+        get submitMethod () {\n+            return this.props.submitMethod || this.requestMethod;\n+        }\n+\n+        refreshData = async (params) => {\n+            return this.handleResponse(\n+                await ajax.fetch(\n+                    this.api,\n+                    params,\n+                    {method: this.requestMethod}));\n+        }\n+\n+        handleResponse = async (response) => {\n+            const {status} = response;\n+            const json = await response.json();\n+            if (status === 200) {\n+                const {data} = json;\n+                this.setState({data, errors: {}});\n+                return;\n+            }\n+            const {errors} = json;\n+            this.setState({errors});\n+        }\n+\n+        handleSubmit = async (params) => {\n+            return this.handleResponse(\n+                await ajax.fetch(\n+                    this.api,\n+                    params,\n+                    {method: this.requestMethod}));\n+        }\n+\n+        render() {\n+            Manager = Manager || DataManager;\n+            const manager = new Manager(this.state);\n+            return (\n+                <WrappedComponent\n+                   manager={manager}\n+                   errors={manager.errors}\n+                   data={manager.data}\n+                   handleSubmit={this.handleSubmit}\n+                   refreshData={this.refreshData}\n+                   {...this.props} />);\n+        }\n+    };\n+}","path":"pontoon/static/js/utils/data.js","position":85,"original_position":85,"commit_id":"f03c1ccd9b4e683e751d61564428a2847cbc550e","original_commit_id":"59cd2864fe8b308ee41c32e6f7fee57f85aeec4d","user":{"login":"phlax","id":454682,"avatar_url":"https://avatars3.githubusercontent.com/u/454682?v=4","gravatar_id":"","url":"https://api.github.com/users/phlax","html_url":"https://github.com/phlax","followers_url":"https://api.github.com/users/phlax/followers","following_url":"https://api.github.com/users/phlax/following{/other_user}","gists_url":"https://api.github.com/users/phlax/gists{/gist_id}","starred_url":"https://api.github.com/users/phlax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phlax/subscriptions","organizations_url":"https://api.github.com/users/phlax/orgs","repos_url":"https://api.github.com/users/phlax/repos","events_url":"https://api.github.com/users/phlax/events{/privacy}","received_events_url":"https://api.github.com/users/phlax/received_events","type":"User","site_admin":false},"body":"> what is not really addressed/factored into this code is how pages are reloaded with partial content <> full page loads\r\n\r\n@adngdb on this point i think it should `Object.assign(state.data, response.data)`","created_at":"2018-03-19T12:57:05Z","updated_at":"2018-03-19T12:57:06Z","html_url":"https://github.com/mozilla/pontoon/pull/857#discussion_r175424185","pull_request_url":"https://api.github.com/repos/mozilla/pontoon/pulls/857","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/comments/175424185"},"html":{"href":"https://github.com/mozilla/pontoon/pull/857#discussion_r175424185"},"pull_request":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/857"}},"in_reply_to_id":174857938},"pull_request":{"url":"https://api.github.com/repos/mozilla/pontoon/pulls/857","id":168824511,"html_url":"https://github.com/mozilla/pontoon/pull/857","diff_url":"https://github.com/mozilla/pontoon/pull/857.diff","patch_url":"https://github.com/mozilla/pontoon/pull/857.patch","issue_url":"https://api.github.com/repos/mozilla/pontoon/issues/857","number":857,"state":"closed","locked":false,"title":"Touch Bug 1243129: React data manager","user":{"login":"phlax","id":454682,"avatar_url":"https://avatars3.githubusercontent.com/u/454682?v=4","gravatar_id":"","url":"https://api.github.com/users/phlax","html_url":"https://github.com/phlax","followers_url":"https://api.github.com/users/phlax/followers","following_url":"https://api.github.com/users/phlax/following{/other_user}","gists_url":"https://api.github.com/users/phlax/gists{/gist_id}","starred_url":"https://api.github.com/users/phlax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phlax/subscriptions","organizations_url":"https://api.github.com/users/phlax/orgs","repos_url":"https://api.github.com/users/phlax/repos","events_url":"https://api.github.com/users/phlax/events{/privacy}","received_events_url":"https://api.github.com/users/phlax/received_events","type":"User","site_admin":false},"body":"Adds \r\n\r\n- ~~a data table component that fetches data and builds a reacttable component onMount~~\r\n- ~~a table with checkboxes that can be selected and submitted~~\r\n\r\nAdds a higher order component that wraps the wrapper component with a \"manager\" that retrieves/submits data from/to an api.\r\n\r\nThe wrapped component is passed `data`  and `errors` , and functions to `refreshData` and `handleSubmit` as props\r\n\r\n~~blocked by #854~~\r\n\r\nrequired for strings tiers project and admin views","created_at":"2018-02-13T11:52:02Z","updated_at":"2018-03-19T12:57:06Z","closed_at":"2018-03-15T17:45:06Z","merged_at":"2018-03-15T17:45:06Z","merge_commit_sha":"f03c1ccd9b4e683e751d61564428a2847cbc550e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/pontoon/pulls/857/commits","review_comments_url":"https://api.github.com/repos/mozilla/pontoon/pulls/857/comments","review_comment_url":"https://api.github.com/repos/mozilla/pontoon/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/pontoon/issues/857/comments","statuses_url":"https://api.github.com/repos/mozilla/pontoon/statuses/f03c1ccd9b4e683e751d61564428a2847cbc550e","head":{"label":"phlax:react-data-table","ref":"react-data-table","sha":"f03c1ccd9b4e683e751d61564428a2847cbc550e","user":{"login":"phlax","id":454682,"avatar_url":"https://avatars3.githubusercontent.com/u/454682?v=4","gravatar_id":"","url":"https://api.github.com/users/phlax","html_url":"https://github.com/phlax","followers_url":"https://api.github.com/users/phlax/followers","following_url":"https://api.github.com/users/phlax/following{/other_user}","gists_url":"https://api.github.com/users/phlax/gists{/gist_id}","starred_url":"https://api.github.com/users/phlax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phlax/subscriptions","organizations_url":"https://api.github.com/users/phlax/orgs","repos_url":"https://api.github.com/users/phlax/repos","events_url":"https://api.github.com/users/phlax/events{/privacy}","received_events_url":"https://api.github.com/users/phlax/received_events","type":"User","site_admin":false},"repo":{"id":108836144,"name":"pontoon","full_name":"phlax/pontoon","owner":{"login":"phlax","id":454682,"avatar_url":"https://avatars3.githubusercontent.com/u/454682?v=4","gravatar_id":"","url":"https://api.github.com/users/phlax","html_url":"https://github.com/phlax","followers_url":"https://api.github.com/users/phlax/followers","following_url":"https://api.github.com/users/phlax/following{/other_user}","gists_url":"https://api.github.com/users/phlax/gists{/gist_id}","starred_url":"https://api.github.com/users/phlax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phlax/subscriptions","organizations_url":"https://api.github.com/users/phlax/orgs","repos_url":"https://api.github.com/users/phlax/repos","events_url":"https://api.github.com/users/phlax/events{/privacy}","received_events_url":"https://api.github.com/users/phlax/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/phlax/pontoon","description":"Localization tool used at Mozilla","fork":true,"url":"https://api.github.com/repos/phlax/pontoon","forks_url":"https://api.github.com/repos/phlax/pontoon/forks","keys_url":"https://api.github.com/repos/phlax/pontoon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phlax/pontoon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phlax/pontoon/teams","hooks_url":"https://api.github.com/repos/phlax/pontoon/hooks","issue_events_url":"https://api.github.com/repos/phlax/pontoon/issues/events{/number}","events_url":"https://api.github.com/repos/phlax/pontoon/events","assignees_url":"https://api.github.com/repos/phlax/pontoon/assignees{/user}","branches_url":"https://api.github.com/repos/phlax/pontoon/branches{/branch}","tags_url":"https://api.github.com/repos/phlax/pontoon/tags","blobs_url":"https://api.github.com/repos/phlax/pontoon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phlax/pontoon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phlax/pontoon/git/refs{/sha}","trees_url":"https://api.github.com/repos/phlax/pontoon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phlax/pontoon/statuses/{sha}","languages_url":"https://api.github.com/repos/phlax/pontoon/languages","stargazers_url":"https://api.github.com/repos/phlax/pontoon/stargazers","contributors_url":"https://api.github.com/repos/phlax/pontoon/contributors","subscribers_url":"https://api.github.com/repos/phlax/pontoon/subscribers","subscription_url":"https://api.github.com/repos/phlax/pontoon/subscription","commits_url":"https://api.github.com/repos/phlax/pontoon/commits{/sha}","git_commits_url":"https://api.github.com/repos/phlax/pontoon/git/commits{/sha}","comments_url":"https://api.github.com/repos/phlax/pontoon/comments{/number}","issue_comment_url":"https://api.github.com/repos/phlax/pontoon/issues/comments{/number}","contents_url":"https://api.github.com/repos/phlax/pontoon/contents/{+path}","compare_url":"https://api.github.com/repos/phlax/pontoon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phlax/pontoon/merges","archive_url":"https://api.github.com/repos/phlax/pontoon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phlax/pontoon/downloads","issues_url":"https://api.github.com/repos/phlax/pontoon/issues{/number}","pulls_url":"https://api.github.com/repos/phlax/pontoon/pulls{/number}","milestones_url":"https://api.github.com/repos/phlax/pontoon/milestones{/number}","notifications_url":"https://api.github.com/repos/phlax/pontoon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phlax/pontoon/labels{/name}","releases_url":"https://api.github.com/repos/phlax/pontoon/releases{/id}","deployments_url":"https://api.github.com/repos/phlax/pontoon/deployments","created_at":"2017-10-30T10:34:33Z","updated_at":"2018-03-18T12:44:30Z","pushed_at":"2018-03-19T12:30:33Z","git_url":"git://github.com/phlax/pontoon.git","ssh_url":"git@github.com:phlax/pontoon.git","clone_url":"https://github.com/phlax/pontoon.git","svn_url":"https://github.com/phlax/pontoon","homepage":"https://pontoon.mozilla.org/","size":22492,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"e07e271e0802e5ea1a85532b5076f3d6388dd7e4","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars2.githubusercontent.com/u/131524?v=4","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":1385890,"name":"pontoon","full_name":"mozilla/pontoon","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars2.githubusercontent.com/u/131524?v=4","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/pontoon","description":"Localization tool used at Mozilla","fork":false,"url":"https://api.github.com/repos/mozilla/pontoon","forks_url":"https://api.github.com/repos/mozilla/pontoon/forks","keys_url":"https://api.github.com/repos/mozilla/pontoon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/pontoon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/pontoon/teams","hooks_url":"https://api.github.com/repos/mozilla/pontoon/hooks","issue_events_url":"https://api.github.com/repos/mozilla/pontoon/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/pontoon/events","assignees_url":"https://api.github.com/repos/mozilla/pontoon/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/pontoon/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/pontoon/tags","blobs_url":"https://api.github.com/repos/mozilla/pontoon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/pontoon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/pontoon/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/pontoon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/pontoon/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/pontoon/languages","stargazers_url":"https://api.github.com/repos/mozilla/pontoon/stargazers","contributors_url":"https://api.github.com/repos/mozilla/pontoon/contributors","subscribers_url":"https://api.github.com/repos/mozilla/pontoon/subscribers","subscription_url":"https://api.github.com/repos/mozilla/pontoon/subscription","commits_url":"https://api.github.com/repos/mozilla/pontoon/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/pontoon/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/pontoon/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/pontoon/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/pontoon/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/pontoon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/pontoon/merges","archive_url":"https://api.github.com/repos/mozilla/pontoon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/pontoon/downloads","issues_url":"https://api.github.com/repos/mozilla/pontoon/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/pontoon/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/pontoon/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/pontoon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/pontoon/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/pontoon/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla/pontoon/deployments","created_at":"2011-02-19T11:25:51Z","updated_at":"2018-03-19T10:04:10Z","pushed_at":"2018-03-19T12:30:34Z","git_url":"git://github.com/mozilla/pontoon.git","ssh_url":"git@github.com:mozilla/pontoon.git","clone_url":"https://github.com/mozilla/pontoon.git","svn_url":"https://github.com/mozilla/pontoon","homepage":"https://pontoon.mozilla.org/","size":22240,"stargazers_count":365,"watchers_count":365,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":111,"mirror_url":null,"archived":false,"open_issues_count":17,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":111,"open_issues":17,"watchers":365,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/857"},"html":{"href":"https://github.com/mozilla/pontoon/pull/857"},"issue":{"href":"https://api.github.com/repos/mozilla/pontoon/issues/857"},"comments":{"href":"https://api.github.com/repos/mozilla/pontoon/issues/857/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/857/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/857/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/pontoon/statuses/f03c1ccd9b4e683e751d61564428a2847cbc550e"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"phlax"}}