From f8d97dac947370aa188d13a675d29a954a02f504 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Sun, 23 Jun 2019 15:05:40 -0700 Subject: [PATCH 01/17] Initial commit. Fixed route --- .../admin/publishers/referrals_controller.rb | 12 +++++ app/controllers/admin/referrals_controller.rb | 44 ------------------- app/javascript/routes/routes.ts | 3 +- .../referrals/index.html.slim | 0 .../admin/publishers/referrals/show.html.slim | 8 ++++ app/views/admin/referrals/show.html.erb | 5 --- app/views/admin/referrals/show.html.slim | 1 - config/routes.rb | 4 +- 8 files changed, 24 insertions(+), 53 deletions(-) create mode 100644 app/controllers/admin/publishers/referrals_controller.rb delete mode 100644 app/controllers/admin/referrals_controller.rb rename app/views/admin/{ => publishers}/referrals/index.html.slim (100%) create mode 100644 app/views/admin/publishers/referrals/show.html.slim delete mode 100644 app/views/admin/referrals/show.html.erb delete mode 100644 app/views/admin/referrals/show.html.slim diff --git a/app/controllers/admin/publishers/referrals_controller.rb b/app/controllers/admin/publishers/referrals_controller.rb new file mode 100644 index 0000000000..c293a0aedf --- /dev/null +++ b/app/controllers/admin/publishers/referrals_controller.rb @@ -0,0 +1,12 @@ +class Admin::Publishers::ReferralsController < Admin::PublishersController + def show + @publisher = Publisher.find(params[:id] || params[:publisher_id]) + @navigation_view = Views::Admin::NavigationView.new(publisher).as_json.merge({ navbarSelection: "Referrals" }).to_json + end + + def stats_by_date + promo_registration = current_publisher.promo_registrations.find_by(referral_code: params[:referral_code]) + render :unauthorized and return if promo_registration.nil? + render json: promo_registration.stats_by_date.to_json + end +end diff --git a/app/controllers/admin/referrals_controller.rb b/app/controllers/admin/referrals_controller.rb deleted file mode 100644 index 18fff85f0b..0000000000 --- a/app/controllers/admin/referrals_controller.rb +++ /dev/null @@ -1,44 +0,0 @@ -module Admin - class ReferralsController < AdminController - include PromosHelper - include PublishersHelper - def show - publisher = Publisher.find(params[:id]) - @navigation_view = Views::Admin::NavigationView.new(publisher).as_json.merge({ navbarSelection: "Referrals" }).to_json - respond_to do |format| - format.html do - @data = show_data(params[:id]) - end - format.json do - render json: show_data(params[:id]) - end - end - end - - def show_data(id) - publisher = Publisher.find(id) - promo_registrations = [] - - publisher.promo_registrations.each do |promo_registration| - stats = [] - JSON.parse(promo_registration.stats).each do |stat| - date = Date.parse(stat["ymd"]).strftime("%m/%d/%Y") - stats.push({ - date: date, - downloads: stat["retrievals"], - installs: stat["first_runs"], - confirmations: stat["finalized"], - }) - end - promo_registrations.push({ - referralCode: promo_registration.referral_code, - stats: stats, - }) - end - - { - referralCodes: promo_registrations, - }.merge(Views::Admin::NavigationView.new(publisher).as_json) - end - end -end diff --git a/app/javascript/routes/routes.ts b/app/javascript/routes/routes.ts index 7c25cd2cb1..3dec08feb1 100644 --- a/app/javascript/routes/routes.ts +++ b/app/javascript/routes/routes.ts @@ -1,6 +1,7 @@ export default { admin: { userNavbar: { + // TODO: These routes aren't RESTful and should be fixed channels: { path: "/admin/channels/{id}" }, @@ -11,7 +12,7 @@ export default { path: "/admin/payments/{id}" }, referrals: { - path: "/admin/referrals/{id}" + path: "/admin/publishers/{id}/referrals" } } }, diff --git a/app/views/admin/referrals/index.html.slim b/app/views/admin/publishers/referrals/index.html.slim similarity index 100% rename from app/views/admin/referrals/index.html.slim rename to app/views/admin/publishers/referrals/index.html.slim diff --git a/app/views/admin/publishers/referrals/show.html.slim b/app/views/admin/publishers/referrals/show.html.slim new file mode 100644 index 0000000000..1130fc2a35 --- /dev/null +++ b/app/views/admin/publishers/referrals/show.html.slim @@ -0,0 +1,8 @@ += hidden_field_tag 'all-channels-referral-stats-starting-month', @publisher.promo_registrations.has_stats.order(created_at: :asc).first.created_at.strftime("%Y-%m-%d") += hidden_field_tag 'referrals-hidden-tags', @publisher.promo_registrations.has_stats.pluck(:referral_code).to_json + +.row + .col.bot-marg + .dashboard-panel--wrapper + #channel-referrals-stats-chart + canvas id="channel-referrals-stats-chart-canvas" diff --git a/app/views/admin/referrals/show.html.erb b/app/views/admin/referrals/show.html.erb deleted file mode 100644 index ad772796b3..0000000000 --- a/app/views/admin/referrals/show.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<%= content_tag :div, - id: "referrals_data", - data: @data.to_json do %> -<%= javascript_pack_tag 'views/admin/referrals/Referrals' %> -<% end %> \ No newline at end of file diff --git a/app/views/admin/referrals/show.html.slim b/app/views/admin/referrals/show.html.slim deleted file mode 100644 index 52f1aab114..0000000000 --- a/app/views/admin/referrals/show.html.slim +++ /dev/null @@ -1 +0,0 @@ -= javascript_pack_tag 'views/admin/referrals/Referrals' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5ae0d955d7..3967827776 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -175,11 +175,11 @@ get :cancel_two_factor_authentication_removal end resources :publisher_notes - resources :reports resources :publisher_status_updates, controller: 'publishers/publisher_status_updates' + resources :referrals, controller: 'publishers/referrals' + resources :reports end resources :channel_transfers - resources :referrals resources :payments resources :channel_approvals resources :security From d7af79db1c8b938d58e6e335b9d19c94e99f581d Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Sun, 23 Jun 2019 17:27:22 -0700 Subject: [PATCH 02/17] Something broke here while trying to import --- app/javascript/packs/chart/Chart.js | 4 +- app/javascript/packs/referral_charts.jsx | 2 +- .../packs/views/admin/referrals/Referrals.jsx | 11 +-- .../packs/views/referrals/Referrals.jsx | 9 +- app/javascript/publishers/dashboard_chart.js | 91 ------------------- .../views/admin/referrals/Referrals.tsx | 5 +- .../publishers/referrals/index.html.slim | 10 +- .../admin/publishers/referrals/show.html.slim | 8 -- package.json | 4 +- yarn.lock | 60 +++++++++++- 10 files changed, 75 insertions(+), 129 deletions(-) delete mode 100644 app/javascript/publishers/dashboard_chart.js delete mode 100644 app/views/admin/publishers/referrals/show.html.slim diff --git a/app/javascript/packs/chart/Chart.js b/app/javascript/packs/chart/Chart.js index 540a15ab6b..3470e5c814 100644 --- a/app/javascript/packs/chart/Chart.js +++ b/app/javascript/packs/chart/Chart.js @@ -2,7 +2,7 @@ import * as React from "react"; import moment from "moment"; import Chart from "chart.js"; -class ReactChart extends React.Component { +export class ReactChart extends React.Component { constructor(props) { super(props); this.chartRef = React.createRef(); @@ -161,5 +161,3 @@ class ReactChart extends React.Component { ); } } - -export default ReactChart; diff --git a/app/javascript/packs/referral_charts.jsx b/app/javascript/packs/referral_charts.jsx index e7634fdc39..3e25662a1b 100644 --- a/app/javascript/packs/referral_charts.jsx +++ b/app/javascript/packs/referral_charts.jsx @@ -7,7 +7,7 @@ import ControlWrapper from "brave-ui/components/formControls/controlWrapper"; import { PrimaryButton } from "../publishers/ReferralChartsStyle"; // import "../publishers/dashboard_chart"; import routes from "../views/routes"; -import Chart from "./chart/Chart"; +import ReactChart from "./chart/Chart"; import { ThemeProvider } from "brave-ui/theme"; import Theme from "brave-ui/theme/brave-default"; diff --git a/app/javascript/packs/views/admin/referrals/Referrals.jsx b/app/javascript/packs/views/admin/referrals/Referrals.jsx index ee9dedecbc..1d466e5816 100644 --- a/app/javascript/packs/views/admin/referrals/Referrals.jsx +++ b/app/javascript/packs/views/admin/referrals/Referrals.jsx @@ -1,14 +1,7 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; -import Referrals from "../../../../views/admin/referrals/Referrals"; +import renderReferralCharts from "../../../../packs/referral_charts" document.addEventListener("DOMContentLoaded", () => { - const node = document.getElementById("referrals_data"); - const data = JSON.parse(node.getAttribute("data")); - ReactDOM.render( - , - document - .getElementById("main-content") - .appendChild(document.createElement("div")) - ); + renderReferralCharts(); }); diff --git a/app/javascript/packs/views/referrals/Referrals.jsx b/app/javascript/packs/views/referrals/Referrals.jsx index 2b80642704..1201634846 100644 --- a/app/javascript/packs/views/referrals/Referrals.jsx +++ b/app/javascript/packs/views/referrals/Referrals.jsx @@ -1,12 +1,7 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; -import Referrals from "../../../views/referrals/Referrals"; +import renderReferralCharts from "../../../packs/referral_charts" document.addEventListener("DOMContentLoaded", () => { - ReactDOM.render( - , - document.body.appendChild( - document.getElementsByClassName("main-content")[0] - ) - ); + renderReferralCharts(); }); diff --git a/app/javascript/publishers/dashboard_chart.js b/app/javascript/publishers/dashboard_chart.js deleted file mode 100644 index 5f2c547736..0000000000 --- a/app/javascript/publishers/dashboard_chart.js +++ /dev/null @@ -1,91 +0,0 @@ -import Chart from 'chart.js'; -import moment from 'moment'; - -let colors = [ - '255, 99, 132', - '54, 162, 235', - '255, 206, 86', - '75, 192, 192', - '153, 102, 255', - '255, 159, 64' -] - -function createLabels(startingDate) { - // https://stackoverflow.com/questions/7556591/is-the-javascript-date-object-always-one-day-off - var loop = new Date(startingDate.replace(/-/g, '\/')); - var dates_array = []; - - while (loop <= new Date()) { - dates_array.push(loop.getFullYear() + '-' + (loop.getMonth() + 1) + '-' + loop.getDate()); - loop.setDate(loop.getDate() + 1); - } - - return dates_array; -} - -// Max of the chart is 80% of the suggested max to be used by Chartjs -function getSuggestedMax(data) { - var currentMax = 0; - Object.keys(data).forEach(function (key) { - var value = data[key]; - currentMax = value.retrievals > currentMax ? value.retrievals : currentMax; - currentMax = value.first_runs > currentMax ? value.first_runs : currentMax; - currentMax = value.finalized > currentMax ? value.finalized : currentMax; - }); - return (currentMax * 100 / 95) -} - -function createChart(data, title, suggestedMax) { - var wrapper = document.getElementById('channel-referrals-stats-chart'); - var canvas = document.getElementById('channel-referrals-stats-chart-canvas'); - if (!canvas) { - canvas = document.createElement('canvas'); - canvas.setAttribute('id', 'channel-referrals-stats-chart-canvas'); - canvas.setAttribute("width", "400"); - canvas.setAttribute("height", "300"); - wrapper.appendChild(canvas); - } - - Chart.defaults.global.defaultFontFamily = 'Poppins'; - - new Chart(canvas, { - type: 'line', - data: { - labels: createLabels(data[0]['ymd']), - datasets: [ - { - label: 'Downloads', - data: data.map(x => x.retrievals), - borderColor: '#F88469', - }, - { - label: 'Installs', - data: data.map(x => x.first_runs), - borderColor: '#7B82E1', - }, - { - label: '30-Day-Use', - data: data.map(x => x.finalized), - borderColor: '#66C3FC', - }, - ] - }, - options: { - tooltips: { - mode: 'x' - }, - title: { - fontSize: 18, - display: true, - text: title.toUpperCase() - }, - scales: { - yAxes: [{ - ticks: { - suggestedMax: suggestedMax - } - }] - } - } - }); -} diff --git a/app/javascript/views/admin/referrals/Referrals.tsx b/app/javascript/views/admin/referrals/Referrals.tsx index 3471495a69..4fbad6bfb8 100644 --- a/app/javascript/views/admin/referrals/Referrals.tsx +++ b/app/javascript/views/admin/referrals/Referrals.tsx @@ -2,7 +2,8 @@ import * as React from "react"; import { Cell, Container, Grid } from "../../../components/grid/Grid"; import UserNavbar from "../components/userNavbar/UserNavbar"; -import ReferralsChart from "./components/referralsChart/ReferralsChart"; +// import ReferralsChart from "./components/referralsChart/ReferralsChart"; +import renderReferralCharts from "../../../packs/referral_charts" import { templateAreas, templateRows } from "./ReferralsStyle"; export enum NavbarSelection { @@ -19,6 +20,7 @@ interface IReferralsProps { export default class Referrals extends React.Component { constructor(props) { super(props); + renderReferralCharts(); } public render() { @@ -35,7 +37,6 @@ export default class Referrals extends React.Component { style={{ marginTop: "30px", marginBottom: "30px" }} > - diff --git a/app/views/admin/publishers/referrals/index.html.slim b/app/views/admin/publishers/referrals/index.html.slim index eabf47a5e6..73281c5863 100644 --- a/app/views/admin/publishers/referrals/index.html.slim +++ b/app/views/admin/publishers/referrals/index.html.slim @@ -1 +1,9 @@ -= javascript_pack_tag 'views/referrals/Referrals' \ No newline at end of file += hidden_field_tag 'all-channels-referral-stats-starting-month', @publisher.promo_registrations.has_stats.order(created_at: :asc).first.created_at.strftime("%Y-%m-%d") += hidden_field_tag 'referrals-hidden-tags', @publisher.promo_registrations.has_stats.pluck(:referral_code).to_json + +.row + .col.bot-marg + .dashboard-panel--wrapper + #channel-referrals-stats-chart + canvas id="channel-referrals-stats-chart-canvas" += javascript_pack_tag 'views/admin/referrals/Referrals' diff --git a/app/views/admin/publishers/referrals/show.html.slim b/app/views/admin/publishers/referrals/show.html.slim deleted file mode 100644 index 1130fc2a35..0000000000 --- a/app/views/admin/publishers/referrals/show.html.slim +++ /dev/null @@ -1,8 +0,0 @@ -= hidden_field_tag 'all-channels-referral-stats-starting-month', @publisher.promo_registrations.has_stats.order(created_at: :asc).first.created_at.strftime("%Y-%m-%d") -= hidden_field_tag 'referrals-hidden-tags', @publisher.promo_registrations.has_stats.pluck(:referral_code).to_json - -.row - .col.bot-marg - .dashboard-panel--wrapper - #channel-referrals-stats-chart - canvas id="channel-referrals-stats-chart-canvas" diff --git a/package.json b/package.json index bc30d510c0..e76894bef5 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,7 @@ "husky": "^1.3.1", "jest": "^24.1.0", "jest-styled-components": "^5.0.1", + "node-gyp": "^5.0.1", "prettier": "1.16.3", "stylelint": "^10.1.0", "stylelint-config-recommended-scss": "^3.3.0", @@ -112,7 +113,6 @@ "webpack-dev-server": "3.7.1" }, "resolutions": { - "js-yaml": "3.13.1", - "node-gyp": "github:brave/node-gyp" + "js-yaml": "3.13.1" } } diff --git a/yarn.lock b/yarn.lock index f13ffec108..f2e98bf77c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2047,6 +2047,13 @@ binary-extensions@^1.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.0.tgz#9523e001306a32444b907423f1de2164222f6ab1" integrity sha512-EgmjVLMn22z7eGGv3kcnHwSnJXmFHjISTY9E/S5lIcTD3Oxw05QTcBLNkJFzcb3cNueUdF/IN4U+d78V0zO8Hw== +block-stream@*: + version "0.0.9" + resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a" + integrity sha1-E+v+d4oDIFz+A3UUgeu0szAMEmo= + dependencies: + inherits "~2.0.0" + bluebird@^3.5.3: version "3.5.3" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7" @@ -4230,6 +4237,16 @@ fsevents@^1.2.7: nan "^2.9.2" node-pre-gyp "^0.10.0" +fstream@^1.0.0, fstream@^1.0.12: + version "1.0.12" + resolved "https://registry.yarnpkg.com/fstream/-/fstream-1.0.12.tgz#4e8ba8ee2d48be4f7d0de505455548eae5932045" + integrity sha512-WvJ193OHa0GHPEL+AycEJgxvBEwyfRkN1vhjca23OaPVMCaLCXTd5qAu82AjTcgP1UJmytkOKb63Ypde7raDIg== + dependencies: + graceful-fs "^4.1.2" + inherits "~2.0.0" + mkdirp ">=0.5 0" + rimraf "2" + function-bind@^1.0.2, function-bind@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" @@ -4868,6 +4885,11 @@ inherits@2.0.1: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" integrity sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE= +inherits@~2.0.0: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + ini@^1.3.4, ini@^1.3.5, ini@~1.3.0: version "1.3.5" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" @@ -6477,7 +6499,7 @@ mixin-object@^2.0.1: for-in "^0.1.3" is-extendable "^0.1.1" -mkdirp@0.5.x, mkdirp@0.x, mkdirp@^0.5, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: +mkdirp@0.5.x, mkdirp@0.x, "mkdirp@>=0.5 0", mkdirp@^0.5, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM= @@ -6614,9 +6636,28 @@ node-forge@0.7.5: resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.5.tgz#6c152c345ce11c52f465c2abd957e8639cd674df" integrity sha512-MmbQJ2MTESTjt3Gi/3yG1wGpIMhUfcIypUCGtTizFR9IiccFwxSpfp0vtIZlkFclEqERemxfnSdZEMR9VqqEFQ== -node-gyp@^3.8.0, "node-gyp@github:brave/node-gyp": - version "4.0.0" - resolved "https://codeload.github.com/brave/node-gyp/tar.gz/1456ef27c72cc4e49f9b1d82cbb047cb673156c8" +node-gyp@^3.8.0: + version "3.8.0" + resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.8.0.tgz#540304261c330e80d0d5edce253a68cb3964218c" + integrity sha512-3g8lYefrRRzvGeSowdJKAKyks8oUpLEd/DyPV4eMhVlhJ0aNaZqIrNUIPuEWWTAoPqyFkfGrM67MC69baqn6vA== + dependencies: + fstream "^1.0.0" + glob "^7.0.3" + graceful-fs "^4.1.2" + mkdirp "^0.5.0" + nopt "2 || 3" + npmlog "0 || 1 || 2 || 3 || 4" + osenv "0" + request "^2.87.0" + rimraf "2" + semver "~5.3.0" + tar "^2.0.0" + which "1" + +node-gyp@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-5.0.1.tgz#db211e9c5d7f611e79d1dcbdc53bca646b99ae4c" + integrity sha512-D68549U6EDVJLrAkSOZCWX/nmlYo0eCX2dYZoTOOZJ7bEIFrSE/MQgsgMFBKjByJ323hNzkifw2OuT3A5bR5mA== dependencies: env-paths "^1.0.0" glob "^7.0.3" @@ -7030,7 +7071,7 @@ os-tmpdir@^1.0.0: resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= -osenv@^0.1.4: +osenv@0, osenv@^0.1.4: version "0.1.5" resolved "https://registry.yarnpkg.com/osenv/-/osenv-0.1.5.tgz#85cdfafaeb28e8677f416e287592b5f3f49ea410" integrity sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g== @@ -9733,6 +9774,15 @@ tapable@^1.0.0, tapable@^1.1.0: resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.1.1.tgz#4d297923c5a72a42360de2ab52dadfaaec00018e" integrity sha512-9I2ydhj8Z9veORCw5PRm4u9uebCn0mcCa6scWoNcbZ6dAtoo2618u9UUzxgmsCOreJpqDDuv61LvwofW7hLcBA== +tar@^2.0.0: + version "2.2.2" + resolved "https://registry.yarnpkg.com/tar/-/tar-2.2.2.tgz#0ca8848562c7299b8b446ff6a4d60cdbb23edc40" + integrity sha512-FCEhQ/4rE1zYv9rYXJw/msRqsnmlje5jHP6huWeBZ704jUTy02c5AZyWujpMR1ax6mVw9NyJMfuK2CMDWVIfgA== + dependencies: + block-stream "*" + fstream "^1.0.12" + inherits "2" + tar@^4, tar@^4.4.8: version "4.4.8" resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.8.tgz#b19eec3fde2a96e64666df9fdb40c5ca1bc3747d" From 9ff03171d28992af7dc22c7c89d41a524fcd9105 Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Mon, 24 Jun 2019 12:17:46 -0400 Subject: [PATCH 03/17] Fix import errors --- app/javascript/packs/chart/Chart.js | 19 +++++-------------- app/javascript/packs/referral_charts.jsx | 7 ++----- .../packs/views/admin/referrals/Referrals.jsx | 2 +- .../publishers/referrals/index.html.slim | 2 +- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/app/javascript/packs/chart/Chart.js b/app/javascript/packs/chart/Chart.js index 3470e5c814..82522a923f 100644 --- a/app/javascript/packs/chart/Chart.js +++ b/app/javascript/packs/chart/Chart.js @@ -2,7 +2,7 @@ import * as React from "react"; import moment from "moment"; import Chart from "chart.js"; -export class ReactChart extends React.Component { +export default class ReactChart extends React.Component { constructor(props) { super(props); this.chartRef = React.createRef(); @@ -40,10 +40,7 @@ export class ReactChart extends React.Component { }); } else { this.chart.data = this.getData(this.props.data); - this.chart.options = this.getOptions( - this.props.title, - this.getSuggestedMax(this.props.data) - ); + this.chart.options = this.getOptions(this.props.title, this.getSuggestedMax(this.props.data)); this.chart.update(); } } @@ -128,10 +125,8 @@ export class ReactChart extends React.Component { var currentMax = 0; Object.keys(data).forEach(function(key) { var value = data[key]; - currentMax = - value.retrievals > currentMax ? value.retrievals : currentMax; - currentMax = - value.first_runs > currentMax ? value.first_runs : currentMax; + currentMax = value.retrievals > currentMax ? value.retrievals : currentMax; + currentMax = value.first_runs > currentMax ? value.first_runs : currentMax; currentMax = value.finalized > currentMax ? value.finalized : currentMax; }); return Math.ceil((currentMax / 95) * 100); @@ -154,10 +149,6 @@ export class ReactChart extends React.Component { } render() { - return ( -
- {this.props.data && } -
- ); + return
{this.props.data && }
; } } diff --git a/app/javascript/packs/referral_charts.jsx b/app/javascript/packs/referral_charts.jsx index 3e25662a1b..5b9a821199 100644 --- a/app/javascript/packs/referral_charts.jsx +++ b/app/javascript/packs/referral_charts.jsx @@ -27,10 +27,7 @@ export default class ReferralCharts extends React.Component { async viewReferralCodeStats() { const node = this.selectMenuRef.current; - var url = routes.publishers.promo_registrations.show.path.replace( - "{id}", - this.props.publisherId - ); + var url = routes.publishers.promo_registrations.show.path.replace("{id}", this.props.publisherId); url = url.replace("{referral_code}", node.state.value); const result = await fetch(url, { headers: { @@ -71,7 +68,7 @@ export default class ReferralCharts extends React.Component { View stats - + ); } diff --git a/app/javascript/packs/views/admin/referrals/Referrals.jsx b/app/javascript/packs/views/admin/referrals/Referrals.jsx index 1d466e5816..ee25e2d399 100644 --- a/app/javascript/packs/views/admin/referrals/Referrals.jsx +++ b/app/javascript/packs/views/admin/referrals/Referrals.jsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; -import renderReferralCharts from "../../../../packs/referral_charts" +import { renderReferralCharts } from "../../../../packs/referral_charts"; document.addEventListener("DOMContentLoaded", () => { renderReferralCharts(); diff --git a/app/views/admin/publishers/referrals/index.html.slim b/app/views/admin/publishers/referrals/index.html.slim index 73281c5863..2159fba28f 100644 --- a/app/views/admin/publishers/referrals/index.html.slim +++ b/app/views/admin/publishers/referrals/index.html.slim @@ -1,6 +1,6 @@ = hidden_field_tag 'all-channels-referral-stats-starting-month', @publisher.promo_registrations.has_stats.order(created_at: :asc).first.created_at.strftime("%Y-%m-%d") = hidden_field_tag 'referrals-hidden-tags', @publisher.promo_registrations.has_stats.pluck(:referral_code).to_json - += hidden_field_tag 'publisher_id', @publisher.id .row .col.bot-marg .dashboard-panel--wrapper From 6e6dc8e556a3b631a179437915bf3dfb0c147738 Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Mon, 24 Jun 2019 12:30:32 -0400 Subject: [PATCH 04/17] Add new route --- app/javascript/packs/referral_charts.jsx | 2 +- app/javascript/views/routes.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/javascript/packs/referral_charts.jsx b/app/javascript/packs/referral_charts.jsx index 5b9a821199..976e5bc85c 100644 --- a/app/javascript/packs/referral_charts.jsx +++ b/app/javascript/packs/referral_charts.jsx @@ -27,7 +27,7 @@ export default class ReferralCharts extends React.Component { async viewReferralCodeStats() { const node = this.selectMenuRef.current; - var url = routes.publishers.promo_registrations.show.path.replace("{id}", this.props.publisherId); + var url = routes.admin.promo_registrations.show.path.replace("{id}", this.props.publisherId); url = url.replace("{referral_code}", node.state.value); const result = await fetch(url, { headers: { diff --git a/app/javascript/views/routes.ts b/app/javascript/views/routes.ts index 97b21d2b26..e56c0809b9 100644 --- a/app/javascript/views/routes.ts +++ b/app/javascript/views/routes.ts @@ -1,5 +1,12 @@ /* tslint:disable:object-literal-sort-keys */ export default { + admin: { + promo_registrations: { + show: { + path: "/publishers/{id}/promo_registrations/for_referral_code?referral_code={referral_code}" + } + } + }, payments: { path: "/partners/payments", invoices: { @@ -18,8 +25,7 @@ export default { publishers: { promo_registrations: { show: { - path: - "{id}/promo_registrations/for_referral_code?referral_code={referral_code}" + path: "{id}/promo_registrations/for_referral_code?referral_code={referral_code}" } } } From 742ffbfa2c9784f627eb0af9bfabd7aabea815e2 Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Mon, 24 Jun 2019 13:56:26 -0400 Subject: [PATCH 05/17] Finish implementation --- app/controllers/admin/promo_registrations_controller.rb | 9 +++++++++ app/javascript/packs/referral_charts.jsx | 2 +- app/javascript/views/routes.ts | 2 +- app/views/admin/publishers/referrals/index.html.slim | 8 +++++--- config/routes.rb | 6 +++++- 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 app/controllers/admin/promo_registrations_controller.rb diff --git a/app/controllers/admin/promo_registrations_controller.rb b/app/controllers/admin/promo_registrations_controller.rb new file mode 100644 index 0000000000..9b037348b9 --- /dev/null +++ b/app/controllers/admin/promo_registrations_controller.rb @@ -0,0 +1,9 @@ +class Admin::PromoRegistrationsController < AdminController + def for_referral_code + publisher = Publisher.find(params[:publisher_id]) + promo_registration = publisher.promo_registrations.find_by(referral_code: params[:referral_code]) + render :unauthorized and return if promo_registration.nil? + render json: promo_registration.stats_by_date.to_json + end +end + \ No newline at end of file diff --git a/app/javascript/packs/referral_charts.jsx b/app/javascript/packs/referral_charts.jsx index 976e5bc85c..56b0ddd2c5 100644 --- a/app/javascript/packs/referral_charts.jsx +++ b/app/javascript/packs/referral_charts.jsx @@ -27,7 +27,7 @@ export default class ReferralCharts extends React.Component { async viewReferralCodeStats() { const node = this.selectMenuRef.current; - var url = routes.admin.promo_registrations.show.path.replace("{id}", this.props.publisherId); + var url = routes.admin.promo_registrations.show.path.replace("{publisher_id}", this.props.publisherId); url = url.replace("{referral_code}", node.state.value); const result = await fetch(url, { headers: { diff --git a/app/javascript/views/routes.ts b/app/javascript/views/routes.ts index e56c0809b9..36ab794079 100644 --- a/app/javascript/views/routes.ts +++ b/app/javascript/views/routes.ts @@ -3,7 +3,7 @@ export default { admin: { promo_registrations: { show: { - path: "/publishers/{id}/promo_registrations/for_referral_code?referral_code={referral_code}" + path: "/admin/promo_registrations/for_referral_code?referral_code={referral_code}&publisher_id={publisher_id}" } } }, diff --git a/app/views/admin/publishers/referrals/index.html.slim b/app/views/admin/publishers/referrals/index.html.slim index 2159fba28f..82b370a8ba 100644 --- a/app/views/admin/publishers/referrals/index.html.slim +++ b/app/views/admin/publishers/referrals/index.html.slim @@ -1,6 +1,8 @@ -= hidden_field_tag 'all-channels-referral-stats-starting-month', @publisher.promo_registrations.has_stats.order(created_at: :asc).first.created_at.strftime("%Y-%m-%d") -= hidden_field_tag 'referrals-hidden-tags', @publisher.promo_registrations.has_stats.pluck(:referral_code).to_json -= hidden_field_tag 'publisher_id', @publisher.id + +- if @publisher.promo_registrations.present? + = hidden_field_tag 'all-channels-referral-stats-starting-month', @publisher.promo_registrations.has_stats.order(created_at: :asc).first.created_at.strftime("%Y-%m-%d") + = hidden_field_tag 'referrals-hidden-tags', @publisher.promo_registrations.has_stats.pluck(:referral_code).to_json + = hidden_field_tag 'publisher_id', @publisher.id .row .col.bot-marg .dashboard-panel--wrapper diff --git a/config/routes.rb b/config/routes.rb index 3967827776..0c168789cc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -154,7 +154,11 @@ get :duplicates end end - + resources :promo_registrations, only: [] do + collection do + get :for_referral_code + end + end resources :faq_categories, except: [:show] resources :faqs, except: [:show] resources :payout_reports, only: %i(index show create) do From 2617c1872adddb92e283fd350f36f4fe4c2984ef Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Mon, 24 Jun 2019 13:59:24 -0400 Subject: [PATCH 06/17] Fix lint errors --- app/javascript/views/admin/referrals/Referrals.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/javascript/views/admin/referrals/Referrals.tsx b/app/javascript/views/admin/referrals/Referrals.tsx index 4fbad6bfb8..5e961232da 100644 --- a/app/javascript/views/admin/referrals/Referrals.tsx +++ b/app/javascript/views/admin/referrals/Referrals.tsx @@ -1,9 +1,10 @@ import * as React from "react"; import { Cell, Container, Grid } from "../../../components/grid/Grid"; +import renderReferralCharts from "../../../packs/referral_charts"; import UserNavbar from "../components/userNavbar/UserNavbar"; // import ReferralsChart from "./components/referralsChart/ReferralsChart"; -import renderReferralCharts from "../../../packs/referral_charts" + import { templateAreas, templateRows } from "./ReferralsStyle"; export enum NavbarSelection { @@ -26,18 +27,14 @@ export default class Referrals extends React.Component { public render() { return ( - + - - + From 4969cda8202dc5f3bb7487b13a90820325d4f526 Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Mon, 24 Jun 2019 14:12:52 -0400 Subject: [PATCH 07/17] Update gemfile.lock --- Gemfile.lock | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1afffc6108..9350124303 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/dlipeles/omniauth-reddit.git - revision: 07724946d9a94c591ada3e43e849b34860fab46e + revision: a9abff8c5a6de217811945dc6f2949d26debfb29 branch: master specs: omniauth-reddit (0.0.2) @@ -87,17 +87,17 @@ GEM autoprefixer-rails (9.6.0) execjs aws-eventstream (1.0.3) - aws-partitions (1.172.0) - aws-sdk-core (3.54.2) + aws-partitions (1.177.0) + aws-sdk-core (3.56.0) aws-eventstream (~> 1.0, >= 1.0.2) aws-partitions (~> 1.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) - aws-sdk-kms (1.21.0) - aws-sdk-core (~> 3, >= 3.53.0) + aws-sdk-kms (1.22.0) + aws-sdk-core (~> 3, >= 3.56.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.42.0) - aws-sdk-core (~> 3, >= 3.53.0) + aws-sdk-s3 (1.43.0) + aws-sdk-core (~> 3, >= 3.56.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.1) aws-sigv4 (1.1.0) @@ -158,7 +158,7 @@ GEM responders warden (~> 1.2.3) dnsruby (1.60.2) - docile (1.3.1) + docile (1.3.2) domain_name (0.5.20180417) unf (>= 0.0.5, < 1.0.0) email_validator (1.6.0) @@ -173,7 +173,7 @@ GEM ffi (1.11.1) font-awesome-rails (4.7.0.5) railties (>= 3.2, < 6.1) - fugit (1.2.1) + fugit (1.2.2) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.1) globalid (0.4.2) @@ -198,18 +198,18 @@ GEM terminal-table (>= 1.5.1) inflection (1.0.0) io-like (0.3.0) - jaro_winkler (1.5.2) + jaro_winkler (1.5.3) jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) jmespath (1.4.0) json (2.2.0) - jsonapi-renderer (0.2.0) + jsonapi-renderer (0.2.2) jwt (2.2.1) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - lograge (0.11.1) + lograge (0.11.2) actionpack (>= 4) activesupport (>= 4) railties (>= 4) @@ -247,9 +247,9 @@ GEM minitest-capybara (~> 0.8) minitest-metadata (~> 0.6) minitest-rails (~> 3.0) - mocha (1.8.0) + mocha (1.9.0) metaclass (~> 0.0.1) - msgpack (1.2.10) + msgpack (1.3.0) multi_json (1.13.1) multi_xml (0.6.0) multipart-post (2.1.1) @@ -371,9 +371,9 @@ GEM redis (4.1.2) request_store (1.4.1) rack (>= 1.4) - responders (2.4.1) - actionpack (>= 4.2.0, < 6.0) - railties (>= 4.2.0, < 6.0) + responders (3.0.0) + actionpack (>= 5.0) + railties (>= 5.0) rest-client (2.0.2) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) @@ -414,7 +414,7 @@ GEM sassc (2.0.1) ffi (~> 1.9) rake - sassc-rails (2.1.1) + sassc-rails (2.1.2) railties (>= 4.0.0) sassc (>= 2.0) sprockets (> 3.0) @@ -497,9 +497,9 @@ GEM activesupport (>= 4.2) rack-proxy (>= 0.6.1) railties (>= 4.2) - websocket-driver (0.7.0) + websocket-driver (0.7.1) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.4) will_paginate (3.1.7) xml-simple (1.1.5) xpath (3.2.0) @@ -508,7 +508,7 @@ GEM activesupport yt-support (>= 0.1) yt-support (0.1.3) - zendesk_api (1.17.0) + zendesk_api (1.19.0) faraday (~> 0.9) hashie (>= 3.5.2, < 4.0.0) inflection From 46b5914f3246fbeed30f4b2d7c712c67748f230a Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Mon, 24 Jun 2019 14:20:08 -0400 Subject: [PATCH 08/17] reset gemfile.lock, package.json, yarn.lock --- Gemfile.lock | 44 ++++++++++++++++++------------------- package.json | 4 ++-- yarn.lock | 62 +++++----------------------------------------------- 3 files changed, 30 insertions(+), 80 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9350124303..ad61dc0cee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/dlipeles/omniauth-reddit.git - revision: a9abff8c5a6de217811945dc6f2949d26debfb29 + revision: 07724946d9a94c591ada3e43e849b34860fab46e branch: master specs: omniauth-reddit (0.0.2) @@ -87,17 +87,17 @@ GEM autoprefixer-rails (9.6.0) execjs aws-eventstream (1.0.3) - aws-partitions (1.177.0) - aws-sdk-core (3.56.0) + aws-partitions (1.172.0) + aws-sdk-core (3.54.2) aws-eventstream (~> 1.0, >= 1.0.2) aws-partitions (~> 1.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) - aws-sdk-kms (1.22.0) - aws-sdk-core (~> 3, >= 3.56.0) + aws-sdk-kms (1.21.0) + aws-sdk-core (~> 3, >= 3.53.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.43.0) - aws-sdk-core (~> 3, >= 3.56.0) + aws-sdk-s3 (1.42.0) + aws-sdk-core (~> 3, >= 3.53.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.1) aws-sigv4 (1.1.0) @@ -158,7 +158,7 @@ GEM responders warden (~> 1.2.3) dnsruby (1.60.2) - docile (1.3.2) + docile (1.3.1) domain_name (0.5.20180417) unf (>= 0.0.5, < 1.0.0) email_validator (1.6.0) @@ -173,7 +173,7 @@ GEM ffi (1.11.1) font-awesome-rails (4.7.0.5) railties (>= 3.2, < 6.1) - fugit (1.2.2) + fugit (1.2.1) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.1) globalid (0.4.2) @@ -198,18 +198,18 @@ GEM terminal-table (>= 1.5.1) inflection (1.0.0) io-like (0.3.0) - jaro_winkler (1.5.3) + jaro_winkler (1.5.2) jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) jmespath (1.4.0) json (2.2.0) - jsonapi-renderer (0.2.2) + jsonapi-renderer (0.2.0) jwt (2.2.1) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - lograge (0.11.2) + lograge (0.11.1) actionpack (>= 4) activesupport (>= 4) railties (>= 4) @@ -247,9 +247,9 @@ GEM minitest-capybara (~> 0.8) minitest-metadata (~> 0.6) minitest-rails (~> 3.0) - mocha (1.9.0) + mocha (1.8.0) metaclass (~> 0.0.1) - msgpack (1.3.0) + msgpack (1.2.10) multi_json (1.13.1) multi_xml (0.6.0) multipart-post (2.1.1) @@ -371,9 +371,9 @@ GEM redis (4.1.2) request_store (1.4.1) rack (>= 1.4) - responders (3.0.0) - actionpack (>= 5.0) - railties (>= 5.0) + responders (2.4.1) + actionpack (>= 4.2.0, < 6.0) + railties (>= 4.2.0, < 6.0) rest-client (2.0.2) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) @@ -414,7 +414,7 @@ GEM sassc (2.0.1) ffi (~> 1.9) rake - sassc-rails (2.1.2) + sassc-rails (2.1.1) railties (>= 4.0.0) sassc (>= 2.0) sprockets (> 3.0) @@ -497,9 +497,9 @@ GEM activesupport (>= 4.2) rack-proxy (>= 0.6.1) railties (>= 4.2) - websocket-driver (0.7.1) + websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.4) + websocket-extensions (0.1.3) will_paginate (3.1.7) xml-simple (1.1.5) xpath (3.2.0) @@ -508,7 +508,7 @@ GEM activesupport yt-support (>= 0.1) yt-support (0.1.3) - zendesk_api (1.19.0) + zendesk_api (1.17.0) faraday (~> 0.9) hashie (>= 3.5.2, < 4.0.0) inflection @@ -600,4 +600,4 @@ RUBY VERSION ruby 2.5.5p157 BUNDLED WITH - 2.0.1 + 2.0.1 \ No newline at end of file diff --git a/package.json b/package.json index e76894bef5..bc30d510c0 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,6 @@ "husky": "^1.3.1", "jest": "^24.1.0", "jest-styled-components": "^5.0.1", - "node-gyp": "^5.0.1", "prettier": "1.16.3", "stylelint": "^10.1.0", "stylelint-config-recommended-scss": "^3.3.0", @@ -113,6 +112,7 @@ "webpack-dev-server": "3.7.1" }, "resolutions": { - "js-yaml": "3.13.1" + "js-yaml": "3.13.1", + "node-gyp": "github:brave/node-gyp" } } diff --git a/yarn.lock b/yarn.lock index f2e98bf77c..a40312e518 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2047,13 +2047,6 @@ binary-extensions@^1.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.0.tgz#9523e001306a32444b907423f1de2164222f6ab1" integrity sha512-EgmjVLMn22z7eGGv3kcnHwSnJXmFHjISTY9E/S5lIcTD3Oxw05QTcBLNkJFzcb3cNueUdF/IN4U+d78V0zO8Hw== -block-stream@*: - version "0.0.9" - resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a" - integrity sha1-E+v+d4oDIFz+A3UUgeu0szAMEmo= - dependencies: - inherits "~2.0.0" - bluebird@^3.5.3: version "3.5.3" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7" @@ -4237,16 +4230,6 @@ fsevents@^1.2.7: nan "^2.9.2" node-pre-gyp "^0.10.0" -fstream@^1.0.0, fstream@^1.0.12: - version "1.0.12" - resolved "https://registry.yarnpkg.com/fstream/-/fstream-1.0.12.tgz#4e8ba8ee2d48be4f7d0de505455548eae5932045" - integrity sha512-WvJ193OHa0GHPEL+AycEJgxvBEwyfRkN1vhjca23OaPVMCaLCXTd5qAu82AjTcgP1UJmytkOKb63Ypde7raDIg== - dependencies: - graceful-fs "^4.1.2" - inherits "~2.0.0" - mkdirp ">=0.5 0" - rimraf "2" - function-bind@^1.0.2, function-bind@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" @@ -4885,11 +4868,6 @@ inherits@2.0.1: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" integrity sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE= -inherits@~2.0.0: - version "2.0.4" - resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" - integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== - ini@^1.3.4, ini@^1.3.5, ini@~1.3.0: version "1.3.5" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" @@ -6499,7 +6477,7 @@ mixin-object@^2.0.1: for-in "^0.1.3" is-extendable "^0.1.1" -mkdirp@0.5.x, mkdirp@0.x, "mkdirp@>=0.5 0", mkdirp@^0.5, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: +mkdirp@0.5.x, mkdirp@0.x, mkdirp@^0.5, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM= @@ -6636,28 +6614,9 @@ node-forge@0.7.5: resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.5.tgz#6c152c345ce11c52f465c2abd957e8639cd674df" integrity sha512-MmbQJ2MTESTjt3Gi/3yG1wGpIMhUfcIypUCGtTizFR9IiccFwxSpfp0vtIZlkFclEqERemxfnSdZEMR9VqqEFQ== -node-gyp@^3.8.0: - version "3.8.0" - resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.8.0.tgz#540304261c330e80d0d5edce253a68cb3964218c" - integrity sha512-3g8lYefrRRzvGeSowdJKAKyks8oUpLEd/DyPV4eMhVlhJ0aNaZqIrNUIPuEWWTAoPqyFkfGrM67MC69baqn6vA== - dependencies: - fstream "^1.0.0" - glob "^7.0.3" - graceful-fs "^4.1.2" - mkdirp "^0.5.0" - nopt "2 || 3" - npmlog "0 || 1 || 2 || 3 || 4" - osenv "0" - request "^2.87.0" - rimraf "2" - semver "~5.3.0" - tar "^2.0.0" - which "1" - -node-gyp@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-5.0.1.tgz#db211e9c5d7f611e79d1dcbdc53bca646b99ae4c" - integrity sha512-D68549U6EDVJLrAkSOZCWX/nmlYo0eCX2dYZoTOOZJ7bEIFrSE/MQgsgMFBKjByJ323hNzkifw2OuT3A5bR5mA== +node-gyp@^3.8.0, "node-gyp@github:brave/node-gyp": + version "4.0.0" + resolved "https://codeload.github.com/brave/node-gyp/tar.gz/1456ef27c72cc4e49f9b1d82cbb047cb673156c8" dependencies: env-paths "^1.0.0" glob "^7.0.3" @@ -7071,7 +7030,7 @@ os-tmpdir@^1.0.0: resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= -osenv@0, osenv@^0.1.4: +osenv@^0.1.4: version "0.1.5" resolved "https://registry.yarnpkg.com/osenv/-/osenv-0.1.5.tgz#85cdfafaeb28e8677f416e287592b5f3f49ea410" integrity sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g== @@ -9774,15 +9733,6 @@ tapable@^1.0.0, tapable@^1.1.0: resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.1.1.tgz#4d297923c5a72a42360de2ab52dadfaaec00018e" integrity sha512-9I2ydhj8Z9veORCw5PRm4u9uebCn0mcCa6scWoNcbZ6dAtoo2618u9UUzxgmsCOreJpqDDuv61LvwofW7hLcBA== -tar@^2.0.0: - version "2.2.2" - resolved "https://registry.yarnpkg.com/tar/-/tar-2.2.2.tgz#0ca8848562c7299b8b446ff6a4d60cdbb23edc40" - integrity sha512-FCEhQ/4rE1zYv9rYXJw/msRqsnmlje5jHP6huWeBZ704jUTy02c5AZyWujpMR1ax6mVw9NyJMfuK2CMDWVIfgA== - dependencies: - block-stream "*" - fstream "^1.0.12" - inherits "2" - tar@^4, tar@^4.4.8: version "4.4.8" resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.8.tgz#b19eec3fde2a96e64666df9fdb40c5ca1bc3747d" @@ -10807,4 +10757,4 @@ yargs@^7.0.0: string-width "^1.0.2" which-module "^1.0.0" y18n "^3.2.1" - yargs-parser "^5.0.0" + yargs-parser "^5.0.0" \ No newline at end of file From 6a49ea9eede0748b1edf9f8b64041aa9d394b42d Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Mon, 24 Jun 2019 12:52:41 -0700 Subject: [PATCH 09/17] Update Gemfile.lock --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index ad61dc0cee..1afffc6108 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -600,4 +600,4 @@ RUBY VERSION ruby 2.5.5p157 BUNDLED WITH - 2.0.1 \ No newline at end of file + 2.0.1 From d3b53db9c192641600555bf3deea5a70c5e3c320 Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Wed, 26 Jun 2019 13:57:44 -0400 Subject: [PATCH 10/17] return partner functionality --- app/javascript/packs/referral_charts.jsx | 1 - app/javascript/packs/views/referrals/Referrals.jsx | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/javascript/packs/referral_charts.jsx b/app/javascript/packs/referral_charts.jsx index 56b0ddd2c5..0ce9200af5 100644 --- a/app/javascript/packs/referral_charts.jsx +++ b/app/javascript/packs/referral_charts.jsx @@ -1,6 +1,5 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; -import "babel-polyfill"; import styled from "brave-ui/theme"; import Select from "brave-ui/components/formControls/select"; import ControlWrapper from "brave-ui/components/formControls/controlWrapper"; diff --git a/app/javascript/packs/views/referrals/Referrals.jsx b/app/javascript/packs/views/referrals/Referrals.jsx index 1201634846..a002fddabe 100644 --- a/app/javascript/packs/views/referrals/Referrals.jsx +++ b/app/javascript/packs/views/referrals/Referrals.jsx @@ -1,7 +1,7 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; -import renderReferralCharts from "../../../packs/referral_charts" +import Referrals from "../../../views/referrals/Referrals"; document.addEventListener("DOMContentLoaded", () => { - renderReferralCharts(); + ReactDOM.render(, document.body.appendChild(document.getElementsByClassName("main-content")[0])); }); From 504252db964be8da244e252fa5f02fdfed9c0f45 Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Wed, 26 Jun 2019 13:59:47 -0400 Subject: [PATCH 11/17] Update yarn.lock --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index a40312e518..f13ffec108 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10757,4 +10757,4 @@ yargs@^7.0.0: string-width "^1.0.2" which-module "^1.0.0" y18n "^3.2.1" - yargs-parser "^5.0.0" \ No newline at end of file + yargs-parser "^5.0.0" From e0f4671fb503feb37c55acc80ec84f65aaab2158 Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Wed, 26 Jun 2019 18:47:41 -0400 Subject: [PATCH 12/17] scope charts for admin / publishers / partners --- app/javascript/packs/referral_charts.jsx | 11 +- .../packs/views/admin/referrals/Referrals.jsx | 2 +- app/javascript/publishers/home.js | 179 +++++------------- .../views/admin/referrals/Referrals.tsx | 2 +- 4 files changed, 54 insertions(+), 140 deletions(-) diff --git a/app/javascript/packs/referral_charts.jsx b/app/javascript/packs/referral_charts.jsx index 0ce9200af5..79656e1c03 100644 --- a/app/javascript/packs/referral_charts.jsx +++ b/app/javascript/packs/referral_charts.jsx @@ -26,7 +26,11 @@ export default class ReferralCharts extends React.Component { async viewReferralCodeStats() { const node = this.selectMenuRef.current; - var url = routes.admin.promo_registrations.show.path.replace("{publisher_id}", this.props.publisherId); + var url = + this.props.scope === "admin" + ? routes.admin.promo_registrations.show.path.replace("{publisher_id}", this.props.publisherId) + : routes.publishers.promo_registrations.show.path.replace("{id}", this.props.publisherId); + url = url.replace("{referral_code}", node.state.value); const result = await fetch(url, { headers: { @@ -73,7 +77,7 @@ export default class ReferralCharts extends React.Component { } } -export function renderReferralCharts() { +export function renderReferralCharts(scope) { const { value } = document.getElementById("referrals-hidden-tags"); const publisherId = document.getElementById("publisher_id").value; if (value === undefined) { @@ -81,7 +85,8 @@ export function renderReferralCharts() { } let referralCodes = JSON.parse(value); let props = { - referralCodes: referralCodes + referralCodes: referralCodes, + scope: scope }; ReactDOM.render( , diff --git a/app/javascript/packs/views/admin/referrals/Referrals.jsx b/app/javascript/packs/views/admin/referrals/Referrals.jsx index ee25e2d399..d0c794e367 100644 --- a/app/javascript/packs/views/admin/referrals/Referrals.jsx +++ b/app/javascript/packs/views/admin/referrals/Referrals.jsx @@ -3,5 +3,5 @@ import * as ReactDOM from "react-dom"; import { renderReferralCharts } from "../../../../packs/referral_charts"; document.addEventListener("DOMContentLoaded", () => { - renderReferralCharts(); + renderReferralCharts("admin"); }); diff --git a/app/javascript/publishers/home.js b/app/javascript/publishers/home.js index 947b927961..1c49b6c202 100644 --- a/app/javascript/publishers/home.js +++ b/app/javascript/publishers/home.js @@ -43,14 +43,9 @@ function updateOverallBalance(balance) { batAmount.innerText = formatAmount(balance.amount_bat); let convertedAmount = document.getElementById("converted_amount"); - if ( - !(balance.default_currency === "BAT" || balance.default_currency === null) - ) { + if (!(balance.default_currency === "BAT" || balance.default_currency === null)) { convertedAmount.style.display = "block"; - convertedAmount.innerText = formatConvertedBalance( - balance.amount_default_currency, - balance.default_currency - ); + convertedAmount.innerText = formatConvertedBalance(balance.amount_default_currency, balance.default_currency); } } @@ -58,22 +53,17 @@ function updateLastSettlement(lastSettlementBalance) { let lastSettlement = document.getElementById("last_settlement"); let lastDepositDate = document.getElementById("last_deposit_date"); let lastDepositBatAmount = document.getElementById("last_deposit_bat_amount"); - let lastDepositConvertedAmount = document.getElementById( - "last_deposit_converted_amount" - ); + let lastDepositConvertedAmount = document.getElementById("last_deposit_converted_amount"); if (lastSettlementBalance.timestamp) { lastSettlement.classList.remove("no-settlement-made"); lastSettlement.classList.add("settlement-made"); - lastDepositDate.innerText = formatFullDate( - new Date(lastSettlementBalance.timestamp * 1000) - ); // Convert to milliseconds + lastDepositDate.innerText = formatFullDate(new Date(lastSettlementBalance.timestamp * 1000)); // Convert to milliseconds lastDepositBatAmount.innerText = lastSettlementBalance.amount_bat; lastDepositConvertedAmount.style.display = - lastSettlementBalance.settlement_currency === "BAT" || - lastSettlementBalance.settlement_currency === null + lastSettlementBalance.settlement_currency === "BAT" || lastSettlementBalance.settlement_currency === null ? "none" : "block"; lastDepositConvertedAmount.innerText = formatConvertedBalance( @@ -92,43 +82,30 @@ function updateLastSettlement(lastSettlementBalance) { function updateChannelBalances(wallet) { for (let channelId in wallet.channelBalances) { - let channelAmount = document.getElementById( - "channel_amount_bat_" + channelId - ); + let channelAmount = document.getElementById("channel_amount_bat_" + channelId); if (channelAmount) { - channelAmount.innerText = formatAmount( - wallet.channelBalances[channelId].amount_bat - ); + channelAmount.innerText = formatAmount(wallet.channelBalances[channelId].amount_bat); } } } function updateDefaultCurrencyValue(wallet) { let upholdStatusElement = document.getElementById("uphold_status"); - upholdStatusElement.setAttribute( - "data-default-currency", - wallet.defaultCurrency || "" - ); + upholdStatusElement.setAttribute("data-default-currency", wallet.defaultCurrency || ""); let defaultCurrencyDisplay = document.getElementById("default_currency_code"); - defaultCurrencyDisplay.innerText = - wallet.defaultCurrency || NO_CURRENCY_SELECTED; + defaultCurrencyDisplay.innerText = wallet.defaultCurrency || NO_CURRENCY_SELECTED; } function updatePossibleCurrencies(wallet) { let possibleCurrencies = wallet.possibleCurrencies; let upholdStatusElement = document.getElementById("uphold_status"); - upholdStatusElement.setAttribute( - "data-possible-currencies", - JSON.stringify(possibleCurrencies) - ); + upholdStatusElement.setAttribute("data-possible-currencies", JSON.stringify(possibleCurrencies)); } function getPossibleCurrencies() { let upholdStatusElement = document.getElementById("uphold_status"); - return JSON.parse( - upholdStatusElement.getAttribute("data-possible-currencies") - ); + return JSON.parse(upholdStatusElement.getAttribute("data-possible-currencies")); } function populateCurrencySelect(select, possibleCurrencies, selectedCurrency) { @@ -146,10 +123,7 @@ function populateCurrencySelect(select, possibleCurrencies, selectedCurrency) { let option = document.createElement("option"); option.value = currency; option.innerHTML = currency; - if ( - (!selectedCurrency || selectedCurrency.length === 0) && - currency === BASIC_ATTENTION_TOKEN - ) { + if ((!selectedCurrency || selectedCurrency.length === 0) && currency === BASIC_ATTENTION_TOKEN) { option.selected = true; } else { option.selected = currency === selectedCurrency; @@ -195,20 +169,14 @@ function refreshBalance() { } function removeChannel(channelId) { - submitForm("remove_channel_" + channelId, "DELETE", true).then(function( - response - ) { + submitForm("remove_channel_" + channelId, "DELETE", true).then(function(response) { let channelRow = document.getElementById("channel_row_" + channelId); channelRow.classList.add("channel-hidden"); // Show channel placeholder if no channels are still visible - let visibleChannelRows = document.querySelectorAll( - "div.channel-row:not(.channel-hidden)" - ); + let visibleChannelRows = document.querySelectorAll("div.channel-row:not(.channel-hidden)"); if (visibleChannelRows.length === 0) { - let addChannelPlaceholder = document.getElementById( - "add_channel_placeholder" - ); + let addChannelPlaceholder = document.getElementById("add_channel_placeholder"); addChannelPlaceholder.classList.remove("hidden"); } flash.clear(); @@ -237,12 +205,8 @@ function checkUpholdStatus() { }) .then(function(body) { let upholdStatus = document.getElementById("uphold_status"); - let upholdStatusSummary = document.querySelector( - "#uphold_status_display .status-summary .text" - ); - let upholdStatusDescription = document.querySelector( - "#uphold_connect .status-description" - ); + let upholdStatusSummary = document.querySelector("#uphold_status_display .status-summary .text"); + let upholdStatusDescription = document.querySelector("#uphold_connect .status-description"); let timedOut = checkUpholdStatusCount >= 15; if (timedOut) { @@ -250,8 +214,7 @@ function checkUpholdStatus() { body = { uphold_status_class: "uphold-timeout", uphold_status_summary: "Connection problems", - uphold_status_description: - "We are experiencing communication problems. Please check back later." + uphold_status_description: "We are experiencing communication problems. Please check back later." }; } @@ -270,9 +233,7 @@ function checkUpholdStatus() { if ( checkUpholdStatusInterval != null && - (timedOut || - body.uphold_status === "verified" || - body.uphold_status === "restricted") + (timedOut || body.uphold_status === "verified" || body.uphold_status === "restricted") ) { hideReconnectButton(); @@ -306,26 +267,16 @@ function disconnectUphold() { } function openDefaultCurrencyModal() { - let template = document.querySelector( - "#confirm_default_currency_modal_wrapper" - ); + let template = document.querySelector("#confirm_default_currency_modal_wrapper"); let closeFn = openModal(template.innerHTML); let form = document.getElementById("confirm_default_currency_form"); // Sync default currency selected in modal with options and value from dashboard let upholdStatusElement = document.getElementById("uphold_status"); - let currentDefaultCurrency = upholdStatusElement.getAttribute( - "data-default-currency" - ); - let currencySelectInModal = document.getElementById( - "publisher_default_currency" - ); - populateCurrencySelect( - currencySelectInModal, - getPossibleCurrencies(), - currentDefaultCurrency || "" - ); + let currentDefaultCurrency = upholdStatusElement.getAttribute("data-default-currency"); + let currencySelectInModal = document.getElementById("publisher_default_currency"); + populateCurrencySelect(currencySelectInModal, getPossibleCurrencies(), currentDefaultCurrency || ""); form.addEventListener( "submit", @@ -333,9 +284,7 @@ function openDefaultCurrencyModal() { event.preventDefault(); let modal = document.getElementById("confirm_default_currency_modal"); - let status = document.querySelector( - "#confirm_default_currency_modal .status" - ); + let status = document.querySelector("#confirm_default_currency_modal .status"); if (!currencySelectInModal.value) { closeFn(); @@ -378,11 +327,7 @@ function toggleDialog(event, elements) { // Do not hide if the clicked element is supposed to show the bubble // Or if the clicked element is the bubble let e = elements[i]; - if ( - e === event.target || - e.nextSibling == event.target || - e.nextSibling.firstChild == event.target - ) { + if (e === event.target || e.nextSibling == event.target || e.nextSibling.firstChild == event.target) { continue; } else { hideVerificationFailureWhatHappened(e); @@ -399,11 +344,7 @@ document.addEventListener("DOMContentLoaded", function() { if (upholdStatusElement.classList.contains("uphold-processing")) { checkUpholdStatusInterval = window.setInterval(checkUpholdStatus, 2000); - } else if ( - upholdStatusElement.getAttribute( - "data-open-confirm-default-currency-modal" - ) === "true" - ) { + } else if (upholdStatusElement.getAttribute("data-open-confirm-default-currency-modal") === "true") { openDefaultCurrencyModal(); } @@ -413,9 +354,7 @@ document.addEventListener("DOMContentLoaded", function() { "click", function(event) { let channelId = event.target.getAttribute("data-channel-id"); - let template = document.querySelector( - '[data-js-channel-removal-confirmation-template="' + channelId + '"]' - ); + let template = document.querySelector('[data-js-channel-removal-confirmation-template="' + channelId + '"]'); openModal( template.innerHTML, function() { @@ -457,9 +396,7 @@ document.addEventListener("DOMContentLoaded", function() { false ); - let changeDefaultCurrencyLink = document.getElementById( - "change_default_currency" - ); + let changeDefaultCurrencyLink = document.getElementById("change_default_currency"); if (changeDefaultCurrencyLink) { changeDefaultCurrencyLink.addEventListener( "click", @@ -485,25 +422,15 @@ document.addEventListener("DOMContentLoaded", function() { let editContact = document.getElementById("edit_contact"); let cancelEditContact = document.getElementById("cancel_edit_contact"); - let verificationFailureWhatHappenedElements = document.getElementsByClassName( - "verification-failed--what-happened" - ); + let verificationFailureWhatHappenedElements = document.getElementsByClassName("verification-failed--what-happened"); for (let i = 0; i < verificationFailureWhatHappenedElements.length; i++) { - verificationFailureWhatHappenedElements[i].addEventListener( - "click", - showWhatHappenedVerificationFailure, - false - ); + verificationFailureWhatHappenedElements[i].addEventListener("click", showWhatHappenedVerificationFailure, false); } let infoText = document.getElementsByClassName("info--what-happened"); for (let i = 0; i < infoText.length; i++) { - infoText[i].addEventListener( - "click", - showWhatHappenedVerificationFailure, - false - ); + infoText[i].addEventListener("click", showWhatHappenedVerificationFailure, false); } // Hide all verification failed bubbles when anywhere on DOM is clicked @@ -512,16 +439,13 @@ document.addEventListener("DOMContentLoaded", function() { toggleDialog(event, infoText); }); - let instantDonationButton = document.getElementById( - "instant-donation-button" - ); + let instantDonationButton = document.getElementById("instant-donation-button"); editContact.addEventListener( "click", function(event) { updateContactName.value = showContactName.innerText; - updateContactEmail.value = - pendingContactEmail.innerText || showContactEmail.innerText; + updateContactEmail.value = pendingContactEmail.innerText || showContactEmail.innerText; showContact.classList.add("hidden"); updateContactForm.classList.remove("hidden"); editContact.classList.add("hidden"); @@ -547,10 +471,8 @@ document.addEventListener("DOMContentLoaded", function() { async function(event) { document.getElementById("intro-container").style.padding = "50px"; document.getElementsByClassName("modal-panel")[0].style.padding = "0px"; - document.getElementsByClassName("modal-panel--content")[0].style.padding = - "0px"; - let preferredCurrency = document.getElementById("preferred_currency") - .value; + document.getElementsByClassName("modal-panel--content")[0].style.padding = "0px"; + let preferredCurrency = document.getElementById("preferred_currency").value; let conversionRate = document.getElementById("conversion_rate").value; let url = "/publishers/get_site_banner_data"; @@ -561,8 +483,7 @@ document.addEventListener("DOMContentLoaded", function() { headers: { Accept: "text/html", "X-Requested-With": "XMLHttpRequest", - "X-CSRF-Token": document.head.querySelector("[name=csrf-token]") - .content + "X-CSRF-Token": document.head.querySelector("[name=csrf-token]").content } }; @@ -600,16 +521,10 @@ document.addEventListener("DOMContentLoaded", function() { ); }; - document.getElementsByClassName( - "modal-panel--close js-deny" - )[0].onclick = function(e) { - document.getElementsByClassName("modal-panel")[0].style.maxWidth = - "40rem"; - document.getElementsByClassName("modal-panel")[0].style.padding = - "2rem 2rem"; - document.getElementsByClassName( - "modal-panel--content" - )[0].style.padding = "1rem 1rem 0 1rem"; + document.getElementsByClassName("modal-panel--close js-deny")[0].onclick = function(e) { + document.getElementsByClassName("modal-panel")[0].style.maxWidth = "40rem"; + document.getElementsByClassName("modal-panel")[0].style.padding = "2rem 2rem"; + document.getElementsByClassName("modal-panel--content")[0].style.padding = "1rem 1rem 0 1rem"; }; }, false @@ -627,15 +542,11 @@ document.addEventListener("DOMContentLoaded", function() { showPendingContactEmail(updatedEmail); let currentUserName = document.querySelector(".js-current-user-name"); - let userNameDropDown = document.querySelector( - ".js-user-name-dropdown" - ); + let userNameDropDown = document.querySelector(".js-user-name-dropdown"); currentUserName.innerText = updateContactName.value; userNameDropDown.innerText = updateContactName.value; } else { - let pendingEmailNotice = document.getElementById( - "pending_email_notice" - ); + let pendingEmailNotice = document.getElementById("pending_email_notice"); pendingEmailNotice.innerHTML = "Unable to change email; the email address may be in use. Please enter a different email address."; pendingEmailNotice.classList.remove("hidden"); @@ -646,9 +557,7 @@ document.addEventListener("DOMContentLoaded", function() { editContact.classList.remove("hidden"); // Re-enable submit button to allow form to be resubmitted - let submitButton = updateContactForm.querySelector( - "input[type=submit][disabled]" - ); + let submitButton = updateContactForm.querySelector("input[type=submit][disabled]"); if (submitButton) { submitButton.removeAttribute("disabled"); submitButton.blur(); @@ -658,5 +567,5 @@ document.addEventListener("DOMContentLoaded", function() { false ); - renderReferralCharts(); + renderReferralCharts("publisher"); }); diff --git a/app/javascript/views/admin/referrals/Referrals.tsx b/app/javascript/views/admin/referrals/Referrals.tsx index 5e961232da..f4e9998852 100644 --- a/app/javascript/views/admin/referrals/Referrals.tsx +++ b/app/javascript/views/admin/referrals/Referrals.tsx @@ -21,7 +21,7 @@ interface IReferralsProps { export default class Referrals extends React.Component { constructor(props) { super(props); - renderReferralCharts(); + renderReferralCharts("admin"); } public render() { From c19fe526ce45ba3011451685a346901a118b9741 Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Wed, 26 Jun 2019 18:48:47 -0400 Subject: [PATCH 13/17] yarn.lock --- yarn.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/yarn.lock b/yarn.lock index f13ffec108..d9c2b7772f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10758,3 +10758,4 @@ yargs@^7.0.0: which-module "^1.0.0" y18n "^3.2.1" yargs-parser "^5.0.0" + From b89a41193d41927b05eb668b1b7c65558607a568 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Wed, 26 Jun 2019 16:24:11 -0700 Subject: [PATCH 14/17] Remove unused route --- app/controllers/admin/publishers/referrals_controller.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/controllers/admin/publishers/referrals_controller.rb b/app/controllers/admin/publishers/referrals_controller.rb index c293a0aedf..166353d008 100644 --- a/app/controllers/admin/publishers/referrals_controller.rb +++ b/app/controllers/admin/publishers/referrals_controller.rb @@ -3,10 +3,4 @@ def show @publisher = Publisher.find(params[:id] || params[:publisher_id]) @navigation_view = Views::Admin::NavigationView.new(publisher).as_json.merge({ navbarSelection: "Referrals" }).to_json end - - def stats_by_date - promo_registration = current_publisher.promo_registrations.find_by(referral_code: params[:referral_code]) - render :unauthorized and return if promo_registration.nil? - render json: promo_registration.stats_by_date.to_json - end end From e54c8f0f9fc68447e34f9659ed83b67fa4e7c09b Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Wed, 26 Jun 2019 16:49:44 -0700 Subject: [PATCH 15/17] Remove dead code from referral charts --- .../views/admin/referrals/Referrals.tsx | 1 - .../referralsChart/ReferralsChart.tsx | 310 ------------------ 2 files changed, 311 deletions(-) delete mode 100644 app/javascript/views/admin/referrals/components/referralsChart/ReferralsChart.tsx diff --git a/app/javascript/views/admin/referrals/Referrals.tsx b/app/javascript/views/admin/referrals/Referrals.tsx index f4e9998852..0da81e1bb4 100644 --- a/app/javascript/views/admin/referrals/Referrals.tsx +++ b/app/javascript/views/admin/referrals/Referrals.tsx @@ -3,7 +3,6 @@ import * as React from "react"; import { Cell, Container, Grid } from "../../../components/grid/Grid"; import renderReferralCharts from "../../../packs/referral_charts"; import UserNavbar from "../components/userNavbar/UserNavbar"; -// import ReferralsChart from "./components/referralsChart/ReferralsChart"; import { templateAreas, templateRows } from "./ReferralsStyle"; diff --git a/app/javascript/views/admin/referrals/components/referralsChart/ReferralsChart.tsx b/app/javascript/views/admin/referrals/components/referralsChart/ReferralsChart.tsx deleted file mode 100644 index ac664bb63b..0000000000 --- a/app/javascript/views/admin/referrals/components/referralsChart/ReferralsChart.tsx +++ /dev/null @@ -1,310 +0,0 @@ -import * as React from "react"; - -import Select from "brave-ui/components/formControls/select"; -import Chart from "chart.js"; -import Card from "../../../../../components/card/Card"; - -interface IReferralsChartProps { - referralCodes: any; -} - -interface IReferralsChartState { - selectedReferralCode: any; - downloadsToggle: any; - installsToggle: any; - confirmationsToggle: any; -} - -export default class Referrals extends React.Component< - IReferralsChartProps, - IReferralsChartState -> { - private node; - constructor(props) { - super(props); - this.state = { - confirmationsToggle: true, - downloadsToggle: true, - installsToggle: true, - selectedReferralCode: 0 - }; - } - - public componentDidMount() { - this.createReferralsChart( - this.props.referralCodes[this.state.selectedReferralCode] - ); - } - - public componentDidUpdate() { - this.createReferralsChart( - this.props.referralCodes[this.state.selectedReferralCode] - ); - } - - public handleReferralCodeSelect = e => { - this.setState({ selectedReferralCode: e.target.value }); - }; - - public handleDataSelect = index => { - switch (index) { - case 0: - this.setState(prevState => ({ - downloadsToggle: !prevState.downloadsToggle - })); - break; - case 1: - this.setState(prevState => ({ - installsToggle: !prevState.installsToggle - })); - break; - case 2: - this.setState(prevState => ({ - confirmationsToggle: !prevState.confirmationsToggle - })); - break; - } - }; - - public createReferralsChart(referralCode) { - const node = this.node; - - if (!referralCode) { - return; - } - const stats = referralCode.stats; - const chartLabels = []; - let downloads = []; - let installs = []; - let confirmations = []; - - stats.forEach((stat, index) => { - if (index < stats.length - 1) { - if (stat.date !== stats[index + 1].date) { - chartLabels.push(stat.date); - downloads.push(stat.downloads); - installs.push(stat.installs); - confirmations.push(stat.confirmations); - } - } - if (index === stats.length - 1) { - chartLabels.push(stat.date); - downloads.push(stat.downloads); - installs.push(stat.installs); - confirmations.push(stat.confirmations); - } - }); - - if (!this.state.downloadsToggle) { - downloads = []; - } - if (!this.state.installsToggle) { - installs = []; - } - if (!this.state.confirmationsToggle) { - confirmations = []; - } - - const chartData = { - datasets: [ - { - backgroundColor: "#FFFFFF00", - borderColor: "#FF6384", - data: downloads, - label: "Downloads" - }, - { - backgroundColor: "#FFFFFF00", - borderColor: "#36A2EB", - data: installs, - label: "Installs" - }, - { - backgroundColor: "#FFFFFF00", - borderColor: "#9966FF", - data: confirmations, - label: "Confirmations" - } - ], - labels: chartLabels - }; - - const chartSettings = { - data: chartData, - options: { - legend: { - display: false - }, - scales: { - yAxes: [ - { - display: false - } - ] - } - }, - type: "line" - }; - - const myChart = new Chart(node, chartSettings); - } - - public render() { - const confirmationsOpacity = this.state.confirmationsToggle ? 1 : 0.5; - const installsOpacity = this.state.installsToggle ? 1 : 0.5; - const downloadsOpacity = this.state.downloadsToggle ? 1 : 0.5; - return ( - -
- Referrals Stats -
-
- {this.props.referralCodes.length > 0 && ( - (this.node = node)} - /> - )} - {this.props.referralCodes.length === 0 && ( -
No referral codes
- )} -
-
- -
-
-
-
-
this.handleDataSelect(2)} - style={{ - backgroundColor: "#9966FF", - borderRadius: "50%", - cursor: "pointer", - height: "16px", - marginRight: "4px", - marginTop: "4px", - opacity: confirmationsOpacity, - width: "16px" - }} - /> -
- Confirmation -
-
-
this.handleDataSelect(1)} - style={{ display: "flex" }} - > -
-
- Installs -
-
-
this.handleDataSelect(0)} - style={{ display: "flex" }} - > -
-
- Downloads -
-
-
-
- - ); - } -} - -function ReferralCodeSelect(props) { - const dropdownOptions = props.referralCodes.map((referralCode, index) => ( - - )); - if (props.referralCodes.length > 0) { - return ( - - ); - } else { - return ; - } -} From 92e4a7b1183949dd7670e9b09cbd4fae271eaef8 Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Thu, 27 Jun 2019 14:12:02 -0400 Subject: [PATCH 16/17] Update app/controllers/admin/promo_registrations_controller.rb Co-Authored-By: Cory McDonald --- app/controllers/admin/promo_registrations_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/admin/promo_registrations_controller.rb b/app/controllers/admin/promo_registrations_controller.rb index 9b037348b9..482114aaf3 100644 --- a/app/controllers/admin/promo_registrations_controller.rb +++ b/app/controllers/admin/promo_registrations_controller.rb @@ -6,4 +6,3 @@ def for_referral_code render json: promo_registration.stats_by_date.to_json end end - \ No newline at end of file From 47130685c745752a32dcd9dadc093455ecfaacd1 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Mon, 1 Jul 2019 11:38:29 -0700 Subject: [PATCH 17/17] Address comments --- app/controllers/admin/publishers/referrals_controller.rb | 3 +-- app/controllers/publishers/promo_registrations_controller.rb | 4 +++- app/javascript/views/routes.ts | 2 +- app/views/admin/publishers/referrals/index.html.slim | 2 -- config/routes.rb | 5 ----- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/publishers/referrals_controller.rb b/app/controllers/admin/publishers/referrals_controller.rb index 166353d008..e0026c7292 100644 --- a/app/controllers/admin/publishers/referrals_controller.rb +++ b/app/controllers/admin/publishers/referrals_controller.rb @@ -1,6 +1,5 @@ class Admin::Publishers::ReferralsController < Admin::PublishersController def show - @publisher = Publisher.find(params[:id] || params[:publisher_id]) - @navigation_view = Views::Admin::NavigationView.new(publisher).as_json.merge({ navbarSelection: "Referrals" }).to_json + @navigation_view = Views::Admin::NavigationView.new(@publisher).as_json.merge({ navbarSelection: "Referrals" }).to_json end end diff --git a/app/controllers/publishers/promo_registrations_controller.rb b/app/controllers/publishers/promo_registrations_controller.rb index 2da15d8080..0b6f9f2759 100644 --- a/app/controllers/publishers/promo_registrations_controller.rb +++ b/app/controllers/publishers/promo_registrations_controller.rb @@ -1,6 +1,8 @@ class Publishers::PromoRegistrationsController < PublishersController def for_referral_code - promo_registration = current_publisher.promo_registrations.find_by(referral_code: params[:referral_code]) + promo_registration = current_publisher.admin? ? + PromoRegistration.find_by(referral_code: params[:referral_code]) : + current_publisher.promo_registrations.find_by(referral_code: params[:referral_code]) render :unauthorized and return if promo_registration.nil? render json: promo_registration.stats_by_date.to_json end diff --git a/app/javascript/views/routes.ts b/app/javascript/views/routes.ts index 36ab794079..c64ccee749 100644 --- a/app/javascript/views/routes.ts +++ b/app/javascript/views/routes.ts @@ -3,7 +3,7 @@ export default { admin: { promo_registrations: { show: { - path: "/admin/promo_registrations/for_referral_code?referral_code={referral_code}&publisher_id={publisher_id}" + path: "/publishers/{publisher_id}/promo_registrations/for_referral_code?referral_code={referral_code}" } } }, diff --git a/app/views/admin/publishers/referrals/index.html.slim b/app/views/admin/publishers/referrals/index.html.slim index 82b370a8ba..6de1075c39 100644 --- a/app/views/admin/publishers/referrals/index.html.slim +++ b/app/views/admin/publishers/referrals/index.html.slim @@ -1,6 +1,4 @@ - - if @publisher.promo_registrations.present? - = hidden_field_tag 'all-channels-referral-stats-starting-month', @publisher.promo_registrations.has_stats.order(created_at: :asc).first.created_at.strftime("%Y-%m-%d") = hidden_field_tag 'referrals-hidden-tags', @publisher.promo_registrations.has_stats.pluck(:referral_code).to_json = hidden_field_tag 'publisher_id', @publisher.id .row diff --git a/config/routes.rb b/config/routes.rb index 3c94bd0742..6c675fc0f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -163,11 +163,6 @@ get :duplicates end end - resources :promo_registrations, only: [] do - collection do - get :for_referral_code - end - end resources :faq_categories, except: [:show] resources :faqs, except: [:show] resources :payout_reports, only: %i(index show create) do