Skip to content

Commit 9c3a8b8

Browse files
authored
Merge pull request #262 from commonknowledge/fix/migrantdemo-fixes
fix: minor bugs seen in the migrantdemo onboarding
2 parents 0b7fb0b + c1c0234 commit 9c3a8b8

File tree

5 files changed

+81
-94
lines changed

5 files changed

+81
-94
lines changed

src/app/(private)/data-sources/[id]/components/ConfigurationForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export default function ConfigurationForm({
155155
variant="secondary"
156156
type="submit"
157157
>
158-
Save and import
158+
{loading ? "Saving (this can take a minute...)" : "Save and import"}
159159
</Button>
160160

161161
{error && <p className="text-xs text-red-500">{error}</p>}

src/app/map/[id]/colors.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,7 @@ export const useFillColor = ({
246246
.fill(null)
247247
.flatMap((_, i) => {
248248
const step = stepScale(i);
249-
const color = isReversed
250-
? colorScheme.colorScale(
251-
colorScheme.maxValue - (step - colorScheme.minValue),
252-
)
253-
: colorScheme.colorScale(step);
249+
const color = colorScheme.colorScale(step);
254250
return [step, color];
255251
});
256252
return [

src/app/map/[id]/components/Markers.tsx

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ import type { FeatureCollection } from "geojson";
1414

1515
const MARKER_CLIENT_EXCLUDED_KEY = "__clientExcluded";
1616

17-
function hexToRgb(hex: string) {
18-
const normalized = hex.replace("#", "");
19-
const bigint = parseInt(normalized, 16);
20-
const r = (bigint >> 16) & 255;
21-
const g = (bigint >> 8) & 255;
22-
const b = bigint & 255;
23-
return { r, g, b };
24-
}
17+
// function hexToRgb(hex: string) {
18+
// const normalized = hex.replace("#", "");
19+
// const bigint = parseInt(normalized, 16);
20+
// const r = (bigint >> 16) & 255;
21+
// const g = (bigint >> 8) & 255;
22+
// const b = bigint & 255;
23+
// return { r, g, b };
24+
// }
2525

26-
function rgbaString(hex: string, alpha: number) {
27-
const { r, g, b } = hexToRgb(hex);
28-
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
29-
}
26+
// function rgbaString(hex: string, alpha: number) {
27+
// const { r, g, b } = hexToRgb(hex);
28+
// return `rgba(${r}, ${g}, ${b}, ${alpha})`;
29+
// }
3030

3131
export default function Markers() {
3232
const { viewConfig } = useMapViews();
@@ -154,57 +154,53 @@ function DataSourceMarkers({
154154
],
155155
}}
156156
>
157-
{publicMap ? (
158-
[
159-
<Layer
160-
id={`${sourceId}-circles`}
161-
key={`${sourceId}-circles`}
162-
type="circle"
163-
source={sourceId}
164-
filter={["has", "point_count"]}
165-
paint={{
166-
// Circle radius based on point_count
167-
"circle-radius": [
168-
"interpolate",
169-
["linear"],
170-
["get", "point_count"],
171-
1,
172-
15,
173-
10,
174-
25,
175-
100,
176-
35,
177-
1000,
178-
50,
179-
10000,
180-
70,
181-
],
182-
// Circle color
183-
"circle-color": color,
184-
// Opacity based on matched_count
185-
"circle-opacity": [
186-
"case",
187-
["==", ["get", "matched_count"], 0],
188-
0.5,
189-
0.8,
190-
],
191-
}}
192-
/>,
193-
194-
<Layer
195-
id={`${sourceId}-counts`}
196-
key={`${sourceId}-counts`}
197-
type="symbol"
198-
source={sourceId}
199-
filter={["has", "point_count"]}
200-
layout={{
201-
"text-field": ["get", "point_count"],
202-
"text-font": ["DIN Pro Medium", "Arial Unicode MS Bold"],
203-
"text-size": 12,
204-
}}
205-
/>,
206-
]
207-
) : (
157+
<Layer
158+
id={`${sourceId}-circles`}
159+
key={`${sourceId}-circles`}
160+
type="circle"
161+
source={sourceId}
162+
filter={["has", "point_count"]}
163+
paint={{
164+
// Circle radius based on point_count
165+
"circle-radius": [
166+
"interpolate",
167+
["linear"],
168+
["get", "point_count"],
169+
1,
170+
15,
171+
10,
172+
25,
173+
100,
174+
35,
175+
1000,
176+
50,
177+
10000,
178+
70,
179+
],
180+
// Circle color
181+
"circle-color": color,
182+
// Opacity based on matched_count
183+
"circle-opacity": [
184+
"case",
185+
["==", ["get", "matched_count"], 0],
186+
0.5,
187+
0.8,
188+
],
189+
}}
190+
/>
191+
<Layer
192+
id={`${sourceId}-counts`}
193+
key={`${sourceId}-counts`}
194+
type="symbol"
195+
source={sourceId}
196+
filter={["has", "point_count"]}
197+
layout={{
198+
"text-field": ["get", "point_count"],
199+
"text-font": ["DIN Pro Medium", "Arial Unicode MS Bold"],
200+
"text-size": 12,
201+
}}
202+
/>
203+
{/* TODO: Restore this with a switch
208204
<Layer
209205
id={`${sourceId}-heatmap`}
210206
type="heatmap"
@@ -273,8 +269,7 @@ function DataSourceMarkers({
273269
],
274270
"heatmap-opacity": 0.7,
275271
}}
276-
/>
277-
)}
272+
/> */}
278273
<Layer
279274
id={`${sourceId}-pins`}
280275
type="circle"

src/server/jobs/importDataSource.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ const getType = (value: unknown): ColumnType => {
182182
}
183183

184184
if (typeof value === "string") {
185-
const trimmedValue = value.trim().replace(/%$/, "");
185+
const trimmedValue = cleanNumber(value);
186186
if (/^[-+]?(\d+\.?\d*|\.\d+)([eE][-+]?\d+)?$/.test(trimmedValue)) {
187187
return ColumnType.Number;
188188
}
@@ -203,7 +203,14 @@ const parseNumber = (value: unknown): number => {
203203
if (typeof value !== "string") {
204204
return Number(value);
205205
}
206-
return Number(value.replace(/%$/, ""));
206+
return Number(cleanNumber(value));
207+
};
208+
209+
/**
210+
* Replace terminating % and commas
211+
*/
212+
const cleanNumber = (value: string): string => {
213+
return value.trim().replace(/%$/, "").replace(/,/g, "");
207214
};
208215

209216
const addColumnDefs = (

src/server/trpc/routers/dataSource.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const dataSourceRouter = router({
5353
return eb.or(filter);
5454
})
5555
.selectAll("dataSource")
56-
.select(db.fn.count("dataRecord.id").as("recordCount"))
56+
.select(db.fn.count("dataRecord.id").distinct().as("recordCount"))
5757
.groupBy("dataSource.id")
5858
.execute();
5959

@@ -65,31 +65,20 @@ export const dataSourceRouter = router({
6565
.leftJoin("dataRecord", "dataRecord.dataSourceId", "dataSource.id")
6666
.where("organisationId", "=", ctx.organisation.id)
6767
.selectAll("dataSource")
68-
.select(db.fn.count("dataRecord.id").as("recordCount"))
68+
.select(db.fn.count("dataRecord.id").distinct().as("recordCount"))
6969
.groupBy("dataSource.id")
7070
.execute();
7171

7272
return addImportInfo(dataSources);
7373
}),
7474
byId: dataSourceOwnerProcedure.query(async ({ ctx }) => {
75-
const dataSource = await db
76-
.selectFrom("dataSource")
77-
.leftJoin("dataRecord", "dataRecord.dataSourceId", "dataSource.id")
78-
.where("organisationId", "=", ctx.organisation.id)
79-
.where("dataSource.id", "=", ctx.dataSource.id)
80-
.selectAll("dataSource")
81-
.select(db.fn.count("dataRecord.id").as("recordCount"))
82-
.groupBy("dataSource.id")
75+
const recordCount = await db
76+
.selectFrom("dataRecord")
77+
.where("dataSourceId", "=", ctx.dataSource.id)
78+
.select(db.fn.countAll().as("count"))
8379
.executeTakeFirst();
8480

85-
if (!dataSource) {
86-
throw new TRPCError({
87-
code: "NOT_FOUND",
88-
message: "Data source not found",
89-
});
90-
}
91-
92-
const dataSourceIds = dataSource.enrichments
81+
const dataSourceIds = ctx.dataSource.enrichments
9382
.filter((e) => e.sourceType === EnrichmentSourceType.DataSource)
9483
.map((e) => e.dataSourceId)
9584
.filter((id) => typeof id === "string");
@@ -103,15 +92,15 @@ export const dataSourceRouter = router({
10392
),
10493
]);
10594
return {
106-
...dataSource,
95+
...ctx.dataSource,
10796
config: {
108-
...dataSource.config,
97+
...ctx.dataSource.config,
10998
__SERIALIZE_CREDENTIALS: true,
11099
},
111100
enrichmentInfo,
112101
importInfo,
113102
enrichmentDataSources,
114-
recordCount: Number(dataSource.recordCount) || 0,
103+
recordCount: Number(recordCount?.count) || 0,
115104
};
116105
}),
117106

0 commit comments

Comments
 (0)