decidim-comments 0.23.6 → 0.24.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/comments/bundle.js.map +1 -1
  3. data/app/assets/javascripts/decidim/comments/comments.component.js.es6 +292 -0
  4. data/app/assets/javascripts/decidim/comments/comments.component.test.js +581 -0
  5. data/app/assets/javascripts/decidim/comments/comments.js.erb +1 -1
  6. data/app/cells/decidim/comments/comment/actions.erb +7 -0
  7. data/app/cells/decidim/comments/comment/alignment_badge.erb +4 -0
  8. data/app/cells/decidim/comments/comment/author.erb +1 -0
  9. data/app/cells/decidim/comments/comment/show.erb +40 -0
  10. data/app/cells/decidim/comments/comment/utilities.erb +13 -0
  11. data/app/cells/decidim/comments/comment/votes.erb +25 -0
  12. data/app/cells/decidim/comments/comment_card_cell.rb +22 -0
  13. data/app/cells/decidim/comments/comment_cell.rb +142 -8
  14. data/app/cells/decidim/comments/comment_form/comment_as.erb +10 -0
  15. data/app/cells/decidim/comments/comment_form/show.erb +24 -0
  16. data/app/cells/decidim/comments/comment_form_cell.rb +94 -0
  17. data/app/cells/decidim/comments/comment_m/top.erb +1 -1
  18. data/app/cells/decidim/comments/comment_thread/show.erb +6 -0
  19. data/app/cells/decidim/comments/comment_thread/title.erb +3 -0
  20. data/app/cells/decidim/comments/comment_thread_cell.rb +30 -0
  21. data/app/cells/decidim/comments/comments/add_comment.erb +30 -0
  22. data/app/cells/decidim/comments/comments/blocked_comments_warning.erb +3 -0
  23. data/app/cells/decidim/comments/comments/order_control.erb +37 -0
  24. data/app/cells/decidim/comments/comments/show.erb +32 -0
  25. data/app/cells/decidim/comments/comments/single_comment_warning.erb +9 -0
  26. data/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb +3 -0
  27. data/app/cells/decidim/comments/comments_cell.rb +134 -0
  28. data/app/commands/decidim/comments/vote_comment.rb +34 -10
  29. data/app/controllers/decidim/comments/application_controller.rb +16 -0
  30. data/app/controllers/decidim/comments/comments_controller.rb +122 -0
  31. data/app/controllers/decidim/comments/votes_controller.rb +41 -0
  32. data/app/events/decidim/comments/comment_created_event.rb +1 -1
  33. data/app/events/decidim/comments/comment_downvoted_event.rb +8 -0
  34. data/app/events/decidim/comments/comment_upvoted_event.rb +8 -0
  35. data/app/events/decidim/comments/comment_voted_event.rb +26 -0
  36. data/app/forms/decidim/comments/comment_form.rb +6 -2
  37. data/app/models/decidim/comments/comment.rb +22 -8
  38. data/app/models/decidim/comments/seed.rb +1 -1
  39. data/app/permissions/decidim/comments/permissions.rb +59 -0
  40. data/app/queries/decidim/comments/metrics/comment_participants_metric_measure.rb +2 -2
  41. data/app/queries/decidim/comments/metrics/comments_metric_manage.rb +5 -6
  42. data/app/queries/decidim/comments/sorted_comments.rb +18 -14
  43. data/app/views/decidim/comments/comments/_comment.html.erb +5 -0
  44. data/app/views/decidim/comments/comments/_comments.html.erb +1 -0
  45. data/app/views/decidim/comments/comments/create.js.erb +16 -0
  46. data/app/views/decidim/comments/comments/error.js.erb +1 -0
  47. data/app/views/decidim/comments/comments/index.js.erb +24 -0
  48. data/app/views/decidim/comments/comments/reload.js.erb +21 -0
  49. data/app/views/decidim/comments/votes/create.js.erb +23 -0
  50. data/app/views/decidim/comments/votes/error.js.erb +1 -0
  51. data/config/locales/ar.yml +0 -2
  52. data/config/locales/ca.yml +7 -2
  53. data/config/locales/cs.yml +24 -7
  54. data/config/locales/de.yml +17 -2
  55. data/config/locales/el.yml +0 -2
  56. data/config/locales/en.yml +17 -2
  57. data/config/locales/es-MX.yml +7 -2
  58. data/config/locales/es-PY.yml +7 -2
  59. data/config/locales/es.yml +7 -2
  60. data/config/locales/eu.yml +0 -2
  61. data/config/locales/fi-plain.yml +17 -2
  62. data/config/locales/fi.yml +17 -2
  63. data/config/locales/fr-CA.yml +17 -2
  64. data/config/locales/fr.yml +17 -2
  65. data/config/locales/gl.yml +7 -2
  66. data/config/locales/hu.yml +0 -2
  67. data/config/locales/id-ID.yml +0 -2
  68. data/config/locales/is-IS.yml +0 -1
  69. data/config/locales/it.yml +4 -2
  70. data/config/locales/ja.yml +8 -4
  71. data/config/locales/lv.yml +0 -2
  72. data/config/locales/nl.yml +0 -2
  73. data/config/locales/no.yml +0 -2
  74. data/config/locales/pl.yml +19 -2
  75. data/config/locales/pt-BR.yml +0 -2
  76. data/config/locales/pt.yml +0 -2
  77. data/config/locales/ro-RO.yml +0 -3
  78. data/config/locales/ru.yml +0 -2
  79. data/config/locales/sk.yml +0 -2
  80. data/config/locales/sv.yml +7 -2
  81. data/config/locales/tr-TR.yml +7 -2
  82. data/config/locales/uk.yml +0 -1
  83. data/config/locales/zh-CN.yml +0 -2
  84. data/lib/decidim/api/add_comment_type.rb +13 -0
  85. data/lib/decidim/api/comment_mutation_type.rb +22 -0
  86. data/lib/decidim/api/comment_type.rb +89 -0
  87. data/lib/decidim/api/commentable_interface.rb +50 -0
  88. data/lib/decidim/api/commentable_mutation_type.rb +30 -0
  89. data/{app/types/decidim/comments → lib/decidim/api}/commentable_type.rb +2 -5
  90. data/lib/decidim/comments/api.rb +12 -0
  91. data/lib/decidim/comments/comments_helper.rb +10 -52
  92. data/lib/decidim/comments/engine.rb +9 -7
  93. data/lib/decidim/comments/mutation_extensions.rb +22 -22
  94. data/lib/decidim/comments/query_extensions.rb +12 -14
  95. data/lib/decidim/comments/test/shared_examples/comment_voted_event.rb +65 -0
  96. data/lib/decidim/comments/test.rb +1 -0
  97. data/lib/decidim/comments/version.rb +1 -1
  98. data/lib/decidim/comments.rb +1 -3
  99. metadata +67 -66
  100. data/app/assets/javascripts/decidim/comments/bundle.js +0 -268
  101. data/app/frontend/application/apollo_client.ts +0 -12
  102. data/app/frontend/application/application.component.test.tsx +0 -23
  103. data/app/frontend/application/application.component.tsx +0 -35
  104. data/app/frontend/application/icon.component.test.tsx +0 -38
  105. data/app/frontend/application/icon.component.tsx +0 -46
  106. data/app/frontend/comments/add_comment_form.component.test.tsx +0 -265
  107. data/app/frontend/comments/add_comment_form.component.tsx +0 -482
  108. data/app/frontend/comments/comment.component.test.tsx +0 -490
  109. data/app/frontend/comments/comment.component.tsx +0 -677
  110. data/app/frontend/comments/comment_order_selector.component.test.tsx +0 -29
  111. data/app/frontend/comments/comment_order_selector.component.tsx +0 -106
  112. data/app/frontend/comments/comment_thread.component.test.tsx +0 -82
  113. data/app/frontend/comments/comment_thread.component.tsx +0 -81
  114. data/app/frontend/comments/comments.component.test.tsx +0 -150
  115. data/app/frontend/comments/comments.component.tsx +0 -289
  116. data/app/frontend/comments/down_vote_button.component.test.tsx +0 -59
  117. data/app/frontend/comments/down_vote_button.component.tsx +0 -133
  118. data/app/frontend/comments/up_vote_button.component.test.tsx +0 -59
  119. data/app/frontend/comments/up_vote_button.component.tsx +0 -133
  120. data/app/frontend/comments/vote_button.component.tsx +0 -50
  121. data/app/frontend/comments/vote_button_component.test.tsx +0 -64
  122. data/app/frontend/entry.ts +0 -38
  123. data/app/frontend/entry_test.ts +0 -6
  124. data/app/frontend/fragments/add_comment_form_commentable.fragment.graphql +0 -4
  125. data/app/frontend/fragments/add_comment_form_session.fragment.graphql +0 -6
  126. data/app/frontend/fragments/comment.fragment.graphql +0 -14
  127. data/app/frontend/fragments/comment_data.fragment.graphql +0 -27
  128. data/app/frontend/fragments/comment_thread.fragment.graphql +0 -6
  129. data/app/frontend/fragments/down_vote_button.fragment.graphql +0 -6
  130. data/app/frontend/fragments/up_vote_button.fragment.graphql +0 -6
  131. data/app/frontend/mutations/add_comment.mutation.graphql +0 -9
  132. data/app/frontend/mutations/down_vote.mutation.graphql +0 -9
  133. data/app/frontend/mutations/up_vote.mutation.graphql +0 -9
  134. data/app/frontend/queries/comments.query.graphql +0 -26
  135. data/app/frontend/support/asset_url.ts +0 -11
  136. data/app/frontend/support/generate_comments_data.ts +0 -49
  137. data/app/frontend/support/generate_user_data.ts +0 -14
  138. data/app/frontend/support/generate_user_group_data.ts +0 -14
  139. data/app/frontend/support/graphql_transformer.js +0 -32
  140. data/app/frontend/support/load_translations.ts +0 -48
  141. data/app/frontend/support/require_all.ts +0 -10
  142. data/app/frontend/support/resolve_graphql_query.ts +0 -37
  143. data/app/frontend/support/schema.ts +0 -2026
  144. data/app/types/decidim/comments/commentable_interface.rb +0 -61
  145. data/app/types/decidim/comments/commentable_mutation_type.rb +0 -33
  146. data/lib/decidim/comments/api/add_comment_type.rb +0 -13
  147. data/lib/decidim/comments/api/comment_mutation_type.rb +0 -20
  148. data/lib/decidim/comments/api/comment_type.rb +0 -89
@@ -1,50 +0,0 @@
1
- import * as React from "react";
2
- import Icon from "../application/icon.component";
3
-
4
- interface VoteButtonProps {
5
- buttonClassName: string;
6
- iconName: string;
7
- text: string;
8
- votes: number;
9
- voteAction?: () => void;
10
- disabled?: boolean;
11
- selectedClass?: string;
12
- userLoggedIn: boolean;
13
- }
14
-
15
- const preventDefault = (event: any) => {
16
- event.preventDefault();
17
- };
18
-
19
- const VoteButton: React.SFC<VoteButtonProps> = ({
20
- buttonClassName,
21
- iconName,
22
- text,
23
- votes,
24
- voteAction,
25
- disabled,
26
- selectedClass,
27
- userLoggedIn
28
- }) => (
29
- <button
30
- className={`${buttonClassName} ${selectedClass}`}
31
- onClick={userLoggedIn ? voteAction : preventDefault}
32
- disabled={disabled}
33
- title={text}
34
- data-open={userLoggedIn ? null : "loginModal"}
35
- >
36
- <span className="show-for-sr">{text}</span>
37
- <Icon name={iconName} iconExtraClassName="icon--small" />
38
- {` ${votes}`}
39
- </button>
40
- );
41
-
42
- VoteButton.defaultProps = {
43
- buttonClassName: "",
44
- iconName: "",
45
- votes: 0,
46
- selectedClass: "selected",
47
- disabled: false
48
- };
49
-
50
- export default VoteButton;
@@ -1,64 +0,0 @@
1
- import { shallow } from "enzyme";
2
- import * as React from "react";
3
- import Icon from "../application/icon.component";
4
- import VoteButton from "./vote_button.component";
5
-
6
- describe("<VoteButton />", () => {
7
- const voteAction: jasmine.Spy = jasmine.createSpy("voteAction");
8
- const preventDefault: jasmine.Spy = jasmine.createSpy("preventDefault");
9
-
10
- beforeEach(() => {
11
- voteAction.calls.reset();
12
- preventDefault.calls.reset();
13
- });
14
-
15
- it("should render the number of votes passed as a prop", () => {
16
- const wrapper = shallow(<VoteButton votes={10} buttonClassName="vote-button" iconName="vote-icon" text="Test" voteAction={voteAction} userLoggedIn={true} />);
17
- expect(wrapper.find("button").text()).toMatch(/10/);
18
- });
19
-
20
- it("should render a button with the given buttonClassName", () => {
21
- const wrapper = shallow(<VoteButton votes={10} buttonClassName="vote-button" iconName="vote-icon" text="Test" voteAction={voteAction} userLoggedIn={true} />);
22
- expect(wrapper.find("button.vote-button").exists()).toBeTruthy();
23
- });
24
-
25
- it("should render a Icon component with the correct name prop", () => {
26
- const wrapper = shallow(<VoteButton votes={10} buttonClassName="vote-button" iconName="vote-icon" text="Test" voteAction={voteAction} userLoggedIn={true} />);
27
- expect(wrapper.find(Icon).prop("name")).toEqual("vote-icon");
28
- });
29
-
30
- it("should render a button with the text as title attribute and screen reader visible element", () => {
31
- const wrapper = shallow(<VoteButton votes={10} buttonClassName="vote-button" iconName="vote-icon" text="Test" voteAction={voteAction} userLoggedIn={true} />);
32
- expect(wrapper.find("button").prop("title")).toBe("Test");
33
- expect(wrapper.find("button span.show-for-sr").text()).toEqual("Test");
34
- });
35
-
36
- it("should call the voteAction prop on click", () => {
37
- const wrapper = shallow(<VoteButton votes={10} buttonClassName="vote-button" iconName="vote-icon" text="Test" voteAction={voteAction} userLoggedIn={true} />);
38
- wrapper.find("button").simulate("click");
39
- expect(voteAction).toHaveBeenCalled();
40
- });
41
-
42
- it("should disable the button based on the disabled prop", () => {
43
- const wrapper = shallow(<VoteButton votes={10} buttonClassName="vote-button" iconName="vote-icon" text="Test" voteAction={voteAction} disabled={true} userLoggedIn={true} />);
44
- expect(wrapper.find("button").props()).toHaveProperty("disabled");
45
- });
46
-
47
- it("should render a button with the given selectedClass", () => {
48
- const wrapper = shallow(<VoteButton votes={10} buttonClassName="vote-button" iconName="vote-icon" text="Test" voteAction={voteAction} disabled={true} selectedClass="is-vote-selected" userLoggedIn={true} />);
49
- expect(wrapper.find(".is-vote-selected").exists()).toBeTruthy();
50
- });
51
-
52
- describe("when userLoggedIn prop is false", () => {
53
- it("should add data-open prop as 'loginModal' to the button", () => {
54
- const wrapper = shallow(<VoteButton votes={10} buttonClassName="vote-button" iconName="vote-icon" text="Test" voteAction={voteAction} userLoggedIn={false} />);
55
- expect(wrapper.find("button").prop("data-open")).toBe("loginModal");
56
- });
57
-
58
- it("should call the event preventDefault method", () => {
59
- const wrapper = shallow(<VoteButton votes={10} buttonClassName="vote-button" iconName="vote-icon" text="Test" voteAction={voteAction} userLoggedIn={false} />);
60
- wrapper.find("button").simulate("click", { preventDefault });
61
- expect(preventDefault).toHaveBeenCalled();
62
- });
63
- });
64
- });
@@ -1,38 +0,0 @@
1
- import * as React from "react";
2
- import * as ReactDOM from "react-dom";
3
-
4
- import Comments, { CommentsApplicationProps } from "./comments/comments.component";
5
- import loadTranslations from "./support/load_translations";
6
-
7
- window.DecidimComments = window.DecidimComments || {};
8
-
9
- interface StorageDict {
10
- [key: string]: string;
11
- }
12
-
13
- window.DecidimComments.renderCommentsComponent = (nodeId: string, props: CommentsApplicationProps) => {
14
- const node = window.$(`#${nodeId}`)[0];
15
- const queryDict: StorageDict = {};
16
- window
17
- .location
18
- .search
19
- .substr(1)
20
- .split("&")
21
- .forEach(item => queryDict[item.split("=")[0]] = item.split("=")[1]);
22
-
23
- props = { ...props, singleCommentId: queryDict.commentId };
24
-
25
- ReactDOM.render(
26
- React.createElement(Comments, props),
27
- node
28
- );
29
-
30
- if (queryDict.commentId) {
31
- $([document.documentElement, document.body]).animate({
32
- scrollTop: $("#comments").offset()!.top
33
- }, 2000);
34
- }
35
- };
36
-
37
- // Load component locales from yaml files
38
- loadTranslations();
@@ -1,6 +0,0 @@
1
- import { configure } from "enzyme";
2
- import * as Adapter from "enzyme-adapter-react-16";
3
-
4
- import "jest-localstorage-mock";
5
-
6
- configure({ adapter: new Adapter() });
@@ -1,4 +0,0 @@
1
- fragment AddCommentFormCommentable on Commentable {
2
- id
3
- type
4
- }
@@ -1,6 +0,0 @@
1
- fragment AddCommentFormSession on Session {
2
- verifiedUserGroups {
3
- id
4
- name
5
- }
6
- }
@@ -1,14 +0,0 @@
1
- #import "../fragments/comment_data.fragment.graphql"
2
-
3
- fragment Comment on Comment {
4
- ...CommentData
5
- comments {
6
- ...CommentData
7
- comments {
8
- ...CommentData
9
- comments {
10
- ...CommentData
11
- }
12
- }
13
- }
14
- }
@@ -1,27 +0,0 @@
1
- #import "../fragments/up_vote_button.fragment.graphql"
2
- #import "../fragments/down_vote_button.fragment.graphql"
3
-
4
- fragment CommentData on Comment {
5
- id
6
- sgid
7
- type
8
- body
9
- formattedBody
10
- createdAt
11
- formattedCreatedAt
12
- author {
13
- name
14
- nickname
15
- avatarUrl
16
- profilePath
17
- deleted
18
- badge
19
- }
20
- hasComments
21
- acceptsNewComments
22
- userAllowedToComment
23
- alignment
24
- alreadyReported
25
- ...UpVoteButton
26
- ...DownVoteButton
27
- }
@@ -1,6 +0,0 @@
1
- #import "../fragments/comment.fragment.graphql"
2
-
3
- fragment CommentThread on Comment {
4
- hasComments
5
- ...Comment
6
- }
@@ -1,6 +0,0 @@
1
- fragment DownVoteButton on Comment {
2
- id
3
- downVotes
4
- downVoted
5
- upVoted
6
- }
@@ -1,6 +0,0 @@
1
- fragment UpVoteButton on Comment {
2
- id
3
- upVotes
4
- upVoted
5
- downVoted
6
- }
@@ -1,9 +0,0 @@
1
- #import "../fragments/comment_thread.fragment.graphql"
2
-
3
- mutation addComment($commentableId: String!, $commentableType: String!, $body: String!, $alignment: Int, $userGroupId: ID, $locale: String!, $toggleTranslations: Boolean!) {
4
- commentable(id: $commentableId, type: $commentableType, locale: $locale, toggleTranslations: $toggleTranslations) {
5
- addComment(body: $body, alignment: $alignment, userGroupId: $userGroupId) {
6
- ...CommentThread
7
- }
8
- }
9
- }
@@ -1,9 +0,0 @@
1
- #import "../fragments/comment.fragment.graphql"
2
-
3
- mutation DownVote($id: ID!, $locale: String!, $toggleTranslations: Boolean!) {
4
- comment(id: $id, locale: $locale, toggleTranslations: $toggleTranslations) {
5
- downVote {
6
- ...Comment
7
- }
8
- }
9
- }
@@ -1,9 +0,0 @@
1
- #import "../fragments/comment.fragment.graphql"
2
-
3
- mutation UpVote($id: ID!, $locale: String!, $toggleTranslations: Boolean!) {
4
- comment(id: $id, locale: $locale, toggleTranslations: $toggleTranslations) {
5
- upVote {
6
- ...Comment
7
- }
8
- }
9
- }
@@ -1,26 +0,0 @@
1
- #import "../fragments/add_comment_form_session.fragment.graphql"
2
- #import "../fragments/comment_thread.fragment.graphql"
3
- #import "../fragments/add_comment_form_commentable.fragment.graphql"
4
- query GetComments($commentableId: String!, $commentableType: String!, $orderBy: String, $singleCommentId: String, $locale: String!, $toggleTranslations: Boolean!) {
5
- session {
6
- user {
7
- name
8
- nickname
9
- avatarUrl
10
- organizationName
11
- }
12
- ...AddCommentFormSession
13
- }
14
- commentable(id: $commentableId, type: $commentableType, locale: $locale, toggleTranslations: $toggleTranslations) {
15
- acceptsNewComments
16
- userAllowedToComment
17
- commentsHaveAlignment
18
- commentsHaveVotes
19
- totalCommentsCount
20
- comments(orderBy: $orderBy, singleCommentId: $singleCommentId) {
21
- id
22
- ...CommentThread
23
- }
24
- ...AddCommentFormCommentable
25
- }
26
- }
@@ -1,11 +0,0 @@
1
- const assetUrl = (name: string): string => {
2
- const url = window.DecidimComments.assets[name];
3
-
4
- if (!url) {
5
- throw new Error(`Asset "${name}" can't be found on decidim comments manifest.`);
6
- }
7
-
8
- return url;
9
- };
10
-
11
- export default assetUrl;
@@ -1,49 +0,0 @@
1
- import { date, image, lorem, name, random } from "faker/locale/en";
2
-
3
- import { CommentFragment } from "../support/schema";
4
-
5
- /**
6
- * Generate random comment data to emulate a database real content
7
- * @param {number} num - The number of comments to generate random data
8
- * @returns {Object[]} - An array of objects representing comments data
9
- */
10
- const generateCommentsData = (num = 1) => {
11
- const commentsData: CommentFragment[] = [];
12
-
13
- for (let idx = 0; idx < num; idx += 1) {
14
- const creationDate = date.recent();
15
- const nickname = name.findName();
16
-
17
- commentsData.push({
18
- id: random.uuid(),
19
- type: "Decidim::Comments::Comment",
20
- body: lorem.words(),
21
- formattedBody: lorem.words(),
22
- createdAt: creationDate.toISOString(),
23
- formattedCreatedAt: creationDate.toLocaleTimeString(),
24
- author: {
25
- name: `${name.firstName()} ${name.lastName()}`,
26
- nickname: `@${nickname}`,
27
- avatarUrl: image.imageUrl(),
28
- profilePath: `/profiles/${nickname}`,
29
- deleted: false,
30
- badge: "verified-badge"
31
- },
32
- hasComments: false,
33
- comments: [],
34
- acceptsNewComments: true,
35
- userAllowedToComment: true,
36
- alignment: 0,
37
- upVotes: random.number(),
38
- upVoted: false,
39
- downVotes: random.number(),
40
- downVoted: false,
41
- sgid: random.uuid(),
42
- alreadyReported: false
43
- });
44
- }
45
-
46
- return commentsData;
47
- };
48
-
49
- export default generateCommentsData;
@@ -1,14 +0,0 @@
1
- import { name } from "faker/locale/en";
2
-
3
- /**
4
- * Generate random user data to emulate a database real content
5
- * @returns {Object} - An object representing user data
6
- */
7
- const generateUserData = () => {
8
- return {
9
- name: `${name.firstName()} ${name.lastName()}`,
10
- nickname: `@${name.findName()}`
11
- };
12
- };
13
-
14
- export default generateUserData;
@@ -1,14 +0,0 @@
1
- import { company, random } from "faker/locale/en";
2
-
3
- /**
4
- * Generate random user group data to emulate a database real content
5
- * @returns {Object} - An object representing user group data
6
- */
7
- const generateUserGrouprData = () => {
8
- return {
9
- id: random.uuid(),
10
- name: company.companyName()
11
- };
12
- };
13
-
14
- export default generateUserGrouprData;
@@ -1,32 +0,0 @@
1
- /* eslint-env node */
2
- const gql = require("graphql-tag");
3
-
4
- // Takes `source` (the source GraphQL query string)
5
- // and `doc` (the parsed GraphQL document) and tacks on
6
- // the imported definitions.
7
- const expandImports = (source) => {
8
- const lines = source.split("\n");
9
- let outputCode = "";
10
-
11
- lines.some((line) => {
12
- if (line[0] === "#" && line.slice(1).split(" ")[0] === "import") {
13
- const importFile = line.slice(1).split(" ")[1];
14
- const parseDocument = `require(${importFile})`;
15
- const appendDef = `doc.definitions = doc.definitions.concat(${parseDocument}.definitions);`;
16
- outputCode += `${appendDef}\n`;
17
- }
18
- return (line.length !== 0 && line[0] !== "#");
19
- });
20
-
21
- return outputCode;
22
- }
23
-
24
- module.exports = {
25
- process(src) {
26
- const doc = gql`${src}`;
27
- const outputCode = `var doc = ${JSON.stringify(doc)};`;
28
- const importOutputCode = expandImports(src, doc);
29
-
30
- return `${outputCode}\n${importOutputCode}\nmodule.exports = doc;`;
31
- }
32
- };
@@ -1,48 +0,0 @@
1
- /* eslint-disable no-param-reassign */
2
- import requireAll from "./require_all";
3
-
4
- const { I18n } = require("react-i18nify");
5
-
6
- /**
7
- * Load components translations from yaml files and import them into
8
- * react-i18ify system so they can be used via `I18n.t` method.
9
- * @returns {Void} - Nothing
10
- */
11
- const loadTranslations = () => {
12
- const translationsContext = (require as any).context("../../../config/locales/", true, /\.yml$/);
13
- const translationFiles = requireAll(translationsContext);
14
-
15
- const translations = translationsContext.keys().reduce((acc: any, key: string, index: number) => {
16
- const match = key.match(/\.\/(.*)\.yml/);
17
-
18
- if (match) {
19
- const locale = match[1];
20
- const translationKeys = translationFiles[index][locale];
21
-
22
- if (translationKeys && translationKeys.decidim) {
23
- acc[locale] = translationKeys.decidim;
24
- }
25
- }
26
-
27
- return acc;
28
- }, {});
29
-
30
- I18n.setTranslations(translations);
31
- };
32
-
33
- /**
34
- * Load components translations from a locale files and import them into
35
- * react-i18ify system so they can be used via `I18n.t` method.
36
- * @returns {Void} - Nothing
37
- */
38
- export const loadLocaleTranslations = (locale: string) => {
39
- const translationFile = require(`./../../../config/locales/${locale}.yml`);
40
- const translations = Object.keys(translationFile).reduce((acc: any, key: string) => {
41
- acc[locale] = translationFile[locale].decidim;
42
- return acc;
43
- }, {});
44
-
45
- I18n.setTranslations(translations);
46
- };
47
-
48
- export default loadTranslations;
@@ -1,10 +0,0 @@
1
- /**
2
- * Given a webpack require context it require all the files
3
- * @param {Object} requireContext - A webpack require context
4
- * @returns {Object[]} - An array of webpack modules
5
- */
6
- const requireAll = (requireContext: any) => {
7
- return requireContext.keys().map(requireContext);
8
- };
9
-
10
- export default requireAll;
@@ -1,37 +0,0 @@
1
- import graphql, { filter } from "graphql-anywhere";
2
-
3
- /**
4
- * A simple resolver which returns object properties to easily
5
- * traverse a graphql response
6
- * @param {String} fieldName - An object property
7
- * @param {Object} root - An object
8
- * @returns {any} - An object's property value
9
- */
10
- const resolver = (fieldName: string, root: any) => root[fieldName];
11
-
12
- /**
13
- * A helper function to mock a graphql api request and return its
14
- * result. The result can be filtered by the same query so it just
15
- * returns a data subset.
16
- * @param {String} document - A graphql query document
17
- * @param {options} options - An object with optional options
18
- * @returns {Object} - The result of the query filtered or not
19
- */
20
- const resolveGraphQLQuery = (document: any, options: any = {}) => {
21
- const { filterResult, rootValue, context, variables } = options;
22
-
23
- const result = graphql(
24
- resolver,
25
- document,
26
- rootValue,
27
- context,
28
- variables
29
- );
30
-
31
- if (filterResult) {
32
- return filter(document, result);
33
- }
34
- return result;
35
- };
36
-
37
- export default resolveGraphQLQuery;