Skip to content

Commit

Permalink
Merge pull request #62 from curieo-org/eng-190
Browse files Browse the repository at this point in the history
New Search and Profile Frontend
  • Loading branch information
rathijitpapon authored Jun 26, 2024
2 parents 54aaa28 + 87a8a50 commit 031a263
Show file tree
Hide file tree
Showing 94 changed files with 2,394 additions and 595 deletions.
4 changes: 2 additions & 2 deletions agency/Makefile_ECR
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Image = curieo-agency
ECR = 698471419283.dkr.ecr.eu-central-1.amazonaws.com/curieo-agency
TAG = 2.0
TAG = 3.0

ecr_deploy: login
docker buildx build --platform linux/amd64 -t $(Image) .
docker tag $(Image) $(ECR):$(TAG)
docker push $(ECR):$(TAG)

login:
aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 698471419283.dkr.ecr.eu-central-1.amazonaws.com
aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 698471419283.dkr.ecr.eu-central-1.amazonaws.com
4 changes: 3 additions & 1 deletion agency/app/pubmed_retrieval/cluster_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,7 @@ async def retrieve_cluster_nodes(
for pubmed_id, pubmed_value in nodes_dict.items()
for child_node_id in pubmed_value.get("children_node_ids", [])
if child_node_id in children_node_texts
for child_node_json in [json.loads(children_node_texts[child_node_id])]
for child_node_json in [
json.loads(json.dumps(children_node_texts[child_node_id]))
]
]
2 changes: 1 addition & 1 deletion agency/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Declare variables to be passed into your templates.

service:
image: 698471419283.dkr.ecr.eu-central-1.amazonaws.com/curieo-agency:2.0
image: 698471419283.dkr.ecr.eu-central-1.amazonaws.com/curieo-agency:3.0
replica_count: 1
port: 50051

Expand Down
4 changes: 4 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ ARG POSTHOG_KEY
ARG POSTHOG_API_HOST
ARG POSTHOG_UI_HOST
ARG API_URL
ARG AUTH_URL
ARG AUTH_SECRET

ENV NEXT_TELEMETRY_DISABLED 1
ENV NEXT_PUBLIC_POSTHOG_KEY $POSTHOG_KEY
ENV NEXT_PUBLIC_POSTHOG_API_HOST $POSTHOG_API_HOST
ENV NEXT_PUBLIC_POSTHOG_UI_HOST $POSTHOG_UI_HOST
ENV NEXT_PUBLIC_API_URL $API_URL
ENV AUTH_URL $AUTH_URL
ENV AUTH_SECRET $AUTH_SECRET

RUN npm run build

Expand Down
4 changes: 3 additions & 1 deletion frontend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ POSTHOG_KEY = <POSTHOG_API_KEY>
POSTHOG_API_HOST = <FRONTEND_URL>/ingest
POSTHOG_UI_HOST = https://app.posthog.com
API_URL = <BACKEND_URL>
AUTH_URL = <FRONTEND_URL>
AUTH_SECRET = <base64 32 bit secret string>

ecr_deploy: login
docker buildx build --platform linux/amd64 --build-arg POSTHOG_KEY=$(POSTHOG_KEY) --build-arg POSTHOG_API_HOST=$(POSTHOG_API_HOST) --build-arg POSTHOG_UI_HOST=$(POSTHOG_UI_HOST) --build-arg API_URL=$(API_URL) -t $(Image) .
docker buildx build --platform linux/amd64 --build-arg POSTHOG_KEY=$(POSTHOG_KEY) --build-arg POSTHOG_API_HOST=$(POSTHOG_API_HOST) --build-arg POSTHOG_UI_HOST=$(POSTHOG_UI_HOST) --build-arg API_URL=$(API_URL) --build-arg AUTH_URL=${AUTH_URL} --build-arg AUTH_SECRET=${AUTH_SECRET} -t $(Image) .
docker tag $(Image) $(ECR):$(TAG)
docker push $(ECR):$(TAG)

Expand Down
14 changes: 9 additions & 5 deletions frontend/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ spec:
template:
metadata:
labels:
app: {{ .Release.Name }}
app: search-{{ .Release.Name }}
spec:
containers:
- image: {{ .Values.service.replica_count }}
- image: {{ .Values.service.image }}
imagePullPolicy: Always
env:
- name: NEXT_PUBLIC_POSTHOG_UI_HOST
value: https://app.posthog.com
- name: NEXT_PUBLIC_POSTHOG_KEY
value: phc_Qau6pGkA8BXUr7JuDxgALufZqhxMKAk9UVGY4UFQyXu
- name: NEXT_PUBLIC_POSTHOG_API_HOST
value: https://search-fronrend.search.svc.cluster.local:3000/ingest
value: https://search.curieo.ai/ingest
- name: NEXT_PUBLIC_API_URL
value: http://search-server.search.svc.cluster.local:3030
value: http://search-server.search.svc.cluster.local:3030
- name: AUTH_URL
value: https://search.curieo.ai
- name: AUTH_SECRET
value: 05mk7ukF/GSG1dHLYVp04Mxa49slQb2W3N9v1aMcRTM=
name: search-{{ .Release.Name }}
ports:
- containerPort: {{ .Values.service.port }}
Expand All @@ -38,4 +42,4 @@ spec:
memory: {{ .Values.resources.limits.memory }}
requests:
cpu: {{ .Values.resources.requests.cpu }}
memory: {{ .Values.resources.requests.memory }}
memory: {{ .Values.resources.requests.memory }}
4 changes: 2 additions & 2 deletions frontend/helm/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ spec:
protocol: TCP
name: http-web
selector:
app: {{ .Release.Name }}
sessionAffinity: "ClientIP"
app: search-{{ .Release.Name }}
sessionAffinity: "ClientIP"
2 changes: 1 addition & 1 deletion frontend/helm/templates/virtualservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spec:
gateways:
- {{ .Release.Name }}-gateway
hosts:
- {{ .Release.Name }}.{{ .Values.service.dns_zone }}
- search.{{ .Values.service.dns_zone }}
http:
- match:
- port: 443
Expand Down
2 changes: 1 addition & 1 deletion frontend/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Declare variables to be passed into your templates.

service:
image: 698471419283.dkr.ecr.eu-central-1.amazonaws.com/curieo-search-frontend:4.0
image: 698471419283.dkr.ecr.eu-central-1.amazonaws.com/curieo-search-frontend:7.0
replica_count: 1
port: 3000
dns_zone: curieo.ai
Expand Down
22 changes: 22 additions & 0 deletions frontend/package-lock.json

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

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@auth/core": "^0.32.0",
"@tanstack/react-query": "^5.37.1",
"date-fns": "^3.6.0",
"dompurify": "^3.1.5",
"lodash": "^4.17.21",
"next": "^14.2.3",
"next-auth": "^5.0.0-beta.19",
Expand All @@ -27,6 +28,7 @@
"zustand": "^4.5.2"
},
"devDependencies": {
"@types/dompurify": "^3.0.5",
"@types/lodash": "^4.17.4",
"@types/node": "^20",
"@types/react": "^18",
Expand Down
44 changes: 44 additions & 0 deletions frontend/public/images/answer-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion frontend/src/actions/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { signOut } from '@/auth'
import { headers as next_headers } from 'next/headers'

function curieoApiUrl(reqInfo?: RequestInfo): URL {
Expand Down Expand Up @@ -36,6 +37,13 @@ export async function curieoFetch(reqInfo: RequestInfo, init?: RequestInit): Pro
} else {
init = { headers }
}

const url: URL = curieoApiUrl(reqInfo)
return fetch(url, init)
const response = await fetch(url, init)

if (response.status === 405) {
await signOut()
}

return response.ok ? Promise.resolve(response) : Promise.reject(response)
}
32 changes: 19 additions & 13 deletions frontend/src/actions/search.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
'use server'

import { SearchReactionBody, SearchResult } from '@/types/search'
import { curieoFetch } from '@/actions/fetch'

export async function search(query: string): Promise<SearchResult> {
const response = await curieoFetch(`/search?${new URLSearchParams({ query })}`)
if (response.ok) {
return (await response.json()) as SearchResult
}
throw new Error('Search failed')
}
import { SearchHistoryResponse, SearchReactionBody, SearchResult, ThreadByIdResponse } from '@/types/search'

export async function searchById(id: string): Promise<SearchResult> {
const response = await curieoFetch(`/search/one?search_history_id=${id}`)
Expand All @@ -19,21 +11,35 @@ export async function searchById(id: string): Promise<SearchResult> {
throw new Error('Retrieving search failed')
}

export async function searchHistory({ limit, offset }: { limit: number; offset: number }): Promise<SearchResult[]> {
export async function searchHistory({
limit,
offset,
}: {
limit: number
offset: number
}): Promise<SearchHistoryResponse> {
const response = await curieoFetch(`/search/history?limit=${limit ?? 10}${offset ? `&offset=${offset}` : ``}`)
if (response.ok) {
return (await response.json()) as SearchResult[]
return (await response.json()) as SearchHistoryResponse
}
throw new Error('Retrieving search history failed')
}

export async function searchReaction(reaction: SearchReactionBody): Promise<SearchResult> {
export async function searchReaction(reaction: SearchReactionBody): Promise<void> {
const response = await curieoFetch('/search/reaction', {
method: 'PATCH',
body: JSON.stringify(reaction),
})
if (response.ok) {
return (await response.json()) as SearchResult
return
}
throw new Error('Could not submit reaction')
}

export async function threadById(id: string): Promise<ThreadByIdResponse> {
const response = await curieoFetch(`/search/threads?thread_id=${id}`)
if (response.ok) {
return (await response.json()) as ThreadByIdResponse
}
throw new Error('Retrieving search failed')
}
38 changes: 38 additions & 0 deletions frontend/src/actions/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use server'

import { UpdatePasswordBody, UpdateProfileBody, UserProfile } from '@/types/settings'
import { encodeAsUrlSearchParams } from '@/utils'
import { curieoFetch } from './fetch'

export async function fetchUserProfile(): Promise<UserProfile> {
const response = await curieoFetch('/users/me')
if (response.ok) {
return (await response.json()) as UserProfile
}
throw new Error('Could not retrieve user profile')
}

export async function updateUserProfile(payload: UpdateProfileBody): Promise<UserProfile> {
const response = await curieoFetch('/users/me', {
method: 'PATCH',
body: JSON.stringify(payload),
})
if (response.ok) {
return (await response.json()) as UserProfile
}
throw new Error('Could not update user profile')
}

export async function updatePassword(payload: UpdatePasswordBody): Promise<void> {
const response = await curieoFetch('/users/update-password', {
method: 'PATCH',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: encodeAsUrlSearchParams(payload),
})
if (response.ok) {
return
}
throw new Error('Could not update password')
}
Loading

0 comments on commit 031a263

Please sign in to comment.