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: Conditional UI for Metadata #362

Closed
estruyf opened this issue Jun 16, 2022 Discussed in #357 · 3 comments
Closed

Enhancement: Conditional UI for Metadata #362

estruyf opened this issue Jun 16, 2022 Discussed in #357 · 3 comments
Labels
enhancement New feature or request Project: v8.2.0
Projects

Comments

@estruyf
Copy link
Owner

estruyf commented Jun 16, 2022

Discussed in #357

Originally posted by bwklein June 13, 2022
I would like to show only the fields that are required based on some boolean or choice field selections.

For example, I have a 'Heading' partial that can either have text based title or a logo based heading.
I would like to allow the editor to choose if they want a text or logo based heading with a boolean choice like "Logo Heading?"

If true, then I would like to show them a Logo choice field and a string field for 'Classes' that they can pass in to style the logo. Essentially showing them a Field Group for the 'Logo' settings.

If false, then I would like to show the fieldgroup for the "Text" heading data.

Solution

{
	"title": "Logo Heading",
	"name": "logoHeading",
	"type": "string",
	"when": {
		"property": "heading",
		"operator": "eq",
		"value": true
	}
}
@michaeltlombardi
Copy link

Love this idea. Another use case for conditional metadata is when it applies only to section pages (for example, _index.md files for a hugo site).

estruyf added a commit that referenced this issue Nov 10, 2022
estruyf added a commit that referenced this issue Nov 12, 2022
@estruyf
Copy link
Owner Author

estruyf commented Nov 14, 2022

Good news @michaeltlombardi and @bwklein, this is now supported in the latest beta version.

Sample

{
  "title": "Description",
  "name": "description",
  "type": "string",
  "when": {
    "fieldRef": "title",
    "operator": "contains",
    "value": "website",
    "caseSensitive": false
  }
}

Important: By default it is case sensitive, if you want, you can turn this off by setting the caseSensitive property to false.

Operator

The following operators are supported:

type value
equals eq
notEquals neq
contains contains
notContains notContains
startsWith startsWith
endsWith endsWith
greaterThan gt
greaterThanOrEqual gte
lessThan lt
lessThanOrEqual lte

@estruyf estruyf added this to Planned in v8.2.0 via automation Nov 14, 2022
@estruyf estruyf added the enhancement New feature or request label Nov 14, 2022
@michaeltlombardi
Copy link

@estruyf I finally got some time to dig in today, looking to make the section-only metadata (in my case, controlling whether a section is collapsed or flattened in site navigation) conditional. I'm not savvy enough with the code base yet to follow things around properly, but I can intuitively see how this implementation works conditionally on other metadata fields - is there a way to reference the file name in this implementation?

I'm looking to make something like this work:

Example JSON Definition
{
  "name": "default",
  "$schema": "https://beta.frontmatter.codes/config/taxonomy.contenttypes.schema.json",
  "pageBundle": false,
  "fields": [
    {
      "title": "Platen",
      "type": "fields",
      "name": "Platen",
      "fields": [
        {
          "title": "Menu options",
          "name": "Menu",
          "type": "fields",
          "fields": [
            {
              "title": "Flatten section in site menu",
              "name": "FlattenSection",
              "type": "boolean",
              "when": {
                "fieldRef": "file.baseName",
                "operator": "eq",
                "value": "_index.md"
              }
            },
            {
              "title": "Collapse section in site menu",
              "name": "CollapseSection",
              "type": "boolean",
              "when": {
                "fieldRef": "file.baseName",
                "operator": "eq",
                "value": "_index.md"
              }
            },
            {
              "title": "Hide from site menu",
              "description": "Applicable to any page.",
              "name": "Hide",
              "type": "boolean"
            }
          ]
        }
      ]
    }
  ]
}

Where the Platen.Menu.Hide setting is available for any page but Platen.Menu.FlattenSection and Platen.Menu.CollapseSection are only visible/usable for section pages, which always have a file name of _index.md.

michaeltlombardi added a commit to michaeltlombardi/platen that referenced this issue Nov 24, 2022
This change adds the `toroidal` and `toroidal/admin` content types to
the Front Matter configuration so that site maintainers can edit the
metadata for those pages in a friendly UI.

For member pages and the admin page, this is fully functional. For the
webring index, this is limited currently by the implementation of
estruyf/vscode-front-matter#362, which introduces `where` logic for the
fields but doesn't yet support using that logic to control behavior
based on the file name, which would allow us to handle section pages
(which are always named `_index.md`) separately from member pages.

This change also updates the archetypes for Toroidal to set the
`type` to `toroidal` for the index and member pages, ensuring that
Front Matter picks up the type correctly for selecting the metadata to
display. Due to a limitation outlined in estruyf/vscode-front-matter#360
(see [this comment for more information][01]), we have to use `type` to
identify files. This has some implications for Hugo sites which don't
_directly_ impact this change.

[01]: estruyf/vscode-front-matter#360 (comment)
@estruyf estruyf moved this from Planned to In development in v8.2.0 Nov 28, 2022
@estruyf estruyf mentioned this issue Dec 8, 2022
@estruyf estruyf moved this from In development to Done in v8.2.0 Dec 8, 2022
@estruyf estruyf closed this as completed Dec 8, 2022
@estruyf estruyf closed this as completed Dec 8, 2022
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
No open projects
Development

No branches or pull requests

2 participants