2023-05-31 06:01:57 -07:00
|
|
|
<script lang="ts" setup>
|
2023-07-26 00:25:01 -07:00
|
|
|
import { computed, nextTick, ref } from 'vue';
|
2023-07-28 00:51:07 -07:00
|
|
|
import { useRouter } from 'vue-router';
|
2023-05-31 06:01:57 -07:00
|
|
|
import { createEventBus } from 'n8n-design-system/utils';
|
2023-06-06 05:27:26 -07:00
|
|
|
import { useI18n, useLoadingService, useMessage, useToast } from '@/composables';
|
2023-07-28 00:51:07 -07:00
|
|
|
import { useUIStore } from '@/stores/ui.store';
|
|
|
|
import { useSourceControlStore } from '@/stores/sourceControl.store';
|
|
|
|
import { useUsersStore } from '@/stores/users.store';
|
2023-06-28 04:59:07 -07:00
|
|
|
import { SOURCE_CONTROL_PULL_MODAL_KEY, SOURCE_CONTROL_PUSH_MODAL_KEY, VIEWS } from '@/constants';
|
2023-07-26 00:25:01 -07:00
|
|
|
import type { SourceControlAggregatedFile } from '../Interface';
|
|
|
|
import { sourceControlEventBus } from '@/event-bus/source-control';
|
2023-05-31 06:01:57 -07:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
isCollapsed: boolean;
|
|
|
|
}>();
|
|
|
|
|
2023-06-28 04:59:07 -07:00
|
|
|
const responseStatuses = {
|
|
|
|
CONFLICT: 409,
|
|
|
|
};
|
|
|
|
|
2023-06-06 05:27:26 -07:00
|
|
|
const router = useRouter();
|
2023-05-31 06:01:57 -07:00
|
|
|
const loadingService = useLoadingService();
|
|
|
|
const uiStore = useUIStore();
|
2023-07-26 00:25:01 -07:00
|
|
|
const usersStore = useUsersStore();
|
2023-06-20 10:13:18 -07:00
|
|
|
const sourceControlStore = useSourceControlStore();
|
2023-05-31 06:01:57 -07:00
|
|
|
const message = useMessage();
|
|
|
|
const toast = useToast();
|
2023-07-28 00:51:07 -07:00
|
|
|
const i18n = useI18n();
|
2023-05-31 06:01:57 -07:00
|
|
|
|
|
|
|
const eventBus = createEventBus();
|
|
|
|
const tooltipOpenDelay = ref(300);
|
|
|
|
|
|
|
|
const currentBranch = computed(() => {
|
2023-06-20 10:13:18 -07:00
|
|
|
return sourceControlStore.preferences.branchName;
|
2023-05-31 06:01:57 -07:00
|
|
|
});
|
2023-07-26 00:25:01 -07:00
|
|
|
const isInstanceOwner = computed(() => usersStore.isInstanceOwner);
|
2023-06-06 05:27:26 -07:00
|
|
|
const setupButtonTooltipPlacement = computed(() => (props.isCollapsed ? 'right' : 'top'));
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
async function pushWorkfolder() {
|
|
|
|
loadingService.startLoading();
|
2023-07-26 00:25:01 -07:00
|
|
|
loadingService.setLoadingText(i18n.baseText('settings.sourceControl.loading.checkingForChanges'));
|
2023-05-31 06:01:57 -07:00
|
|
|
try {
|
2023-06-20 10:13:18 -07:00
|
|
|
const status = await sourceControlStore.getAggregatedStatus();
|
2023-05-31 06:01:57 -07:00
|
|
|
|
|
|
|
uiStore.openModalWithData({
|
2023-06-20 10:13:18 -07:00
|
|
|
name: SOURCE_CONTROL_PUSH_MODAL_KEY,
|
2023-05-31 06:01:57 -07:00
|
|
|
data: { eventBus, status },
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
toast.showError(error, i18n.baseText('error'));
|
|
|
|
} finally {
|
|
|
|
loadingService.stopLoading();
|
|
|
|
loadingService.setLoadingText(i18n.baseText('genericHelpers.loading'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function pullWorkfolder() {
|
|
|
|
loadingService.startLoading();
|
2023-06-20 10:13:18 -07:00
|
|
|
loadingService.setLoadingText(i18n.baseText('settings.sourceControl.loading.pull'));
|
2023-06-28 04:59:07 -07:00
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
try {
|
2023-07-26 00:25:01 -07:00
|
|
|
const status: SourceControlAggregatedFile[] =
|
|
|
|
((await sourceControlStore.pullWorkfolder(
|
|
|
|
false,
|
|
|
|
)) as unknown as SourceControlAggregatedFile[]) || [];
|
|
|
|
|
|
|
|
const statusWithoutLocallyCreatedWorkflows = status.filter((file) => {
|
|
|
|
return !(file.type === 'workflow' && file.status === 'created' && file.location === 'local');
|
|
|
|
});
|
|
|
|
if (statusWithoutLocallyCreatedWorkflows.length === 0) {
|
|
|
|
toast.showMessage({
|
|
|
|
title: i18n.baseText('settings.sourceControl.pull.upToDate.title'),
|
|
|
|
message: i18n.baseText('settings.sourceControl.pull.upToDate.description'),
|
|
|
|
type: 'success',
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
toast.showMessage({
|
|
|
|
title: i18n.baseText('settings.sourceControl.pull.success.title'),
|
|
|
|
type: 'success',
|
|
|
|
});
|
|
|
|
|
|
|
|
const incompleteFileTypes = ['variables', 'credential'];
|
|
|
|
const hasVariablesOrCredentials = (status || []).some((file) => {
|
|
|
|
return incompleteFileTypes.includes(file.type);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (hasVariablesOrCredentials) {
|
2023-07-28 00:51:07 -07:00
|
|
|
void nextTick(() => {
|
2023-07-26 00:25:01 -07:00
|
|
|
toast.showMessage({
|
|
|
|
message: i18n.baseText('settings.sourceControl.pull.oneLastStep.description'),
|
|
|
|
title: i18n.baseText('settings.sourceControl.pull.oneLastStep.title'),
|
|
|
|
type: 'info',
|
|
|
|
duration: 0,
|
|
|
|
showClose: true,
|
|
|
|
offset: 0,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sourceControlEventBus.emit('pull');
|
2023-05-31 06:01:57 -07:00
|
|
|
} catch (error) {
|
2023-06-15 23:34:14 -07:00
|
|
|
const errorResponse = error.response;
|
2023-05-31 06:01:57 -07:00
|
|
|
|
2023-06-28 04:59:07 -07:00
|
|
|
if (errorResponse?.status === responseStatuses.CONFLICT) {
|
|
|
|
uiStore.openModalWithData({
|
|
|
|
name: SOURCE_CONTROL_PULL_MODAL_KEY,
|
|
|
|
data: { eventBus, status: errorResponse.data.data },
|
|
|
|
});
|
2023-06-15 23:34:14 -07:00
|
|
|
} else {
|
2023-05-31 06:01:57 -07:00
|
|
|
toast.showError(error, 'Error');
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
loadingService.stopLoading();
|
|
|
|
loadingService.setLoadingText(i18n.baseText('genericHelpers.loading'));
|
|
|
|
}
|
|
|
|
}
|
2023-06-06 05:27:26 -07:00
|
|
|
|
2023-06-20 10:13:18 -07:00
|
|
|
const goToSourceControlSetup = async () => {
|
|
|
|
await router.push({ name: VIEWS.SOURCE_CONTROL });
|
2023-06-06 05:27:26 -07:00
|
|
|
};
|
2023-05-31 06:01:57 -07:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-06-06 02:23:53 -07:00
|
|
|
<div
|
2023-07-27 03:11:43 -07:00
|
|
|
v-if="sourceControlStore.isEnterpriseSourceControlEnabled && isInstanceOwner"
|
2023-06-06 05:27:26 -07:00
|
|
|
:class="{
|
|
|
|
[$style.sync]: true,
|
|
|
|
[$style.collapsed]: isCollapsed,
|
2023-07-27 03:11:43 -07:00
|
|
|
[$style.isConnected]: sourceControlStore.isEnterpriseSourceControlEnabled,
|
2023-06-06 05:27:26 -07:00
|
|
|
}"
|
2023-06-20 10:13:18 -07:00
|
|
|
:style="{ borderLeftColor: sourceControlStore.preferences.branchColor }"
|
|
|
|
data-test-id="main-sidebar-source-control"
|
2023-06-06 02:23:53 -07:00
|
|
|
>
|
2023-06-06 05:27:26 -07:00
|
|
|
<div
|
2023-06-20 10:13:18 -07:00
|
|
|
v-if="sourceControlStore.preferences.connected && sourceControlStore.preferences.branchName"
|
2023-06-06 05:27:26 -07:00
|
|
|
:class="$style.connected"
|
2023-06-20 10:13:18 -07:00
|
|
|
data-test-id="main-sidebar-source-control-connected"
|
2023-06-06 05:27:26 -07:00
|
|
|
>
|
2023-07-26 00:25:01 -07:00
|
|
|
<span :class="$style.branchName">
|
2023-06-06 05:27:26 -07:00
|
|
|
<n8n-icon icon="code-branch" />
|
|
|
|
{{ currentBranch }}
|
|
|
|
</span>
|
|
|
|
<div :class="{ 'pt-xs': !isCollapsed }">
|
2023-07-28 03:57:33 -07:00
|
|
|
<n8n-tooltip :disabled="!isCollapsed" :show-after="tooltipOpenDelay" placement="right">
|
2023-06-06 05:27:26 -07:00
|
|
|
<template #content>
|
|
|
|
<div>
|
2023-06-20 10:13:18 -07:00
|
|
|
{{ i18n.baseText('settings.sourceControl.button.pull') }}
|
2023-06-06 05:27:26 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<n8n-button
|
|
|
|
:class="{
|
|
|
|
'mr-2xs': !isCollapsed,
|
2023-06-20 10:13:18 -07:00
|
|
|
'mb-2xs': isCollapsed && !sourceControlStore.preferences.branchReadOnly,
|
2023-06-06 05:27:26 -07:00
|
|
|
}"
|
|
|
|
icon="arrow-down"
|
|
|
|
type="tertiary"
|
|
|
|
size="mini"
|
|
|
|
:square="isCollapsed"
|
2023-07-28 00:51:07 -07:00
|
|
|
:label="isCollapsed ? '' : i18n.baseText('settings.sourceControl.button.pull')"
|
2023-06-06 05:27:26 -07:00
|
|
|
@click="pullWorkfolder"
|
2023-07-28 00:51:07 -07:00
|
|
|
/>
|
2023-06-06 05:27:26 -07:00
|
|
|
</n8n-tooltip>
|
|
|
|
<n8n-tooltip
|
2023-06-20 10:13:18 -07:00
|
|
|
v-if="!sourceControlStore.preferences.branchReadOnly"
|
2023-06-06 05:27:26 -07:00
|
|
|
:disabled="!isCollapsed"
|
2023-07-28 03:57:33 -07:00
|
|
|
:show-after="tooltipOpenDelay"
|
2023-06-06 05:27:26 -07:00
|
|
|
placement="right"
|
2023-05-31 06:01:57 -07:00
|
|
|
>
|
2023-06-06 05:27:26 -07:00
|
|
|
<template #content>
|
|
|
|
<div>
|
2023-06-20 10:13:18 -07:00
|
|
|
{{ i18n.baseText('settings.sourceControl.button.push') }}
|
2023-06-06 05:27:26 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<n8n-button
|
|
|
|
:square="isCollapsed"
|
2023-07-28 00:51:07 -07:00
|
|
|
:label="isCollapsed ? '' : i18n.baseText('settings.sourceControl.button.push')"
|
2023-06-06 05:27:26 -07:00
|
|
|
icon="arrow-up"
|
|
|
|
type="tertiary"
|
|
|
|
size="mini"
|
|
|
|
@click="pushWorkfolder"
|
2023-07-28 00:51:07 -07:00
|
|
|
/>
|
2023-06-06 05:27:26 -07:00
|
|
|
</n8n-tooltip>
|
|
|
|
</div>
|
2023-05-31 06:01:57 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.sync {
|
2023-06-06 05:27:26 -07:00
|
|
|
padding: var(--spacing-s) var(--spacing-s) var(--spacing-s) var(--spacing-l);
|
|
|
|
margin: var(--spacing-2xs) 0 calc(var(--spacing-2xs) * -1);
|
2023-05-31 06:01:57 -07:00
|
|
|
background: var(--color-background-light);
|
2023-06-06 02:23:53 -07:00
|
|
|
border-top: var(--border-width-base) var(--border-style-base) var(--color-foreground-base);
|
2023-05-31 06:01:57 -07:00
|
|
|
font-size: var(--font-size-2xs);
|
|
|
|
|
2023-06-06 05:27:26 -07:00
|
|
|
&.isConnected {
|
|
|
|
padding-left: var(--spacing-m);
|
|
|
|
border-left: var(--spacing-3xs) var(--border-style-base) var(--color-foreground-base);
|
|
|
|
|
|
|
|
&.collapsed {
|
|
|
|
padding-left: var(--spacing-xs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
span {
|
|
|
|
color: var(--color-text-base);
|
|
|
|
}
|
|
|
|
|
|
|
|
button {
|
|
|
|
font-size: var(--font-size-3xs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-26 00:25:01 -07:00
|
|
|
.branchName {
|
|
|
|
white-space: normal;
|
|
|
|
line-break: anywhere;
|
|
|
|
}
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
.collapsed {
|
|
|
|
text-align: center;
|
2023-06-06 05:27:26 -07:00
|
|
|
padding-left: var(--spacing-s);
|
|
|
|
padding-right: var(--spacing-s);
|
2023-05-31 06:01:57 -07:00
|
|
|
|
2023-06-06 05:27:26 -07:00
|
|
|
.connected {
|
|
|
|
> span {
|
|
|
|
display: none;
|
|
|
|
}
|
2023-05-31 06:01:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|