2024-09-03 07:52:12 -07:00
|
|
|
<script setup lang="ts">
|
2024-09-11 05:22:55 -07:00
|
|
|
import { onMounted, onBeforeUnmount, computed, watch } from 'vue';
|
|
|
|
import { useDocumentVisibility } from '@vueuse/core';
|
|
|
|
|
2024-09-03 07:52:12 -07:00
|
|
|
import { useUsersStore } from '@/stores/users.store';
|
|
|
|
import { useCollaborationStore } from '@/stores/collaboration.store';
|
|
|
|
import { isUserGlobalOwner } from '@/utils/userUtils';
|
|
|
|
|
|
|
|
const collaborationStore = useCollaborationStore();
|
|
|
|
const usersStore = useUsersStore();
|
|
|
|
|
2024-09-11 05:22:55 -07:00
|
|
|
const visibility = useDocumentVisibility();
|
|
|
|
watch(visibility, (visibilityState) => {
|
|
|
|
if (visibilityState === 'hidden') {
|
|
|
|
collaborationStore.stopHeartbeat();
|
|
|
|
} else {
|
|
|
|
collaborationStore.startHeartbeat();
|
|
|
|
}
|
|
|
|
});
|
2024-09-03 07:52:12 -07:00
|
|
|
|
2024-09-11 09:18:19 -07:00
|
|
|
const showUserStack = computed(() => collaborationStore.collaborators.length > 1);
|
|
|
|
|
2024-09-11 05:22:55 -07:00
|
|
|
const collaboratorsSorted = computed(() => {
|
|
|
|
const currentWorkflowUsers = collaborationStore.collaborators.map(({ user }) => user);
|
2024-09-03 07:52:12 -07:00
|
|
|
const owner = currentWorkflowUsers.find(isUserGlobalOwner);
|
|
|
|
return {
|
|
|
|
defaultGroup: owner
|
|
|
|
? [owner, ...currentWorkflowUsers.filter((user) => user.id !== owner.id)]
|
|
|
|
: currentWorkflowUsers,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2024-09-11 05:22:55 -07:00
|
|
|
const currentUserEmail = computed(() => usersStore.currentUser?.email);
|
2024-09-03 07:52:12 -07:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
collaborationStore.initialize();
|
|
|
|
});
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
collaborationStore.terminate();
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
:class="`collaboration-pane-container ${$style.container}`"
|
|
|
|
data-test-id="collaboration-pane"
|
|
|
|
>
|
2024-09-11 09:18:19 -07:00
|
|
|
<n8n-user-stack
|
|
|
|
v-if="showUserStack"
|
|
|
|
:users="collaboratorsSorted"
|
|
|
|
:current-user-email="currentUserEmail"
|
|
|
|
/>
|
2024-09-03 07:52:12 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.container {
|
|
|
|
margin: 0 var(--spacing-4xs);
|
|
|
|
}
|
|
|
|
</style>
|