luci-base: reimplement the add method of CBIJSONConfig#8347
Open
emzet wants to merge 1 commit intoopenwrt:masterfrom
Open
luci-base: reimplement the add method of CBIJSONConfig#8347emzet wants to merge 1 commit intoopenwrt:masterfrom
emzet wants to merge 1 commit intoopenwrt:masterfrom
Conversation
a14a31b to
d1704cb
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d1704cb to
fa3977b
Compare
This comment has been minimized.
This comment has been minimized.
fix the calculation of section_id in the add method of CBIJSONConfig Signed-off-by: Marek Zavacky <zavacky.m@gmail.com>
fa3977b to
c94fb37
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug in the calculation of
section_idin theaddmethod ofCBIJSONConfigwhen using nested sections (subsections).When using the JSONMap, data are retrieved via a JSON file or a custom JS object. Internally, the object is converted into a UCI-like format. Its top-level keys are treated as UCI section types, while the object or array-of-object values are treated as section content.
Section types are stored in the main
dataobject withkey:valuepairs (just plain JS object). Keys are generated during init method and stored in a flat structure. Indexing increments globally, regardless of the section type.The problem in the original code occurred when using nested sections, e.g., a
GridSectioninside anotherGridSection. In this case, adding a new section (via the UI "add" button) would compute the wrongsection_id, causing it to always return the last section instead of creating a new blank one.Changes in this PR fixes this problem:
next_indextomax_indexto make its purpose clearernext_indexis now computed by incrementing themax_indexfound in data, regardless of section typenum_sections_typeas it is no longer usednext_indexvalue is now used both for creating thesection_idand as the value of.index, ensuring uniqueness