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

Composable Content Groups #369

Merged
merged 3 commits into from
May 17, 2019
Merged

Composable Content Groups #369

merged 3 commits into from
May 17, 2019

Conversation

dbaines
Copy link
Contributor

@dbaines dbaines commented May 15, 2019

What problem does this solve?

Creating more than one composable content section on a single record / view.
Say you want a composable content in a sidebar and another in the main area of the page.
This isn't currently possible without hacks or abusing the sectioning component

Current state

For reference, currently the composable config in the model looks like this:

composable: [
  :component_1,
  :component_2,
  :component_3,
]

And the output of the composable content JSON is similar:

components: [{
  component_type: "component_1",
  data: [{
    field1: value,
    field2: value,
  }]
}]

Introducing groups

Screen Shot 2019-05-15 at 4 06 19 pm

This change proposes a change to both the crud config and the output:

composable: {
  main: [
    :component_1,
    :component_2,
    :component_3,
  ],
  sidebar: [
    :component_2,
    :component_4,
    :component_5,
  ]
}
components: [{
  main: [{
    component_type: "component_1",
    data: [{
      field1: value,
      field2: value,
    }]
  }],
  sidebar: [{
    component_type: "component_5",
    data: [{
      field1: value,
    }]
  }]
}]

This change in structure will unfortunately mean it's a breaking change.

The code will assume all composable content will always have groups, so even if you aren't utilising groups, make sure you define a default group, eg. "main" or "default"
This will make the UI and implementation consistent and won't rely on hacks checking on whether groups exist or not

Once more than one group is detected, the UI of the composable content screen will update to show tabs to switch between content groups.
If you are only utilising a single group the UI will not change at all.

In your views you can now use composable_json(:main) and composable_data(:sidebar) to access your groups.
These flags also flow through to the existing composable_sections(:main) and composable_sections_with_drafts(:main)

…posableTypes` prop to `config` to better describe what it is, added `group` flag for composable view helpers, updated dummy app with base group
@dbaines dbaines requested a review from Obversity May 15, 2019 06:44
const composition = [ ...this.props.helpers.composition ];
composition[this.props.index].advanced = props.values;
const composition = { ...this.props.helpers.composition };
composition[this.props.helpers.group][this.props.index].advanced = props.values;
this.props.helpers.replaceComposition(composition);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot the code now reads helpers.group or this.state.group which is the current visible group. This means that there is no way to modify anything in a non-visible group. I can't think of any use-cases where a non-visible group would need to be updated (reorder, add item, remove item etc.) but something worth keeping in mind I guess.

@@ -8,7 +8,7 @@

<%= react_component("Composable", props: {
composition: value,
composableTypes: f.object.class.composable_config,
config: f.object.class.composable_config,
allComposableTypes: Koi::ComposableContent.components,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed composableTypes to config to better describe what it is

@dbaines dbaines merged commit d124346 into master May 17, 2019
@dbaines dbaines deleted the feature/composable-groups branch May 17, 2019 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant