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

fix(plugins.js) : makes the config parameter 'withHeadings' works when data is empty #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

loic-bellinger
Copy link

@loic-bellinger loic-bellinger commented Sep 20, 2023

Noticed that the config parameter withHeadings was not properly working.

More precisely:

table: {
  class: Table,
  inlineToolbar: true,
  config: {
    withHeadings: true
  }
}

was not creating an empty table with headings.

So I made a fix. Tried to change as little code as possible (but I believe getConfig should be optimized further)

This PR #126 also tackles the issue

src/plugin.js Outdated Show resolved Hide resolved
src/plugin.js Outdated
if (data) {
return data[configName] ? data[configName] : defaultValue;
}
if (data && configName in data) return data[configName]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (data && configName in data) return data[configName]
if (data && configName in data) {
return data[configName]
}

Copy link
Author

Choose a reason for hiding this comment

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

I accepted this change (maybe adding a prettier to the project could avoid this kind of formatting stuffs)


return this.config && this.config[configName] ? this.config[configName] : defaultValue;
return this.config && this.config[configName] ? this.config[configName] : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

it will always return false event when there is no value in the config. I think it is not what is expected here. Why default value have been removed?

Copy link
Author

@loic-bellinger loic-bellinger Sep 23, 2023

Choose a reason for hiding this comment

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

Originally, getConfig() was called with defaultValue = false, as you can see here: this.getConfig('withHeadings', false, data)

  getConfig(configName, defaultValue = undefined, savedData = undefined) {
    const data = this.data || savedData;

    if (data) {
      return data[configName] ? data[configName] : defaultValue;
    }

    return this.config && this.config[configName] ? this.config[configName] : defaultValue;
  }

So the result remains the same: false is returned when none of the conditions are met (so technically there is still a default value, it has not been removed).

To provide more context:

I don't really understand the point of having a defaultValue parameter defaulting to undefined (notably because we'd like getConfig() to return a clear value for withHeadings - which should be a boolean according to the documentation) .

And since:

  • getConfig() is not used elsewhere
  • With the update I made to getConfig a default value is needed only once (versus 2 before)

I just get rid of defaultValue and made getConfig directly return false if none of the conditions are met.

Copy link
Author

@loic-bellinger loic-bellinger Oct 27, 2023

Choose a reason for hiding this comment

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

@neSpecc Any feedback on this issue?

* @param {object} savedData - previously saved data. If passed, the key will be got from there, otherwise from the config
* @returns {any} - config value.
*/
getConfig(configName, defaultValue = undefined, savedData = undefined) {
getConfig(configName, savedData = undefined) {
const data = this.data || savedData;
Copy link

@shcshcshc shcshcshc Nov 16, 2023

Choose a reason for hiding this comment

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

To achieve fixing config, I suggest not using this.data because getConfig is being used for making this.data.
and it works in my case.

Suggested change
const data = this.data || savedData;
const data = savedData;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants