Skip to content
Merged
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
@@ -1,4 +1,5 @@
<script lang="ts">
import { page } from "$app/stores";
import { Button } from "@rilldata/web-common/components/button";
import * as Dialog from "@rilldata/web-common/components/dialog";
import Search from "@rilldata/web-common/components/search/Search.svelte";
Expand All @@ -17,6 +18,7 @@
import { eventBus } from "@rilldata/web-common/lib/event-bus/event-bus";
import { m } from "@rilldata/web-common/lib/i18n/gen/messages";
import { CUSTOM_VIZ_FOLDER } from "@rilldata/web-common/features/custom-viz/params";
import { removeLeadingSlash } from "@rilldata/web-common/features/entity-management/entity-mappers.ts";
import { useRuntimeClient } from "@rilldata/web-common/runtime-client/v2";
import ExampleCard from "./ExampleCard.svelte";
import {
Expand Down Expand Up @@ -49,6 +51,15 @@
.finally(() => (loading = false));
}

$: currentFile = $page.params.file;
$: currentDirectory = currentFile
? currentFile.split("/").slice(0, -1).join("/")
: "";
$: componentFolder =
currentDirectory !== ""
? removeLeadingSlash(currentDirectory)
: CUSTOM_VIZ_FOLDER;

$: componentsQuery = useFilteredResources(client, ResourceKind.Component);
$: existingNames = ($componentsQuery?.data ?? [])
.map((res) => res.meta?.name?.name)
Expand Down Expand Up @@ -111,7 +122,7 @@
client,
ResourceKind.Component,
undefined,
CUSTOM_VIZ_FOLDER,
componentFolder,
);
}

Expand Down
11 changes: 11 additions & 0 deletions web-common/src/features/entity-management/add/new-files.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, expect, it } from "vitest";
import { ResourceKind } from "../resource-selectors.ts";
import { getPathForNewResourceFile } from "./new-files.ts";

describe("getPathForNewResourceFile", () => {
it("uses the current directory when creating a component", () => {
expect(
getPathForNewResourceFile(ResourceKind.Component, undefined, "Something"),
).toMatch(/^Something\/component/);
});
});
Loading