Skip to content

Commit

Permalink
refactor(cc-env-var-create)!: change property mode to validationMode
Browse files Browse the repository at this point in the history
  • Loading branch information
pdesoyres-cc committed Feb 15, 2024
1 parent c8243a4 commit 264208b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
17 changes: 9 additions & 8 deletions src/components/cc-env-var-create/cc-env-var-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { linkStyles } from '../../templates/cc-link/cc-link.js';

/**
* @typedef {import('../common.types.js').Variable} Variable
* @typedef {import('../common.types.js').EnvVarValidationMode} EnvVarValidationMode
*/

/**
Expand All @@ -28,7 +29,7 @@ export class CcEnvVarCreate extends LitElement {
static get properties () {
return {
disabled: { type: Boolean },
mode: { type: String },
validationMode: { type: String, attribute: 'validation-mode' },
variablesNames: { type: Array, attribute: 'variables-names' },
_variableName: { type: String, state: true },
_variableValue: { type: String, state: true },
Expand All @@ -41,8 +42,8 @@ export class CcEnvVarCreate extends LitElement {
/** @type {boolean} Sets `disabled` attribute on inputs and button. */
this.disabled = false;

/** @type {string} Sets the mode of the variables name validation. */
this.mode = '';
/** @type {EnvVarValidationMode} Sets the mode of the variables name validation. */
this.validationMode = 'simple';

/** @type {string[]} Sets list of existing variables names (so we can display an error if it already exists). */
this.variablesNames = [];
Expand Down Expand Up @@ -74,7 +75,7 @@ export class CcEnvVarCreate extends LitElement {
value: this._variableValue,
});
this.reset();
// Put focus back on name input so we can add something else directly
// Put focus back on name input, so we can add something else directly
this.shadowRoot.querySelector('cc-input-text.name').focus();
}

Expand All @@ -90,7 +91,7 @@ export class CcEnvVarCreate extends LitElement {
const isNameInvalidSimple = !validateName(this._variableName, 'simple');
const isNameInvalidStrict = !validateName(this._variableName, 'strict');
const isNameAlreadyDefined = this.variablesNames.includes(this._variableName);
const hasErrors = (this.mode === 'strict')
const hasErrors = (this.validationMode === 'strict')
? isNameInvalidStrict || isNameAlreadyDefined
: isNameInvalidSimple || isNameAlreadyDefined;

Expand Down Expand Up @@ -128,21 +129,21 @@ export class CcEnvVarCreate extends LitElement {
</div>
</div>
${(isNameInvalidStrict && this.mode === 'strict' && this._variableName !== '') ? html`
${(isNameInvalidStrict && this.validationMode === 'strict' && this._variableName !== '') ? html`
<cc-notice intent="warning">
<div slot="message">
${i18n(`cc-env-var-create.errors.invalid-name`, { name: this._variableName })}
</div>
</cc-notice>
` : ''}
${(isNameInvalidStrict && isNameInvalidSimple && this.mode !== 'strict' && this._variableName !== '') ? html`
${(isNameInvalidStrict && isNameInvalidSimple && this.validationMode !== 'strict' && this._variableName !== '') ? html`
<cc-notice intent="warning">
<div slot="message">
${i18n(`cc-env-var-create.errors.invalid-name`, { name: this._variableName })}
</div>
</cc-notice>
` : ''}
${(isNameInvalidStrict && !isNameInvalidSimple && this.mode !== 'strict' && this._variableName !== '') ? html`
${(isNameInvalidStrict && !isNameInvalidSimple && this.validationMode !== 'strict' && this._variableName !== '') ? html`
<cc-notice intent="info">
<div slot="message">
${i18n(`cc-env-var-create.info.java-prop`, { name: this._variableName })}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const validationWithExistingNames = makeStory(conf, {
});

export const validationWithStrictMode = makeStory(conf, {
items: [{ mode: 'strict' }],
items: [{ validationMode: 'strict' }],
});

export const disabled = makeStory(conf, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class CcEnvVarEditorSimple extends LitElement {
${!this.readonly ? html`
<cc-env-var-create
?disabled=${skeleton || this.disabled}
mode=${this.mode}
.validationMode=${this.mode}
.variablesNames=${variablesNames}
@cc-env-var-create:create=${this._onCreate}
></cc-env-var-create>
Expand Down
7 changes: 4 additions & 3 deletions src/components/common.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ interface Flavor {
export interface Variable {
name: string;
value: string;
isNew?: boolean;
isDeleted?: boolean;
isEdited?: boolean;
}

export interface IconModel {
Expand Down Expand Up @@ -172,9 +175,7 @@ interface ParseError {
isWarning: Boolean;
}

interface ParserOptions {
mode: string;
}
type EnvVarValidationMode = 'simple' | 'strict';

interface Service {
name: string;
Expand Down

0 comments on commit 264208b

Please sign in to comment.