Skip to content

Commit

Permalink
Wires the queries for the artifact page (#1912)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenac95 authored Aug 3, 2024
1 parent 3039f64 commit 43bc528
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
18 changes: 17 additions & 1 deletion apps/frontend/app/artifact/[source]/[...name]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { cache } from "react";
import { PlasmicComponent } from "@plasmicapp/loader-nextjs";
import { PLASMIC } from "../../../../plasmic-init";
import { PlasmicClientRootProvider } from "../../../../plasmic-init-client";
import { cachedGetArtifactByName } from "../../../../lib/clickhouse/cached-queries";
import {
cachedGetAllEventTypes,
cachedGetArtifactByName,
cachedGetCodeMetricsByArtifactIds,
} from "../../../../lib/clickhouse/cached-queries";
import { logger } from "../../../../lib/logger";

const PLASMIC_COMPONENT = "ArtifactPage";
Expand Down Expand Up @@ -79,6 +83,16 @@ export default async function ArtifactPage(props: ArtifactPageProps) {
notFound();
}
const artifact = artifactArray[0];
const artifactId = artifact.artifact_id;

const data = await Promise.all([
cachedGetAllEventTypes(),
cachedGetCodeMetricsByArtifactIds({
artifactIds: [artifactId],
}),
]);
const eventTypes = data[0];
const codeMetrics = data[1];

//console.log(artifact);
const plasmicData = await cachedFetchComponent(PLASMIC_COMPONENT);
Expand All @@ -97,6 +111,8 @@ export default async function ArtifactPage(props: ArtifactPageProps) {
component={compMeta.displayName}
componentProps={{
metadata: artifact,
eventTypes: eventTypes,
codeMetrics: codeMetrics,
}}
/>
</PlasmicClientRootProvider>
Expand Down
10 changes: 10 additions & 0 deletions apps/frontend/lib/clickhouse/cached-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
GET_CODE_METRICS_BY_PROJECT,
GET_ONCHAIN_METRICS_BY_PROJECT,
GET_ALL_EVENT_TYPES,
GET_CODE_METRICS_BY_ARTIFACT,
} from "./queries";
import { getClickhouseClient } from "../clients/clickhouse";

Expand Down Expand Up @@ -113,6 +114,14 @@ const cachedGetOnchainMetricsByProjectIds = cache(
}),
);

const cachedGetCodeMetricsByArtifactIds = cache(
async (variables: { artifactIds: string[] }) =>
queryWrapper({
query: GET_CODE_METRICS_BY_ARTIFACT,
variables,
}),
);

export {
cachedGetArtifactsByIds,
cachedGetArtifactByName,
Expand All @@ -123,4 +132,5 @@ export {
cachedGetCodeMetricsByProjectIds,
cachedGetOnchainMetricsByProjectIds,
cachedGetAllEventTypes,
cachedGetCodeMetricsByArtifactIds,
};
2 changes: 1 addition & 1 deletion apps/frontend/lib/clickhouse/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const GET_ARTIFACT_BY_SOURCE_NAMESPACE_NAME = define(
WHERE
artifact_source = {artifactSource: String}
and artifact_name = {artifactName: String}
and artifact_namespace {artifactNamespace: String}
and artifact_namespace = {artifactNamespace: String}
`,
artifactResponse,
);
Expand Down

0 comments on commit 43bc528

Please sign in to comment.