From 4eb6edc73a437b8d638ade08eb20a8eeb4310898 Mon Sep 17 00:00:00 2001 From: Csaba Tuncsik Date: Mon, 3 Jun 2024 14:24:26 +0200 Subject: [PATCH] refactor(editor): Fix type errors (no-changelog) (#9584) --- .../src/components/MainHeader/MainHeader.vue | 15 +++--- .../MainHeader/WorkflowDetails.spec.ts | 5 -- .../editor-ui/src/components/MainSidebar.vue | 14 ++--- .../src/components/SettingsSidebar.vue | 5 -- .../components/SourceControlPushModal.ee.vue | 51 ++++++++++++++----- .../editor-ui/src/components/WorkflowCard.vue | 13 +++-- .../src/components/WorkflowSettings.vue | 24 ++++----- .../executions/ExecutionsFilter.vue | 2 +- .../WorkflowExecutionsPreview.test.ts | 11 ++-- .../workflow/WorkflowExecutionsSidebar.vue | 4 +- .../src/plugins/i18n/locales/en.json | 1 + 11 files changed, 83 insertions(+), 62 deletions(-) diff --git a/packages/editor-ui/src/components/MainHeader/MainHeader.vue b/packages/editor-ui/src/components/MainHeader/MainHeader.vue index ca1b76e38..8f484042c 100644 --- a/packages/editor-ui/src/components/MainHeader/MainHeader.vue +++ b/packages/editor-ui/src/components/MainHeader/MainHeader.vue @@ -81,13 +81,10 @@ export default defineComponent({ return this.workflowsStore.workflow; }, currentWorkflow(): string { - return this.$route.params.name || this.workflowsStore.workflowId; + return String(this.$route.params.name || this.workflowsStore.workflowId); }, onWorkflowPage(): boolean { - return ( - this.$route.meta && - (this.$route.meta.nodeView || this.$route.meta.keepWorkflowAlive === true) - ); + return !!(this.$route.meta.nodeView || this.$route.meta.keepWorkflowAlive); }, readOnly(): boolean { return this.sourceControlStore.preferences.branchReadOnly; @@ -124,11 +121,15 @@ export default defineComponent({ this.activeHeaderTab = MAIN_HEADER_TABS.WORKFLOW; } - if (to.params.name !== 'new') { + if (to.params.name !== 'new' && typeof to.params.name === 'string') { this.workflowToReturnTo = to.params.name; } - if (from?.name === VIEWS.EXECUTION_PREVIEW && to.params.name === from.params.name) { + if ( + from?.name === VIEWS.EXECUTION_PREVIEW && + to.params.name === from.params.name && + typeof from.params.executionId === 'string' + ) { this.executionToReturnTo = from.params.executionId; } }, diff --git a/packages/editor-ui/src/components/MainHeader/WorkflowDetails.spec.ts b/packages/editor-ui/src/components/MainHeader/WorkflowDetails.spec.ts index 75562638b..075ba6bea 100644 --- a/packages/editor-ui/src/components/MainHeader/WorkflowDetails.spec.ts +++ b/packages/editor-ui/src/components/MainHeader/WorkflowDetails.spec.ts @@ -3,7 +3,6 @@ import { createComponentRenderer } from '@/__tests__/render'; import { STORES, WORKFLOW_SHARE_MODAL_KEY } from '@/constants'; import { createTestingPinia } from '@pinia/testing'; import userEvent from '@testing-library/user-event'; -import { useWorkflowsStore } from '@/stores/workflows.store'; import { useUIStore } from '@/stores/ui.store'; vi.mock('vue-router', async () => { @@ -48,12 +47,10 @@ const renderComponent = createComponentRenderer(WorkflowDetails, { pinia: createTestingPinia({ initialState }), }); -let workflowsStore: ReturnType; let uiStore: ReturnType; describe('WorkflowDetails', () => { beforeEach(() => { - workflowsStore = useWorkflowsStore(); uiStore = useUIStore(); }); it('renders workflow name and tags', async () => { @@ -101,8 +98,6 @@ describe('WorkflowDetails', () => { }); it('opens share modal on share button click', async () => { - vi.spyOn(workflowsStore, 'getWorkflowById', 'get').mockReturnValue(() => ({})); - const openModalSpy = vi.spyOn(uiStore, 'openModalWithData'); const { getByTestId } = renderComponent({ diff --git a/packages/editor-ui/src/components/MainSidebar.vue b/packages/editor-ui/src/components/MainSidebar.vue index b88c0ac9f..fae341cdc 100644 --- a/packages/editor-ui/src/components/MainSidebar.vue +++ b/packages/editor-ui/src/components/MainSidebar.vue @@ -67,8 +67,8 @@ >
@@ -88,7 +88,7 @@ :class="{ ['ml-2xs']: true, [$style.userName]: true, [$style.expanded]: fullyExpanded }" > {{ - usersStore.currentUser.fullName + usersStore.currentUser?.fullName }}
@@ -142,7 +142,7 @@ export default defineComponent({ ProjectNavigation, }, mixins: [userHelpers], - setup(props, ctx) { + setup() { const externalHooks = useExternalHooks(); const { callDebounced } = useDebounce(); @@ -435,11 +435,11 @@ export default defineComponent({ findFirstAccessibleSettingsRoute() { const settingsRoutes = this.$router .getRoutes() - .find((route) => route.path === '/settings')! - .children.map((route) => route.name ?? ''); + .find((route) => route.path === '/settings') + ?.children.map((route) => route.name ?? ''); let defaultSettingsRoute = { name: VIEWS.USERS_SETTINGS }; - for (const route of settingsRoutes) { + for (const route of settingsRoutes ?? []) { if (this.canUserAccessRouteByName(route.toString())) { defaultSettingsRoute = { name: route.toString() as VIEWS, diff --git a/packages/editor-ui/src/components/SettingsSidebar.vue b/packages/editor-ui/src/components/SettingsSidebar.vue index 1b341183a..a9ff876d2 100644 --- a/packages/editor-ui/src/components/SettingsSidebar.vue +++ b/packages/editor-ui/src/components/SettingsSidebar.vue @@ -193,11 +193,6 @@ export default defineComponent({ openUpdatesPanel() { this.uiStore.openModal(VERSIONS_MODAL_KEY); }, - async navigateTo(routeName: (typeof VIEWS)[keyof typeof VIEWS]) { - if (this.$router.currentRoute.name !== routeName) { - await this.$router.push({ name: routeName }); - } - }, async handleSelect(key: string) { switch (key) { case 'users': // Fakedoor feature added via hooks when user management is disabled on cloud diff --git a/packages/editor-ui/src/components/SourceControlPushModal.ee.vue b/packages/editor-ui/src/components/SourceControlPushModal.ee.vue index 212516588..c7bf91427 100644 --- a/packages/editor-ui/src/components/SourceControlPushModal.ee.vue +++ b/packages/editor-ui/src/components/SourceControlPushModal.ee.vue @@ -42,9 +42,9 @@ const files = ref( const commitMessage = ref(''); const loading = ref(true); -const context = ref<'workflow' | 'workflows' | 'credentials' | string>(''); +const context = ref<'workflow' | 'workflows' | 'credentials' | ''>(''); -const statusToBadgeThemeMap = { +const statusToBadgeThemeMap: Record = { created: 'success', deleted: 'danger', modified: 'warning', @@ -64,7 +64,7 @@ const workflowId = computed(() => { }); const sortedFiles = computed(() => { - const statusPriority = { + const statusPriority: Record = { modified: 1, renamed: 2, created: 3, @@ -86,7 +86,11 @@ const sortedFiles = computed(() => { return 1; } - return a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : 0; + return (a.updatedAt ?? 0) < (b.updatedAt ?? 0) + ? 1 + : (a.updatedAt ?? 0) > (b.updatedAt ?? 0) + ? -1 + : 0; }); }); @@ -151,13 +155,18 @@ function getContext() { return ''; } -function getStagedFilesByContext(files: SourceControlAggregatedFile[]): Record { - const stagedFiles = files.reduce((acc, file) => { - acc[file.file] = false; - return acc; - }, {}); +function getStagedFilesByContext( + filesByContext: SourceControlAggregatedFile[], +): Record { + const stagedFiles = filesByContext.reduce( + (acc, file) => { + acc[file.file] = false; + return acc; + }, + {} as Record, + ); - files.forEach((file) => { + filesByContext.forEach((file) => { if (defaultStagedFileTypes.includes(file.type)) { stagedFiles[file.file] = true; } @@ -184,13 +193,13 @@ function close() { } function renderUpdatedAt(file: SourceControlAggregatedFile) { - const currentYear = new Date().getFullYear(); + const currentYear = new Date().getFullYear().toString(); return i18n.baseText('settings.sourceControl.lastUpdated', { interpolate: { date: dateformat( file.updatedAt, - `d mmm${file.updatedAt.startsWith(currentYear) ? '' : ', yyyy'}`, + `d mmm${file.updatedAt?.startsWith(currentYear) ? '' : ', yyyy'}`, ), time: dateformat(file.updatedAt, 'HH:MM'), }, @@ -227,6 +236,22 @@ async function commitAndPush() { loadingService.stopLoading(); } } + +function getStatusText(file: SourceControlAggregatedFile): string { + if (file.status === 'deleted') { + return i18n.baseText('settings.sourceControl.status.deleted'); + } + + if (file.status === 'created') { + return i18n.baseText('settings.sourceControl.status.created'); + } + + if (file.status === 'modified') { + return i18n.baseText('settings.sourceControl.status.modified'); + } + + return i18n.baseText('settings.sourceControl.status.renamed'); +}