Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { useQuery } from "@tanstack/react-query";
import DataRecordsPanel from "@/app/(private)/map/[id]/components/InspectorPanel/DataRecordsPanel";
import { useInspectorDataSourceConfig } from "@/app/(private)/map/[id]/hooks/useInspectorDataSourceConfig";
import { useDataSources } from "@/hooks/useDataSources";
import { useTRPC } from "@/services/trpc/react";
import { cn } from "@/shadcn/utils";

Expand All @@ -16,6 +17,8 @@ export function DefaultInspectorPreview({
const trpc = useTRPC();

const inspectorConfig = useInspectorDataSourceConfig(dataSourceId);
const { data: dataSources } = useDataSources();
const dataSource = dataSources?.find((ds) => ds.id === dataSourceId);

const selectedCount =
inspectorConfig?.items.filter((i) => i.type === "column").length ?? 0;
Expand Down Expand Up @@ -58,6 +61,11 @@ export function DefaultInspectorPreview({
/>
)}
</div>
<div className="shrink-0 px-3 py-2 border-t border-neutral-200">
<p className="text-xs text-muted-foreground">
Organisation: {dataSource?.organisationName ?? "—"}
</p>
</div>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ export default function DataSourceConfigPage() {
<h1 className="text-3xl font-medium tracking-tight mt-3 min-w-0">
{dataSource.name}
</h1>
<p className="text-sm text-muted-foreground mt-1">
Organisation: {dataSource.organisationName ?? "—"}
</p>
<p className="text-sm text-muted-foreground mt-1">
Configure default inspector settings for this public data source.
</p>
Expand Down
2 changes: 2 additions & 0 deletions src/app/(private)/(dashboards)/superadmin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export default function SuperadminPage() {
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Organisation</TableHead>
<TableHead>Record type</TableHead>
<TableHead>Records</TableHead>
<TableHead>Inspector config</TableHead>
Expand All @@ -331,6 +332,7 @@ export default function SuperadminPage() {
publicDataSources?.map((ds) => (
<TableRow key={ds.id}>
<TableCell className="font-medium">{ds.name}</TableCell>
<TableCell>{ds.organisationName ?? "-"}</TableCell>
<TableCell>{ds.recordType}</TableCell>
<TableCell>{ds.recordCount.toLocaleString()}</TableCell>
<TableCell>
Expand Down
18 changes: 16 additions & 2 deletions src/app/(private)/hooks/useDataSourceListCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,29 @@ export function useDataSourceListCache() {
(old: DataSourceByOrganisation[] | undefined) =>
old?.map((ds) =>
ds.id === dataSourceId
? { ...ds, ...updater({ ...ds, organisationOverride: null }) }
? {
...ds,
...updater({
...ds,
organisationName: "",
organisationOverride: null,
}),
}
: ds,
),
);
queryClient.setQueriesData(
{ queryKey: trpc.dataSource.byId.queryKey() },
(old: DataSourceById | undefined) => {
if (!old || old.id !== dataSourceId) return old;
return { ...old, ...updater({ ...old, organisationOverride: null }) };
return {
...old,
...updater({
...old,
organisationName: "",
organisationOverride: null,
}),
};
},
);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { Settings } from "lucide-react";
import { BookOpen, BookOpenIcon, Settings } from "lucide-react";

Check failure on line 3 in src/app/(private)/map/[id]/components/InspectorPanel/DataRecordsPanel.tsx

View workflow job for this annotation

GitHub Actions / lint

'BookOpenIcon' is defined but never used

Check failure on line 3 in src/app/(private)/map/[id]/components/InspectorPanel/DataRecordsPanel.tsx

View workflow job for this annotation

GitHub Actions / lint

'BookOpenIcon' is defined but never used
import TogglePanel from "@/app/(private)/map/[id]/components/TogglePanel";
import DataSourceIcon from "@/components/DataSourceIcon";
import IconButtonWithTooltip from "@/components/IconButtonWithTooltip";
Expand Down Expand Up @@ -102,6 +102,16 @@
))}
</ul>
)}

{dataSource?.organisationName && (
<div className="flex items-center gap-1 pt-2 border-t border-neutral-200/70 text-muted-foreground">
<BookOpen className="w-3 h-3 shrink-0" />
<p className="text-[11px] truncate">
Published by <span className="text-neutral-400">•</span>{" "}
{dataSource.organisationName}
</p>
</div>
)}
</div>
</TogglePanel>
);
Expand Down
52 changes: 47 additions & 5 deletions src/components/DataSourceItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ function LastImportedOrDateAddedMeta({
return null;
}

function OrganisationMeta({
organisationName,
compact,
}: {
organisationName: string | null | undefined;
compact?: boolean;
}) {
const name = organisationName?.trim();
if (!name) return null;
return (
<span
className={cn(
"inline-flex items-center gap-1 whitespace-nowrap text-muted-foreground",
compact ? "text-[11px]" : "text-xs",
)}
>
Published by
<span className="text-neutral-400">•</span>
<span className="truncate">{name}</span>
</span>
);
}

export interface DataSourceItemProps {
dataSource: DataSourceWithImportInfo;
className?: string;
Expand Down Expand Up @@ -235,15 +258,25 @@ export function DataSourceItem({
</p>
)}

{(lastImportedText || dataSource.createdAt) && (
<div className="flex items-center gap-4">


<div className="mt-1">
<LastImportedOrDateAddedMeta
lastImportedText={lastImportedText}
createdAt={dataSource.createdAt}
<OrganisationMeta
organisationName={dataSource.organisationName}
compact
/>
</div>
)}
{(lastImportedText || dataSource.createdAt) && (
<div className="mt-1">
<LastImportedOrDateAddedMeta
lastImportedText={lastImportedText}
createdAt={dataSource.createdAt}
compact
/>
</div>
)}
</div>

{columnPills.length > 0 && columnPreviewVariant === "pills" && (
<div className="flex flex-wrap gap-1.5 mt-2">
Expand Down Expand Up @@ -405,6 +438,13 @@ export function DataSourceItem({
)}
</div>
) : null}

<div className="col-span-2 pt-1">
<OrganisationMeta
organisationName={dataSource.organisationName}
compact
/>
</div>
</div>
</div>
);
Expand Down Expand Up @@ -463,6 +503,8 @@ export function DataSourceItem({
</span>
)}
</div>

<OrganisationMeta organisationName={dataSource.organisationName} />
</div>

{showColumnPreview && columnPreviewVariant === "text" ? (
Expand Down
54 changes: 49 additions & 5 deletions src/server/trpc/routers/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
deleteDataSource,
findDataSourceById,
findDataSourcesByIds,
findPublicDataSources,

Check failure on line 31 in src/server/trpc/routers/dataSource.ts

View workflow job for this annotation

GitHub Actions / lint

'findPublicDataSources' is defined but never used

Check failure on line 31 in src/server/trpc/routers/dataSource.ts

View workflow job for this annotation

GitHub Actions / lint

'findPublicDataSources' is defined but never used
getJobInfo,
getUniqueColumnValues,
updateDataSource,
Expand Down Expand Up @@ -57,15 +57,26 @@
router,
superadminProcedure,
} from "../index";
import type { DataSource } from "@/models/DataSource";

Check failure on line 60 in src/server/trpc/routers/dataSource.ts

View workflow job for this annotation

GitHub Actions / lint

'DataSource' is defined but never used

Check failure on line 60 in src/server/trpc/routers/dataSource.ts

View workflow job for this annotation

GitHub Actions / lint

'DataSource' is defined but never used
import type { DataSourceEvent } from "@/server/events";
import type { DataSourceUpdate } from "@/server/models/DataSource";

export const dataSourceRouter = router({
listPublic: superadminProcedure.query(async () => {
const dataSources = await findPublicDataSources();
const dataSources = await db
.selectFrom("dataSource")
.leftJoin("organisation", "dataSource.organisationId", "organisation.id")
.where("dataSource.public", "=", true)
.selectAll("dataSource")
.select(["organisation.name as organisationName"])
.execute();

const withImportInfo = await addImportInfo(dataSources);
return withImportInfo.map((ds) => ({ ...ds, organisationOverride: null }));
return withImportInfo.map((ds) => ({
...ds,
organisationName: ds.organisationName ?? "",
organisationOverride: null,
}));
}),
updateDefaultInspectorConfig: superadminProcedure
.input(
Expand Down Expand Up @@ -100,7 +111,26 @@
const ids = getVisualisedDataSourceIds(map.config, view);
if (!ids.length) return [];
const dataSources = await findDataSourcesByIds(ids);
const withImportInfo = await addImportInfo(dataSources);
const organisationIds = [
...new Set(dataSources.map((ds) => ds.organisationId).filter(Boolean)),
];
const organisations =
organisationIds.length > 0
? await db
.selectFrom("organisation")
.where("id", "in", organisationIds)
.select(["id", "name"])
.execute()
: [];
const organisationNameById = new Map(
organisations.map((o) => [o.id, o.name ?? null]),
);
const withOrg = dataSources.map((ds) => ({
...ds,
organisationName: organisationNameById.get(ds.organisationId) ?? "",
}));

const withImportInfo = await addImportInfo(withOrg);
return withImportInfo.map((ds) => ({
...ds,
organisationOverride: null,
Expand Down Expand Up @@ -137,6 +167,7 @@
return eb.or(filter);
})
.selectAll("dataSource")
.select(["organisation.name as organisationName"])
.execute();

const orgId = input?.activeOrganisationId;
Expand All @@ -162,6 +193,7 @@
const withImportInfo = await addImportInfo(filteredDataSources);
return withImportInfo.map((ds) => ({
...ds,
organisationName: ds.organisationName ?? "",
organisationOverride: overrideMap.get(ds.id) ?? null,
}));
}),
Expand All @@ -172,9 +204,20 @@
.selectAll("dataSource")
.execute();

return addImportInfo(dataSources);
const withOrg = dataSources.map((ds) => ({
...ds,
organisationName: ctx.organisation.name ?? "",
}));

return addImportInfo(withOrg);
}),
byId: dataSourceOwnerProcedure.query(async ({ ctx }) => {
const organisation = await db
.selectFrom("organisation")
.where("id", "=", ctx.dataSource.organisationId)
.select(["name"])
.executeTakeFirst();

const recordCount = await db
.selectFrom("dataRecord")
.where("dataSourceId", "=", ctx.dataSource.id)
Expand All @@ -196,6 +239,7 @@
]);
return {
...ctx.dataSource,
organisationName: organisation?.name ?? "",
config: {
...ctx.dataSource.config,
__SERIALIZE_CREDENTIALS: true,
Expand Down Expand Up @@ -760,7 +804,7 @@
}),
});

const addImportInfo = async (dataSources: DataSource[]) => {
const addImportInfo = async <T extends { id: string }>(dataSources: T[]) => {
// Get import info for all data sources
const importInfos = await Promise.all(
dataSources.map((dataSource) =>
Expand Down
Loading