Skip to content

Commit

Permalink
Merge pull request writer#685 from writer/feat-support-icon-alias
Browse files Browse the repository at this point in the history
feat: Support icon alias
  • Loading branch information
ramedina86 authored Dec 9, 2024
2 parents 462dcab + 428425d commit f663ac2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "writer"
version = "0.8.2"
version = "0.8.3rc1"
description = "An open-source, Python framework for building feature-rich apps that are fully integrated with the Writer platform."
authors = ["Writer, Inc."]
readme = "README.md"
Expand Down
52 changes: 37 additions & 15 deletions src/ui/src/components/workflows/abstract/WorkflowsNode.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<template>
<div class="WorkflowsNode">
<div class="title">
<img
:src="`./../../../../components/${component.type}.svg`"
@error="
(ev) =>
!isImageFallback ? handleImageError(ev) : undefined
"
/>
<img :src="imagePath" />
<WorkflowsNodeNamer
:component-id="componentId"
class="nodeNamer"
Expand Down Expand Up @@ -75,7 +69,7 @@ export default {
};
</script>
<script setup lang="ts">
import { computed, inject, ref, watch } from "vue";
import { computed, inject, onMounted, ref, watch } from "vue";
import injectionKeys from "@/injectionKeys";
import { FieldType, WriterComponentDefinition } from "@/writerTypes";
import WorkflowsNodeNamer from "../base/WorkflowsNodeNamer.vue";
Expand All @@ -85,7 +79,7 @@ const wf = inject(injectionKeys.core);
const wfbm = inject(injectionKeys.builderManager);
const componentId = inject(injectionKeys.componentId);
const fields = inject(injectionKeys.evaluatedFields);
const isImageFallback = ref(false);
const imagePath = ref<string>(null);
const component = computed(() => {
const component = wf.getComponentById(componentId);
Expand All @@ -110,12 +104,6 @@ const staticOuts = computed<WriterComponentDefinition["outs"]>(() => {
return processedOuts;
});
function handleImageError(ev: Event) {
const imageEl = ev.target as HTMLImageElement;
imageEl.src = `./../../../../components/workflows_category_${def.value.category}.svg`;
isImageFallback.value = true;
}
function getDynamicKeysFromField(fieldKey: string) {
const fieldType = def.value.fields[fieldKey].type;
const isToolsField = fieldType == FieldType.Tools;
Expand Down Expand Up @@ -154,6 +142,40 @@ function handleOutMousedown(ev: DragEvent, outId: string) {
emit("outMousedown", outId);
}
async function checkIfUrlExists(url: string) {
try {
const response = await fetch(url, { method: "HEAD" });
return response.ok;
} catch {
return false;
}
}
async function getBestAvailableImagePath() {
const paths = [
`./../../../../components/${component.value.type}.svg`,
`./../../../../components/workflows_category_${def.value.category}.svg`,
];
if (wf.featureFlags.value.includes("custom_block_icons")) {
paths.unshift(
`./../../../../static/components/${component.value.id}.svg`,
);
}
for (let i = 0; i < paths.length; i++) {
const path = paths[i];
if (await checkIfUrlExists(path)) {
return path;
}
}
return "";
}
onMounted(async () => {
imagePath.value = await getBestAvailableImagePath();
});
watch(isEngaged, () => {
emit("engaged");
});
Expand Down

0 comments on commit f663ac2

Please sign in to comment.