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

Feature request: Object property / key selection #95

Open
acidMyke opened this issue Jul 22, 2024 · 5 comments
Open

Feature request: Object property / key selection #95

acidMyke opened this issue Jul 22, 2024 · 5 comments
Labels
enhancement New feature or request user request Requested by user

Comments

@acidMyke
Copy link

Hi CarlosNZ,

To provide easier selection of object properties.

I'm proposing a new prop restrictAddSelection, similar to restrictTypeSelection, where the user is given a dropdown, if prop is provided and if the data is object, to be able to select the appropriate key to add, instead of requiring user to type out the prop key.

My original plan is for this feature to merge with the existing restrictAdd prop but, after thinking it through, it will conflict with existing usage. In order for the dropdown to appear, restrictAddSelection needs to be called when the add input field is rendered, whereas restrictAdd is only called after the new key is added for validation. Do let me your opinion on this.

Possible Syntax:

type AddFilterFunction = (input: NodeData) => boolean | string[]
interface JsonEditorProps {
  //...
  restrictAddSelection?: boolean | string[] | AddFilterFunction
}

Mock-up:
add-dropdown-mockup

I could try to implement the feature if you don't mind.

Look forward to your response.

@CarlosNZ CarlosNZ added enhancement New feature or request user request Requested by user labels Jul 22, 2024
@CarlosNZ
Copy link
Owner

Hey, this sounds like a good idea. My only concern would be that it could be quite tedious to define a function to handle all the different possible options for different parts of the data structure if it's a reasonably complex one, but I guess it would be handy for smaller data sets.

I think I'd call it addPropertyOptions, or something like that, not totally sure yet.

I'll try and do this in the next couple of weeks, but feel free to make a start or post a PR if I haven't got to it soon enough.

(That reminds me, I should probably update the README with some info about setting up a dev environment -- let me know if you have any trouble with it)

@dreglad
Copy link

dreglad commented Nov 17, 2024

It’d be even better to work this by providing a JSON Schema instead of manual definitions. That way, it’d address @CarlosNZ’s concern about handling complex data structures and also add cool benefits like autocompletion.

@CarlosNZ
Copy link
Owner

It’d be even better to work this by providing a JSON Schema instead of manual definitions. That way, it’d address @CarlosNZ’s concern about handling complex data structures and also add cool benefits like autocompletion.

Yes, I agree. We can currently implement JSON schema validation fairly easily, so in a sense you can get this functionality after the fact (i.e. error if you add an illegal key).

I'm not sure I want to start adding a full JSON schema parser into this, so it'd be good to come up with a solution that allowed the requested suggestion without bloating the codebase. Integrating with existing tools (like we do for schema validation) would seem to be the approach to take, so I'll have a think about what's possible.

Suggestions welcome :)

@DameNianch
Copy link

Does the "select the appropriate key to add" function automatically assign values?
I'm having trouble with the new key becoming NULL value when I add it. I'm imitating the onUpdate validation in the demo source code. But I can't add a value because it's rejected by that validation.

@CarlosNZ
Copy link
Owner

I'm having trouble with the new key becoming NULL value when I add it. I'm imitating the onUpdate validation in the demo source code. But I can't add a value because it's rejected by that validation

I'm not totally clear what you're asking. Can you start a new issue with a bit more detail of your specific problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request user request Requested by user
Projects
None yet
Development

No branches or pull requests

4 participants