Skip to content

Enhancement: Option for single-entry data files #406

Description

@michaeltlombardi

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions