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

Skip load config.yml config #1866

Closed

Conversation

LoicMahieu
Copy link
Contributor

Summary

I would like to make config more "programmable". Collections may comes from functions, uses reusable fields etc...

With this PR, we'll be able to specify config only by JS with a manual init.

@verythorough
Copy link
Contributor

verythorough commented Nov 9, 2018

Deploy preview for netlify-cms-www ready!

Built with commit 59340ad

https://deploy-preview-1866--netlify-cms-www.netlify.com

@LoicMahieu LoicMahieu force-pushed the feature/bootstrap-config branch 2 times, most recently from accc5ed to 39acd47 Compare November 9, 2018 16:04
@talves
Copy link
Collaborator

talves commented Nov 9, 2018

Can you explain with an example of what it changes? Not sure I am following how your change improves the current process.

Specifically, I want to make sure we are not breaking current functionality. Also want to see what it adds also.

@LoicMahieu
Copy link
Contributor Author

@talves Sure! Sorry if it is not clear. Don't hesitate to take me back if it's still not.

My ambition is the declare the whole config in JS. Since whole config is loaded at init time, this is not necessary to load an empty config.yml.
Also it'll allow to not depends on this static file if the environment does not permit it.

Another thing is that configuration will be centralized in one file. If you use a "dynamic" backend configuration, for example, switch to different branch from environment variable, you will have a project like:

.
├── public
│   └── admin
│       └── config.yml
└── src
    └── cms
        └── cms.js

Configuration is split in 2 folders located at the opposite side of the project.


I want to use JS only for configuration because my collections are very similar and I would like to generate them from utilities functions:

const createFooCollection = (options) => ({ name: options.name, fields: ... })

@LoicMahieu LoicMahieu force-pushed the feature/bootstrap-config branch from 39acd47 to bc05701 Compare November 9, 2018 16:40
@verythorough
Copy link
Contributor

verythorough commented Nov 9, 2018

Deploy preview for cms-demo ready!

Built with commit 59340ad

https://deploy-preview-1866--cms-demo.netlify.com

@LoicMahieu LoicMahieu force-pushed the feature/bootstrap-config branch from bc05701 to bea25af Compare November 10, 2018 23:23
@@ -111,12 +106,15 @@ export function loadConfig() {
try {
const preloadedConfig = getState().config;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't believe this has a role any longer with the changes in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Surely, I confess that I can't say if it is still relevant. Do you confirm that we can remove this ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, passing bootstrapConfig into loadConfig supersedes the old preloadedConfig behavior, you can drop it.

@erquhart
Copy link
Contributor

@talves would you have time to give this a quick review?

@talves
Copy link
Collaborator

talves commented Nov 22, 2018

@erquhart isn't this still waiting for your requested changes?

@erquhart
Copy link
Contributor

He added commits to resolve those.

Sent with GitHawk

@talves
Copy link
Collaborator

talves commented Nov 22, 2018

#1866 (comment) has been resolved?

Sorry, I am not seeing a commit for it.

@erquhart
Copy link
Contributor

Ah, that one is just eliminating dead code, no actual impact on behavior.

Sent with GitHawk

@talves
Copy link
Collaborator

talves commented Nov 24, 2018

I just can't get my head around why we want to pass the bootstrapConfig object to the App component as a prop to make this change. We can already load a config using the import of init/bootstrap.

import React, { Component } from 'react';
import CMS, { init } from 'netlify-cms';

const config = {
  "backend": {
    "name": "test-repo"
  },
  "display_url": "https://example.com",
  "publish_mode": "editorial_workflow",
  "media_folder": "assets/uploads",
  "load_config_file": false,
  "collections": [
    {
      "name": "posts",
      "label": "Posts",
      "label_singular": "Post",
      "description": "The description is a great place for tone setting, high level information, and editing guidelines that are specific to a collection.\n",
      "folder": "_posts",
      "slug": "{{year}}-{{month}}-{{day}}-{{slug}}",
      "create": true,
      "fields": [
        {
          "label": "Title",
          "name": "title",
          "widget": "string",
          "tagname": "h1"
        },
        {
          "label": "Publish Date",
          "name": "date",
          "widget": "datetime",
          "dateFormat": "YYYY-MM-DD",
          "timeFormat": "HH:mm",
          "format": "YYYY-MM-DD HH:mm"
        }
      ]
    }
  ]
};

CMS.init = init;

class NetlifyCMS extends Component {
  componentDidMount () {
    CMS.init({config});
  }
  render() {
    return (
      <div id="nc-root" />
    );
  }
}

export default NetlifyCMS;

I do like the idea of ignoring the config.yml based on a flag in the init config, because we can avoid the error of a missing config.yml and request. I think we can do it with just the simple check proposed. The only change really needed is:

src/actions/config.js line 114 to:

const loadedConfig =
        preloadedConfig && preloadedConfig.load_config_file === false
          ? {}
          : await getConfig(configUrl, preloadedConfig && preloadedConfig.size > 1);

@erquhart
Copy link
Contributor

Really good point @talves, didn't even notice that. @LoicMahieu any thoughts on Tony's comment? We should remove any unnecessary changes to reduce risk.

@LoicMahieu LoicMahieu force-pushed the feature/bootstrap-config branch from cf3ace6 to 09ad3c3 Compare December 5, 2018 16:39
@LoicMahieu
Copy link
Contributor Author

LoicMahieu commented Dec 5, 2018

I just can't get my head around why we want to pass the bootstrapConfig object to the App component as a prop to make this change. We can already load a config using the import of init/bootstrap.

Indeed...

Really good point @talves, didn't even notice that. @LoicMahieu any thoughts on Tony's comment? We should remove any unnecessary changes to reduce risk.

I confess that I am lacking of time to refactor this changes in a new branch with only these "small" changes.
Furthermore, I don't think theses changes introduce a breaking change (but certainly should be released as minor). I agree that we should minimize the risk to break something but something, it is necessary to go ahead.

…-config

* official/master: (48 commits)
  docs: fix broken link to dev configuration file (decaporg#1941)
  docs: link releases to tag comparisons
  update release ticker
  Publish
  feat: add cloudinary support (decaporg#1932)
  fix(netlify-cms-core): duplicate key warning (decaporg#1930)
  Update image.md (decaporg#1923)
  chore(netlify-cms-core): upgrade react-frame-component to 4.x (decaporg#1925)
  chore(netlify-cms-core): upgrade gray-matter to 4.x (decaporg#1924)
  feat(netlify-cms-widget-select): add support for multiple selection (decaporg#1901)
  chore: improve publish scripts
  Publish
  chore: test before publishing
  chore(netlify-cms-core): upgrade react-dnd to 7.x (decaporg#1922)
  chore(netlify-cms-widget-text): upgrade to react-textarea-autosize 7.x (decaporg#1921)
  chore(netlify-cms-core): upgrade to react-waypoint 8.x (decaporg#1920)
  fix(backend): use singular label in custom commit message (decaporg#1917)
  docs: add GAE-specific oAuth client (decaporg#1918)
  fix(netlify-cms-widget-text): set correct font family (decaporg#1916)
  chore(netlify-cms-core): upgrade redux and related dependencies (decaporg#1914)
  ...
Copy link
Contributor

@erquhart erquhart left a comment

Choose a reason for hiding this comment

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

@talves after revisiting, this does seem a worthwhile improvement, especially considering our Netlify-CMS-as-a-component ambitions. It does include a breaking change, so considering just dropping as abandoned for now and revisiting in the future. What do you think?


/**
* Merge any existing configuration so the result can be validated.
*/
const mergedConfig = mergePreloadedConfig(preloadedConfig, loadedConfig);
const mergedConfig = mergePreloadedConfig(bootstrapConfig, loadedConfig, window.CMS_CONFIG);
Copy link
Contributor

@erquhart erquhart Feb 2, 2019

Choose a reason for hiding this comment

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

This is breaking, window.CMS_CONFIG currently overrides any other config loading if present.

@talves
Copy link
Collaborator

talves commented Feb 2, 2019

I agree.

Do you want me to send a PR to only do what I said in this comment, since it would not be a breaking change?

@erquhart
Copy link
Contributor

erquhart commented Feb 2, 2019

That'd be awesome 👍

@erquhart
Copy link
Contributor

erquhart commented Feb 5, 2019

Closing in favor of #2053.

@erquhart erquhart closed this Feb 5, 2019
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.

4 participants