disco_app 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (367) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +37 -0
  3. data/app/assets/components/disco_app/buttons/model-destroy-button.es6.jsx +31 -0
  4. data/app/assets/components/disco_app/forms/model-form.es6.jsx +64 -0
  5. data/app/assets/components/embedded_app/bar.es6.jsx +31 -0
  6. data/app/assets/components/shopify/buttons/_buttons.scss +546 -0
  7. data/app/assets/components/shopify/buttons/button.es6.jsx +15 -0
  8. data/app/assets/components/shopify/card/_card.scss +342 -0
  9. data/app/assets/components/shopify/card/card-header.es6.jsx +34 -0
  10. data/app/assets/components/shopify/card/card-section.es6.jsx +26 -0
  11. data/app/assets/components/shopify/card/card.es6.jsx +16 -0
  12. data/app/assets/components/shopify/typography/_typography.scss +23 -0
  13. data/app/assets/components/shopify/typography/ui-heading.es6.jsx +16 -0
  14. data/app/assets/components/shopify/ui-layout/_ui-layout.scss +157 -0
  15. data/app/assets/components/shopify/ui-layout/ui-annotated-section.es6.jsx +29 -0
  16. data/app/assets/components/shopify/ui-layout/ui-empty-state.es6.jsx +35 -0
  17. data/app/assets/components/shopify/ui-layout/ui-footer-help.es6.jsx +13 -0
  18. data/app/assets/components/shopify/ui-layout/ui-layout-item.es6.jsx +11 -0
  19. data/app/assets/components/shopify/ui-layout/ui-layout-section.es6.jsx +19 -0
  20. data/app/assets/components/shopify/ui-layout/ui-layout-sections.es6.jsx +11 -0
  21. data/app/assets/components/shopify/ui-layout/ui-layout.es6.jsx +11 -0
  22. data/app/assets/components/shopify/ui-layout/ui-page-actions.es6.jsx +13 -0
  23. data/app/assets/components/shopify/ui-layout/ui-page-actions__buttons.es6.jsx +27 -0
  24. data/app/assets/components/shopify/ui-stack/_ui-stack.scss +39 -0
  25. data/app/assets/components/shopify/ui-stack/ui-stack-item.es6.jsx +21 -0
  26. data/app/assets/components/shopify/ui-stack/ui-stack.es6.jsx +24 -0
  27. data/app/assets/images/disco_app/icon.svg +1 -0
  28. data/app/assets/images/disco_app/icons.svg +0 -0
  29. data/app/assets/javascripts/disco_app/components/custom/filterable_shop_list.js.jsx +61 -0
  30. data/app/assets/javascripts/disco_app/components/custom/inline-radio-options.es6.jsx +59 -0
  31. data/app/assets/javascripts/disco_app/components/custom/rules-editor.es6.jsx +432 -0
  32. data/app/assets/javascripts/disco_app/components/custom/shop_filter_query.js.jsx +13 -0
  33. data/app/assets/javascripts/disco_app/components/custom/shop_filter_tab.js.jsx +34 -0
  34. data/app/assets/javascripts/disco_app/components/custom/shop_filter_tabs.js.jsx +21 -0
  35. data/app/assets/javascripts/disco_app/components/custom/shop_list.js.jsx +142 -0
  36. data/app/assets/javascripts/disco_app/components/custom/shop_row.js.jsx +43 -0
  37. data/app/assets/javascripts/disco_app/components/custom/shopify_admin_link.js.jsx +29 -0
  38. data/app/assets/javascripts/disco_app/components/ui-kit/forms/base_form.es6.jsx +72 -0
  39. data/app/assets/javascripts/disco_app/components/ui-kit/forms/base_input.es6.jsx +20 -0
  40. data/app/assets/javascripts/disco_app/components/ui-kit/forms/input-checkbox.es6.jsx +30 -0
  41. data/app/assets/javascripts/disco_app/components/ui-kit/forms/input-radio.es6.jsx +30 -0
  42. data/app/assets/javascripts/disco_app/components/ui-kit/forms/input-select.es6.jsx +45 -0
  43. data/app/assets/javascripts/disco_app/components/ui-kit/forms/input-text.es6.jsx +69 -0
  44. data/app/assets/javascripts/disco_app/components/ui-kit/forms/input-textarea.es6.jsx +48 -0
  45. data/app/assets/javascripts/disco_app/components/ui-kit/forms/input-time.es6.jsx +7 -0
  46. data/app/assets/javascripts/disco_app/components/ui-kit/forms/ui-form__element.es6.jsx +17 -0
  47. data/app/assets/javascripts/disco_app/components/ui-kit/forms/ui-form__group.es6.jsx +11 -0
  48. data/app/assets/javascripts/disco_app/components/ui-kit/forms/ui-form__section.es6.jsx +11 -0
  49. data/app/assets/javascripts/disco_app/components/ui-kit/icons/icon-chevron.es6.jsx +33 -0
  50. data/app/assets/javascripts/disco_app/components/ui-kit/icons/next-icon.es6.jsx +18 -0
  51. data/app/assets/javascripts/disco_app/components/ui-kit/input_select.es6.jsx +21 -0
  52. data/app/assets/javascripts/disco_app/components/ui-kit/tables/table.es6.jsx +27 -0
  53. data/app/assets/javascripts/disco_app/components.js +3 -0
  54. data/app/assets/javascripts/disco_app/disco_app.js +9 -0
  55. data/app/assets/javascripts/disco_app/frame.js +152 -0
  56. data/app/assets/javascripts/disco_app/shopify-turbolinks.js +7 -0
  57. data/app/assets/javascripts/disco_app/ui-kit.js +1 -0
  58. data/app/assets/stylesheets/disco_app/admin/_header.scss +75 -0
  59. data/app/assets/stylesheets/disco_app/admin/_layout.scss +32 -0
  60. data/app/assets/stylesheets/disco_app/admin/_nav.scss +184 -0
  61. data/app/assets/stylesheets/disco_app/admin.scss +11 -0
  62. data/app/assets/stylesheets/disco_app/disco_app.scss +24 -0
  63. data/app/assets/stylesheets/disco_app/frame/_buttons.scss +54 -0
  64. data/app/assets/stylesheets/disco_app/frame/_forms.scss +26 -0
  65. data/app/assets/stylesheets/disco_app/frame/_layout.scss +77 -0
  66. data/app/assets/stylesheets/disco_app/frame/_type.scss +25 -0
  67. data/app/assets/stylesheets/disco_app/frame.scss +10 -0
  68. data/app/assets/stylesheets/disco_app/mixins/_flexbox.scss +400 -0
  69. data/app/assets/stylesheets/disco_app/ui-kit/_ui-forms.scss +69 -0
  70. data/app/assets/stylesheets/disco_app/ui-kit/_ui-icons.scss +28 -0
  71. data/app/assets/stylesheets/disco_app/ui-kit/_ui-kit.scss +5116 -0
  72. data/app/assets/stylesheets/disco_app/ui-kit/_ui-layout.scss +15 -0
  73. data/app/assets/stylesheets/disco_app/ui-kit/_ui-tabs.scss +75 -0
  74. data/app/assets/stylesheets/disco_app/ui-kit/_ui-type.scss +13 -0
  75. data/app/controllers/disco_app/admin/app_settings_controller.rb +3 -0
  76. data/app/controllers/disco_app/admin/application_controller.rb +3 -0
  77. data/app/controllers/disco_app/admin/concerns/app_settings_controller.rb +24 -0
  78. data/app/controllers/disco_app/admin/concerns/authenticated_controller.rb +20 -0
  79. data/app/controllers/disco_app/admin/concerns/plans_controller.rb +54 -0
  80. data/app/controllers/disco_app/admin/concerns/shops_controller.rb +7 -0
  81. data/app/controllers/disco_app/admin/concerns/subscriptions_controller.rb +29 -0
  82. data/app/controllers/disco_app/admin/plans_controller.rb +3 -0
  83. data/app/controllers/disco_app/admin/resources/shops_controller.rb +3 -0
  84. data/app/controllers/disco_app/admin/shops_controller.rb +3 -0
  85. data/app/controllers/disco_app/admin/subscriptions_controller.rb +3 -0
  86. data/app/controllers/disco_app/charges_controller.rb +47 -0
  87. data/app/controllers/disco_app/concerns/app_proxy_controller.rb +40 -0
  88. data/app/controllers/disco_app/concerns/authenticated_controller.rb +56 -0
  89. data/app/controllers/disco_app/concerns/carrier_request_controller.rb +35 -0
  90. data/app/controllers/disco_app/frame_controller.rb +9 -0
  91. data/app/controllers/disco_app/install_controller.rb +27 -0
  92. data/app/controllers/disco_app/subscriptions_controller.rb +32 -0
  93. data/app/controllers/disco_app/webhooks_controller.rb +46 -0
  94. data/app/controllers/sessions_controller.rb +28 -0
  95. data/app/helpers/disco_app/application_helper.rb +68 -0
  96. data/app/jobs/disco_app/app_installed_job.rb +3 -0
  97. data/app/jobs/disco_app/app_uninstalled_job.rb +3 -0
  98. data/app/jobs/disco_app/concerns/app_installed_job.rb +39 -0
  99. data/app/jobs/disco_app/concerns/app_uninstalled_job.rb +20 -0
  100. data/app/jobs/disco_app/concerns/render_asset_group_job.rb +8 -0
  101. data/app/jobs/disco_app/concerns/shop_update_job.rb +13 -0
  102. data/app/jobs/disco_app/concerns/subscription_changed_job.rb +7 -0
  103. data/app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb +55 -0
  104. data/app/jobs/disco_app/concerns/synchronise_resources_job.rb +12 -0
  105. data/app/jobs/disco_app/concerns/synchronise_webhooks_job.rb +52 -0
  106. data/app/jobs/disco_app/render_asset_group_job.rb +3 -0
  107. data/app/jobs/disco_app/shop_job.rb +27 -0
  108. data/app/jobs/disco_app/shop_update_job.rb +3 -0
  109. data/app/jobs/disco_app/subscription_changed_job.rb +3 -0
  110. data/app/jobs/disco_app/synchronise_carrier_service_job.rb +3 -0
  111. data/app/jobs/disco_app/synchronise_resources_job.rb +3 -0
  112. data/app/jobs/disco_app/synchronise_webhooks_job.rb +3 -0
  113. data/app/models/disco_app/app_settings.rb +3 -0
  114. data/app/models/disco_app/application_charge.rb +18 -0
  115. data/app/models/disco_app/concerns/app_settings.rb +7 -0
  116. data/app/models/disco_app/concerns/can_be_liquified.rb +45 -0
  117. data/app/models/disco_app/concerns/has_metafields.rb +48 -0
  118. data/app/models/disco_app/concerns/plan.rb +26 -0
  119. data/app/models/disco_app/concerns/plan_code.rb +15 -0
  120. data/app/models/disco_app/concerns/renders_assets.rb +166 -0
  121. data/app/models/disco_app/concerns/shop.rb +84 -0
  122. data/app/models/disco_app/concerns/subscription.rb +60 -0
  123. data/app/models/disco_app/concerns/synchronises.rb +58 -0
  124. data/app/models/disco_app/concerns/taggable.rb +16 -0
  125. data/app/models/disco_app/plan.rb +3 -0
  126. data/app/models/disco_app/plan_code.rb +3 -0
  127. data/app/models/disco_app/recurring_application_charge.rb +18 -0
  128. data/app/models/disco_app/session_storage.rb +18 -0
  129. data/app/models/disco_app/shop.rb +3 -0
  130. data/app/models/disco_app/subscription.rb +3 -0
  131. data/app/resources/disco_app/admin/resources/concerns/shop_resource.rb +100 -0
  132. data/app/resources/disco_app/admin/resources/shop_resource.rb +4 -0
  133. data/app/services/disco_app/carrier_request_service.rb +15 -0
  134. data/app/services/disco_app/charges_service.rb +81 -0
  135. data/app/services/disco_app/proxy_service.rb +17 -0
  136. data/app/services/disco_app/subscription_service.rb +46 -0
  137. data/app/services/disco_app/webhook_service.rb +30 -0
  138. data/app/views/disco_app/admin/app_settings/edit.html.erb +5 -0
  139. data/app/views/disco_app/admin/plans/_form.html.erb +72 -0
  140. data/app/views/disco_app/admin/plans/_plan_code_fields.html.erb +15 -0
  141. data/app/views/disco_app/admin/plans/edit.html.erb +7 -0
  142. data/app/views/disco_app/admin/plans/index.html.erb +43 -0
  143. data/app/views/disco_app/admin/plans/new.html.erb +7 -0
  144. data/app/views/disco_app/admin/shops/index.html.erb +13 -0
  145. data/app/views/disco_app/admin/subscriptions/edit.html.erb +33 -0
  146. data/app/views/disco_app/charges/activate.html.erb +1 -0
  147. data/app/views/disco_app/charges/create.html.erb +1 -0
  148. data/app/views/disco_app/charges/new.html.erb +23 -0
  149. data/app/views/disco_app/frame/frame.html.erb +36 -0
  150. data/app/views/disco_app/install/installing.html.erb +22 -0
  151. data/app/views/disco_app/install/uninstalling.html.erb +1 -0
  152. data/app/views/disco_app/proxy_errors/404.html.erb +1 -0
  153. data/app/views/disco_app/shared/_card.html.erb +14 -0
  154. data/app/views/disco_app/shared/_icons.html.erb +1 -0
  155. data/app/views/disco_app/shared/_section.html.erb +17 -0
  156. data/app/views/disco_app/subscriptions/new.html.erb +25 -0
  157. data/app/views/layouts/admin/_nav_items.erb +20 -0
  158. data/app/views/layouts/admin.html.erb +67 -0
  159. data/app/views/layouts/application.html.erb +18 -0
  160. data/app/views/layouts/embedded_app.html.erb +50 -0
  161. data/app/views/layouts/embedded_app_modal.html.erb +28 -0
  162. data/app/views/sessions/new.html.erb +28 -0
  163. data/config/routes.rb +63 -0
  164. data/db/migrate/20150525000000_create_shops_if_not_existent.rb +15 -0
  165. data/db/migrate/20150525162112_add_status_to_shops.rb +5 -0
  166. data/db/migrate/20150525171422_add_meta_to_shops.rb +11 -0
  167. data/db/migrate/20150629210346_add_charge_status_to_shop.rb +5 -0
  168. data/db/migrate/20150814214025_add_more_meta_to_shops.rb +15 -0
  169. data/db/migrate/20151017231302_create_disco_app_plans.rb +13 -0
  170. data/db/migrate/20151017232027_create_disco_app_subscriptions.rb +15 -0
  171. data/db/migrate/20151017234409_move_shop_to_disco_app_engine.rb +5 -0
  172. data/db/migrate/20160112233706_create_disco_app_sessions.rb +12 -0
  173. data/db/migrate/20160113194418_add_shop_id_to_disco_app_sessions.rb +6 -0
  174. data/db/migrate/20160223111044_create_disco_app_settings.rb +8 -0
  175. data/db/migrate/20160301223215_update_plans.rb +22 -0
  176. data/db/migrate/20160301224558_update_subscriptions.rb +13 -0
  177. data/db/migrate/20160302104816_create_disco_app_recurring_application_charges.rb +14 -0
  178. data/db/migrate/20160302105259_create_disco_app_application_charges.rb +14 -0
  179. data/db/migrate/20160302134728_drop_charge_status_from_shops.rb +5 -0
  180. data/db/migrate/20160302142941_add_shopify_attributes_to_charges.rb +8 -0
  181. data/db/migrate/20160331093148_create_disco_app_plan_codes.rb +14 -0
  182. data/db/migrate/20160401044420_add_status_to_plan_codes.rb +5 -0
  183. data/db/migrate/20160401045551_add_amount_and_plan_code_to_disco_app_subscriptions.rb +7 -0
  184. data/db/migrate/20160425205211_add_source_to_disco_app_subscriptions.rb +5 -0
  185. data/db/migrate/20160426033520_add_trial_period_days_to_disco_app_subscriptions.rb +5 -0
  186. data/db/migrate/20160513140727_add_name_to_disco_app_shops.rb +5 -0
  187. data/db/migrate/20160521135510_move_shop_to_synchronises.rb +61 -0
  188. data/lib/disco_app/configuration.rb +45 -0
  189. data/lib/disco_app/constants.rb +4 -0
  190. data/lib/disco_app/engine.rb +26 -0
  191. data/lib/disco_app/session.rb +14 -0
  192. data/lib/disco_app/support/file_fixtures.rb +23 -0
  193. data/lib/disco_app/test_help.rb +11 -0
  194. data/lib/disco_app/version.rb +3 -0
  195. data/lib/disco_app.rb +7 -0
  196. data/lib/generators/disco_app/USAGE +5 -0
  197. data/lib/generators/disco_app/disco_app_generator.rb +239 -0
  198. data/lib/generators/disco_app/templates/assets/javascripts/application.js +17 -0
  199. data/lib/generators/disco_app/templates/assets/javascripts/components.js +3 -0
  200. data/lib/generators/disco_app/templates/assets/stylesheets/application.scss +5 -0
  201. data/lib/generators/disco_app/templates/config/database.yml.tt +20 -0
  202. data/lib/generators/disco_app/templates/config/newrelic.yml +26 -0
  203. data/lib/generators/disco_app/templates/config/puma.rb +15 -0
  204. data/lib/generators/disco_app/templates/controllers/home_controller.rb +7 -0
  205. data/lib/generators/disco_app/templates/initializers/disco_app.rb +28 -0
  206. data/lib/generators/disco_app/templates/initializers/rollbar.rb +19 -0
  207. data/lib/generators/disco_app/templates/initializers/session_store.rb +2 -0
  208. data/lib/generators/disco_app/templates/initializers/shopify_app.rb +7 -0
  209. data/lib/generators/disco_app/templates/initializers/shopify_session_repository.rb +7 -0
  210. data/lib/generators/disco_app/templates/root/CHECKS +4 -0
  211. data/lib/generators/disco_app/templates/root/Procfile +2 -0
  212. data/lib/generators/disco_app/templates/views/home/index.html.erb +2 -0
  213. data/lib/tasks/carrier_service.rake +10 -0
  214. data/lib/tasks/database.rake +8 -0
  215. data/lib/tasks/sessions.rake +9 -0
  216. data/lib/tasks/shops.rake +10 -0
  217. data/lib/tasks/start.rake +3 -0
  218. data/lib/tasks/webhooks.rake +10 -0
  219. data/test/controllers/disco_app/admin/shops_controller_test.rb +54 -0
  220. data/test/controllers/disco_app/charges_controller_test.rb +99 -0
  221. data/test/controllers/disco_app/install_controller_test.rb +50 -0
  222. data/test/controllers/disco_app/subscriptions_controller_test.rb +68 -0
  223. data/test/controllers/disco_app/webhooks_controller_test.rb +58 -0
  224. data/test/controllers/home_controller_test.rb +92 -0
  225. data/test/controllers/proxy_controller_test.rb +42 -0
  226. data/test/disco_app_test.rb +7 -0
  227. data/test/dummy/Rakefile +6 -0
  228. data/test/dummy/app/assets/javascripts/application.js +17 -0
  229. data/test/dummy/app/assets/stylesheets/application.scss +5 -0
  230. data/test/dummy/app/controllers/application_controller.rb +6 -0
  231. data/test/dummy/app/controllers/carrier_request_controller.rb +10 -0
  232. data/test/dummy/app/controllers/disco_app/admin/shops_controller.rb +8 -0
  233. data/test/dummy/app/controllers/home_controller.rb +7 -0
  234. data/test/dummy/app/controllers/proxy_controller.rb +8 -0
  235. data/test/dummy/app/helpers/application_helper.rb +2 -0
  236. data/test/dummy/app/jobs/carts_update_job.rb +7 -0
  237. data/test/dummy/app/jobs/disco_app/app_installed_job.rb +16 -0
  238. data/test/dummy/app/jobs/disco_app/app_uninstalled_job.rb +11 -0
  239. data/test/dummy/app/jobs/products_create_job.rb +7 -0
  240. data/test/dummy/app/jobs/products_delete_job.rb +7 -0
  241. data/test/dummy/app/jobs/products_update_job.rb +7 -0
  242. data/test/dummy/app/models/cart.rb +24 -0
  243. data/test/dummy/app/models/disco_app/shop.rb +15 -0
  244. data/test/dummy/app/models/js_configuration.rb +8 -0
  245. data/test/dummy/app/models/product.rb +9 -0
  246. data/test/dummy/app/models/widget_configuration.rb +10 -0
  247. data/test/dummy/app/views/assets/script_tag.js.erb +1 -0
  248. data/test/dummy/app/views/assets/test.js.erb +1 -0
  249. data/test/dummy/app/views/assets/widget.js.erb +2 -0
  250. data/test/dummy/app/views/assets/widget.scss.erb +3 -0
  251. data/test/dummy/app/views/home/index.html.erb +2 -0
  252. data/test/dummy/app/views/snippets/widget.liquid.erb +1 -0
  253. data/test/dummy/bin/bundle +3 -0
  254. data/test/dummy/bin/rails +4 -0
  255. data/test/dummy/bin/rake +4 -0
  256. data/test/dummy/bin/setup +29 -0
  257. data/test/dummy/config/application.rb +38 -0
  258. data/test/dummy/config/boot.rb +5 -0
  259. data/test/dummy/config/database.codeship.yml +23 -0
  260. data/test/dummy/config/database.gitlab-ci.yml +24 -0
  261. data/test/dummy/config/database.yml +20 -0
  262. data/test/dummy/config/environment.rb +5 -0
  263. data/test/dummy/config/environments/development.rb +41 -0
  264. data/test/dummy/config/environments/production.rb +85 -0
  265. data/test/dummy/config/environments/test.rb +42 -0
  266. data/test/dummy/config/initializers/assets.rb +11 -0
  267. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  268. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  269. data/test/dummy/config/initializers/disco_app.rb +28 -0
  270. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  271. data/test/dummy/config/initializers/inflections.rb +16 -0
  272. data/test/dummy/config/initializers/mime_types.rb +4 -0
  273. data/test/dummy/config/initializers/omniauth.rb +9 -0
  274. data/test/dummy/config/initializers/session_store.rb +2 -0
  275. data/test/dummy/config/initializers/shopify_app.rb +7 -0
  276. data/test/dummy/config/initializers/shopify_session_repository.rb +7 -0
  277. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  278. data/test/dummy/config/locales/en.yml +23 -0
  279. data/test/dummy/config/routes.rb +11 -0
  280. data/test/dummy/config/secrets.yml +22 -0
  281. data/test/dummy/config.ru +4 -0
  282. data/test/dummy/db/migrate/20160307182229_create_products.rb +11 -0
  283. data/test/dummy/db/migrate/20160530160739_create_asset_models.rb +19 -0
  284. data/test/dummy/db/migrate/20161105054746_create_carts.rb +13 -0
  285. data/test/dummy/db/schema.rb +152 -0
  286. data/test/dummy/public/404.html +67 -0
  287. data/test/dummy/public/422.html +67 -0
  288. data/test/dummy/public/500.html +66 -0
  289. data/test/dummy/public/favicon.ico +0 -0
  290. data/test/fixtures/api/widget_store/assets/create_script_tag_js_request.json +6 -0
  291. data/test/fixtures/api/widget_store/assets/create_script_tag_js_response.json +12 -0
  292. data/test/fixtures/api/widget_store/assets/create_script_tag_request.json +6 -0
  293. data/test/fixtures/api/widget_store/assets/create_script_tag_response.json +10 -0
  294. data/test/fixtures/api/widget_store/assets/create_test_js_request.json +6 -0
  295. data/test/fixtures/api/widget_store/assets/create_test_js_response.json +12 -0
  296. data/test/fixtures/api/widget_store/assets/create_widget_js_request.json +6 -0
  297. data/test/fixtures/api/widget_store/assets/create_widget_js_response.json +12 -0
  298. data/test/fixtures/api/widget_store/assets/create_widget_liquid_request.json +6 -0
  299. data/test/fixtures/api/widget_store/assets/create_widget_liquid_response.json +12 -0
  300. data/test/fixtures/api/widget_store/assets/create_widget_scss_request.json +6 -0
  301. data/test/fixtures/api/widget_store/assets/create_widget_scss_response.json +12 -0
  302. data/test/fixtures/api/widget_store/assets/get_script_tags_empty_request.json +1 -0
  303. data/test/fixtures/api/widget_store/assets/get_script_tags_empty_response.json +1 -0
  304. data/test/fixtures/api/widget_store/assets/get_script_tags_preexisting_request.json +1 -0
  305. data/test/fixtures/api/widget_store/assets/get_script_tags_preexisting_response.json +12 -0
  306. data/test/fixtures/api/widget_store/assets/update_script_tag_request.json +10 -0
  307. data/test/fixtures/api/widget_store/assets/update_script_tag_response.json +10 -0
  308. data/test/fixtures/api/widget_store/carrier_services.json +1 -0
  309. data/test/fixtures/api/widget_store/carrier_services_create.json +8 -0
  310. data/test/fixtures/api/widget_store/charges/activate_application_charge_request.json +16 -0
  311. data/test/fixtures/api/widget_store/charges/activate_application_charge_response.json +1 -0
  312. data/test/fixtures/api/widget_store/charges/activate_recurring_application_charge_request.json +20 -0
  313. data/test/fixtures/api/widget_store/charges/activate_recurring_application_charge_response.json +1 -0
  314. data/test/fixtures/api/widget_store/charges/create_application_charge_request.json +9 -0
  315. data/test/fixtures/api/widget_store/charges/create_application_charge_response.json +16 -0
  316. data/test/fixtures/api/widget_store/charges/create_recurring_application_charge_request.json +9 -0
  317. data/test/fixtures/api/widget_store/charges/create_recurring_application_charge_response.json +20 -0
  318. data/test/fixtures/api/widget_store/charges/create_second_recurring_application_charge_request.json +9 -0
  319. data/test/fixtures/api/widget_store/charges/create_second_recurring_application_charge_response.json +20 -0
  320. data/test/fixtures/api/widget_store/charges/get_accepted_application_charge_response.json +16 -0
  321. data/test/fixtures/api/widget_store/charges/get_accepted_recurring_application_charge_response.json +20 -0
  322. data/test/fixtures/api/widget_store/charges/get_declined_application_charge_response.json +16 -0
  323. data/test/fixtures/api/widget_store/charges/get_declined_recurring_application_charge_response.json +20 -0
  324. data/test/fixtures/api/widget_store/charges/get_pending_application_charge_response.json +16 -0
  325. data/test/fixtures/api/widget_store/charges/get_pending_recurring_application_charge_response.json +20 -0
  326. data/test/fixtures/api/widget_store/products/write_metafields_multiple_namespaces_request.json +31 -0
  327. data/test/fixtures/api/widget_store/products/write_metafields_multiple_namespaces_response.json +1 -0
  328. data/test/fixtures/api/widget_store/products/write_metafields_single_namespace_request.json +19 -0
  329. data/test/fixtures/api/widget_store/products/write_metafields_single_namespace_response.json +1 -0
  330. data/test/fixtures/api/widget_store/shop.json +46 -0
  331. data/test/fixtures/api/widget_store/webhooks.json +1 -0
  332. data/test/fixtures/assets/test.js +1 -0
  333. data/test/fixtures/assets/test.min.js +1 -0
  334. data/test/fixtures/carts.yml +5 -0
  335. data/test/fixtures/disco_app/application_charges.yml +11 -0
  336. data/test/fixtures/disco_app/plan_codes.yml +13 -0
  337. data/test/fixtures/disco_app/plans.yml +37 -0
  338. data/test/fixtures/disco_app/recurring_application_charges.yml +11 -0
  339. data/test/fixtures/disco_app/shops.yml +10 -0
  340. data/test/fixtures/disco_app/subscriptions.yml +22 -0
  341. data/test/fixtures/js_configurations.yml +3 -0
  342. data/test/fixtures/liquid/model.liquid +8 -0
  343. data/test/fixtures/products.yml +4 -0
  344. data/test/fixtures/webhooks/app_uninstalled.json +46 -0
  345. data/test/fixtures/webhooks/cart_updated.json +28 -0
  346. data/test/fixtures/webhooks/product_created.json +167 -0
  347. data/test/fixtures/webhooks/product_deleted.json +3 -0
  348. data/test/fixtures/webhooks/product_updated.json +167 -0
  349. data/test/fixtures/widget_configurations.yml +4 -0
  350. data/test/integration/synchronises_test.rb +62 -0
  351. data/test/jobs/disco_app/app_installed_job_test.rb +57 -0
  352. data/test/jobs/disco_app/app_uninstalled_job_test.rb +30 -0
  353. data/test/jobs/disco_app/synchronise_carrier_service_job_test.rb +25 -0
  354. data/test/jobs/disco_app/synchronise_webhooks_job_test.rb +30 -0
  355. data/test/models/disco_app/can_be_liquified_test.rb +55 -0
  356. data/test/models/disco_app/has_metafields_test.rb +40 -0
  357. data/test/models/disco_app/plan_test.rb +5 -0
  358. data/test/models/disco_app/renders_assets_test.rb +109 -0
  359. data/test/models/disco_app/session_test.rb +31 -0
  360. data/test/models/disco_app/shop_test.rb +43 -0
  361. data/test/models/disco_app/subscription_test.rb +19 -0
  362. data/test/services/disco_app/charges_service_test.rb +112 -0
  363. data/test/services/disco_app/subscription_service_test.rb +60 -0
  364. data/test/support/test_file_fixtures.rb +29 -0
  365. data/test/support/test_shopify_api.rb +16 -0
  366. data/test/test_helper.rb +55 -0
  367. metadata +893 -0
@@ -0,0 +1,432 @@
1
+ /**
2
+ * Defines a generic RulesEditor class. This class can't be used directly, but
3
+ * should be inherited, with the inheriting class defining a list of column
4
+ * types and corresponding relations and condition data types, like so:
5
+ *
6
+ * class MyRulesEditor extends RulesEditor {};
7
+ * MyRulesEditor.defaultProps = {
8
+ * columns: {
9
+ * title: {
10
+ * label: 'Product title',
11
+ * column: 'title',
12
+ * relations: RulesEditor.buildRelationsObj([RulesEditor.EQUALS_STRING])
13
+ * }
14
+ * }
15
+ */
16
+ class RulesEditor extends React.Component {
17
+
18
+ /**
19
+ * Initialise the Rules Editor, and set the initial state.
20
+ * @param props
21
+ */
22
+ constructor(props) {
23
+ super(props);
24
+ this.state = {
25
+ rules: props.rules.map((rule, i) => {
26
+ return Object.assign({}, rule, {
27
+ column: Object.keys(this.props.columns).filter((columnKey) => {
28
+ return this.props.columns[columnKey].column == rule.column;
29
+ })[0]
30
+ });
31
+ })
32
+ }
33
+ }
34
+
35
+ componentDidMount() {
36
+ if(this.state.rules.length === 0 && this.props.blankOk === false) {
37
+ this.onAddRule();
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Add a new rule, with an immutable state change.
43
+ */
44
+ onAddRule() {
45
+ const column = Object.keys(this.props.columns)[0];
46
+ const relation = this.getNextRelation(column);
47
+ const condition = this.getNextCondition(column, relation);
48
+
49
+ this.setState({
50
+ rules: this.state.rules.concat([{
51
+ column,
52
+ relation,
53
+ condition
54
+ }])
55
+ });
56
+ }
57
+
58
+ /**
59
+ * Remove a rule, with an immutable state change.
60
+ */
61
+ onRemoveRule(index) {
62
+ this.setState({
63
+ rules: [
64
+ ...this.state.rules.slice(0, index),
65
+ ...this.state.rules.slice(index + 1)
66
+ ]
67
+ });
68
+ }
69
+
70
+ /**
71
+ * Handle a change in a rule's column attribute.
72
+ *
73
+ * @param index
74
+ * @param column
75
+ */
76
+ onRuleColumnChange(index, column) {
77
+ const relation = this.getNextRelation(column, this.state.rules[index]);
78
+ const condition = this.getNextCondition(column, relation, this.state.rules[index]);
79
+
80
+ this.updateRule(index, {
81
+ column,
82
+ relation,
83
+ condition
84
+ })
85
+ }
86
+
87
+ /**
88
+ * Handle a change in a rule's relation attribute.
89
+ *
90
+ * @param index
91
+ * @param relation
92
+ */
93
+ onRuleRelationChange(index, relation) {
94
+ const condition = this.getNextCondition(this.state.rules[index].column, relation, this.state.rules[index]);
95
+
96
+ this.updateRule(index, {
97
+ relation,
98
+ condition
99
+ });
100
+ }
101
+
102
+ /**
103
+ * Handle a change in a rule's condition attribute.
104
+ *
105
+ * @param index
106
+ * @param condition
107
+ */
108
+ onRuleConditionChange(index, condition) {
109
+ this.updateRule(index, {
110
+ condition
111
+ });
112
+ }
113
+
114
+ /**
115
+ * Handle a change in a rule's variables
116
+ *
117
+ * @param index
118
+ * @param name
119
+ * @param value
120
+ */
121
+ onRuleVariableChange(index, name, value) {
122
+ this.updateRule(index, {
123
+ [name]: value
124
+ });
125
+ }
126
+
127
+ /**
128
+ * Given the column we're changing to and the current rule, return the next
129
+ * relation value.
130
+ *
131
+ * @param nextColumn
132
+ * @param currentRule
133
+ */
134
+ getNextRelation(nextColumn, currentRule) {
135
+ // If the new column provides for the same relation, keep it.
136
+ if(currentRule && (this.props.columns[nextColumn].relations[currentRule.relation] !== undefined)) {
137
+ return currentRule.relation;
138
+ }
139
+ // Otherwise, return the first relation for the new column.
140
+ return Object.keys(this.props.columns[nextColumn].relations)[0];
141
+ }
142
+
143
+ /**
144
+ * Given the column and relation we're changing to and the current condition,
145
+ * return the value that the condition should be changed to.
146
+ *
147
+ * @param nextColumn
148
+ * @param nextRelation
149
+ * @param currentRule
150
+ */
151
+ getNextCondition(nextColumn, nextRelation, currentRule) {
152
+ // If the new relation provides for the same condition type, keep it.
153
+ if(currentRule) {
154
+ const currentConditionType = this.props.columns[currentRule.column].relations[currentRule.relation].type;
155
+ const nextConditionType = this.props.columns[nextColumn].relations[nextRelation].type;
156
+
157
+ if(currentConditionType === nextConditionType) {
158
+ return currentRule.condition;
159
+ }
160
+ }
161
+
162
+ // Otherwise, reset the condition to an empty string.
163
+ return '';
164
+ }
165
+
166
+ /**
167
+ * Handle the updating of a rule in our array in an immutable manner.
168
+ *
169
+ * @param index
170
+ * @param updates
171
+ */
172
+ updateRule(index, updates) {
173
+ let updatedRule = Object.assign({}, this.state.rules[index], updates);
174
+
175
+ // Ensure only valid variables are present in the rule
176
+ const columnPath = this.props.columns[updatedRule.column].column;
177
+ const columnVariables = RulesEditor.getColumnPathVariables(columnPath);
178
+ Object.keys(updatedRule).forEach(function (key) {
179
+ if ('$' === key[0] && -1 === columnVariables.indexOf(key)) {
180
+ delete updatedRule[key];
181
+ }
182
+ });
183
+
184
+ this.setState({
185
+ rules: [
186
+ ...this.state.rules.slice(0, index),
187
+ updatedRule,
188
+ ...this.state.rules.slice(index + 1)
189
+ ]
190
+ });
191
+ }
192
+
193
+ /**
194
+ * Render the Rules Editor.
195
+ */
196
+ render() {
197
+ const { name } = this.props;
198
+ const { rules } = this.state;
199
+
200
+ const ruleElements = rules.map((rule, i) => {
201
+ return <RulesEditorRule
202
+ key={i}
203
+ rule={rule}
204
+ columns={this.props.columns}
205
+ onRemove={this.onRemoveRule.bind(this, i)}
206
+ onColumnChange={this.onRuleColumnChange.bind(this, i)}
207
+ onRelationChange={this.onRuleRelationChange.bind(this, i)}
208
+ onConditionChange={this.onRuleConditionChange.bind(this, i)}
209
+ onVariableChange={this.onRuleVariableChange.bind(this, i)}
210
+ ruleCount={rules.length}
211
+ blankOk = {this.props.blankOk}
212
+ />
213
+ });
214
+
215
+ // Convert the current rules JSON into a format using the correct column
216
+ // format used by our more advanced key checker.
217
+ const rulesJSON = JSON.stringify(this.state.rules.map((rule, i) => {
218
+ return Object.assign({}, rule, {
219
+ column: this.props.columns[rule.column].column
220
+ });
221
+ }));
222
+
223
+ return(
224
+ <CardSection>
225
+ <div className="next-grid next-grid--no-outside-padding">
226
+ <div style={{ width: '100%'}}>
227
+ {ruleElements}
228
+ </div>
229
+ </div>
230
+ <Button onClick={this.onAddRule.bind(this)}>
231
+ Add another condition
232
+ </Button>
233
+ <input type="hidden" name={name} value={rulesJSON} />
234
+ </CardSection>
235
+ );
236
+ }
237
+
238
+ /**
239
+ * Get the variable names present in a column definition
240
+ *
241
+ * @param column
242
+ * @returns {Array.<String>}
243
+ */
244
+ static getColumnPathVariables(column) {
245
+ return column.split(/[^$a-z_A-Z]/).filter((key) => '$' === key[0]);
246
+ }
247
+
248
+ /**
249
+ * Return a relations object, which is just the passed array
250
+ * turned into an object which is keyed by the `relation` value
251
+ *
252
+ * @param relations
253
+ * @returns {{}}
254
+ */
255
+ static buildRelationsObj(relations) {
256
+ var relationsObj = {};
257
+
258
+ relations.forEach(function (relation) {
259
+ return relationsObj[relation.relation] = relation;
260
+ });
261
+
262
+ return relationsObj;
263
+ }
264
+
265
+ }
266
+
267
+
268
+ RulesEditor.EQUALS_STRING = {
269
+ label: 'is equal to',
270
+ relation: 'is_equal_to',
271
+ type: 'text'
272
+ };
273
+ RulesEditor.NOT_EQUALS_STRING = {
274
+ label: 'is not equal to',
275
+ relation: 'is_not_equal_to',
276
+ type: 'text'
277
+ };
278
+ RulesEditor.EQUALS_COUNTRY_CODE = {
279
+ label: 'is equal to',
280
+ relation: 'is_equal_to',
281
+ type: 'country_code'
282
+ };
283
+ RulesEditor.NOT_EQUALS_COUNTRY_CODE = {
284
+ label: 'is not equal to',
285
+ relation: 'is_not_equal_to',
286
+ type: 'country_code'
287
+ };
288
+ RulesEditor.CONTAINS_STRING = {
289
+ label: 'contains',
290
+ relation: 'contains_string',
291
+ type: 'text'
292
+ };
293
+ RulesEditor.DOES_NOT_CONTAIN_STRING = {
294
+ label: 'does not contain',
295
+ relation: 'does_not_contain_string',
296
+ type: 'text'
297
+ };
298
+ RulesEditor.EQUALS_TAG = {
299
+ label: 'is equal to',
300
+ relation: 'find_in_set',
301
+ type: 'tag'
302
+ };
303
+ RulesEditor.GREATER_THAN = {
304
+ label: 'is greater than',
305
+ relation: 'is_greater_than',
306
+ type: 'numeric'
307
+ };
308
+ RulesEditor.LESS_THAN = {
309
+ label: 'is less than',
310
+ relation: 'is_less_than',
311
+ type: 'numeric'
312
+ };
313
+
314
+ const RulesEditorRule = ({ rule, columns, onRemove, onColumnChange, onVariableChange, onRelationChange, onConditionChange, ruleCount, blankOk }) => {
315
+ const { column, relation, condition } = rule;
316
+
317
+ const currentColumn = columns[column];
318
+ const currentRelation = currentColumn.relations[relation];
319
+
320
+ let conditionEditor = null;
321
+ switch(currentRelation.type) {
322
+ case 'text':
323
+ case 'numeric':
324
+ case 'tag':
325
+ conditionEditor = <RulesEditorConditionInputText condition={condition} onChange={onConditionChange} />;
326
+ break;
327
+ case 'country_code':
328
+ conditionEditor = <RulesEditorConditionInputCountryCode condition={condition} onChange={onConditionChange} />;
329
+ break;
330
+ }
331
+
332
+ let deleteIconCell = null;
333
+ if(ruleCount > 1 || blankOk === true) {
334
+ deleteIconCell = (
335
+ <div className="sl">
336
+ <button type="button" className="btn btn--icon" onClick={onRemove}>
337
+ <i className="ico ico-14-svg ico-delete" />
338
+ </button>
339
+ </div>
340
+ );
341
+ }
342
+
343
+ const columnVariables = RulesEditor.getColumnPathVariables(currentColumn.column);
344
+
345
+ let variablesEditor = columnVariables.map(function(name) {
346
+ return (
347
+ <div className="next-grid__cell" key={name}>
348
+ <RulesEditorVariableInput name={name} value={rule[name]} onChange={onVariableChange.bind(this, name)} />
349
+ </div>
350
+ );
351
+ });
352
+
353
+ return (
354
+ <div>
355
+ <div className="next-grid next-grid--no-padding next-grid--compact">
356
+ <div className="next-grid__cell">
357
+ <div className="next-grid next-grid--compact next-grid--no-outside-padding">
358
+ <div className="next-grid__cell">
359
+ <RulesEditorColumnSelect currentColumnName={column} columns={columns} onChange={onColumnChange} />
360
+ </div>
361
+ {variablesEditor}
362
+ <div className="next-grid__cell">
363
+ <RulesEditorRelationSelect currentRelationName={relation} relations={currentColumn.relations} onChange={onRelationChange} />
364
+ </div>
365
+ <div className="next-grid__cell">
366
+ {conditionEditor}
367
+ </div>
368
+ </div>
369
+ </div>
370
+ {deleteIconCell}
371
+ </div>
372
+ <hr className="next-card__section__separator" />
373
+ </div>
374
+ );
375
+
376
+ };
377
+
378
+ const RulesEditorColumnSelect = ({ currentColumnName, columns, onChange }) => {
379
+ const options = Object.keys(columns).map((columnName) => {
380
+ return { label: columns[columnName].label, value: columnName }
381
+ });
382
+
383
+ return <InputSelect options={options} value={currentColumnName} onChange={onChange} label="Field" labelHidden={true} />;
384
+ };
385
+
386
+ const RulesEditorVariableInput = ({ name, value, onChange }) => {
387
+
388
+ const handleChange = (e) => {
389
+ onChange && onChange(e);
390
+ };
391
+
392
+ let label = name.substr(1).trim().replace( /([A-Z])/g, " $1" );
393
+ label = label.charAt(0).toUpperCase() + label.substr(1);
394
+
395
+ return (
396
+ <InputText value={value} onChange={handleChange} label={label} labelHidden={true} placeholder={label} required={true} />
397
+ );
398
+ };
399
+
400
+ const RulesEditorRelationSelect = ({ currentRelationName, relations, onChange }) => {
401
+ const options = Object.keys(relations).map((relationName) => {
402
+ return { label: relations[relationName].label, value: relationName }
403
+ });
404
+
405
+ return <InputSelect options={options} value={currentRelationName} onChange={onChange} label="Relation" labelHidden={true} />;
406
+ };
407
+
408
+ const RulesEditorConditionInputText = ({ condition, onChange }) => {
409
+
410
+ const handleChange = (e) => {
411
+ onChange && onChange(e);
412
+ };
413
+
414
+ return (
415
+ <InputText value={condition} onChange={handleChange} label="Value" labelHidden={true} />
416
+ );
417
+
418
+ };
419
+
420
+ const RulesEditorConditionInputCountryCode = ({ condition, onChange }) => {
421
+
422
+ const handleChange = (e) => {
423
+ onChange && onChange(e);
424
+ };
425
+
426
+ const countryOptions = [{"label":"Australia","value":"AU"},{"label":"Canada","value":"CA"},{"label":"United Kingdom","value":"GB"},{"label":"United States","value":"US"},{"label":"Afghanistan","value":"AF"},{"label":"Åland Islands","value":"AX"},{"label":"Albania","value":"AL"},{"label":"Algeria","value":"DZ"},{"label":"Andorra","value":"AD"},{"label":"Angola","value":"AO"},{"label":"Anguilla","value":"AI"},{"label":"Antigua & Barbuda","value":"AG"},{"label":"Argentina","value":"AR"},{"label":"Armenia","value":"AM"},{"label":"Aruba","value":"AW"},{"label":"Australia","value":"AU"},{"label":"Austria","value":"AT"},{"label":"Azerbaijan","value":"AZ"},{"label":"Bahamas","value":"BS"},{"label":"Bahrain","value":"BH"},{"label":"Bangladesh","value":"BD"},{"label":"Barbados","value":"BB"},{"label":"Belarus","value":"BY"},{"label":"Belgium","value":"BE"},{"label":"Belize","value":"BZ"},{"label":"Benin","value":"BJ"},{"label":"Bermuda","value":"BM"},{"label":"Bhutan","value":"BT"},{"label":"Bolivia","value":"BO"},{"label":"Bosnia & Herzegovina","value":"BA"},{"label":"Botswana","value":"BW"},{"label":"Bouvet Island","value":"BV"},{"label":"Brazil","value":"BR"},{"label":"British Indian Ocean Territory","value":"IO"},{"label":"British Virgin Islands","value":"VG"},{"label":"Brunei","value":"BN"},{"label":"Bulgaria","value":"BG"},{"label":"Burkina Faso","value":"BF"},{"label":"Burundi","value":"BI"},{"label":"Cambodia","value":"KH"},{"label":"Cameroon","value":"CM"},{"label":"Canada","value":"CA"},{"label":"Cape Verde","value":"CV"},{"label":"Cayman Islands","value":"KY"},{"label":"Central African Republic","value":"CF"},{"label":"Chad","value":"TD"},{"label":"Chile","value":"CL"},{"label":"China","value":"CN"},{"label":"Christmas Island","value":"CX"},{"label":"Cocos (Keeling) Islands","value":"CC"},{"label":"Colombia","value":"CO"},{"label":"Comoros","value":"KM"},{"label":"Congo - Brazzaville","value":"CG"},{"label":"Congo - Kinshasa","value":"CD"},{"label":"Cook Islands","value":"CK"},{"label":"Costa Rica","value":"CR"},{"label":"Croatia","value":"HR"},{"label":"Cuba","value":"CU"},{"label":"Curaçao","value":"CW"},{"label":"Cyprus","value":"CY"},{"label":"Czech Republic","value":"CZ"},{"label":"Côte d’Ivoire","value":"CI"},{"label":"Denmark","value":"DK"},{"label":"Djibouti","value":"DJ"},{"label":"Dominica","value":"DM"},{"label":"Dominican Republic","value":"DO"},{"label":"Ecuador","value":"EC"},{"label":"Egypt","value":"EG"},{"label":"El Salvador","value":"SV"},{"label":"Equatorial Guinea","value":"GQ"},{"label":"Eritrea","value":"ER"},{"label":"Estonia","value":"EE"},{"label":"Ethiopia","value":"ET"},{"label":"Falkland Islands","value":"FK"},{"label":"Faroe Islands","value":"FO"},{"label":"Fiji","value":"FJ"},{"label":"Finland","value":"FI"},{"label":"France","value":"FR"},{"label":"French Guiana","value":"GF"},{"label":"French Polynesia","value":"PF"},{"label":"French Southern Territories","value":"TF"},{"label":"Gabon","value":"GA"},{"label":"Gambia","value":"GM"},{"label":"Georgia","value":"GE"},{"label":"Germany","value":"DE"},{"label":"Ghana","value":"GH"},{"label":"Gibraltar","value":"GI"},{"label":"Greece","value":"GR"},{"label":"Greenland","value":"GL"},{"label":"Grenada","value":"GD"},{"label":"Guadeloupe","value":"GP"},{"label":"Guatemala","value":"GT"},{"label":"Guernsey","value":"GG"},{"label":"Guinea","value":"GN"},{"label":"Guinea-Bissau","value":"GW"},{"label":"Guyana","value":"GY"},{"label":"Haiti","value":"HT"},{"label":"Heard & McDonald Islands","value":"HM"},{"label":"Honduras","value":"HN"},{"label":"Hong Kong SAR China","value":"HK"},{"label":"Hungary","value":"HU"},{"label":"Iceland","value":"IS"},{"label":"India","value":"IN"},{"label":"Indonesia","value":"ID"},{"label":"Iran","value":"IR"},{"label":"Iraq","value":"IQ"},{"label":"Ireland","value":"IE"},{"label":"Isle of Man","value":"IM"},{"label":"Israel","value":"IL"},{"label":"Italy","value":"IT"},{"label":"Jamaica","value":"JM"},{"label":"Japan","value":"JP"},{"label":"Jersey","value":"JE"},{"label":"Jordan","value":"JO"},{"label":"Kazakhstan","value":"KZ"},{"label":"Kenya","value":"KE"},{"label":"Kiribati","value":"KI"},{"label":"Kosovo","value":"KV"},{"label":"Kuwait","value":"KW"},{"label":"Kyrgyzstan","value":"KG"},{"label":"Laos","value":"LA"},{"label":"Latvia","value":"LV"},{"label":"Lebanon","value":"LB"},{"label":"Lesotho","value":"LS"},{"label":"Liberia","value":"LR"},{"label":"Libya","value":"LY"},{"label":"Liechtenstein","value":"LI"},{"label":"Lithuania","value":"LT"},{"label":"Luxembourg","value":"LU"},{"label":"Macau SAR China","value":"MO"},{"label":"Macedonia","value":"MK"},{"label":"Madagascar","value":"MG"},{"label":"Malawi","value":"MW"},{"label":"Malaysia","value":"MY"},{"label":"Maldives","value":"MV"},{"label":"Mali","value":"ML"},{"label":"Malta","value":"MT"},{"label":"Martinique","value":"MQ"},{"label":"Mauritania","value":"MR"},{"label":"Mauritius","value":"MU"},{"label":"Mayotte","value":"YT"},{"label":"Mexico","value":"MX"},{"label":"Moldova","value":"MD"},{"label":"Monaco","value":"MC"},{"label":"Mongolia","value":"MN"},{"label":"Montenegro","value":"ME"},{"label":"Montserrat","value":"MS"},{"label":"Morocco","value":"MA"},{"label":"Mozambique","value":"MZ"},{"label":"Myanmar (Burma)","value":"MM"},{"label":"Namibia","value":"NA"},{"label":"Nauru","value":"NR"},{"label":"Nepal","value":"NP"},{"label":"Netherlands","value":"NL"},{"label":"Netherlands Antilles","value":"AN"},{"label":"New Caledonia","value":"NC"},{"label":"New Zealand","value":"NZ"},{"label":"Nicaragua","value":"NI"},{"label":"Niger","value":"NE"},{"label":"Nigeria","value":"NG"},{"label":"Niue","value":"NU"},{"label":"Norfolk Island","value":"NF"},{"label":"North Korea","value":"KP"},{"label":"Norway","value":"NO"},{"label":"Oman","value":"OM"},{"label":"Pakistan","value":"PK"},{"label":"Palestinian Territories","value":"PS"},{"label":"Panama","value":"PA"},{"label":"Papua New Guinea","value":"PG"},{"label":"Paraguay","value":"PY"},{"label":"Peru","value":"PE"},{"label":"Philippines","value":"PH"},{"label":"Pitcairn Islands","value":"PN"},{"label":"Poland","value":"PL"},{"label":"Portugal","value":"PT"},{"label":"Qatar","value":"QA"},{"label":"Réunion","value":"RE"},{"label":"Romania","value":"RO"},{"label":"Russia","value":"RU"},{"label":"Rwanda","value":"RW"},{"label":"Samoa","value":"WS"},{"label":"San Marino","value":"SM"},{"label":"São Tomé & Príncipe","value":"ST"},{"label":"Saudi Arabia","value":"SA"},{"label":"Senegal","value":"SN"},{"label":"Serbia","value":"RS"},{"label":"Seychelles","value":"SC"},{"label":"Sierra Leone","value":"SL"},{"label":"Singapore","value":"SG"},{"label":"Sint Maarten","value":"SX"},{"label":"Slovakia","value":"SK"},{"label":"Slovenia","value":"SI"},{"label":"Solomon Islands","value":"SB"},{"label":"Somalia","value":"SO"},{"label":"South Africa","value":"ZA"},{"label":"South Georgia & South Sandwich Islands","value":"GS"},{"label":"South Korea","value":"KR"},{"label":"Spain","value":"ES"},{"label":"Sri Lanka","value":"LK"},{"label":"St. Barthélemy","value":"BL"},{"label":"St. Helena","value":"SH"},{"label":"St. Kitts & Nevis","value":"KN"},{"label":"St. Lucia","value":"LC"},{"label":"St. Martin","value":"MF"},{"label":"St. Pierre & Miquelon","value":"PM"},{"label":"St. Vincent & Grenadines","value":"VC"},{"label":"Sudan","value":"SD"},{"label":"Suriname","value":"SR"},{"label":"Svalbard & Jan Mayen","value":"SJ"},{"label":"Swaziland","value":"SZ"},{"label":"Sweden","value":"SE"},{"label":"Switzerland","value":"CH"},{"label":"Syria","value":"SY"},{"label":"Taiwan","value":"TW"},{"label":"Tajikistan","value":"TJ"},{"label":"Tanzania","value":"TZ"},{"label":"Thailand","value":"TH"},{"label":"Timor-Leste","value":"TL"},{"label":"Togo","value":"TG"},{"label":"Tokelau","value":"TK"},{"label":"Tonga","value":"TO"},{"label":"Trinidad & Tobago","value":"TT"},{"label":"Tunisia","value":"TN"},{"label":"Turkey","value":"TR"},{"label":"Turkmenistan","value":"TM"},{"label":"Turks & Caicos Islands","value":"TC"},{"label":"Tuvalu","value":"TV"},{"label":"U.S. Outlying Islands","value":"UM"},{"label":"Uganda","value":"UG"},{"label":"Ukraine","value":"UA"},{"label":"United Arab Emirates","value":"AE"},{"label":"United Kingdom","value":"GB"},{"label":"United States","value":"US"},{"label":"Uruguay","value":"UY"},{"label":"Uzbekistan","value":"UZ"},{"label":"Vanuatu","value":"VU"},{"label":"Vatican City","value":"VA"},{"label":"Venezuela","value":"VE"},{"label":"Vietnam","value":"VN"},{"label":"Wallis & Futuna","value":"WF"},{"label":"Western Sahara","value":"EH"},{"label":"Yemen","value":"YE"},{"label":"Zambia","value":"ZM"},{"label":"Zimbabwe","value":"ZW"}];
427
+
428
+ return (
429
+ <InputSelect options={countryOptions} value={condition} onChange={handleChange} label="Value" labelHidden={true} />
430
+ );
431
+
432
+ };
@@ -0,0 +1,13 @@
1
+ const ShopFilterQuery = ({ filter, onFilterSet }) => {
2
+
3
+ const onChange = (value) => {
4
+ onFilterSet('filter[query]', value);
5
+ };
6
+
7
+ return (
8
+ <CardSection>
9
+ <InputText label="Search" placeholder="Start typing to search for stores..." labelHidden={true} value={filter.query} onChange={onChange} />
10
+ </CardSection>
11
+ );
12
+
13
+ };
@@ -0,0 +1,34 @@
1
+ var ShopFilterTab = React.createClass({
2
+
3
+ /**
4
+ * Handle a click event on the individual tab link.
5
+ * @param e
6
+ */
7
+ handleClick: function(e) {
8
+ e.preventDefault();
9
+
10
+ // Don't do anything if this is already the currently selected tab.
11
+ if(this.isActive()) return;
12
+
13
+ this.props.onFilterTabSelected(this.props.filterTab);
14
+ },
15
+
16
+ /**
17
+ * Return true if this is the currently active tab, determined by whether the filter values for this tab match the
18
+ * currently active filter.
19
+ * @returns {boolean}
20
+ */
21
+ isActive: function() {
22
+ return (JSON.stringify(this.props.filterTab.filter) == JSON.stringify(this.props.filter));
23
+ },
24
+
25
+ render: function() {
26
+ var tabClassName = this.isActive() ? 'next-tab next-tab--is-active' : 'next-tab';
27
+ return (
28
+ <li role="presentation">
29
+ <a href="#" className={tabClassName} onClick={this.handleClick}>{this.props.filterTab.label}</a>
30
+ </li>
31
+ )
32
+ }
33
+
34
+ });
@@ -0,0 +1,21 @@
1
+ var ShopFilterTabs = React.createClass({
2
+
3
+ onFilterTabSelected: function(filterTab) {
4
+ this.props.onFilterReplace(filterTab.filter);
5
+ },
6
+
7
+ render: function() {
8
+ var filterTabNodes = this.props.filterTabs.map(function(filterTab) {
9
+ return (
10
+ <ShopFilterTab key={filterTab.label} filter={this.props.filter} filterTab={filterTab} onFilterTabSelected={this.onFilterTabSelected} />
11
+ )
12
+ }, this);
13
+
14
+ return (
15
+ <ul className="next-tab__list">
16
+ {filterTabNodes}
17
+ </ul>
18
+ )
19
+ }
20
+
21
+ });
@@ -0,0 +1,142 @@
1
+ var ShopList = React.createClass({
2
+
3
+ getDefaultProps: function() {
4
+ return {
5
+ pageSize: 20
6
+ }
7
+ },
8
+
9
+ getInitialState: function() {
10
+ return {
11
+ shops: [],
12
+ page: 1
13
+ }
14
+ },
15
+
16
+ componentDidMount: function() {
17
+ this.getShops();
18
+ $(document).on('shops.changed', this.onShopsChanged);
19
+ },
20
+
21
+ componentWillUnmount: function() {
22
+ $(document).off('shops.changed', this.onShopsChanged);
23
+ },
24
+
25
+ componentDidUpdate: function (prevProps, prevState) {
26
+ if(prevProps.filter != this.props.filter) {
27
+ this.onShopsChanged();
28
+ }
29
+ if(prevState.page != this.state.page) {
30
+ this.getShops();
31
+ }
32
+ },
33
+
34
+ onPageChanged: function(increment) {
35
+ this.setState({page: this.state.page + increment});
36
+ },
37
+
38
+ /* get shops with a different filter */
39
+ onShopsChanged: function() {
40
+ this.setState({page: 1});
41
+ this.getShops();
42
+ },
43
+
44
+ getShops: function() {
45
+ //ShopifyApp.Bar.loadingOn();
46
+
47
+ // Set up request data with filter and pagination parameters.
48
+ var data = $.extend({
49
+ 'page[size]': this.props.pageSize,
50
+ 'page[number]': this.state.page
51
+ }, this.props.filter);
52
+
53
+ // Make the request to fetch the order list.
54
+ $.getJSON(this.props.shopsUrl, data, function(result) {
55
+ if(this.isMounted()) {
56
+ this.setState({
57
+ shops: result.data
58
+ });
59
+ }
60
+ }.bind(this))
61
+ .always(function() {
62
+ //ShopifyApp.Bar.loadingOff();
63
+ });
64
+ },
65
+
66
+ render: function() {
67
+ var shopRows = this.state.shops.map(function(shop, index) {
68
+ if ((index >= ((this.state.page - 1) * this.props.pageSize)) && (index < this.state.page * this.props.pageSize)) {
69
+ return (
70
+ <ShopRow shop={shop} editShopUrl={this.props.editShopUrl} editSubscriptionUrl={this.props.editSubscriptionUrl} key={shop.id} />
71
+ )
72
+ } else {
73
+ return null;
74
+ }
75
+ }.bind(this));
76
+
77
+ return (
78
+ <div>
79
+ <div className="next-card__section">
80
+ <table className="table-hover expanded">
81
+ <thead>
82
+ <tr>
83
+ <th>Shop</th>
84
+ <th>Status</th>
85
+ <th>Country</th>
86
+ <th>Shopify Plan</th>
87
+ <th>Subscription</th>
88
+ <th>Source</th>
89
+ <th>Installed for</th>
90
+ </tr>
91
+ </thead>
92
+ <tbody>
93
+ {shopRows}
94
+ </tbody>
95
+ </table>
96
+ </div>
97
+ <div className="next-card__section">
98
+ <div className="next-grid next-grid--no-padding next-grid--center-aligned">
99
+ <div className="next-grid__cell next-grid__cell--no-flex">
100
+ <ShopList.Paginator page={this.state.page} pageSize={this.props.pageSize} items={this.state.shops} onPageChanged={this.onPageChanged} />
101
+ </div>
102
+ </div>
103
+ </div>
104
+ </div>
105
+ )
106
+ }
107
+
108
+ });
109
+
110
+ /**
111
+ * Paginator.
112
+ */
113
+ ShopList.Paginator = React.createClass({
114
+
115
+ handlePreviousClick: function(e) {
116
+ this.props.onPageChanged(-1);
117
+ },
118
+
119
+ handleNextClick: function(e) {
120
+ this.props.onPageChanged(1);
121
+ },
122
+
123
+ render: function() {
124
+ return (
125
+ <div className="btn-group" role="group">
126
+ <ShopList.PaginatorButton label="&lsaquo;" isDisabled={this.props.page < 2} onClick={this.handlePreviousClick} />
127
+ <ShopList.PaginatorButton label="&rsaquo;" isDisabled={this.props.items.length < this.props.pageSize * this.props.page} onClick={this.handleNextClick} />
128
+ </div>
129
+ )
130
+ }
131
+
132
+ });
133
+
134
+ /**
135
+ * Individual button within a paginator.
136
+ */
137
+ ShopList.PaginatorButton = (props) => {
138
+ var className = 'btn btn-default' + (props.isDisabled ? ' disabled' : '');
139
+ return (
140
+ <button className={className} disabled={props.isDisabled} onClick={props.onClick}>{props.label}</button>
141
+ )
142
+ };