From e318a6323ad5300e9520f3b7ed226b82b4ffc33e Mon Sep 17 00:00:00 2001 From: Csaba Tuncsik Date: Thu, 5 Sep 2024 09:17:46 +0200 Subject: [PATCH] refactor(editor): Refactor project utils `splitName` (no-changelog) (#10669) --- .../CredentialEdit/CredentialSharing.ee.vue | 4 +- .../components/Projects/ProjectCardBadge.vue | 4 +- .../Projects/ProjectMoveResourceModal.vue | 4 +- .../Projects/ProjectSharingInfo.vue | 11 ++++- .../editor-ui/src/stores/credentials.store.ts | 16 +++---- .../src/stores/workflows.ee.store.ts | 6 +-- .../{__tests__ => }/projects.utils.test.ts | 43 +++++++++++++------ .../editor-ui/src/utils/projects.utils.ts | 26 +++-------- 8 files changed, 59 insertions(+), 55 deletions(-) rename packages/editor-ui/src/utils/{__tests__ => }/projects.utils.test.ts (58%) diff --git a/packages/editor-ui/src/components/CredentialEdit/CredentialSharing.ee.vue b/packages/editor-ui/src/components/CredentialEdit/CredentialSharing.ee.vue index 8caa52c015..1c2242195c 100644 --- a/packages/editor-ui/src/components/CredentialEdit/CredentialSharing.ee.vue +++ b/packages/editor-ui/src/components/CredentialEdit/CredentialSharing.ee.vue @@ -45,8 +45,8 @@ const isSharingEnabled = computed( () => settingsStore.isEnterpriseFeatureEnabled[EnterpriseEditionFeature.Sharing], ); const credentialOwnerName = computed(() => { - const { firstName, lastName, email } = splitName(props.credential?.homeProject?.name ?? ''); - return firstName || lastName ? `${firstName}${lastName ? ' ' + lastName : ''}` : email ?? ''; + const { name, email } = splitName(props.credential?.homeProject?.name ?? ''); + return name ?? email ?? ''; }); const credentialDataHomeProject = computed(() => { diff --git a/packages/editor-ui/src/components/Projects/ProjectCardBadge.vue b/packages/editor-ui/src/components/Projects/ProjectCardBadge.vue index 6bcd1aade7..e0ff41f5a8 100644 --- a/packages/editor-ui/src/components/Projects/ProjectCardBadge.vue +++ b/packages/editor-ui/src/components/Projects/ProjectCardBadge.vue @@ -59,8 +59,8 @@ const badgeText = computed(() => { ) { return i18n.baseText('generic.ownedByMe'); } else { - const { firstName, lastName, email } = splitName(props.resource.homeProject?.name ?? ''); - return (!firstName ? email : `${firstName}${lastName ? ' ' + lastName : ''}`) ?? ''; + const { name, email } = splitName(props.resource.homeProject?.name ?? ''); + return name ?? email ?? ''; } }); const badgeIcon = computed(() => { diff --git a/packages/editor-ui/src/components/Projects/ProjectMoveResourceModal.vue b/packages/editor-ui/src/components/Projects/ProjectMoveResourceModal.vue index fab4d765c8..d115a18f39 100644 --- a/packages/editor-ui/src/components/Projects/ProjectMoveResourceModal.vue +++ b/packages/editor-ui/src/components/Projects/ProjectMoveResourceModal.vue @@ -26,8 +26,8 @@ const telemetry = useTelemetry(); const projectId = ref(null); const processedName = computed(() => { - const { firstName, lastName, email } = splitName(props.data.resource.homeProject?.name ?? ''); - return !firstName ? email : `${firstName}${lastName ? ' ' + lastName : ''}`; + const { name, email } = splitName(props.data.resource.homeProject?.name ?? ''); + return name ?? email; }); const availableProjects = computed(() => { return projectsStore.teamProjects.filter((p) => p.id !== props.data.resource.homeProject?.id); diff --git a/packages/editor-ui/src/components/Projects/ProjectSharingInfo.vue b/packages/editor-ui/src/components/Projects/ProjectSharingInfo.vue index bf4133f7dd..c138b695db 100644 --- a/packages/editor-ui/src/components/Projects/ProjectSharingInfo.vue +++ b/packages/editor-ui/src/components/Projects/ProjectSharingInfo.vue @@ -9,7 +9,16 @@ type Props = { const props = defineProps(); -const processedName = computed(() => splitName(props.project.name ?? '')); +const processedName = computed(() => { + const { name, email } = splitName(props.project.name ?? ''); + const nameArray = name?.split(' '); + const lastName = nameArray?.pop() ?? ''; + return { + firstName: nameArray?.join(' ') ?? '', + lastName, + email, + }; +});