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

Check config on save #2346

Merged
merged 9 commits into from Jan 3, 2019
Merged

Check config on save #2346

merged 9 commits into from Jan 3, 2019

Conversation

bramkragten
Copy link
Member

@bramkragten bramkragten commented Dec 17, 2018

Warns when # is found, but can also be a color or anything with a # in a string...

@ghost ghost assigned bramkragten Dec 17, 2018
@ghost ghost added the in progress label Dec 17, 2018
@@ -118,13 +124,30 @@ class LovelaceFullConfigEditor extends hassLocalizeLitMixin(LitElement) {

private _handleSave() {
let value;
const text = this.textArea.value;

if (text.includes("#")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to change this to # (with a space), so we don't catch colors?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But # without space is also a comment, and we wouldn't warn... I think that's tricky...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a warning. I think it's fine to warn even if it's not truly a comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imagine having an extra warning every time you click save because you have a color? That's annoying.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True... idk... you're the boss 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set schema to FAILSAFE_SCHEMA ?

https://github.com/nodeca/js-yaml#safeload-string---options-

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so this is difficult. What about we show a warning below the editor if we notice any # . ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that meets every concern in the middle and has my vote

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not first get rid of all # within hex color codes using a regex #([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}) then throw a warning or error for any other #?


if (this._hashAdded) {
if (
!confirm(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we need to do this confirm because we're showing a warning?

}

private _yamlChanged() {
this._hash = this._hashAdded || this.textArea.value.includes("#");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should skip this. I think that it's perfect to only check if a user adds a hash. That way we don't have to worry about any colors that already exist.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem is when a user pastes something but might be an edge case (it is possible to check the pasted content but might be overkill...)

></paper-icon-button>
<div main-title>Edit Config</div>
${
this._hash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels a bit weird to put in the title. If there is not enough space (ie on mobile), it will look very weird. It also won't work as an element above the text area because showing it will push the whole textarea down, and that's annoying. Wonder if this should be a toast that's shown when entering a # character?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about a toast too but figured it should be close to the save button...

@balloob balloob merged commit 88d23eb into dev Jan 3, 2019
@ghost ghost removed the in progress label Jan 3, 2019
@delete-merged-branch delete-merged-branch bot deleted the check-config-save branch January 3, 2019 21:47
@balloob balloob mentioned this pull request Jan 9, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants