-
Notifications
You must be signed in to change notification settings - Fork 9k
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 tooltips to workflow history button (#10570)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
- Loading branch information
Showing
5 changed files
with
172 additions
and
76 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
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
63 changes: 63 additions & 0 deletions
63
packages/editor-ui/src/components/MainHeader/WorkflowHistoryButton.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,63 @@ | ||
import { createComponentRenderer } from '@/__tests__/render'; | ||
import { within } from '@testing-library/vue'; | ||
import userEvent from '@testing-library/user-event'; | ||
import WorkflowHistoryButton from '@/components/MainHeader/WorkflowHistoryButton.vue'; | ||
|
||
vi.mock('vue-router', () => ({ | ||
useRoute: () => vi.fn(), | ||
useRouter: () => vi.fn(), | ||
RouterLink: vi.fn(), | ||
})); | ||
|
||
const renderComponent = createComponentRenderer(WorkflowHistoryButton, { | ||
global: { | ||
stubs: { | ||
RouterLink: true, | ||
'router-link': { | ||
template: '<div><slot /></div>', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
describe('WorkflowHistoryButton', () => { | ||
it('should be disabled if the feature is disabled', async () => { | ||
const { getByRole, emitted } = renderComponent({ | ||
props: { | ||
workflowId: '1', | ||
isNewWorkflow: false, | ||
isFeatureEnabled: false, | ||
}, | ||
}); | ||
expect(getByRole('button')).toBeDisabled(); | ||
|
||
await userEvent.hover(getByRole('button')); | ||
expect(getByRole('tooltip')).toBeVisible(); | ||
|
||
within(getByRole('tooltip')).getByText('View plans').click(); | ||
|
||
expect(emitted()).toHaveProperty('upgrade'); | ||
}); | ||
|
||
it('should be disabled if the feature is enabled but the workflow is new', async () => { | ||
const { getByRole } = renderComponent({ | ||
props: { | ||
workflowId: '1', | ||
isNewWorkflow: true, | ||
isFeatureEnabled: true, | ||
}, | ||
}); | ||
expect(getByRole('button')).toBeDisabled(); | ||
}); | ||
|
||
it('should be enabled if the feature is enabled and the workflow is not new', async () => { | ||
const { getByRole } = renderComponent({ | ||
props: { | ||
workflowId: '1', | ||
isNewWorkflow: false, | ||
isFeatureEnabled: true, | ||
}, | ||
}); | ||
expect(getByRole('button')).toBeEnabled(); | ||
}); | ||
}); |
73 changes: 73 additions & 0 deletions
73
packages/editor-ui/src/components/MainHeader/WorkflowHistoryButton.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,73 @@ | ||
<script lang="ts" setup> | ||
import { computed } from 'vue'; | ||
import { VIEWS } from '@/constants'; | ||
import { useI18n } from '@/composables/useI18n'; | ||
const locale = useI18n(); | ||
const props = defineProps<{ | ||
workflowId: string; | ||
isNewWorkflow: boolean; | ||
isFeatureEnabled: boolean; | ||
}>(); | ||
const emit = defineEmits<{ | ||
upgrade: []; | ||
}>(); | ||
const workflowHistoryRoute = computed<{ name: string; params: { workflowId: string } }>(() => ({ | ||
name: VIEWS.WORKFLOW_HISTORY, | ||
params: { | ||
workflowId: props.workflowId, | ||
}, | ||
})); | ||
</script> | ||
|
||
<template> | ||
<N8nTooltip placement="bottom"> | ||
<RouterLink :to="workflowHistoryRoute" :class="$style.workflowHistoryButton"> | ||
<N8nIconButton | ||
:disabled="isNewWorkflow || !isFeatureEnabled" | ||
data-test-id="workflow-history-button" | ||
type="tertiary" | ||
icon="history" | ||
size="medium" | ||
text | ||
/> | ||
</RouterLink> | ||
<template #content> | ||
<span v-if="isFeatureEnabled && isNewWorkflow"> | ||
{{ locale.baseText('workflowHistory.button.tooltip.empty') }} | ||
</span> | ||
<span v-else-if="isFeatureEnabled">{{ | ||
locale.baseText('workflowHistory.button.tooltip.enabled') | ||
}}</span> | ||
<i18n-t v-else keypath="workflowHistory.button.tooltip.disabled"> | ||
<template #link> | ||
<N8nLink size="small" @click="emit('upgrade')"> | ||
{{ locale.baseText('workflowHistory.button.tooltip.disabled.link') }} | ||
</N8nLink> | ||
</template> | ||
</i18n-t> | ||
</template> | ||
</N8nTooltip> | ||
</template> | ||
|
||
<style lang="scss" module> | ||
.workflowHistoryButton { | ||
width: 30px; | ||
height: 30px; | ||
color: var(--color-text-dark); | ||
border-radius: var(--border-radius-base); | ||
&:hover { | ||
background-color: var(--color-background-base); | ||
} | ||
:disabled { | ||
background: transparent; | ||
border: none; | ||
opacity: 0.5; | ||
} | ||
} | ||
</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