Skip to content

Commit

Permalink
fix(editor): proper typings for node related translations
Browse files Browse the repository at this point in the history
  • Loading branch information
cstuncsik committed Nov 2, 2022
1 parent abaed57 commit ca52ee4
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions packages/editor-ui/src/plugins/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'n8n-design-system';

import englishBaseText from './locales/en.json';
import { INodeProperties } from "n8n-workflow";
import {INodeProperties, INodePropertyCollection, INodePropertyOptions} from "n8n-workflow";

Vue.use(VueI18n);
locale.use('en');
Expand Down Expand Up @@ -105,7 +105,7 @@ export class I18nClass {
* Display name for a top-level param.
*/
inputLabelDisplayName(
{ name: parameterName, displayName }: { name: string; displayName: string; },
{ name: parameterName, displayName }: Pick<INodeProperties, 'name' | 'displayName'>,
) {
if (['clientId', 'clientSecret'].includes(parameterName)) {
return context.dynamicRender({
Expand All @@ -124,32 +124,32 @@ export class I18nClass {
* Hint for a top-level param.
*/
hint(
{ name: parameterName, hint }: { name: string; hint?: string; },
{ name: parameterName, hint }: Pick<INodeProperties, 'name' | 'hint'>,
) {
return context.dynamicRender({
key: `${credentialPrefix}.${parameterName}.hint`,
fallback: hint || '',
fallback: hint ?? '',
});
},

/**
* Description (tooltip text) for an input label param.
*/
inputLabelDescription(
{ name: parameterName, description }: { name: string; description: string; },
{ name: parameterName, description }: Pick<INodeProperties, 'name' | 'description'>,
) {
return context.dynamicRender({
key: `${credentialPrefix}.${parameterName}.description`,
fallback: description,
fallback: description ?? '',
});
},

/**
* Display name for an option inside an `options` or `multiOptions` param.
*/
optionsOptionDisplayName(
{ name: parameterName }: { name: string; },
{ value: optionName, name: displayName }: { value: string; name: string; },
{ name: parameterName }: Pick<INodeProperties, 'name'>,
{ value: optionName, name: displayName }: Pick<INodePropertyOptions, 'value' | 'name'>,
) {
return context.dynamicRender({
key: `${credentialPrefix}.${parameterName}.options.${optionName}.displayName`,
Expand All @@ -161,24 +161,24 @@ export class I18nClass {
* Description for an option inside an `options` or `multiOptions` param.
*/
optionsOptionDescription(
{ name: parameterName }: { name: string; },
{ value: optionName, description }: { value: string; description: string; },
{ name: parameterName }: Pick<INodeProperties, 'name'>,
{ value: optionName, description }: Pick<INodePropertyOptions, 'value' | 'description'>,
) {
return context.dynamicRender({
key: `${credentialPrefix}.${parameterName}.options.${optionName}.description`,
fallback: description,
fallback: description ?? '',
});
},

/**
* Placeholder for a `string` param.
*/
placeholder(
{ name: parameterName, placeholder }: { name: string; placeholder?: string; },
{ name: parameterName, placeholder }: Pick<INodeProperties, 'name' | 'placeholder'>,
) {
return context.dynamicRender({
key: `${credentialPrefix}.${parameterName}.placeholder`,
fallback: placeholder || '',
fallback: placeholder ?? '',
});
},
};
Expand All @@ -199,7 +199,7 @@ export class I18nClass {
* Display name for an input label, whether top-level or nested.
*/
inputLabelDisplayName(
parameter: { name: string; displayName: string; type: string },
parameter: INodeProperties,
path: string,
) {
const middleKey = deriveMiddleKey(path, parameter);
Expand All @@ -214,14 +214,14 @@ export class I18nClass {
* Description (tooltip text) for an input label, whether top-level or nested.
*/
inputLabelDescription(
parameter: { name: string; description: string; type: string },
parameter: INodeProperties,
path: string,
) {
const middleKey = deriveMiddleKey(path, parameter);

return context.dynamicRender({
key: `${initialKey}.${middleKey}.description`,
fallback: parameter.description,
fallback: parameter.description ?? '',
});
},

Expand All @@ -236,7 +236,7 @@ export class I18nClass {

return context.dynamicRender({
key: `${initialKey}.${middleKey}.hint`,
fallback: parameter.hint || '',
fallback: parameter.hint ?? '',
});
},

Expand All @@ -247,7 +247,7 @@ export class I18nClass {
* - For a `collection` or `fixedCollection`, the placeholder is the button text.
*/
placeholder(
parameter: { name: string; placeholder?: string; type: string },
parameter: Pick<INodeProperties, 'name' | 'type' | 'placeholder'>,
path: string,
) {
let middleKey = parameter.name;
Expand All @@ -259,7 +259,7 @@ export class I18nClass {

return context.dynamicRender({
key: `${initialKey}.${middleKey}.placeholder`,
fallback: parameter.placeholder || '',
fallback: parameter.placeholder ?? '',
});
},

Expand All @@ -268,8 +268,8 @@ export class I18nClass {
* whether top-level or nested.
*/
optionsOptionDisplayName(
parameter: { name: string; },
{ value: optionName, name: displayName }: { value: string; name: string; },
parameter: Pick<INodeProperties, 'name'>,
{ value: optionName, name: displayName }: Pick<INodePropertyOptions, 'value' | 'name'>,
path: string,
) {
let middleKey = parameter.name;
Expand All @@ -290,8 +290,8 @@ export class I18nClass {
* whether top-level or nested.
*/
optionsOptionDescription(
parameter: { name: string; },
{ value: optionName, description }: { value: string; description: string; },
parameter: Pick<INodeProperties, 'name'>,
{ value: optionName, description }: Pick<INodePropertyOptions, 'value' | 'description'>,
path: string,
) {
let middleKey = parameter.name;
Expand All @@ -303,7 +303,7 @@ export class I18nClass {

return context.dynamicRender({
key: `${initialKey}.${middleKey}.options.${optionName}.description`,
fallback: description,
fallback: description ?? '',
});
},

Expand All @@ -313,8 +313,8 @@ export class I18nClass {
* be nested in a `collection` or in a `fixedCollection`.
*/
collectionOptionDisplayName(
parameter: { name: string; },
{ name: optionName, displayName }: { name: string; displayName: string; },
parameter: Pick<INodeProperties, 'name'>,
{ name: optionName, displayName }: Pick<INodePropertyCollection, 'name' | 'displayName'>,
path: string,
) {
let middleKey = parameter.name;
Expand All @@ -335,7 +335,7 @@ export class I18nClass {
* `fixedCollection` param having `multipleValues: true`.
*/
multipleValueButtonText(
{ name: parameterName, typeOptions}: INodeProperties,
{ name: parameterName, typeOptions}: Pick<INodeProperties, 'name' | 'typeOptions'>,
) {
return context.dynamicRender({
key: `${initialKey}.${parameterName}.multipleValueButtonText`,
Expand Down

0 comments on commit ca52ee4

Please sign in to comment.