2023-05-31 06:01:57 -07:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import Modal from './Modal.vue';
|
2023-06-20 10:13:18 -07:00
|
|
|
import { CREDENTIAL_EDIT_MODAL_KEY, SOURCE_CONTROL_PUSH_MODAL_KEY } from '@/constants';
|
2023-05-31 06:01:57 -07:00
|
|
|
import { computed, onMounted, ref } from 'vue';
|
|
|
|
import type { PropType } from 'vue';
|
|
|
|
import type { EventBus } from 'n8n-design-system/utils';
|
2023-06-20 10:13:18 -07:00
|
|
|
import type { SourceControlAggregatedFile } from '@/Interface';
|
2023-11-28 03:15:08 -08:00
|
|
|
import { useI18n } from '@/composables/useI18n';
|
|
|
|
import { useLoadingService } from '@/composables/useLoadingService';
|
|
|
|
import { useToast } from '@/composables/useToast';
|
2023-06-20 10:13:18 -07:00
|
|
|
import { useSourceControlStore } from '@/stores/sourceControl.store';
|
2023-11-28 03:15:08 -08:00
|
|
|
import { useUIStore } from '@/stores/ui.store';
|
2023-07-28 00:51:07 -07:00
|
|
|
import { useRoute } from 'vue-router';
|
2023-06-28 04:59:07 -07:00
|
|
|
import dateformat from 'dateformat';
|
2023-05-31 06:01:57 -07:00
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
data: {
|
2023-06-20 10:13:18 -07:00
|
|
|
type: Object as PropType<{ eventBus: EventBus; status: SourceControlAggregatedFile[] }>,
|
2023-05-31 06:01:57 -07:00
|
|
|
default: () => ({}),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-06-28 04:59:07 -07:00
|
|
|
const defaultStagedFileTypes = ['tags', 'variables', 'credential'];
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
const loadingService = useLoadingService();
|
|
|
|
const uiStore = useUIStore();
|
|
|
|
const toast = useToast();
|
2023-07-28 00:51:07 -07:00
|
|
|
const i18n = useI18n();
|
2023-06-20 10:13:18 -07:00
|
|
|
const sourceControlStore = useSourceControlStore();
|
2023-05-31 06:01:57 -07:00
|
|
|
const route = useRoute();
|
|
|
|
|
|
|
|
const staged = ref<Record<string, boolean>>({});
|
2023-07-26 00:25:01 -07:00
|
|
|
const files = ref<SourceControlAggregatedFile[]>(
|
|
|
|
props.data.status.filter((file, index, self) => {
|
|
|
|
// do not show remote workflows that are not yet created locally during push
|
|
|
|
if (file.location === 'remote' && file.type === 'workflow' && file.status === 'created') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return self.findIndex((f) => f.id === file.id) === index;
|
|
|
|
}) || [],
|
|
|
|
);
|
2023-05-31 06:01:57 -07:00
|
|
|
|
|
|
|
const commitMessage = ref('');
|
|
|
|
const loading = ref(true);
|
|
|
|
const context = ref<'workflow' | 'workflows' | 'credentials' | string>('');
|
|
|
|
|
2023-06-28 04:59:07 -07:00
|
|
|
const statusToBadgeThemeMap = {
|
|
|
|
created: 'success',
|
|
|
|
deleted: 'danger',
|
|
|
|
modified: 'warning',
|
|
|
|
renamed: 'warning',
|
|
|
|
};
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
const isSubmitDisabled = computed(() => {
|
|
|
|
return !commitMessage.value || Object.values(staged.value).every((value) => !value);
|
|
|
|
});
|
|
|
|
|
2023-06-28 04:59:07 -07:00
|
|
|
const workflowId = computed(() => {
|
|
|
|
if (context.value === 'workflow') {
|
|
|
|
return route.params.name as string;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
});
|
|
|
|
|
|
|
|
const sortedFiles = computed(() => {
|
|
|
|
const statusPriority = {
|
2023-07-26 00:25:01 -07:00
|
|
|
modified: 1,
|
|
|
|
renamed: 2,
|
|
|
|
created: 3,
|
|
|
|
deleted: 4,
|
2023-06-28 04:59:07 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return [...files.value].sort((a, b) => {
|
|
|
|
if (context.value === 'workflow') {
|
|
|
|
if (a.id === workflowId.value) {
|
|
|
|
return -1;
|
|
|
|
} else if (b.id === workflowId.value) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (statusPriority[a.status] < statusPriority[b.status]) {
|
|
|
|
return -1;
|
|
|
|
} else if (statusPriority[a.status] > statusPriority[b.status]) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : 0;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const selectAll = computed(() => {
|
|
|
|
return files.value.every((file) => staged.value[file.file]);
|
|
|
|
});
|
|
|
|
|
|
|
|
const workflowFiles = computed(() => {
|
|
|
|
return files.value.filter((file) => file.type === 'workflow');
|
|
|
|
});
|
|
|
|
|
|
|
|
const stagedWorkflowFiles = computed(() => {
|
|
|
|
return workflowFiles.value.filter((workflow) => staged.value[workflow.file]);
|
|
|
|
});
|
|
|
|
|
|
|
|
const selectAllIndeterminate = computed(() => {
|
|
|
|
return (
|
|
|
|
stagedWorkflowFiles.value.length > 0 &&
|
|
|
|
stagedWorkflowFiles.value.length < workflowFiles.value.length
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
onMounted(async () => {
|
|
|
|
context.value = getContext();
|
|
|
|
try {
|
|
|
|
staged.value = getStagedFilesByContext(files.value);
|
|
|
|
} catch (error) {
|
2023-07-28 00:51:07 -07:00
|
|
|
toast.showError(error, i18n.baseText('error'));
|
2023-05-31 06:01:57 -07:00
|
|
|
} finally {
|
|
|
|
loading.value = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-06-28 04:59:07 -07:00
|
|
|
function onToggleSelectAll() {
|
|
|
|
if (selectAll.value) {
|
|
|
|
files.value.forEach((file) => {
|
|
|
|
if (!defaultStagedFileTypes.includes(file.type)) {
|
|
|
|
staged.value[file.file] = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
files.value.forEach((file) => {
|
|
|
|
if (!defaultStagedFileTypes.includes(file.type)) {
|
|
|
|
staged.value[file.file] = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
function getContext() {
|
|
|
|
if (route.fullPath.startsWith('/workflows')) {
|
|
|
|
return 'workflows';
|
|
|
|
} else if (
|
|
|
|
route.fullPath.startsWith('/credentials') ||
|
|
|
|
uiStore.modals[CREDENTIAL_EDIT_MODAL_KEY].open
|
|
|
|
) {
|
|
|
|
return 'credentials';
|
|
|
|
} else if (route.fullPath.startsWith('/workflow/')) {
|
|
|
|
return 'workflow';
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2023-06-20 10:13:18 -07:00
|
|
|
function getStagedFilesByContext(files: SourceControlAggregatedFile[]): Record<string, boolean> {
|
2023-06-28 04:59:07 -07:00
|
|
|
const stagedFiles = files.reduce((acc, file) => {
|
|
|
|
acc[file.file] = false;
|
2023-05-31 06:01:57 -07:00
|
|
|
return acc;
|
|
|
|
}, {});
|
2023-06-28 04:59:07 -07:00
|
|
|
|
|
|
|
files.forEach((file) => {
|
|
|
|
if (defaultStagedFileTypes.includes(file.type)) {
|
|
|
|
stagedFiles[file.file] = true;
|
|
|
|
}
|
|
|
|
|
2023-07-26 00:25:01 -07:00
|
|
|
if (context.value === 'workflow') {
|
|
|
|
if (file.type === 'workflow' && file.id === workflowId.value) {
|
|
|
|
stagedFiles[file.file] = true;
|
|
|
|
}
|
2023-06-28 04:59:07 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return stagedFiles;
|
2023-05-31 06:01:57 -07:00
|
|
|
}
|
|
|
|
|
2023-06-20 10:13:18 -07:00
|
|
|
function setStagedStatus(file: SourceControlAggregatedFile, status: boolean) {
|
2023-05-31 06:01:57 -07:00
|
|
|
staged.value = {
|
|
|
|
...staged.value,
|
|
|
|
[file.file]: status,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function close() {
|
2023-06-20 10:13:18 -07:00
|
|
|
uiStore.closeModal(SOURCE_CONTROL_PUSH_MODAL_KEY);
|
2023-05-31 06:01:57 -07:00
|
|
|
}
|
|
|
|
|
2023-06-28 04:59:07 -07:00
|
|
|
function renderUpdatedAt(file: SourceControlAggregatedFile) {
|
|
|
|
const currentYear = new Date().getFullYear();
|
|
|
|
|
2023-07-28 00:51:07 -07:00
|
|
|
return i18n.baseText('settings.sourceControl.lastUpdated', {
|
2023-06-28 04:59:07 -07:00
|
|
|
interpolate: {
|
|
|
|
date: dateformat(
|
|
|
|
file.updatedAt,
|
|
|
|
`d mmm${file.updatedAt.startsWith(currentYear) ? '' : ', yyyy'}`,
|
|
|
|
),
|
|
|
|
time: dateformat(file.updatedAt, 'HH:MM'),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-26 00:25:01 -07:00
|
|
|
async function onCommitKeyDownEnter() {
|
|
|
|
if (!isSubmitDisabled.value) {
|
|
|
|
await commitAndPush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
async function commitAndPush() {
|
2023-07-26 00:25:01 -07:00
|
|
|
const fileNames = files.value.filter((file) => staged.value[file.file]);
|
2023-05-31 06:01:57 -07:00
|
|
|
|
2023-07-28 00:51:07 -07:00
|
|
|
loadingService.startLoading(i18n.baseText('settings.sourceControl.loading.push'));
|
2023-05-31 06:01:57 -07:00
|
|
|
close();
|
|
|
|
|
|
|
|
try {
|
2023-06-20 10:13:18 -07:00
|
|
|
await sourceControlStore.pushWorkfolder({
|
2023-07-26 00:25:01 -07:00
|
|
|
force: true,
|
2023-05-31 06:01:57 -07:00
|
|
|
commitMessage: commitMessage.value,
|
|
|
|
fileNames,
|
|
|
|
});
|
|
|
|
|
|
|
|
toast.showToast({
|
2023-07-28 00:51:07 -07:00
|
|
|
title: i18n.baseText('settings.sourceControl.modals.push.success.title'),
|
|
|
|
message: i18n.baseText('settings.sourceControl.modals.push.success.description'),
|
2023-05-31 06:01:57 -07:00
|
|
|
type: 'success',
|
|
|
|
});
|
|
|
|
} catch (error) {
|
2023-07-28 00:51:07 -07:00
|
|
|
toast.showError(error, i18n.baseText('error'));
|
2023-05-31 06:01:57 -07:00
|
|
|
} finally {
|
|
|
|
loadingService.stopLoading();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<Modal
|
|
|
|
width="812px"
|
2023-07-28 00:51:07 -07:00
|
|
|
:title="i18n.baseText('settings.sourceControl.modals.push.title')"
|
2023-12-28 00:49:58 -08:00
|
|
|
:event-bus="data.eventBus"
|
2023-06-20 10:13:18 -07:00
|
|
|
:name="SOURCE_CONTROL_PUSH_MODAL_KEY"
|
2024-03-14 02:26:04 -07:00
|
|
|
max-height="80%"
|
2023-05-31 06:01:57 -07:00
|
|
|
>
|
|
|
|
<template #content>
|
|
|
|
<div :class="$style.container">
|
2023-07-26 00:25:01 -07:00
|
|
|
<div v-if="files.length > 0">
|
|
|
|
<div v-if="workflowFiles.length > 0">
|
|
|
|
<n8n-text>
|
2023-07-28 00:51:07 -07:00
|
|
|
{{ i18n.baseText('settings.sourceControl.modals.push.description') }}
|
|
|
|
<n8n-link :to="i18n.baseText('settings.sourceControl.docs.using.pushPull.url')">
|
|
|
|
{{ i18n.baseText('settings.sourceControl.modals.push.description.learnMore') }}
|
2023-07-26 00:25:01 -07:00
|
|
|
</n8n-link>
|
|
|
|
</n8n-text>
|
|
|
|
|
|
|
|
<div class="mt-l mb-2xs">
|
2023-05-31 06:01:57 -07:00
|
|
|
<n8n-checkbox
|
2023-07-26 00:25:01 -07:00
|
|
|
:indeterminate="selectAllIndeterminate"
|
2023-12-28 00:49:58 -08:00
|
|
|
:model-value="selectAll"
|
2024-03-26 06:22:57 -07:00
|
|
|
@update:model-value="onToggleSelectAll"
|
2023-07-26 00:25:01 -07:00
|
|
|
>
|
|
|
|
<n8n-text bold tag="strong">
|
2023-07-28 00:51:07 -07:00
|
|
|
{{ i18n.baseText('settings.sourceControl.modals.push.workflowsToCommit') }}
|
2023-06-28 04:59:07 -07:00
|
|
|
</n8n-text>
|
2023-12-28 00:49:58 -08:00
|
|
|
<n8n-text v-show="workflowFiles.length > 0" tag="strong">
|
2023-07-26 00:25:01 -07:00
|
|
|
({{ stagedWorkflowFiles.length }}/{{ workflowFiles.length }})
|
2023-06-28 04:59:07 -07:00
|
|
|
</n8n-text>
|
2023-07-26 00:25:01 -07:00
|
|
|
</n8n-checkbox>
|
|
|
|
</div>
|
|
|
|
<n8n-card
|
|
|
|
v-for="file in sortedFiles"
|
|
|
|
v-show="!defaultStagedFileTypes.includes(file.type)"
|
|
|
|
:key="file.file"
|
|
|
|
:class="$style.listItem"
|
|
|
|
@click="setStagedStatus(file, !staged[file.file])"
|
|
|
|
>
|
|
|
|
<div :class="$style.listItemBody">
|
|
|
|
<n8n-checkbox
|
2023-12-28 00:49:58 -08:00
|
|
|
:model-value="staged[file.file]"
|
2023-07-26 00:25:01 -07:00
|
|
|
:class="$style.listItemCheckbox"
|
2024-03-26 06:22:57 -07:00
|
|
|
@update:model-value="setStagedStatus(file, !staged[file.file])"
|
2023-07-26 00:25:01 -07:00
|
|
|
/>
|
|
|
|
<div>
|
|
|
|
<n8n-text v-if="file.status === 'deleted'" color="text-light">
|
|
|
|
<span v-if="file.type === 'workflow'"> Deleted Workflow: </span>
|
|
|
|
<span v-if="file.type === 'credential'"> Deleted Credential: </span>
|
|
|
|
<strong>{{ file.name || file.id }}</strong>
|
2023-06-28 04:59:07 -07:00
|
|
|
</n8n-text>
|
2023-12-28 00:49:58 -08:00
|
|
|
<n8n-text v-else bold> {{ file.name }} </n8n-text>
|
2023-07-26 00:25:01 -07:00
|
|
|
<div v-if="file.updatedAt">
|
|
|
|
<n8n-text color="text-light" size="small">
|
|
|
|
{{ renderUpdatedAt(file) }}
|
|
|
|
</n8n-text>
|
|
|
|
</div>
|
2023-06-28 04:59:07 -07:00
|
|
|
</div>
|
2023-07-26 00:25:01 -07:00
|
|
|
<div :class="$style.listItemStatus">
|
|
|
|
<n8n-badge
|
|
|
|
v-if="workflowId === file.id && file.type === 'workflow'"
|
2023-12-28 00:49:58 -08:00
|
|
|
class="mr-2xs"
|
2023-07-26 00:25:01 -07:00
|
|
|
>
|
|
|
|
Current workflow
|
|
|
|
</n8n-badge>
|
|
|
|
<n8n-badge :theme="statusToBadgeThemeMap[file.status] || 'default'">
|
2023-07-28 00:51:07 -07:00
|
|
|
{{ i18n.baseText(`settings.sourceControl.status.${file.status}`) }}
|
2023-07-26 00:25:01 -07:00
|
|
|
</n8n-badge>
|
2023-06-28 04:59:07 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-07-26 00:25:01 -07:00
|
|
|
</n8n-card>
|
|
|
|
</div>
|
2023-12-28 00:49:58 -08:00
|
|
|
<n8n-notice v-else class="mt-0">
|
2023-07-28 00:51:07 -07:00
|
|
|
<i18n-t keypath="settings.sourceControl.modals.push.noWorkflowChanges">
|
2023-07-26 00:25:01 -07:00
|
|
|
<template #link>
|
2023-07-28 00:51:07 -07:00
|
|
|
<n8n-link size="small" :to="i18n.baseText('settings.sourceControl.docs.using.url')">
|
2023-07-26 00:25:01 -07:00
|
|
|
{{
|
2023-07-28 00:51:07 -07:00
|
|
|
i18n.baseText('settings.sourceControl.modals.push.noWorkflowChanges.moreInfo')
|
2023-07-26 00:25:01 -07:00
|
|
|
}}
|
|
|
|
</n8n-link>
|
|
|
|
</template>
|
2023-07-28 00:51:07 -07:00
|
|
|
</i18n-t>
|
2023-07-26 00:25:01 -07:00
|
|
|
</n8n-notice>
|
2023-05-31 06:01:57 -07:00
|
|
|
|
|
|
|
<n8n-text bold tag="p" class="mt-l mb-2xs">
|
2023-07-28 00:51:07 -07:00
|
|
|
{{ i18n.baseText('settings.sourceControl.modals.push.commitMessage') }}
|
2023-05-31 06:01:57 -07:00
|
|
|
</n8n-text>
|
|
|
|
<n8n-input
|
|
|
|
v-model="commitMessage"
|
2023-12-28 00:49:58 -08:00
|
|
|
type="text"
|
2023-05-31 06:01:57 -07:00
|
|
|
:placeholder="
|
2023-07-28 00:51:07 -07:00
|
|
|
i18n.baseText('settings.sourceControl.modals.push.commitMessage.placeholder')
|
2023-05-31 06:01:57 -07:00
|
|
|
"
|
2023-07-28 00:51:07 -07:00
|
|
|
@keydown.enter="onCommitKeyDownEnter"
|
2023-05-31 06:01:57 -07:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="!loading">
|
2023-07-26 00:25:01 -07:00
|
|
|
<n8n-notice class="mt-0 mb-0">
|
2023-07-28 00:51:07 -07:00
|
|
|
{{ i18n.baseText('settings.sourceControl.modals.push.everythingIsUpToDate') }}
|
2023-07-26 00:25:01 -07:00
|
|
|
</n8n-notice>
|
2023-05-31 06:01:57 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #footer>
|
|
|
|
<div :class="$style.footer">
|
|
|
|
<n8n-button type="tertiary" class="mr-2xs" @click="close">
|
2023-07-28 00:51:07 -07:00
|
|
|
{{ i18n.baseText('settings.sourceControl.modals.push.buttons.cancel') }}
|
2023-05-31 06:01:57 -07:00
|
|
|
</n8n-button>
|
|
|
|
<n8n-button type="primary" :disabled="isSubmitDisabled" @click="commitAndPush">
|
2023-07-28 00:51:07 -07:00
|
|
|
{{ i18n.baseText('settings.sourceControl.modals.push.buttons.save') }}
|
2023-05-31 06:01:57 -07:00
|
|
|
</n8n-button>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</Modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style module lang="scss">
|
|
|
|
.container > * {
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
}
|
|
|
|
|
|
|
|
.actionButtons {
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.listItem {
|
|
|
|
margin-top: var(--spacing-2xs);
|
|
|
|
margin-bottom: var(--spacing-2xs);
|
|
|
|
cursor: pointer;
|
|
|
|
transition: border 0.3s ease;
|
|
|
|
padding: var(--spacing-xs);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
border-color: var(--color-foreground-dark);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:first-child {
|
|
|
|
margin-top: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:last-child {
|
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
2023-06-28 04:59:07 -07:00
|
|
|
}
|
2023-05-31 06:01:57 -07:00
|
|
|
|
2023-06-28 04:59:07 -07:00
|
|
|
.listItemBody {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
|
|
|
}
|
2023-05-31 06:01:57 -07:00
|
|
|
|
2023-06-28 04:59:07 -07:00
|
|
|
.listItemCheckbox {
|
|
|
|
display: inline-flex !important;
|
|
|
|
margin-bottom: 0 !important;
|
|
|
|
margin-right: var(--spacing-2xs) !important;
|
|
|
|
}
|
2023-05-31 06:01:57 -07:00
|
|
|
|
2023-06-28 04:59:07 -07:00
|
|
|
.listItemStatus {
|
|
|
|
margin-left: auto;
|
2023-05-31 06:01:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-end;
|
|
|
|
}
|
|
|
|
</style>
|