Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Mar 15, 2024
1 parent 063abdb commit 024e3a0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 55 deletions.
6 changes: 3 additions & 3 deletions runtime/resolvers/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestSimpleSQLApi(t *testing.T) {
require.NotNil(t, res)

var rows []map[string]interface{}
require.NoError(t, json.Unmarshal(res, &rows))
require.NoError(t, json.Unmarshal(res.Data, &rows))
require.Equal(t, 5, len(rows))
require.Equal(t, 5, len(rows[0]))
require.Equal(t, 4.09, rows[0]["bid_price"])
Expand All @@ -54,7 +54,7 @@ func TestTemplateSQLApi(t *testing.T) {
require.NotNil(t, res)

var rows []map[string]interface{}
require.NoError(t, json.Unmarshal(res, &rows))
require.NoError(t, json.Unmarshal(res.Data, &rows))
require.Equal(t, 5, len(rows))
require.Equal(t, 5, len(rows[0]))
require.Equal(t, 1.81, rows[0]["bid_price"])
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestTemplateSQLApi2(t *testing.T) {
require.NotNil(t, res)

var rows []map[string]interface{}
require.NoError(t, json.Unmarshal(res, &rows))
require.NoError(t, json.Unmarshal(res.Data, &rows))
require.Equal(t, 5, len(rows))
require.Equal(t, 5, len(rows[0]))
require.Equal(t, 4.09, rows[0]["bid_price"])
Expand Down
3 changes: 3 additions & 0 deletions runtime/server/generate_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func (s *Server) GenerateChartSpec(ctx context.Context, req *runtimev1.GenerateC
Args: nil,
UserAttributes: auth.GetClaims(ctx).Attributes(),
})
if err != nil {
return nil, err
}

start := time.Now()

Expand Down
4 changes: 0 additions & 4 deletions web-common/src/features/charts/ChartDisplay.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@
$chartPromptStore.charts[
getFilePathFromNameAndType(chartName, EntityType.Chart)
];
$: console.log(
getFilePathFromNameAndType(chartName, EntityType.Chart),
promptStatus,
);
</script>

<div class="m-2 w-1/2">
Expand Down
26 changes: 26 additions & 0 deletions web-common/src/features/charts/chartYaml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Document } from "yaml";

export function getChartYaml(
vegaLite: string | undefined,
resolver: string | undefined,
resolverProperties: Record<string, any> | undefined,
) {
const doc = new Document();
doc.set("kind", "chart");

// TODO: more fields from resolverProperties
if (resolver === "SQL") {
doc.set("data", { sql: (resolverProperties?.sql as string) ?? "" });
} else if (resolver === "MetricsSQL") {
doc.set("data", { metrics_sql: (resolverProperties?.sql as string) ?? "" });
} else if (resolver === "API") {
doc.set("data", { api: (resolverProperties?.api as string) ?? "" });
}

doc.set(
"vega_lite",
JSON.stringify(JSON.parse(vegaLite ?? "{}"), null, 2).replace(/^/gm, " "),
);

return doc.toString();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getChartYaml } from "@rilldata/web-common/features/charts/prompt/generateChart";
import { getChartYaml } from "@rilldata/web-common/features/charts/chartYaml";
import { describe, it, expect } from "vitest";

const VegaLiteSpec = `{
Expand Down
32 changes: 1 addition & 31 deletions web-common/src/features/charts/prompt/generateChart.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { goto } from "$app/navigation";
import { getChartYaml } from "@rilldata/web-common/features/charts/chartYaml";
import {
ChartPromptStatus,
chartPromptStore,
Expand All @@ -15,7 +16,6 @@ import {
runtimeServicePutFile,
} from "@rilldata/web-common/runtime-client";
import { get } from "svelte/store";
import { Document } from "yaml";

export function createChartGenerator(instanceId: string, chart: string) {
const generateVegaConfig = createRuntimeServiceGenerateChartSpec();
Expand Down Expand Up @@ -74,9 +74,7 @@ export function createFullChartGenerator(instanceId: string) {
blob: `kind: chart`,
});
chartPromptStore.setStatus(chartPath, ChartPromptStatus.GeneratingData);
console.log(chartPath, "...1");
await goto(getRouteFromName(newChartName, EntityType.Chart));
console.log(chartPath, "...2");
const resolverResp = await get(generateResolver).mutateAsync({
instanceId,
data: {
Expand All @@ -86,7 +84,6 @@ export function createFullChartGenerator(instanceId: string) {
prompt,
},
});
console.log(chartPath, "...3");

// add a chart with just the resolver
await runtimeServicePutFile(instanceId, chartPath, {
Expand All @@ -96,7 +93,6 @@ export function createFullChartGenerator(instanceId: string) {
resolverResp.resolverProperties,
),
});
console.log(chartPath, "...4");
chartPromptStore.setStatus(
chartPath,
ChartPromptStatus.GeneratingChartSpec,
Expand All @@ -109,7 +105,6 @@ export function createFullChartGenerator(instanceId: string) {
resolverProperties: resolverResp.resolverProperties,
},
});
console.log(chartPath, "...5");

chartPromptStore.deleteStatus(chartPath);
await runtimeServicePutFile(instanceId, chartPath, {
Expand All @@ -124,28 +119,3 @@ export function createFullChartGenerator(instanceId: string) {
}
};
}

export function getChartYaml(
vegaLite: string | undefined,
resolver: string | undefined,
resolverProperties: Record<string, any> | undefined,
) {
const doc = new Document();
doc.set("kind", "chart");

// TODO: more fields from resolverProperties
if (resolver === "SQL") {
doc.set("data", { sql: (resolverProperties?.sql as string) ?? "" });
} else if (resolver === "MetricsSQL") {
doc.set("data", { metrics_sql: (resolverProperties?.sql as string) ?? "" });
} else if (resolver === "API") {
doc.set("data", { api: (resolverProperties?.api as string) ?? "" });
}

doc.set(
"vega_lite",
JSON.stringify(JSON.parse(vegaLite ?? "{}"), null, 2).replace(/^/gm, " "),
);

return doc.toString();
}
16 changes: 0 additions & 16 deletions web-common/src/features/tables/TableMenuItems.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
BehaviourEventMedium.Menu,
MetricsEventSpace.LeftPanel,
);
let generateOpen = false;
</script>

{#if $isModelingSupportedForCurrentOlapDriver.data}
Expand All @@ -79,17 +77,3 @@
<WandIcon class="w-3 h-3" />
</div>
</MenuItem>
<MenuItem
icon
on:select={() => {
generateOpen = true;
toggleMenu();
}}
propogateSelect={false}
>
<Explore slot="icon" />
<div class="flex gap-x-2 items-center">
Generate chart with AI
<WandIcon class="w-3 h-3" />
</div>
</MenuItem>

0 comments on commit 024e3a0

Please sign in to comment.