Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: decode known yaml fields, display errors in generic file workspace #6240

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
13 changes: 13 additions & 0 deletions runtime/compilers/rillv1/parse_rillyaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"
"fmt"
"io"
"strings"

"github.com/rilldata/rill/runtime/pkg/env"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -40,6 +42,7 @@ type VariableDef struct {

// rillYAML is the raw YAML structure of rill.yaml
type rillYAML struct {
briangregoryholmes marked this conversation as resolved.
Show resolved Hide resolved
Compiler string `yaml:"compiler"`
// Title of the project
DisplayName string `yaml:"display_name"`
// Title of the project
Expand Down Expand Up @@ -92,10 +95,20 @@ func (p *Parser) parseRillYAML(ctx context.Context, path string) error {
}

tmp := &rillYAML{}

if err := yaml.Unmarshal([]byte(data), tmp); err != nil {
return newYAMLError(err)
}

dec := yaml.NewDecoder(strings.NewReader(data))
dec.KnownFields(true)

err = dec.Decode(tmp)

if err != nil && !errors.Is(err, io.EOF) {
briangregoryholmes marked this conversation as resolved.
Show resolved Hide resolved
return newYAMLError(err)
}

// Look for environment-specific overrides
for k, v := range tmp.Env { // nolint: gocritic // Using a pointer changes parser behavior
if v.Kind == yaml.ScalarNode {
Expand Down
2 changes: 1 addition & 1 deletion runtime/connections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ connectors:
AWS_ACCESS_KEY_ID: us-east-1
aws_secret_access_key: xxxx

variables:
vars:
foo: bar
allow_host_access: false
`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import { FileArtifact } from "@rilldata/web-common/features/entity-management/file-artifact";
import { yamlSchema } from "codemirror-json-schema/yaml";
import type { JSONSchema7 } from "json-schema";
import MetricsEditorContainer from "./MetricsEditorContainer.svelte";
import { createPlaceholder } from "./create-placeholder";
import metricsSchema from "./metrics-schema.json";
import WorkspaceEditorContainer from "@rilldata/web-common/layout/workspace/WorkspaceEditorContainer.svelte";

export let filePath: string;
export let metricsViewName: string;
Expand All @@ -36,7 +36,7 @@
$: mainError = errors?.at(0);
</script>

<MetricsEditorContainer error={mainError}>
<WorkspaceEditorContainer error={mainError}>
<Editor
bind:autoSave
bind:editor
Expand All @@ -59,4 +59,4 @@
yamlSchema(metricsJsonSchema),
]}
/>
</MetricsEditorContainer>
</WorkspaceEditorContainer>

This file was deleted.

8 changes: 4 additions & 4 deletions web-common/src/features/project/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export function useProjectTitle(instanceId: string) {
// Ignore
}

return (
return String(
projectData?.display_name ||
projectData?.title ||
projectData?.name ||
"Untitled Rill Project"
projectData?.title ||
projectData?.name ||
"Untitled Rill Project",
);
},
},
Expand Down
6 changes: 3 additions & 3 deletions web-common/src/features/workspaces/ExploreWorkspace.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import { workspaces } from "@rilldata/web-common/layout/workspace/workspace-stores";
import ViewSelector from "@rilldata/web-common/features/visual-editing/ViewSelector.svelte";
import VisualExploreEditing from "./VisualExploreEditing.svelte";
import MetricsEditorContainer from "../metrics-views/editor/MetricsEditorContainer.svelte";
import { mapParseErrorsToLines } from "../metrics-views/errors";
import ErrorPage from "@rilldata/web-common/components/ErrorPage.svelte";
import { createRuntimeServiceGetExplore } from "@rilldata/web-common/runtime-client";
import Spinner from "../entity-management/Spinner.svelte";
import DashboardWithProviders from "../dashboards/workspace/DashboardWithProviders.svelte";
import WorkspaceEditorContainer from "@rilldata/web-common/layout/workspace/WorkspaceEditorContainer.svelte";

export let fileArtifact: FileArtifact;

Expand Down Expand Up @@ -98,7 +98,7 @@
</div>
</WorkspaceHeader>

<MetricsEditorContainer
<WorkspaceEditorContainer
slot="body"
error={mainError}
showError={!!$remoteContent && selectedView === "code"}
Expand All @@ -125,7 +125,7 @@
<Spinner status={1} size="48px" />
{/if}
{/if}
</MetricsEditorContainer>
</WorkspaceEditorContainer>

<VisualExploreEditing
autoSave={selectedView === "viz" || $autoSave}
Expand Down
34 changes: 29 additions & 5 deletions web-common/src/layout/workspace/WorkspaceEditorContainer.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
<div
class="size-full flex-shrink-1 overflow-hidden border rounded-[2px]"
style:min-height="150px"
>
<slot />
<script lang="ts">
import type { LineStatus } from "@rilldata/web-common/components/editor/line-status/state";
import CancelCircle from "@rilldata/web-common/components/icons/CancelCircle.svelte";
import { LIST_SLIDE_DURATION } from "@rilldata/web-common/layout/config";
import { slide } from "svelte/transition";

export let error: LineStatus | undefined = undefined;
export let showError = true;
</script>

<div class="flex flex-col size-full gap-y-1">
<div
class="size-full border overflow-y-hidden rounded-[2px] bg-background flex flex-col items-center justify-center"
class:!border-red-500={error}
>
<slot />
</div>

{#if error && showError}
<div
role="status"
transition:slide={{ duration: LIST_SLIDE_DURATION }}
class="editor-error ui-editor-text-error ui-editor-bg-error border border-red-500 border-l-4 px-2 py-5 max-h-72 overflow-auto"
>
<div class="flex gap-x-2 items-center">
<CancelCircle />{error.message}
</div>
</div>
{/if}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import { queryClient } from "@rilldata/web-common/lib/svelte-query/globalQueryClient.js";
import { onMount } from "svelte";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
import type { PageData } from "./$types";
import { mapParseErrorsToLines } from "@rilldata/web-common/features/metrics-views/errors";

const workspaces = new Map([
[ResourceKind.Source, SourceWorkspace],
Expand All @@ -30,7 +32,7 @@
[undefined, null],
]);

export let data;
export let data: PageData;

let editor: EditorView;

Expand All @@ -44,7 +46,9 @@
resourceName,
inferredResourceKind,
path,
remoteContent,
getResource,
getAllErrors,
} = fileArtifact);

$: resourceKind = <ResourceKind | undefined>$resourceName?.kind;
Expand All @@ -60,6 +64,13 @@
? [customYAMLwithJSONandSQL]
: getExtensionsForFile(path);

$: allErrorsQuery = getAllErrors(queryClient, instanceId);
$: allErrors = $allErrorsQuery;

$: errors = mapParseErrorsToLines(allErrors, $remoteContent ?? "");

$: mainError = errors?.at(0);

onMount(() => {
expandDirectory(path);
// TODO: Focus on the code editor
Expand Down Expand Up @@ -93,7 +104,7 @@
filePath={path}
hasUnsavedChanges={$hasUnsavedChanges}
/>
<WorkspaceEditorContainer slot="body">
<WorkspaceEditorContainer slot="body" error={mainError}>
<Editor
{fileArtifact}
{extensions}
Expand Down
Loading