mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
refactor(editor): Refactor project utils splitName
(no-changelog) (#10669)
This commit is contained in:
parent
7da234d8b1
commit
e318a6323a
|
@ -45,8 +45,8 @@ const isSharingEnabled = computed(
|
||||||
() => settingsStore.isEnterpriseFeatureEnabled[EnterpriseEditionFeature.Sharing],
|
() => settingsStore.isEnterpriseFeatureEnabled[EnterpriseEditionFeature.Sharing],
|
||||||
);
|
);
|
||||||
const credentialOwnerName = computed(() => {
|
const credentialOwnerName = computed(() => {
|
||||||
const { firstName, lastName, email } = splitName(props.credential?.homeProject?.name ?? '');
|
const { name, email } = splitName(props.credential?.homeProject?.name ?? '');
|
||||||
return firstName || lastName ? `${firstName}${lastName ? ' ' + lastName : ''}` : email ?? '';
|
return name ?? email ?? '';
|
||||||
});
|
});
|
||||||
|
|
||||||
const credentialDataHomeProject = computed<ProjectSharingData | undefined>(() => {
|
const credentialDataHomeProject = computed<ProjectSharingData | undefined>(() => {
|
||||||
|
|
|
@ -59,8 +59,8 @@ const badgeText = computed(() => {
|
||||||
) {
|
) {
|
||||||
return i18n.baseText('generic.ownedByMe');
|
return i18n.baseText('generic.ownedByMe');
|
||||||
} else {
|
} else {
|
||||||
const { firstName, lastName, email } = splitName(props.resource.homeProject?.name ?? '');
|
const { name, email } = splitName(props.resource.homeProject?.name ?? '');
|
||||||
return (!firstName ? email : `${firstName}${lastName ? ' ' + lastName : ''}`) ?? '';
|
return name ?? email ?? '';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const badgeIcon = computed(() => {
|
const badgeIcon = computed(() => {
|
||||||
|
|
|
@ -26,8 +26,8 @@ const telemetry = useTelemetry();
|
||||||
|
|
||||||
const projectId = ref<string | null>(null);
|
const projectId = ref<string | null>(null);
|
||||||
const processedName = computed(() => {
|
const processedName = computed(() => {
|
||||||
const { firstName, lastName, email } = splitName(props.data.resource.homeProject?.name ?? '');
|
const { name, email } = splitName(props.data.resource.homeProject?.name ?? '');
|
||||||
return !firstName ? email : `${firstName}${lastName ? ' ' + lastName : ''}`;
|
return name ?? email;
|
||||||
});
|
});
|
||||||
const availableProjects = computed(() => {
|
const availableProjects = computed(() => {
|
||||||
return projectsStore.teamProjects.filter((p) => p.id !== props.data.resource.homeProject?.id);
|
return projectsStore.teamProjects.filter((p) => p.id !== props.data.resource.homeProject?.id);
|
||||||
|
|
|
@ -9,7 +9,16 @@ type Props = {
|
||||||
|
|
||||||
const props = defineProps<Props>();
|
const props = defineProps<Props>();
|
||||||
|
|
||||||
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,
|
||||||
|
};
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div :class="$style.projectInfo" data-test-id="project-sharing-info">
|
<div :class="$style.projectInfo" data-test-id="project-sharing-info">
|
||||||
|
|
|
@ -183,17 +183,13 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, () => {
|
||||||
|
|
||||||
const getCredentialOwnerName = computed(() => {
|
const getCredentialOwnerName = computed(() => {
|
||||||
return (credential: ICredentialsResponse | IUsedCredential | undefined): string => {
|
return (credential: ICredentialsResponse | IUsedCredential | undefined): string => {
|
||||||
const { firstName, lastName, email } = splitName(credential?.homeProject?.name ?? '');
|
const { name, email } = splitName(credential?.homeProject?.name ?? '');
|
||||||
|
|
||||||
if (credential?.homeProject?.name) {
|
return name
|
||||||
if (lastName && email) {
|
? email
|
||||||
return `${firstName} ${lastName} (${email})`;
|
? `${name} (${email})`
|
||||||
} else {
|
: name
|
||||||
return firstName;
|
: email ?? i18n.baseText('credentialEdit.credentialSharing.info.sharee.fallback');
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return i18n.baseText('credentialEdit.credentialSharing.info.sharee.fallback');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,9 @@ export const useWorkflowsEEStore = defineStore(STORES.WORKFLOWS_EE, {
|
||||||
fallback = i18n.baseText('workflows.shareModal.info.sharee.fallback'),
|
fallback = i18n.baseText('workflows.shareModal.info.sharee.fallback'),
|
||||||
): string => {
|
): string => {
|
||||||
const workflow = useWorkflowsStore().getWorkflowById(workflowId);
|
const workflow = useWorkflowsStore().getWorkflowById(workflowId);
|
||||||
const { firstName, lastName, email } = splitName(workflow?.homeProject?.name ?? '');
|
const { name, email } = splitName(workflow?.homeProject?.name ?? '');
|
||||||
|
|
||||||
return workflow?.homeProject?.name
|
return name ? (email ? `${name} (${email})` : name) : email ?? fallback;
|
||||||
? `${firstName} ${lastName ?? ''} ${email ? `(${email})` : ''}`
|
|
||||||
: fallback;
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,54 +5,71 @@ describe('splitName', () => {
|
||||||
[
|
[
|
||||||
'First Last <email@domain.com>',
|
'First Last <email@domain.com>',
|
||||||
{
|
{
|
||||||
firstName: 'First',
|
name: 'First Last',
|
||||||
lastName: 'Last',
|
|
||||||
email: 'email@domain.com',
|
email: 'email@domain.com',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'First Last Third <email@domain.com>',
|
'First Last Third <email@domain.com>',
|
||||||
{
|
{
|
||||||
firstName: 'First Last',
|
name: 'First Last Third',
|
||||||
lastName: 'Third',
|
|
||||||
email: 'email@domain.com',
|
email: 'email@domain.com',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'First Last Third Fourth <email@domain.com>',
|
'First Last Third Fourth <email@domain.com>',
|
||||||
{
|
{
|
||||||
firstName: 'First Last Third',
|
name: 'First Last Third Fourth',
|
||||||
lastName: 'Fourth',
|
email: 'email@domain.com',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
' First Last Third Fourth <email@domain.com>',
|
||||||
|
{
|
||||||
|
name: 'First Last Third Fourth',
|
||||||
email: 'email@domain.com',
|
email: 'email@domain.com',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'<email@domain.com>',
|
'<email@domain.com>',
|
||||||
{
|
{
|
||||||
firstName: undefined,
|
name: undefined,
|
||||||
lastName: undefined,
|
|
||||||
email: 'email@domain.com',
|
email: 'email@domain.com',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
' <email@domain.com>',
|
' <email@domain.com>',
|
||||||
{
|
{
|
||||||
firstName: '',
|
name: undefined,
|
||||||
lastName: '',
|
|
||||||
email: 'email@domain.com',
|
email: 'email@domain.com',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'My project',
|
'My project',
|
||||||
{
|
{
|
||||||
firstName: 'My',
|
name: 'My project',
|
||||||
lastName: 'project',
|
email: undefined,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
' My project ',
|
||||||
|
{
|
||||||
|
name: 'My project',
|
||||||
|
email: undefined,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'MyProject',
|
'MyProject',
|
||||||
{
|
{
|
||||||
firstName: 'MyProject',
|
name: 'MyProject',
|
||||||
|
email: undefined,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
name: undefined,
|
||||||
|
email: undefined,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
])('should split a name in the format "First Last <email@domain.com>"', (input, result) => {
|
])('should split a name in the format "First Last <email@domain.com>"', (input, result) => {
|
|
@ -1,30 +1,14 @@
|
||||||
// Splits a project name into first name, last name, and email when it is in the format "First Last <email@domain.com>"
|
// Splits a project name into first name, last name, and email when it is in the format "First Last <email@domain.com>"
|
||||||
export const splitName = (
|
export const splitName = (
|
||||||
projectName: string,
|
projectName = '',
|
||||||
): {
|
): {
|
||||||
firstName: string;
|
name?: string;
|
||||||
lastName?: string;
|
|
||||||
email?: string;
|
email?: string;
|
||||||
} => {
|
} => {
|
||||||
const regex = /^(.+)?\s?<([^>]+)>$/;
|
const regex = /^(.*?)(?:\s*<([^>]+)>)?$/;
|
||||||
const match = projectName.match(regex);
|
const match = projectName.match(regex);
|
||||||
|
const [, name, email] = match ?? [];
|
||||||
if (match) {
|
return { name: name.trim() || undefined, email };
|
||||||
const [_, fullName, email] = match;
|
|
||||||
const nameParts = fullName?.trim().split(/\s+/);
|
|
||||||
const lastName = nameParts?.pop();
|
|
||||||
const firstName = nameParts?.join(' ');
|
|
||||||
return { firstName, lastName, email };
|
|
||||||
} else {
|
|
||||||
const nameParts = projectName.split(/\s+/) ?? [];
|
|
||||||
if (nameParts.length < 2) {
|
|
||||||
return { firstName: projectName };
|
|
||||||
} else {
|
|
||||||
const lastName = nameParts.pop();
|
|
||||||
const firstName = nameParts.join(' ');
|
|
||||||
return { firstName, lastName };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const enum ResourceType {
|
export const enum ResourceType {
|
||||||
|
|
Loading…
Reference in a new issue