Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: re-add frontend amplitude and simplify backend #176

Merged
merged 7 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install modules
run: cd frontend && npm i
- name: Svelte check
run: cd frontend && npm run check
run: cd frontend && PUBLIC_AMPLITUDE_API_KEY="" npm run check

format-backend:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -95,4 +95,4 @@ jobs:
- name: Build frontend
run: |
cd frontend/
npm run build
PUBLIC_AMPLITUDE_API_KEY="" npm run build
40 changes: 1 addition & 39 deletions backend/zeno_backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import pandas as pd
import uvicorn
from amplitude import BaseEvent
from dotenv import load_dotenv
from fastapi import Depends, FastAPI, HTTPException, Request, Response, status
from fastapi.middleware.cors import CORSMiddleware
Expand All @@ -17,7 +16,6 @@
import zeno_backend.database.select as select
import zeno_backend.database.update as update
import zeno_backend.util as util
from zeno_backend.classes.amplitude import AmplitudeHandler
from zeno_backend.classes.base import (
GroupMetric,
ZenoColumn,
Expand Down Expand Up @@ -344,24 +342,6 @@ def get_project_state(
project.editor = True
return select.project_state(project_uuid, project)

@api_app.post("/project/{owner}/{project}", response_model=Project, tags=["zeno"])
def get_project(owner_name: str, project_name: str, request: Request):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer called with the big project_stats call

uuid = select.project_uuid(owner_name, project_name)
if uuid is None:
return Response(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
if not util.access_valid(uuid, request):
return Response(status_code=401)
AmplitudeHandler().track(
BaseEvent(
event_type="Project Viewed",
user_id="ProjectViewedUser",
event_properties={"project_uuid": uuid},
)
)
return select.project(
owner_name, project_name, util.get_user_from_token(request)
)

@api_app.get(
"/report/{owner}/{report}", response_model=ReportResponse, tags=["zeno"]
)
Expand Down Expand Up @@ -416,12 +396,6 @@ def get_projects(current_user=Depends(auth.claim())):
tags=["zeno"],
)
def get_public_projects():
AmplitudeHandler().track(
BaseEvent(
event_type="Home Viewed",
user_id="HomeViewedUser",
)
)
return select.public_projects()

@api_app.get(
Expand Down Expand Up @@ -577,13 +551,7 @@ def login(name: str):
if fetched_user is None:
try:
user = User(id=-1, name=name, admin=None)
user_id = insert.user(user)
AmplitudeHandler().track(
BaseEvent(
event_type="User Registered",
user_id="00000" + str(user_id) if user_id else "",
)
)
insert.user(user)
insert.api_key(user)
return select.user(name)
except Exception as exc:
Expand All @@ -592,12 +560,6 @@ def login(name: str):
detail=str(exc),
) from exc
else:
AmplitudeHandler().track(
BaseEvent(
event_type="User Logged In",
user_id="00000" + str(fetched_user.id),
)
)
return fetched_user

@api_app.post(
Expand Down
65 changes: 65 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"vitest": "^0.25.3"
},
"dependencies": {
"@amplitude/analytics-browser": "^2.2.3",
"@auth/core": "^0.13.0",
"@auth/sveltekit": "^0.3.6",
"@mdi/js": "^7.2.96",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import { authToken } from '$lib/stores';
import { getEndpoint } from '$lib/util/util';
import { OpenAPI } from '$lib/zenoapi/index';
import * as amplitude from '@amplitude/analytics-browser';

export let data;

$: {
OpenAPI.BASE = `${getEndpoint()}/api`;
if (data.cognitoUser !== null) {
authToken.set(data.cognitoUser.accessToken);
amplitude.setUserId('00000' + data.cognitoUser.id);
OpenAPI.HEADERS = {
Authorization: 'Bearer ' + data.cognitoUser.accessToken
};
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<script lang="ts">
import { browser } from '$app/environment';
import { PUBLIC_AMPLITUDE_API_KEY } from '$env/static/public';
import { featureFlags } from '$lib/stores';
import { zenoFeatureFlags } from '$lib/util/features';
import * as amplitude from '@amplitude/analytics-browser';
import '../app.css';

export let data;

featureFlags.set({ ...zenoFeatureFlags, ...data.features });

if (browser && PUBLIC_AMPLITUDE_API_KEY)
amplitude.init(PUBLIC_AMPLITUDE_API_KEY, {
defaultTracking: true
});
</script>

<div class="w-full h-full overflow-hidden">
Expand Down
Loading