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

refactor(editor): Fix remaining FE type check errors (no-changelog) #9607

Merged
merged 18 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const validationError = computed<string | null>(() => {

if (error) {
if ('messageKey' in error) {
return t(error.messageKey, error.options as object);
return t(error.messageKey, error.options);
} else if ('message' in error) {
return error.message;
}
Expand Down
19 changes: 12 additions & 7 deletions packages/design-system/src/locale/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const RE_NARGS = /(%|)\{([0-9a-zA-Z_]+)\}/g;
* https://github.com/Matt-Esch/string-template/index.js
*/
export default function () {
const isReplacementGroup = (target: object, key: string): target is Record<string, unknown> =>
key in target;

function template(
value: string | ((...args: unknown[]) => string),
...args: Array<string | object>
Expand All @@ -15,21 +18,23 @@ export default function () {
}

const str = value;
let replacements: object = args;
if (args.length === 1 && typeof args[0] === 'object') {
args = args[0] as unknown as Array<string | object>;
replacements = args[0];
}

if (!args?.hasOwnProperty) {
args = {} as unknown as Array<string | object>;
if (!replacements?.hasOwnProperty) {
replacements = {};
}

return str.replace(RE_NARGS, (match, _, i, index: number) => {
let result: string | object | null;
return str.replace(RE_NARGS, (match, _, group: string, index: number): string => {
let result: string | null;

if (str[index - 1] === '{' && str[index + match.length] === '}') {
return i;
return `${group}`;
} else {
result = Object.hasOwn(args, i) ? args[i] : null;
result = isReplacementGroup(replacements, group) ? `${replacements[group]}` : null;

if (result === null || result === undefined) {
return '';
}
Expand Down
6 changes: 3 additions & 3 deletions packages/design-system/src/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const t = function (

// only support flat keys
if (lang[path] !== undefined) {
return format(lang[path], options);
return format(lang[path], ...(options ? [options] : []));
}

return '';
Expand All @@ -44,8 +44,8 @@ export async function use(l: string) {
} catch (e) {}
}

export const i18n = function (fn: N8nLocaleTranslateFn) {
export function i18n(fn: N8nLocaleTranslateFn) {
i18nHandler = fn || i18nHandler;
};
}

export default { use, t, i18n };
2 changes: 1 addition & 1 deletion packages/design-system/src/mixins/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { t } from '../locale';

export default {
methods: {
t(path: string, options: object) {
t(path: string, options: string[]) {
return t.call(this, path, options);
},
},
Expand Down
7 changes: 0 additions & 7 deletions packages/design-system/src/shims-types.d.ts

This file was deleted.

13 changes: 10 additions & 3 deletions packages/design-system/src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
declare module '*.vue' {
import Vue from 'vue';
export default Vue;
export {};

/**
* @docs https://vuejs.org/guide/typescript/options-api.html#augmenting-global-properties
*/

declare module 'vue' {
interface ComponentCustomProperties {
$style: Record<string, string>;
}
}
8 changes: 5 additions & 3 deletions packages/design-system/src/types/form.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { N8nLocaleTranslateFnOptions } from 'n8n-design-system/types/i18n';

export type Rule = { name: string; config?: unknown };

export type RuleGroup = {
rules: Array<Rule | RuleGroup>;
defaultError?: { messageKey: string; options?: unknown };
defaultError?: { messageKey: string; options?: N8nLocaleTranslateFnOptions };
};

export type Validatable = string | number | boolean | null | undefined;
Expand All @@ -13,8 +15,8 @@ export type IValidator<T = unknown> = {
config: T,
) =>
| false
| { message: string; options?: unknown }
| { messageKey: string; options?: unknown }
| { message: string; options?: N8nLocaleTranslateFnOptions }
| { messageKey: string; options?: N8nLocaleTranslateFnOptions }
| null;
};

Expand Down
4 changes: 3 additions & 1 deletion packages/design-system/src/types/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type N8nLocaleTranslateFn = (path: string, options: object) => string;
export type N8nLocaleTranslateFnOptions = string[] | Record<string, unknown>;

export type N8nLocaleTranslateFn = (path: string, options?: N8nLocaleTranslateFnOptions) => string;

export type N8nLocale = Record<string, string | ((...args: unknown[]) => string)>;
23 changes: 0 additions & 23 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,6 @@ export type EndpointStyle = {
hoverMessage?: string;
};

export type EndpointMeta = {
__meta?: {
nodeName: string;
nodeId: string;
index: number;
totalEndpoints: number;
endpointLabelLength: number;
};
};

export interface IUpdateInformation<T extends NodeParameterValueType = NodeParameterValueType> {
name: string;
key?: string;
Expand Down Expand Up @@ -410,19 +400,6 @@ export interface IExecutionResponse extends IExecutionBase {
executedNode?: string;
}

export interface IExecutionShortResponse {
id: string;
workflowData: {
id: string;
name: string;
};
mode: WorkflowExecuteMode;
finished: boolean;
startedAt: Date;
stoppedAt: Date;
executionTime?: number;
}

export interface IExecutionsListResponse {
count: number;
results: ExecutionSummary[];
Expand Down
20 changes: 19 additions & 1 deletion packages/editor-ui/src/__tests__/data/projects.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { faker } from '@faker-js/faker';
import type { ProjectListItem, ProjectSharingData, ProjectType } from '@/types/projects.types';
import type {
Project,
ProjectListItem,
ProjectSharingData,
ProjectType,
} from '@/types/projects.types';
import { ProjectTypes } from '@/types/projects.types';

export const createProjectSharingData = (projectType?: ProjectType): ProjectSharingData => ({
Expand All @@ -19,3 +24,16 @@ export const createProjectListItem = (projectType?: ProjectType): ProjectListIte
updatedAt: faker.date.recent().toISOString(),
};
};

export function createTestProject(data: Partial<Project>): Project {
return {
id: faker.string.uuid(),
name: faker.lorem.words({ min: 1, max: 3 }),
createdAt: faker.date.past().toISOString(),
updatedAt: faker.date.recent().toISOString(),
type: 'team',
relations: [],
scopes: [],
...data,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { EnvironmentVariable } from '@/Interface';

export const variableFactory = Factory.extend<EnvironmentVariable>({
id(i: number) {
return i;
return `${i}`;
},
key() {
return `${faker.lorem.word()}`.toUpperCase();
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/api/eventbus.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function deleteDestinationFromDb(context: IRestApiContext, destinat
export async function sendTestMessageToDestination(
context: IRestApiContext,
destination: ApiMessageEventBusDestinationOptions,
) {
): Promise<boolean> {
const data: IDataObject = {
...destination,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/api/nodeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type {
INodePropertyOptions,
INodeTypeDescription,
INodeTypeNameVersion,
ResourceMapperFields,
} from 'n8n-workflow';
import axios from 'axios';
import type { ResourceMapperFields } from 'n8n-workflow/src/Interfaces';

export async function getNodeTypes(baseUrl: string) {
const { data } = await axios.get(baseUrl + 'types/nodes.json', { withCredentials: true });
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/api/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
} from '@/Interface';
import { get } from '@/utils/apiUtils';

function stringifyArray(arr: number[]) {
function stringifyArray(arr: string[]) {
return arr.join(',');
}

Expand Down Expand Up @@ -41,7 +41,7 @@ export async function getCollections(

export async function getWorkflows(
apiEndpoint: string,
query: { page: number; limit: number; categories: number[]; search: string },
query: { page: number; limit: number; categories: string[]; search: string },
headers?: RawAxiosRequestHeaders,
): Promise<{
totalWorkflows: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ export default defineComponent({

this.credentialData = {
...this.credentialData,
scopes,
scopes: scopes as unknown as CredentialInformation,
OlegIvaniv marked this conversation as resolved.
Show resolved Hide resolved
homeProject,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</template>

<script lang="ts">
import type { ICredentialsResponse, IUser, IUserListAction } from '@/Interface';
import type { ICredentialsResponse, IUserListAction } from '@/Interface';
import { defineComponent } from 'vue';
import type { PropType } from 'vue';
import { useMessage } from '@/composables/useMessage';
Expand All @@ -87,7 +87,7 @@ import ProjectSharing from '@/components/Projects/ProjectSharing.vue';
import { useProjectsStore } from '@/stores/projects.store';
import type { ProjectListItem, ProjectSharingData, Project } from '@/types/projects.types';
import { ProjectTypes } from '@/types/projects.types';
import type { ICredentialDataDecryptedObject } from 'n8n-workflow';
import type { ICredentialDataDecryptedObject, IDataObject } from 'n8n-workflow';
import type { PermissionsMap } from '@/permissions';
import type { CredentialScope } from '@n8n/permissions';
import type { EventBus } from 'n8n-design-system/utils';
Expand Down Expand Up @@ -157,22 +157,37 @@ export default defineComponent({
credentialOwnerName(): string {
return this.credentialsStore.getCredentialOwnerNameById(`${this.credentialId}`);
},
credentialDataHomeProject(): ProjectSharingData | undefined {
const credentialContainsProjectSharingData = (
data: ICredentialDataDecryptedObject,
): data is { homeProject: ProjectSharingData } => {
return 'homeProject' in data;
};

return this.credentialData && credentialContainsProjectSharingData(this.credentialData)
? this.credentialData.homeProject
: undefined;
},
isCredentialSharedWithCurrentUser(): boolean {
return (this.credentialData.sharedWithProjects ?? []).some((sharee: IUser) => {
return sharee.id === this.usersStore.currentUser?.id;
return (
Array.isArray(this.credentialData.sharedWithProjects)
? this.credentialData.sharedWithProjects
: []
).some((sharee) => {
return typeof sharee === 'object' && 'id' in sharee
? sharee.id === this.usersStore.currentUser?.id
: false;
OlegIvaniv marked this conversation as resolved.
Show resolved Hide resolved
});
},
projects(): ProjectListItem[] {
return this.projectsStore.personalProjects.filter(
(project) =>
project.id !== this.credential?.homeProject?.id &&
project.id !== this.credentialData?.homeProject?.id,
project.id !== this.credentialDataHomeProject?.id,
);
},
homeProject(): ProjectSharingData | undefined {
return (
this.credential?.homeProject ?? (this.credentialData?.homeProject as ProjectSharingData)
);
return this.credential?.homeProject ?? this.credentialDataHomeProject;
},
isHomeTeamProject(): boolean {
return this.homeProject?.type === ProjectTypes.Team;
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/components/HoverableNodeIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div
:class="$style.wrapper"
:style="iconStyleData"
@click="(e) => $emit('click')"
@click="() => $emit('click')"
@mouseover="showTooltip = true"
@mouseleave="showTooltip = false"
>
Expand Down Expand Up @@ -126,7 +126,7 @@ export default defineComponent({

const restUrl = this.rootStore.getRestUrl;

if (nodeType.icon) {
if (nodeType.icon && typeof nodeType.icon === 'string') {
OlegIvaniv marked this conversation as resolved.
Show resolved Hide resolved
const [type, path] = nodeType.icon.split(':');
const returnData: NodeIconData = {
type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ const isWorkflowHistoryButtonDisabled = computed(() => {
return isNewWorkflow.value;
});

const workflowTagIds = computed(() => {
return (props.workflow.tags ?? []).map((tag) => (typeof tag === 'string' ? tag : tag.id));
});

watch(
() => props.workflow.id,
() => {
Expand Down Expand Up @@ -601,7 +605,7 @@ function showCreateWorkflowSuccessToast(id?: string) {
<TagsContainer
v-else
:key="workflow.id"
:tag-ids="workflow.tags"
:tag-ids="workflowTagIds"
:clickable="true"
:responsive="true"
data-test-id="workflow-tags"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ function onSelected(item: INodeCreateElement) {

const icon = item.properties.iconUrl
? `${baseUrl}${item.properties.iconUrl}`
: item.properties.icon?.split(':')[1];
: typeof item.properties.icon === 'string'
? item.properties.icon?.split(':')[1]
: undefined;

const transformedActions = nodeActions?.map((a) =>
transformNodeType(a, item.properties.displayName, 'action'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const mockSimplifiedNodeType = (
): SimplifiedNodeType => ({
displayName: 'Sample DisplayName',
name: 'sampleName',
icon: 'sampleIcon',
icon: 'fa:sampleIcon',
iconUrl: 'https://example.com/icon.png',
group: ['group1', 'group2'],
description: 'Sample description',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { useI18n } from '@/composables/useI18n';
import { useKeyboardNavigation } from './useKeyboardNavigation';

import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import type { INodeInputFilter, NodeConnectionType } from 'n8n-workflow';
import type { INodeInputFilter, NodeConnectionType, Themed } from 'n8n-workflow';
import { useCanvasStore } from '@/stores/canvas.store';

interface ViewStack {
Expand All @@ -48,7 +48,7 @@ interface ViewStack {
info?: string;
nodeIcon?: {
iconType?: string;
icon?: string;
icon?: Themed<string>;
color?: string;
};
iconUrl?: string;
Expand Down
Loading
Loading