Skip to content

Commit

Permalink
fix(ui): handle subpath. WF-141
Browse files Browse the repository at this point in the history
  • Loading branch information
madeindjs committed Dec 23, 2024
1 parent 0b7778b commit 3aea564
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/ui/src/builder/sidebar/BuilderSidebarToolkit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
<SharedImgWithFallback
:alt="`(Icon for ${tool.name})`"
draggable="false"
:urls="[
`/components/${tool.type}.svg`,
`/components/category_${tool.category}.svg`,
]"
:urls="getToolIcons(tool)"
/>
<div class="name">{{ tool.name }}</div>
</div>
Expand All @@ -49,6 +46,7 @@ import injectionKeys from "@/injectionKeys";
import { useDragDropComponent } from "../useDragDropComponent";
import { Component } from "@/writerTypes";
import SharedImgWithFallback from "@/components/shared/SharedImgWithFallback.vue";
import { convertAbsolutePathtoFullURL } from "@/utils/url";
const wf = inject(injectionKeys.core);
const wfbm = inject(injectionKeys.builderManager);
Expand Down Expand Up @@ -117,6 +115,13 @@ function handleDragEnd(ev: DragEvent) {
removeInsertionCandidacy(ev);
}
function getToolIcons(tool: ReturnType<typeof getRelevantToolsInCategory>[0]) {
return [
`/components/${tool.type}.svg`,
`/components/category_${tool.category}.svg`,
].map((p) => convertAbsolutePathtoFullURL(p));
}
watch(activeToolkit, () => {
query.value = "";
});
Expand Down
3 changes: 2 additions & 1 deletion src/ui/src/components/workflows/abstract/WorkflowsNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import injectionKeys from "@/injectionKeys";
import { FieldType, WriterComponentDefinition } from "@/writerTypes";
import WorkflowsNodeNamer from "../base/WorkflowsNodeNamer.vue";
import SharedImgWithFallback from "@/components/shared/SharedImgWithFallback.vue";
import { convertAbsolutePathtoFullURL } from "@/utils/url";
const emit = defineEmits(["outMousedown", "engaged"]);
const wf = inject(injectionKeys.core);
Expand Down Expand Up @@ -152,7 +153,7 @@ const possibleImageUrls = computed(() => {
paths.unshift(`/static/components/${component.value.id}.svg`);
}
return paths;
return paths.map((p) => convertAbsolutePathtoFullURL(p));
});
watch(isEngaged, () => {
Expand Down
22 changes: 22 additions & 0 deletions src/ui/src/utils/url.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import { convertAbsolutePathtoFullURL } from "./url";

describe(convertAbsolutePathtoFullURL.name, () => {
it("should convert the URL", () => {
expect(
convertAbsolutePathtoFullURL(
"/assets/image.png",
"http://localhost:3000/",
),
).toBe("http://localhost:3000/assets/image.png");
});

it("should convert the URL with a current path", () => {
expect(
convertAbsolutePathtoFullURL(
"/assets/image.png",
"http://localhost:3000/hello/?foo=bar",
),
).toBe("http://localhost:3000/hello/assets/image.png");
});
});
14 changes: 14 additions & 0 deletions src/ui/src/utils/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Convert absoule URL to full URLs in case the application is hosted on a subpath.
*
* ```js
* convertAbsolutePathtoFullURL("/assets/image.png", "http://localhost:3000/hello/?foo=bar")
* // => 'http://localhost:3000/hello/assets/image.png'
* ```
*/
export function convertAbsolutePathtoFullURL(
path: string,
base = window.location.toString(),
) {
return new URL(`.${path}`, base).toString();
}

0 comments on commit 3aea564

Please sign in to comment.