From 3e30dad27c019071fc84a39f86514184511c121d Mon Sep 17 00:00:00 2001 From: Brian Holmes <120223836+briangregoryholmes@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:05:19 -0500 Subject: [PATCH] fix: decode known yaml fields, display errors in generic file workspace (#6240) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: display parse errors on generic file workspaces * decode known yaml fields * test fix * actual test fix * test and lint fix * consolidate error code block Co-authored-by: Benjamin Egelund-Müller * add mock_users yaml property --------- Co-authored-by: Benjamin Egelund-Müller --- runtime/compilers/rillv1/parse_rillyaml.go | 19 ++++++++++ runtime/connections_test.go | 2 +- .../metrics-views/editor/MetricsEditor.svelte | 6 ++-- .../editor/MetricsEditorContainer.svelte | 35 ------------------- web-common/src/features/project/selectors.ts | 8 ++--- .../workspaces/ExploreWorkspace.svelte | 6 ++-- .../workspace/WorkspaceEditorContainer.svelte | 34 +++++++++++++++--- .../(workspace)/files/[...file]/+page.svelte | 15 ++++++-- 8 files changed, 72 insertions(+), 53 deletions(-) delete mode 100644 web-common/src/features/metrics-views/editor/MetricsEditorContainer.svelte diff --git a/runtime/compilers/rillv1/parse_rillyaml.go b/runtime/compilers/rillv1/parse_rillyaml.go index bbf2c984b0a..d02fdbba618 100644 --- a/runtime/compilers/rillv1/parse_rillyaml.go +++ b/runtime/compilers/rillv1/parse_rillyaml.go @@ -4,6 +4,8 @@ import ( "context" "errors" "fmt" + "io" + "strings" "github.com/rilldata/rill/runtime/pkg/env" "gopkg.in/yaml.v3" @@ -40,6 +42,7 @@ type VariableDef struct { // rillYAML is the raw YAML structure of rill.yaml type rillYAML struct { + Compiler string `yaml:"compiler"` // Title of the project DisplayName string `yaml:"display_name"` // Title of the project @@ -82,6 +85,13 @@ type rillYAML struct { Features yaml.Node `yaml:"features"` // Paths to expose over HTTP (defaults to ./public) PublicPaths []string `yaml:"public_paths"` + // A list of mock users to test against dashboard security policies + MockUsers []struct { + Email string `yaml:"email"` + Name string `yaml:"name"` + Admin bool `yaml:"admin"` + Groups []string `yaml:"groups"` + } `yaml:"mock_users"` } // parseRillYAML parses rill.yaml @@ -92,10 +102,19 @@ 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) { + 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 { diff --git a/runtime/connections_test.go b/runtime/connections_test.go index 01e704957af..23a5de4f2b9 100644 --- a/runtime/connections_test.go +++ b/runtime/connections_test.go @@ -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 `, diff --git a/web-common/src/features/metrics-views/editor/MetricsEditor.svelte b/web-common/src/features/metrics-views/editor/MetricsEditor.svelte index e3ff9b8c351..ff9361c882f 100644 --- a/web-common/src/features/metrics-views/editor/MetricsEditor.svelte +++ b/web-common/src/features/metrics-views/editor/MetricsEditor.svelte @@ -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; @@ -36,7 +36,7 @@ $: mainError = errors?.at(0); - + - + diff --git a/web-common/src/features/metrics-views/editor/MetricsEditorContainer.svelte b/web-common/src/features/metrics-views/editor/MetricsEditorContainer.svelte deleted file mode 100644 index 4d774d63510..00000000000 --- a/web-common/src/features/metrics-views/editor/MetricsEditorContainer.svelte +++ /dev/null @@ -1,35 +0,0 @@ - - - - -
-
- -
- - {#if error && showError} -
-
- {error.message} -
-
- {/if} -
diff --git a/web-common/src/features/project/selectors.ts b/web-common/src/features/project/selectors.ts index 2892ae6d506..f0fbe7dab07 100644 --- a/web-common/src/features/project/selectors.ts +++ b/web-common/src/features/project/selectors.ts @@ -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", ); }, }, diff --git a/web-common/src/features/workspaces/ExploreWorkspace.svelte b/web-common/src/features/workspaces/ExploreWorkspace.svelte index 921777f3921..8a6615a1a04 100644 --- a/web-common/src/features/workspaces/ExploreWorkspace.svelte +++ b/web-common/src/features/workspaces/ExploreWorkspace.svelte @@ -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; @@ -98,7 +98,7 @@ - {/if} {/if} - + - + + +
+
+ +
+ + {#if error && showError} +
+
+ {error.message} +
+
+ {/if}
diff --git a/web-local/src/routes/(application)/(workspace)/files/[...file]/+page.svelte b/web-local/src/routes/(application)/(workspace)/files/[...file]/+page.svelte index 76d4817a42c..d92d414af35 100644 --- a/web-local/src/routes/(application)/(workspace)/files/[...file]/+page.svelte +++ b/web-local/src/routes/(application)/(workspace)/files/[...file]/+page.svelte @@ -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], @@ -30,7 +32,7 @@ [undefined, null], ]); - export let data; + export let data: PageData; let editor: EditorView; @@ -44,7 +46,9 @@ resourceName, inferredResourceKind, path, + remoteContent, getResource, + getAllErrors, } = fileArtifact); $: resourceKind = $resourceName?.kind; @@ -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 @@ -93,7 +104,7 @@ filePath={path} hasUnsavedChanges={$hasUnsavedChanges} /> - +