Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions web-common/src/features/entity-management/entity-mappers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ describe("entity-mappers", () => {
expect(getNameFromFile("/path/to/data/adbids.csv.tgz")).toBe("adbids");
});

it("keeps dots in YAML resource names", () => {
expect(getNameFromFile("/dashboards/dashboard.canvas.yaml")).toBe(
"dashboard.canvas",
);
});

it("keeps dots in YML resource names", () => {
expect(getNameFromFile("/dashboards/dashboard.canvas.yml")).toBe(
"dashboard.canvas",
);
});

it("keeps dots in SQL resource names", () => {
expect(getNameFromFile("/models/orders.latest.sql")).toBe(
"orders.latest",
);
});

it("no folder", () => {
expect(getNameFromFile("adbids.csv")).toBe("adbids");
});
Expand Down
15 changes: 13 additions & 2 deletions web-common/src/features/entity-management/entity-mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,20 @@ export function getFileAPIPathFromNameAndType(
}

export function getNameFromFile(fileName: string): string {
// TODO: do we need a library here?
const splits = fileName.split("/");
const extensionSplits = splits[splits.length - 1]?.split(".");
const basename = splits[splits.length - 1] ?? "";

// Rill resource names are inferred by removing only the final resource file
// extension, so dotted names like `dashboard.canvas.yaml` stay intact.
for (const extension of [".yaml", ".yml", ".sql"]) {
if (basename.endsWith(extension)) {
return basename.slice(0, -extension.length);
}
}
Comment on lines +71 to +77

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in bbaa274. I centralized the resource extension list in file-path-utils and made extractFileExtension resource-aware, so dotted resource files return .yaml/.yml/.sql while non-resource data files keep the existing compound-extension behavior. Added regression coverage for dotted resource extension extraction and kind inference.


// Non-resource data files keep the legacy behavior of removing compound
// extensions, e.g. `adbids.csv.tgz` -> `adbids`.
const extensionSplits = basename.split(".");
return extensionSplits[0];
}

Expand Down
Loading