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

Enhancement: Option for single-entry data files #406

Closed
michaeltlombardi opened this issue Sep 10, 2022 · 2 comments
Closed

Enhancement: Option for single-entry data files #406

michaeltlombardi opened this issue Sep 10, 2022 · 2 comments
Labels
enhancement New feature or request Project: v8.2.0

Comments

@michaeltlombardi
Copy link

Is your feature request related to a problem? Please describe.

Some of the data in my site is organized into folders where each file is a different object. I do this because each object can be fairly large on its own, and I find this easier to reason about/review/track. The data dashboard only allows me to define data files that are arrays of the defined type.

Take for example this configuration (simplified, my actual schema and data is longer):

"frontMatter.data.folders": [
  {
    "id": "Testable",
    "path": "[[workspace]]/data/tests",
    "labelField": "name",
    "schema": {
      "title": "Test Files",
      "type": "object",
      "properties": {
        "name": {
          "title": "Entry Name",
          "type": "string"
        },
        "example": {
          "title": "Example data",
          "type": "string"
        }
      }
    }
  }
]

And the data file I want:

name: This is a shortened example.
example: |
  This is a long and busy bunch of text,
  many lines. Normally, there's several
  other properties here too, so the data
  for a single entry might be 150+ lines
  long.

Describe the solution you'd like

I would like an additional key, perhaps flat (to not conflict with the existing single for strings) which would mark a data folder (or file) as a single object, not an array of objects.

For example:

"frontMatter.data.folders": [
  {
    "id": "Testable",
    "path": "[[workspace]]/data/tests",
    "labelField": "name",
    "flat": true,
    "schema": {
      "title": "Test Files",
      "type": "object",
      "properties": {
        "name": {
          "title": "Entry Name",
          "type": "string"
        },
        "example": {
          "title": "Example data",
          "type": "string"
        }
      }
    }
  }
]

Describe alternatives you've considered

Instead of requiring an additional key, omitting labelField could mark a file as being flat/a single object. I like this less since it isn't as clear/explicit and could be confusing for users.

It could also be implemented to require that data files define their schema as an array of objects, but that would break backwards compatibility and be worse DevX I think, since the list behavior is probably the default expectation.

Additional context

Another use case for this, beyond my specific data files, would be configuration files. Config files are typically single objects too. That would allow me to schematize and provide a UI for updating the configuration files in my project.

@estruyf
Copy link
Owner

estruyf commented Sep 27, 2022

Named the new property singleEntry as that makes it a bit clearer. When this is added to folder or file level, you can expect the data dashboard to load the file as follows:

Screenshot 2022-09-27 at 13 09 37

Example configuration:

{
	"frontMatter.data.files": [
	    {
	      "id": "singleEntry",
	      "title": "Single entry",
	      "file": "[[workspace]]/data/single-entry.json",
	      "labelField": "name",
	      "singleEntry": true,
	      "schema": {
	        "title": "Test Files",
	        "type": "object",
	        "properties": {
	          "name": {
	            "title": "Entry Name",
	            "type": "string"
	          },
	          "example": {
	            "title": "Example data",
	            "type": "string"
	          }
	        }
	      }
	    }
	],
	"frontMatter.data.folders": [
    {
      "id": "Testable",
      "path": "[[workspace]]/data/tests",
      "labelField": "name",
      "singleEntry": true,
      "schema": {
        "title": "Test Files",
        "type": "object",
        "properties": {
          "name": {
            "title": "Entry Name",
            "type": "string"
          },
          "example": {
            "title": "Example data",
            "type": "string"
          }
        }
      }
    }
  ]
}

PS: Available to test out in the latest beta version.

@michaeltlombardi
Copy link
Author

@estruyf tested on my primary site and it works a treat!

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

No branches or pull requests

2 participants