Skip to content

Commit c549a43

Browse files
authored
Bug/diverging analysis id uifix to main (#663)
* Bug/654/census codespace block w corsanywhere (#658) * Workaround "Census API appears to have blocked Codespaces" Fixes #645 * env var proxy option * Prettier fix for #658 (#659) * prettier * env var proxy option * Fix bug where UI could not link to cases where analysis and caseid were not the same
1 parent df5cb63 commit c549a43

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

.github/workflows/heat-stack.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ jobs:
217217
name: 🎭 Playwright
218218
runs-on: ubuntu-22.04
219219
timeout-minutes: 60
220+
# CORS proxy settings for geocoding API calls
221+
env:
222+
VITE_CORS_PROXY_URL: ${{ secrets.VITE_CORS_PROXY_URL }}
223+
VITE_CORS_ORIGIN: ${{ secrets.VITE_CORS_ORIGIN }}
220224
steps:
221225
- name: ⬇️ Checkout repo
222226
uses: actions/checkout@v4

heat-stack/app/routes/cases+/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export default function Cases({
139139
<td className="whitespace-nowrap px-6 py-4">
140140
<div className="text-sm font-medium text-gray-900">
141141
<Link
142-
to={`/cases/${firstAnalysis?.id}/edit?edit_mode=true`}
142+
to={`/cases/${caseItem.id}/edit?edit_mode=true`}
143143
className="text-sm font-medium text-indigo-700 underline hover:underline"
144144
>
145145
{caseItem.id}
@@ -170,19 +170,19 @@ export default function Cases({
170170
</td>
171171
<td className="whitespace-nowrap px-6 py-4">
172172
<Link
173-
to={`/cases/${firstAnalysis?.id}`}
173+
to={`/cases/${caseItem.id}`}
174174
className="mx-1 text-indigo-600 hover:text-indigo-900"
175175
>
176176
View
177177
</Link>
178178
<Link
179-
to={`/cases/${firstAnalysis?.id}/edit`}
179+
to={`/cases/${caseItem.id}/edit`}
180180
className="mx-1 text-indigo-600 hover:text-indigo-900"
181181
>
182182
Edit
183183
</Link>
184184
<Link
185-
to={`/cases/${firstAnalysis?.id}/delete`}
185+
to={`/cases/${caseItem.id}/delete`}
186186
className="hover:text-indigo-9001 mx-1 text-indigo-600"
187187
>
188188
Delete

heat-stack/app/utils/GeocodeUtil.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
const BASE_URL = 'https://geocoding.geo.census.gov'
1+
const BASE_URL =
2+
import.meta.env.VITE_CORS_PROXY_URL ?? 'https://geocoding.geo.census.gov'
3+
const CORS_ORIGIN = import.meta.env.VITE_CORS_ORIGIN
24
const ADDRESS_ENDPOINT = '/geocoder/geographies/onelineaddress'
35

6+
// Build headers only if origin is defined
7+
const headers = CORS_ORIGIN
8+
? {
9+
Origin: CORS_ORIGIN,
10+
'X-Requested-With': 'XMLHttpRequest',
11+
}
12+
: undefined
13+
414
// example: https://geocoding.geo.census.gov/geocoder/geographies/onelineaddress?address=1%20broadway%2C%20cambridge%2C%20ma%2002142&benchmark=4&vintage=4&format=json
515
interface CensusGeocoderResponse {
616
result: {
@@ -93,8 +103,8 @@ class GeocodeUtil {
93103

94104
/** TODO: note that for this Census API you can specify particular parts of this that
95105
we want (x, y, state_id, and county_id for now), read the docs */
96-
let url = new URL(BASE_URL + ADDRESS_ENDPOINT + '?' + params.toString())
97-
let rezzy = await fetch(url)
106+
const url = new URL(BASE_URL + ADDRESS_ENDPOINT + '?' + params.toString())
107+
let rezzy = await fetch(url, headers ? { headers } : undefined)
98108
let jrez = (await rezzy.json()) as CensusGeocoderResponse
99109
// TODO: Return all addresses and let the user choose the right one
100110
// const fs = await import('node:fs')

0 commit comments

Comments
 (0)