Skip to content

Commit

Permalink
Added note on using snake case for enum values
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Aug 6, 2021
1 parent ff21e07 commit 0e4c4d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions IHP/IDE/SchemaDesigner/View/EnumValues/New.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ instance View NewEnumValueView where
<label class="col-sm-2 col-form-label">Name:</label>
<div class="col-sm-10">
<input name="enumValueName" type="text" class="form-control" autofocus="autofocus"/>
<div class="invalid-feedback">It's highly recommended to use sneak case / underscores for naming your enum values</div>

This comment has been minimized.

Copy link
@fritzfeger

fritzfeger Aug 6, 2021

should be "snake case" instead of "sneak case"

This comment has been minimized.

Copy link
@mpscholten

mpscholten Aug 9, 2021

Author Member

Thanks :) Good catch, fixed via 4d1084d

<small class="text-muted">
Use underscores instead of camel case. E.g.: <code>public_user</code>, <code>in_progress</code>, <code>currency_eur</code>
</small>
</div>
</div>

Expand Down
21 changes: 21 additions & 0 deletions lib/IHP/static/IDE/ihp-schemadesigner.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ function initSchemaDesigner() {
$('label[data-attribute="' + $("#colName").val() +'"] > input').prop('checked', true);
$('input[name="referenceTable"]').val($('label[style="font-size: 12px;"]').data("table"));
});

initEnumValueNameSnakeCaseCheck();
}

function initCodeEditor() {
Expand Down Expand Up @@ -277,4 +279,23 @@ function setCheckboxSqlMode(id, sqlMode) {
altField.name = id + "-inactive";
checkBoxContainer.className = "form-control";
}
}

/** Shows a warning if a new enum value is going to be added that is not in snake case */
function initEnumValueNameSnakeCaseCheck() {
const input = document.querySelector('input[name="enumValueName"]');
if (!input) {
return;
}

input.onkeyup = event => {
const enumValueName = event.target.value;
const isCamelCase = /[A-Z]/.test(enumValueName)

if (isCamelCase) {
input.classList.add('is-invalid');
} else {
input.classList.remove('is-invalid');
}
}
}

0 comments on commit 0e4c4d7

Please sign in to comment.