Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): Add new create first project CTA #12189

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createComponentRenderer } from '@/__tests__/render';
import { createTestingPinia } from '@pinia/testing';
import { createRouter, createMemoryHistory } from 'vue-router';
import { createTestingPinia } from '@pinia/testing';
import { createComponentRenderer } from '@/__tests__/render';
import { mockedStore } from '@/__tests__/utils';
import { createProjectListItem } from '@/__tests__/data/projects';
import ProjectsNavigation from '@/components/Projects//ProjectNavigation.vue';
import ProjectsNavigation from '@/components/Projects/ProjectNavigation.vue';
import { useProjectsStore } from '@/stores/projects.store';
import { mockedStore } from '@/__tests__/utils';

vi.mock('vue-router', async () => {
const actual = await vi.importActual('vue-router');
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('ProjectsNavigation', () => {
});

it('should show "Projects" title and Personal project when the feature is enabled', async () => {
projectsStore.isTeamProjectFeatureEnabled = true;
projectsStore.teamProjectsLimit = -1;
projectsStore.myProjects = [...personalProjects, ...teamProjects];

const { getByRole, getAllByTestId, getByTestId } = renderComponent({
Expand All @@ -97,7 +97,7 @@ describe('ProjectsNavigation', () => {
});

it('should not show "Projects" title when the menu is collapsed', async () => {
projectsStore.isTeamProjectFeatureEnabled = true;
projectsStore.teamProjectsLimit = -1;

const { queryByRole } = renderComponent({
props: {
Expand All @@ -109,7 +109,7 @@ describe('ProjectsNavigation', () => {
});

it('should not show "Projects" title when the feature is not enabled', async () => {
projectsStore.isTeamProjectFeatureEnabled = false;
projectsStore.teamProjectsLimit = 0;

const { queryByRole } = renderComponent({
props: {
Expand All @@ -121,7 +121,7 @@ describe('ProjectsNavigation', () => {
});

it('should not show project icons when the menu is collapsed', async () => {
projectsStore.isTeamProjectFeatureEnabled = true;
projectsStore.teamProjectsLimit = -1;

const { getByTestId } = renderComponent({
props: {
Expand All @@ -132,4 +132,43 @@ describe('ProjectsNavigation', () => {
expect(getByTestId('project-personal-menu-item')).toBeVisible();
expect(getByTestId('project-personal-menu-item').querySelector('svg')).not.toBeInTheDocument();
});

it('should not show add first project button if there are projects already', async () => {
projectsStore.teamProjectsLimit = -1;
projectsStore.myProjects = [...teamProjects];

const { queryByTestId } = renderComponent({
props: {
collapsed: false,
},
});

expect(queryByTestId('add-first-project-button')).not.toBeInTheDocument();
});

it('should not show project plus button and add first project button if user cannot create projects', async () => {
projectsStore.teamProjectsLimit = 0;

const { queryByTestId } = renderComponent({
props: {
collapsed: false,
},
});

expect(queryByTestId('project-plus-button')).not.toBeInTheDocument();
expect(queryByTestId('add-first-project-button')).not.toBeInTheDocument();
});

it('should show project plus button and add first project button if user can create projects', async () => {
projectsStore.teamProjectsLimit = -1;

const { getByTestId } = renderComponent({
props: {
collapsed: false,
},
});

expect(getByTestId('project-plus-button')).toBeVisible();
expect(getByTestId('add-first-project-button')).toBeVisible();
});
});
88 changes: 74 additions & 14 deletions packages/editor-ui/src/components/Projects/ProjectNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useI18n } from '@/composables/useI18n';
import { VIEWS } from '@/constants';
import { useProjectsStore } from '@/stores/projects.store';
import type { ProjectListItem } from '@/types/projects.types';
import { sortByProperty } from '@/utils/sortUtils';
import { useGlobalEntityCreation } from '@/composables/useGlobalEntityCreation';

type Props = {
collapsed: boolean;
Expand All @@ -16,6 +16,10 @@ const props = defineProps<Props>();

const locale = useI18n();
const projectsStore = useProjectsStore();
const globalEntityCreation = useGlobalEntityCreation();

const isCreatingProject = computed(() => globalEntityCreation.isCreatingProject.value);
const displayProjects = computed(() => globalEntityCreation.displayProjects.value);

const home = computed<IMenuItem>(() => ({
id: 'home',
Expand Down Expand Up @@ -50,11 +54,8 @@ const personalProject = computed<IMenuItem>(() => ({
},
}));

const displayProjects = computed(() =>
sortByProperty(
'name',
projectsStore.myProjects.filter((p) => p.type === 'team'),
),
const showAddFirstProject = computed(
() => projectsStore.isTeamProjectFeatureEnabled && !displayProjects.value.length,
);
</script>

Expand All @@ -70,13 +71,19 @@ const displayProjects = computed(() =>
/>
</ElMenu>
<hr v-if="projectsStore.isTeamProjectFeatureEnabled" class="mt-m mb-m" />
<N8nText
v-if="!props.collapsed && projectsStore.isTeamProjectFeatureEnabled"
:class="$style.projectsLabel"
tag="h3"
bold
>
<span>{{ locale.baseText('projects.menu.title') }}</span>
<N8nText :class="[$style.projectsLabel, { [$style.collapsed]: props.collapsed }]" tag="h3" bold>
<span v-if="!props.collapsed && projectsStore.isTeamProjectFeatureEnabled">{{
locale.baseText('projects.menu.title')
}}</span>
<N8nButton
v-if="projectsStore.canCreateProjects"
icon="plus"
text
data-test-id="project-plus-button"
:disabled="isCreatingProject"
:class="$style.plusBtn"
@click="globalEntityCreation.createProject"
/>
</N8nText>
<ElMenu
v-if="projectsStore.isTeamProjectFeatureEnabled"
Expand All @@ -103,6 +110,22 @@ const displayProjects = computed(() =>
data-test-id="project-menu-item"
/>
</ElMenu>
<N8nButton
v-if="showAddFirstProject"
:class="[
$style.addFirstProjectBtn,
{
[$style.collapsed]: props.collapsed,
},
]"
:disabled="isCreatingProject"
type="tertiary"
icon="plus"
data-test-id="add-first-project-button"
@click="globalEntityCreation.createProject"
>
{{ locale.baseText('projects.menu.addFirstProject') }}
</N8nButton>
<hr v-if="projectsStore.isTeamProjectFeatureEnabled" class="mb-m" />
</div>
</template>
Expand All @@ -114,6 +137,11 @@ const displayProjects = computed(() =>
width: 100%;
overflow: hidden;
align-items: start;
&:hover {
.plusBtn {
display: block;
}
}
}

.projectItems {
Expand All @@ -132,12 +160,44 @@ const displayProjects = computed(() =>
}

.projectsLabel {
margin: 0 var(--spacing-xs) var(--spacing-s);
display: flex;
justify-content: space-between;
margin: 0 0 var(--spacing-s) var(--spacing-xs);
padding: 0 var(--spacing-s);
text-overflow: ellipsis;
overflow: hidden;
box-sizing: border-box;
color: var(--color-text-base);

&.collapsed {
padding: 0;
margin-left: 0;
justify-content: center;

.plusBtn {
display: block;
}
}
}

.plusBtn {
margin: 0;
padding: 0;
color: var(--color-text-lighter);
display: none;
}

.addFirstProjectBtn {
border: 1px solid var(--color-background-dark);
font-size: var(--font-size-xs);
padding: var(--spacing-3xs);
margin: 0 var(--spacing-m) var(--spacing-m);

&.collapsed {
> span:last-child {
display: none;
}
}
}
</style>

Expand Down
12 changes: 11 additions & 1 deletion packages/editor-ui/src/composables/useGlobalEntityCreation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed } from 'vue';
import { computed, ref } from 'vue';
import { VIEWS } from '@/constants';
import { useRouter } from 'vue-router';
import { useI18n } from '@/composables/useI18n';
Expand Down Expand Up @@ -35,6 +35,9 @@ export const useGlobalEntityCreation = () => {
const router = useRouter();
const i18n = useI18n();
const toast = useToast();

const isCreatingProject = ref(false);

const displayProjects = computed(() =>
sortByProperty(
'name',
Expand Down Expand Up @@ -156,6 +159,8 @@ export const useGlobalEntityCreation = () => {
});

const createProject = async () => {
isCreatingProject.value = true;

try {
const newProject = await projectsStore.createProject({
name: i18n.baseText('projects.settings.newProjectName'),
Expand All @@ -169,6 +174,8 @@ export const useGlobalEntityCreation = () => {
});
} catch (error) {
toast.showError(error, i18n.baseText('projects.error.title'));
} finally {
isCreatingProject.value = false;
}
};

Expand Down Expand Up @@ -226,5 +233,8 @@ export const useGlobalEntityCreation = () => {
createProjectAppendSlotName,
projectsLimitReachedMessage,
upgradeLabel,
createProject,
isCreatingProject,
displayProjects,
};
};
2 changes: 1 addition & 1 deletion packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,7 @@
"projects.menu.overview": "Overview",
"projects.menu.title": "Projects",
"projects.menu.personal": "Personal",
"projects.menu.addProject": "Add project",
"projects.menu.addFirstProject": "Add first project",
"projects.settings": "Project settings",
"projects.settings.newProjectName": "My project",
"projects.settings.name": "Project name",
Expand Down
Loading