mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
refactor(editor): Migrate TemplatesWorkflowView.vue
to composition API (#10918)
This commit is contained in:
parent
f9515b9afa
commit
f96977e6e4
|
@ -3,7 +3,7 @@ import { nextTick, onBeforeMount, onMounted, ref, watch } from 'vue';
|
||||||
import type { ITemplatesCollection } from '@/Interface';
|
import type { ITemplatesCollection } from '@/Interface';
|
||||||
import Card from '@/components/CollectionWorkflowCard.vue';
|
import Card from '@/components/CollectionWorkflowCard.vue';
|
||||||
import TemplatesInfoCard from '@/components/TemplatesInfoCard.vue';
|
import TemplatesInfoCard from '@/components/TemplatesInfoCard.vue';
|
||||||
import type { VueAgile } from 'vue-agile';
|
import { VueAgile } from 'vue-agile';
|
||||||
|
|
||||||
type SliderRef = InstanceType<typeof VueAgile>;
|
type SliderRef = InstanceType<typeof VueAgile>;
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ const carouselScrollPosition = ref(0);
|
||||||
const cardWidth = ref(parseInt(props.cardsWidth, 10));
|
const cardWidth = ref(parseInt(props.cardsWidth, 10));
|
||||||
const scrollEnd = ref(false);
|
const scrollEnd = ref(false);
|
||||||
const listElement = ref<null | Element>(null);
|
const listElement = ref<null | Element>(null);
|
||||||
const sliderRef = ref<null | SliderRef>(null);
|
const sliderRef = ref<SliderRef>(null);
|
||||||
|
|
||||||
const updateCarouselScroll = () => {
|
const updateCarouselScroll = () => {
|
||||||
if (listElement.value) {
|
if (listElement.value) {
|
||||||
|
@ -80,9 +80,11 @@ watch(
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await nextTick();
|
await nextTick();
|
||||||
|
|
||||||
if (!sliderRef.value) {
|
if (!sliderRef.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
listElement.value = sliderRef.value.$el.querySelector('.agile__list');
|
listElement.value = sliderRef.value.$el.querySelector('.agile__list');
|
||||||
if (listElement.value) {
|
if (listElement.value) {
|
||||||
listElement.value.addEventListener('scroll', updateCarouselScroll);
|
listElement.value.addEventListener('scroll', updateCarouselScroll);
|
||||||
|
@ -99,7 +101,7 @@ onBeforeMount(() => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-show="loading || collections.length" :class="$style.container">
|
<div v-show="loading || collections.length" :class="$style.container">
|
||||||
<agile
|
<VueAgile
|
||||||
ref="sliderRef"
|
ref="sliderRef"
|
||||||
:dots="false"
|
:dots="false"
|
||||||
:nav-buttons="false"
|
:nav-buttons="false"
|
||||||
|
@ -117,7 +119,7 @@ onBeforeMount(() => {
|
||||||
:width="cardsWidth"
|
:width="cardsWidth"
|
||||||
@click="(e) => onCardClick(e, collection.id)"
|
@click="(e) => onCardClick(e, collection.id)"
|
||||||
/>
|
/>
|
||||||
</agile>
|
</VueAgile>
|
||||||
<button
|
<button
|
||||||
v-show="showNavigation && carouselScrollPosition > 0"
|
v-show="showNavigation && carouselScrollPosition > 0"
|
||||||
:class="{ [$style.leftButton]: true }"
|
:class="{ [$style.leftButton]: true }"
|
||||||
|
|
|
@ -1,94 +1,55 @@
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { computed, onMounted, ref, watch } from 'vue';
|
||||||
import { mapStores } from 'pinia';
|
|
||||||
|
|
||||||
import TemplateDetails from '@/components/TemplateDetails.vue';
|
|
||||||
import TemplatesView from './TemplatesView.vue';
|
|
||||||
import WorkflowPreview from '@/components/WorkflowPreview.vue';
|
|
||||||
|
|
||||||
import type { ITemplatesWorkflowFull } from '@/Interface';
|
|
||||||
import { setPageTitle } from '@/utils/htmlUtils';
|
import { setPageTitle } from '@/utils/htmlUtils';
|
||||||
import { useTemplatesStore } from '@/stores/templates.store';
|
import { useTemplatesStore } from '@/stores/templates.store';
|
||||||
import { usePostHog } from '@/stores/posthog.store';
|
import { usePostHog } from '@/stores/posthog.store';
|
||||||
import { useTemplateWorkflow } from '@/utils/templates/templateActions';
|
import { useTemplateWorkflow } from '@/utils/templates/templateActions';
|
||||||
import { useExternalHooks } from '@/composables/useExternalHooks';
|
import { useExternalHooks } from '@/composables/useExternalHooks';
|
||||||
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
import { useTelemetry } from '@/composables/useTelemetry';
|
||||||
|
import { useI18n } from '@/composables/useI18n';
|
||||||
|
import TemplatesView from './TemplatesView.vue';
|
||||||
|
|
||||||
export default defineComponent({
|
|
||||||
name: 'TemplatesWorkflowView',
|
|
||||||
components: {
|
|
||||||
TemplateDetails,
|
|
||||||
TemplatesView,
|
|
||||||
WorkflowPreview,
|
|
||||||
},
|
|
||||||
setup() {
|
|
||||||
const externalHooks = useExternalHooks();
|
const externalHooks = useExternalHooks();
|
||||||
|
const templatesStore = useTemplatesStore();
|
||||||
|
const posthogStore = usePostHog();
|
||||||
|
const nodeTypesStore = useNodeTypesStore();
|
||||||
|
|
||||||
return {
|
const route = useRoute();
|
||||||
externalHooks,
|
const router = useRouter();
|
||||||
};
|
const telemetry = useTelemetry();
|
||||||
},
|
const i18n = useI18n();
|
||||||
computed: {
|
|
||||||
...mapStores(useTemplatesStore, usePostHog),
|
|
||||||
template(): ITemplatesWorkflowFull | null {
|
|
||||||
return this.templatesStore.getFullTemplateById(this.templateId);
|
|
||||||
},
|
|
||||||
templateId() {
|
|
||||||
return Array.isArray(this.$route.params.id)
|
|
||||||
? this.$route.params.id[0]
|
|
||||||
: this.$route.params.id;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
loading: true,
|
|
||||||
showPreview: true,
|
|
||||||
notFoundError: false,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
template(template: ITemplatesWorkflowFull) {
|
|
||||||
if (template) {
|
|
||||||
setPageTitle(`n8n - Template template: ${template.name}`);
|
|
||||||
} else {
|
|
||||||
setPageTitle('n8n - Templates');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
async mounted() {
|
|
||||||
this.scrollToTop();
|
|
||||||
|
|
||||||
if (this.template && this.template.full) {
|
const loading = ref(true);
|
||||||
this.loading = false;
|
const showPreview = ref(true);
|
||||||
return;
|
const notFoundError = ref(false);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
const templateId = computed(() =>
|
||||||
await this.templatesStore.fetchTemplateById(this.templateId);
|
Array.isArray(route.params.id) ? route.params.id[0] : route.params.id,
|
||||||
} catch (e) {
|
);
|
||||||
this.notFoundError = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.loading = false;
|
const template = computed(() => templatesStore.getFullTemplateById(templateId.value));
|
||||||
},
|
|
||||||
methods: {
|
const openTemplateSetup = async (id: string, e: PointerEvent) => {
|
||||||
async openTemplateSetup(id: string, e: PointerEvent) {
|
|
||||||
await useTemplateWorkflow({
|
await useTemplateWorkflow({
|
||||||
posthogStore: this.posthogStore,
|
posthogStore,
|
||||||
router: this.$router,
|
router,
|
||||||
templateId: id,
|
templateId: id,
|
||||||
inNewBrowserTab: e.metaKey || e.ctrlKey,
|
inNewBrowserTab: e.metaKey || e.ctrlKey,
|
||||||
externalHooks: this.externalHooks,
|
externalHooks,
|
||||||
nodeTypesStore: useNodeTypesStore(),
|
nodeTypesStore,
|
||||||
telemetry: this.$telemetry,
|
telemetry,
|
||||||
templatesStore: useTemplatesStore(),
|
templatesStore,
|
||||||
source: 'template_preview',
|
source: 'template_preview',
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
onHidePreview() {
|
|
||||||
this.showPreview = false;
|
const onHidePreview = () => {
|
||||||
},
|
showPreview.value = false;
|
||||||
scrollToTop() {
|
};
|
||||||
|
|
||||||
|
const scrollToTop = () => {
|
||||||
const contentArea = document.getElementById('content');
|
const contentArea = document.getElementById('content');
|
||||||
|
|
||||||
if (contentArea) {
|
if (contentArea) {
|
||||||
|
@ -96,8 +57,34 @@ export default defineComponent({
|
||||||
top: 0,
|
top: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => template.value,
|
||||||
|
(newTemplate) => {
|
||||||
|
if (newTemplate) {
|
||||||
|
setPageTitle(`n8n - Template template: ${newTemplate.name}`);
|
||||||
|
} else {
|
||||||
|
setPageTitle('n8n - Templates');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
);
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
scrollToTop();
|
||||||
|
|
||||||
|
if (template.value?.full) {
|
||||||
|
loading.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await templatesStore.fetchTemplateById(templateId.value);
|
||||||
|
} catch (e) {
|
||||||
|
notFoundError.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = false;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -110,7 +97,7 @@ export default defineComponent({
|
||||||
template.name
|
template.name
|
||||||
}}</n8n-heading>
|
}}</n8n-heading>
|
||||||
<n8n-text v-if="template && template.name" color="text-base" size="small">
|
<n8n-text v-if="template && template.name" color="text-base" size="small">
|
||||||
{{ $locale.baseText('generic.workflow') }}
|
{{ i18n.baseText('generic.workflow') }}
|
||||||
</n8n-text>
|
</n8n-text>
|
||||||
<n8n-loading :loading="!template || !template.name" :rows="2" variant="h1" />
|
<n8n-loading :loading="!template || !template.name" :rows="2" variant="h1" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -118,7 +105,7 @@ export default defineComponent({
|
||||||
<n8n-button
|
<n8n-button
|
||||||
v-if="template"
|
v-if="template"
|
||||||
data-test-id="use-template-button"
|
data-test-id="use-template-button"
|
||||||
:label="$locale.baseText('template.buttons.useThisWorkflowButton')"
|
:label="i18n.baseText('template.buttons.useThisWorkflowButton')"
|
||||||
size="large"
|
size="large"
|
||||||
@click="openTemplateSetup(templateId, $event)"
|
@click="openTemplateSetup(templateId, $event)"
|
||||||
/>
|
/>
|
||||||
|
@ -126,7 +113,7 @@ export default defineComponent({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else :class="$style.notFound">
|
<div v-else :class="$style.notFound">
|
||||||
<n8n-text color="text-base">{{ $locale.baseText('templates.workflowsNotFound') }}</n8n-text>
|
<n8n-text color="text-base">{{ i18n.baseText('templates.workflowsNotFound') }}</n8n-text>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="!notFoundError" #content>
|
<template v-if="!notFoundError" #content>
|
||||||
|
@ -148,7 +135,7 @@ export default defineComponent({
|
||||||
</div>
|
</div>
|
||||||
<div :class="$style.details">
|
<div :class="$style.details">
|
||||||
<TemplateDetails
|
<TemplateDetails
|
||||||
:block-title="$locale.baseText('template.details.appsInTheWorkflow')"
|
:block-title="i18n.baseText('template.details.appsInTheWorkflow')"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
:template="template"
|
:template="template"
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue