Responsive styles for session page.

This commit is contained in:
Mike Cao 2024-07-30 22:10:32 -07:00
parent b3e6e52473
commit 10f65cae68
7 changed files with 18 additions and 14 deletions

View File

@ -2,7 +2,6 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 20px; gap: 20px;
width: 200px;
position: relative; position: relative;
} }
@ -22,11 +21,10 @@
} }
.type { .type {
font-size: 10px; font-size: 11px;
text-transform: uppercase;
padding: 0 6px; padding: 0 6px;
border-radius: 4px; border-radius: 4px;
border: 1px solid var(--base300); border: 1px solid var(--base400);
} }
.name { .name {

View File

@ -1,8 +1,8 @@
import { Loading, TextOverflow } from 'react-basics'; import { Loading, TextOverflow } from 'react-basics';
import { useMessages, useSessionData } from 'components/hooks'; import { useMessages, useSessionData } from 'components/hooks';
import Empty from 'components/common/Empty'; import Empty from 'components/common/Empty';
import styles from './SessionData.module.css';
import { DATA_TYPES } from 'lib/constants'; import { DATA_TYPES } from 'lib/constants';
import styles from './SessionData.module.css';
export function SessionData({ websiteId, sessionId }: { websiteId: string; sessionId: string }) { export function SessionData({ websiteId, sessionId }: { websiteId: string; sessionId: string }) {
const { formatMessage, labels } = useMessages(); const { formatMessage, labels } = useMessages();

View File

@ -1,6 +1,6 @@
.page { .page {
display: grid; display: grid;
grid-template-columns: 300px 1fr max-content; grid-template-columns: max-content 1fr max-content;
margin-bottom: 40px; margin-bottom: 40px;
position: relative; position: relative;
} }
@ -11,6 +11,7 @@
align-items: center; align-items: center;
justify-content: flex-start; justify-content: flex-start;
gap: 20px; gap: 20px;
width: 300px;
padding-right: 20px; padding-right: 20px;
border-right: 1px solid var(--base300); border-right: 1px solid var(--base300);
position: relative; position: relative;
@ -25,6 +26,7 @@
} }
.data { .data {
width: 300px;
border-left: 1px solid var(--base300); border-left: 1px solid var(--base300);
padding-left: 20px; padding-left: 20px;
position: relative; position: relative;
@ -40,5 +42,6 @@
.sidebar, .sidebar,
.data { .data {
border: 0; border: 0;
width: auto;
} }
} }

View File

@ -3,6 +3,10 @@
gap: 10px; gap: 10px;
} }
.info dl {
width: 100%;
}
.info dt { .info dt {
color: var(--font-color200); color: var(--font-color200);
font-weight: bold; font-weight: bold;

View File

@ -33,7 +33,7 @@ export default async (
return unauthorized(res); return unauthorized(res);
} }
const data = await getWebsiteSession(websiteId, sessionId); const data = await getWebsiteSession(sessionId);
return ok(res, data); return ok(res, data);
} }

View File

@ -35,6 +35,7 @@ async function clickhouseQuery(websiteId: string, sessionId: string) {
from session_data from session_data
where website_id = {websiteId:UUID} where website_id = {websiteId:UUID}
and session_id = {sessionId:UUID} and session_id = {sessionId:UUID}
order by data_key asc
`, `,
{ websiteId, sessionId }, { websiteId, sessionId },
); );

View File

@ -2,23 +2,22 @@ import prisma from 'lib/prisma';
import clickhouse from 'lib/clickhouse'; import clickhouse from 'lib/clickhouse';
import { runQuery, PRISMA, CLICKHOUSE } from 'lib/db'; import { runQuery, PRISMA, CLICKHOUSE } from 'lib/db';
export async function getWebsiteSession(...args: [websiteId: string, sessionId: string]) { export async function getWebsiteSession(...args: [sessionId: string]) {
return runQuery({ return runQuery({
[PRISMA]: () => relationalQuery(...args), [PRISMA]: () => relationalQuery(...args),
[CLICKHOUSE]: () => clickhouseQuery(...args), [CLICKHOUSE]: () => clickhouseQuery(...args),
}); });
} }
async function relationalQuery(websiteId: string, sessionId: string) { async function relationalQuery(sessionId: string) {
return prisma.client.session.findUnique({ return prisma.client.session.findUnique({
where: { where: {
id: sessionId, id: sessionId,
websiteId,
}, },
}); });
} }
async function clickhouseQuery(websiteId: string, sessionId: string) { async function clickhouseQuery(sessionId: string) {
const { rawQuery } = clickhouse; const { rawQuery } = clickhouse;
return rawQuery( return rawQuery(
@ -41,10 +40,9 @@ async function clickhouseQuery(websiteId: string, sessionId: string) {
sumIf(1, event_type = 1) as views, sumIf(1, event_type = 1) as views,
sumIf(1, event_type = 2) as events sumIf(1, event_type = 2) as events
from website_event from website_event
where website_id = {websiteId:UUID} where session_id = {sessionId:UUID}
and session_id = {sessionId:UUID}
group by session_id, website_id, hostname, browser, os, device, screen, language, country, subdivision1, city group by session_id, website_id, hostname, browser, os, device, screen, language, country, subdivision1, city
`, `,
{ websiteId, sessionId }, { sessionId },
).then(result => result?.[0]); ).then(result => result?.[0]);
} }