-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(editor): Add execution concurrency info and paywall (#11847)
- Loading branch information
Showing
11 changed files
with
315 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/editor-ui/src/components/executions/ConcurrentExecutionsHeader.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { createTestingPinia } from '@pinia/testing'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { createComponentRenderer } from '@/__tests__/render'; | ||
import ConcurrentExecutionsHeader from '@/components/executions/ConcurrentExecutionsHeader.vue'; | ||
|
||
vi.mock('vue-router', () => { | ||
return { | ||
useRouter: vi.fn(), | ||
useRoute: vi.fn(), | ||
RouterLink: { | ||
template: '<a><slot /></a>', | ||
}, | ||
}; | ||
}); | ||
|
||
const renderComponent = createComponentRenderer(ConcurrentExecutionsHeader, { | ||
pinia: createTestingPinia(), | ||
}); | ||
|
||
describe('ConcurrentExecutionsHeader', () => { | ||
it('should not throw error when rendered', async () => { | ||
expect(() => | ||
renderComponent({ | ||
props: { | ||
runningExecutionsCount: 0, | ||
concurrencyCap: 0, | ||
}, | ||
}), | ||
).not.toThrow(); | ||
}); | ||
|
||
test.each([ | ||
[0, 5, 'No active executions'], | ||
[2, 5, '2/5 active executions'], | ||
])( | ||
'shows the correct text when there are %i running executions of %i', | ||
async (runningExecutionsCount, concurrencyCap, text) => { | ||
const { getByText } = renderComponent({ | ||
props: { | ||
runningExecutionsCount, | ||
concurrencyCap, | ||
}, | ||
}); | ||
|
||
expect(getByText(text)).toBeVisible(); | ||
}, | ||
); | ||
|
||
it('should show tooltip on hover and call "goToUpgrade" on click', async () => { | ||
const windowOpenSpy = vi.spyOn(window, 'open').mockImplementation(() => null); | ||
|
||
const { container, getByText, getByRole, queryByRole } = renderComponent({ | ||
props: { | ||
runningExecutionsCount: 2, | ||
concurrencyCap: 5, | ||
}, | ||
}); | ||
|
||
const tooltipTrigger = container.querySelector('svg') as SVGSVGElement; | ||
|
||
expect(tooltipTrigger).toBeVisible(); | ||
expect(queryByRole('tooltip')).not.toBeInTheDocument(); | ||
|
||
await userEvent.hover(tooltipTrigger); | ||
|
||
expect(getByRole('tooltip')).toBeVisible(); | ||
expect(getByText('Upgrade now')).toBeVisible(); | ||
|
||
await userEvent.click(getByText('Upgrade now')); | ||
|
||
expect(windowOpenSpy).toHaveBeenCalled(); | ||
}); | ||
}); |
65 changes: 65 additions & 0 deletions
65
packages/editor-ui/src/components/executions/ConcurrentExecutionsHeader.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<script lang="ts" setup> | ||
import { computed, defineProps } from 'vue'; | ||
import { useI18n } from '@/composables/useI18n'; | ||
import { usePageRedirectionHelper } from '@/composables/usePageRedirectionHelper'; | ||
const props = defineProps<{ | ||
runningExecutionsCount: number; | ||
concurrencyCap: number; | ||
}>(); | ||
const i18n = useI18n(); | ||
const pageRedirectionHelper = usePageRedirectionHelper(); | ||
const tooltipText = computed(() => | ||
i18n.baseText('executionsList.activeExecutions.tooltip', { | ||
interpolate: { | ||
running: props.runningExecutionsCount, | ||
cap: props.concurrencyCap, | ||
}, | ||
}), | ||
); | ||
const headerText = computed(() => { | ||
if (props.runningExecutionsCount === 0) { | ||
return i18n.baseText('executionsList.activeExecutions.none'); | ||
} | ||
return i18n.baseText('executionsList.activeExecutions.header', { | ||
interpolate: { | ||
running: props.runningExecutionsCount, | ||
cap: props.concurrencyCap, | ||
}, | ||
}); | ||
}); | ||
const goToUpgrade = () => { | ||
void pageRedirectionHelper.goToUpgrade('concurrency', 'upgrade-concurrency'); | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div data-test-id="concurrent-executions-header"> | ||
<n8n-tooltip> | ||
<template #content> | ||
<div :class="$style.tooltip"> | ||
{{ tooltipText }} | ||
<n8n-link bold size="small" :class="$style.upgrade" @click="goToUpgrade"> | ||
{{ i18n.baseText('generic.upgradeNow') }} | ||
</n8n-link> | ||
</div> | ||
</template> | ||
<font-awesome-icon icon="info-circle" class="mr-2xs" /> | ||
</n8n-tooltip> | ||
<n8n-text>{{ headerText }}</n8n-text> | ||
</div> | ||
</template> | ||
|
||
<style module scoped> | ||
.tooltip { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
.upgrade { | ||
margin-top: var(--spacing-xs); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.