From 394f7b8f346089092f62cd9c82fea83251d50083 Mon Sep 17 00:00:00 2001 From: bboysoul <31786046+bboysoulcn@users.noreply.github.com> Date: Mon, 22 Nov 2021 15:29:16 +0800 Subject: [PATCH 1/3] update node 12.22 error next@12.0.1: The engine "node" is incompatible with this module. Expected version ">=12.22.0". Got "12.18.4" error Found incompatible module. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7d086546..d0943392 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build image -FROM node:12.18-alpine AS build +FROM node:12.22-alpine AS build ARG BASE_PATH ARG DATABASE_TYPE ENV BASE_PATH=$BASE_PATH From 8874357bed1b3a306050fbaf15929fd91457df7c Mon Sep 17 00:00:00 2001 From: Chris Walsh Date: Wed, 1 Dec 2021 15:07:10 -0800 Subject: [PATCH 2/3] Remove comparison metrics from realtime header --- components/metrics/MetricCard.js | 5 +++-- components/metrics/RealtimeHeader.js | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/components/metrics/MetricCard.js b/components/metrics/MetricCard.js index d0394b97..9b407f37 100644 --- a/components/metrics/MetricCard.js +++ b/components/metrics/MetricCard.js @@ -9,6 +9,7 @@ const MetricCard = ({ label, reverseColors = false, format = formatNumber, + hideComparison = false, }) => { const props = useSpring({ x: Number(value) || 0, from: { x: 0 } }); const changeProps = useSpring({ x: Number(change) || 0, from: { x: 0 } }); @@ -18,8 +19,8 @@ const MetricCard = ({ {props.x.interpolate(x => format(x))}
{label} - {~~change === 0 && {format(0)}} - {~~change !== 0 && ( + {~~change === 0 && !hideComparison && {format(0)}} + {~~change !== 0 && !hideComparison && ( = 0 diff --git a/components/metrics/RealtimeHeader.js b/components/metrics/RealtimeHeader.js index c501937a..8273b88c 100644 --- a/components/metrics/RealtimeHeader.js +++ b/components/metrics/RealtimeHeader.js @@ -30,18 +30,22 @@ export default function RealtimeHeader({ websites, data, websiteId, onSelect }) } value={pageviews.length} + hideComparison /> } value={sessions.length} + hideComparison /> } value={events.length} + hideComparison /> } value={countries.length} + hideComparison />
From 9cff0257844c070844299a868eaeee256989b54a Mon Sep 17 00:00:00 2001 From: Chris Walsh Date: Wed, 1 Dec 2021 16:03:18 -0800 Subject: [PATCH 3/3] Add owner column to admin website settings table --- components/settings/WebsiteSettings.js | 62 +++++++++++++++++++++----- lib/queries.js | 23 ++++++++++ pages/api/websites.js | 9 ++-- 3 files changed, 80 insertions(+), 14 deletions(-) diff --git a/components/settings/WebsiteSettings.js b/components/settings/WebsiteSettings.js index ee23e549..998df40e 100644 --- a/components/settings/WebsiteSettings.js +++ b/components/settings/WebsiteSettings.js @@ -1,5 +1,6 @@ import React, { useState } from 'react'; import { FormattedMessage } from 'react-intl'; +import { useSelector } from 'react-redux'; import classNames from 'classnames'; import Link from 'components/common/Link'; import Table from 'components/common/Table'; @@ -25,6 +26,7 @@ import useFetch from 'hooks/useFetch'; import styles from './WebsiteSettings.module.css'; export default function WebsiteSettings() { + const user = useSelector(state => state.user); const [editWebsite, setEditWebsite] = useState(); const [resetWebsite, setResetWebsite] = useState(); const [deleteWebsite, setDeleteWebsite] = useState(); @@ -33,7 +35,9 @@ export default function WebsiteSettings() { const [showUrl, setShowUrl] = useState(); const [saved, setSaved] = useState(0); const [message, setMessage] = useState(); - const { data } = useFetch(`/api/websites`, {}, [saved]); + const { data } = useFetch(`/api/websites` + (user.is_admin ? '?include_all=true' : ''), {}, [ + saved, + ]); const Buttons = row => ( @@ -55,15 +59,27 @@ export default function WebsiteSettings() { tooltipId={`button-code-${row.website_id}`} onClick={() => setShowCode(row)} /> - - - + - +
{editWebsite && ( }> diff --git a/lib/queries.js b/lib/queries.js index 13f4181d..f54b9267 100644 --- a/lib/queries.js +++ b/lib/queries.js @@ -115,6 +115,29 @@ export async function getUserWebsites(user_id) { ); } +export async function getAllWebsites() { + let data = await runQuery( + prisma.website.findMany({ + orderBy: [ + { + user_id: 'asc', + }, + { + name: 'asc', + }, + ], + include: { + account: { + select: { + username: true, + }, + }, + }, + }), + ); + return data.map(i => ({ ...i, account: i.account.username })); +} + export async function createWebsite(user_id, data) { return runQuery( prisma.website.create({ diff --git a/pages/api/websites.js b/pages/api/websites.js index 6f51754f..589b7315 100644 --- a/pages/api/websites.js +++ b/pages/api/websites.js @@ -1,4 +1,4 @@ -import { getUserWebsites } from 'lib/queries'; +import { getAllWebsites, getUserWebsites } from 'lib/queries'; import { useAuth } from 'lib/middleware'; import { ok, methodNotAllowed, unauthorized } from 'lib/response'; @@ -6,7 +6,7 @@ export default async (req, res) => { await useAuth(req, res); const { user_id: current_user_id, is_admin } = req.auth; - const { user_id } = req.query; + const { user_id, include_all } = req.query; const userId = +user_id; if (req.method === 'GET') { @@ -14,7 +14,10 @@ export default async (req, res) => { return unauthorized(res); } - const websites = await getUserWebsites(userId || current_user_id); + const websites = + is_admin && include_all + ? await getAllWebsites() + : await getUserWebsites(userId || current_user_id); return ok(res, websites); }