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

Cockpit CMS source #194

Closed
wants to merge 19 commits into from
Closed

Cockpit CMS source #194

wants to merge 19 commits into from

Conversation

tanc
Copy link
Member

@tanc tanc commented Feb 15, 2019

A first pass at a Cockpit source. To resolve:

  • Readme file
  • Fix repeater fields
  • References

Repeater fields are currently the main issue. In Cockpit there is a 'repeater' field type which allows the admin to have a single repeating field which can be of any given types. So you could have a 'content section' field which allows an editor add one or multiple instances of the field in their content. When the editor adds an instance they can choose from a selection of different fields (selection configured by admin).

Using this source, at the moment if you have a repeater field made up of two (or more) different field types, only the first field type is added in Gridsome.

I haven't tested reference fields at all.

packages/source-cockpit/index.js Outdated Show resolved Hide resolved
packages/source-cockpit/index.js Outdated Show resolved Hide resolved
@tanc
Copy link
Member Author

tanc commented Feb 21, 2019

@hjvedvik have modified to allow the JSON field on any top level repeater field. Nested repeater fields inside set fields will not get picked up but I think this is a slightly unusual situation and one we can tackle later. A nested repeater with only one field type allowed is fine anyway and Gridsome will automatically handle that.

@tanc
Copy link
Member Author

tanc commented Feb 22, 2019

Have fixed repeater fields, added/processed reference fields and added a README.

This is now ready for review and merging.

packages/source-cockpit/index.js Outdated Show resolved Hide resolved
packages/source-cockpit/index.js Outdated Show resolved Hide resolved
@hjvedvik
Copy link
Member

Just tested the plugin and seems like it works pretty good. Good job :)

The fetch method has a limit at 1000 items and it fetches the first page. Maybe the method should also check if there are more items to fetch?

@tanc
Copy link
Member Author

tanc commented Feb 25, 2019

@hjvedvik thanks for the review 👍 I've added paged fetches with a config option to specify the limit (default is 1000).

@tanc
Copy link
Member Author

tanc commented Feb 25, 2019

Do you know how to fix the lint error? Is it a case of adding Gridsome as a dependency to package.json

@hjvedvik
Copy link
Member

You can try to add "gridsome": "0.x" as a peerDependency.

@tanc
Copy link
Member Author

tanc commented Feb 26, 2019

ok, now its ready to merge!

@tanc
Copy link
Member Author

tanc commented Feb 26, 2019

Slightly frustrated by peer dependencies as yarn install now reports:

@gridsome/source-cockpit@0.0.0" has unmet peer dependency "camelcase@5.x.x"

I guess this is because camelcase is a dependency of the gridsome package rather than the top level. So I've added camelcase as a dependency of this plugin.

@tanc
Copy link
Member Author

tanc commented Mar 2, 2019

I've just added localized field support so translated fields will be pulled into GraphQL on the same node as the originals.

@hjvedvik
Copy link
Member

hjvedvik commented Apr 4, 2019

Great work @tanc :) Do you think the localization will work with how Gridsome is now, or would it require changes in core?

@robaxelsen robaxelsen requested a review from hjvedvik April 7, 2019 16:12

## API limit

You can also set a limit per request if you have thousands of collections or assets and want to pull in a paged set of results. To do this set the `APILIMIT` environment variable, for example: │
Copy link
Member

Choose a reason for hiding this comment

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

Why, there's a pipe | too far from the text.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just a typo, can be removed

@jasonday
Copy link

jasonday commented Jul 2, 2019

Is there a timeline for when this will be merged?

@smokeyfro
Copy link
Contributor

Hi team :) I've been testing this extensively over the past couple days and it's working great. The only catch that is holding me back from pushing the update is the fact the source is not merged or available on NPM, so Netlify has no way of installing it at build. Is there anything I can help with to get this merged into the core? After testing all the different headless cms that work with Gridsome, Cockpit is by far the one I'm most excited about. Keep up the great work!

@u12206050
Copy link
Contributor

Might be better as its own discussion but, Isn't it better to have source plugins in their own repos than being so tightly dependent on the core?

@smokeyfro
Copy link
Contributor

Might be better as its own discussion but, Isn't it better to have source plugins in their own repos than being so tightly dependent on the core?

Yeah, I'd think as a separate NPM module would make the most sense. That way development can continue independently from the main project.

Either way I'm super duper chuffed it's coming :D

@tanc
Copy link
Member Author

tanc commented Aug 13, 2019

@hjvedvik I realise I didn't answer your question about the localization working without changes in core... yes, it will work without changes in core :-) You can see it (kind of) working on this work in progress site: https://rockriders.tanc.me/en/mtb
When flicking between Italian and English the menu items change and the page contents changes. It's very rough and ready at the moment. It relies on the pages API to provide variants for languages, which means the same component is used but on a different language-prefixed path:

api.createPages(async ({ graphql, createPage }) => {
  const { data } = await graphql(`{
    allCockpitPage {
      edges {
        node {
          id
          path
        }
      }
    }
  }`)

  data.allCockpitPage.edges.forEach(({ node }) => {
    for (const code of languages) {
      createPage({
        path: `/${code}${node.path}`,
        component: './src/templates/CockpitPage.vue',
        context: {
          id: node.id,
          lang: code
        }
      })
    }
  })

Any thoughts on whether you want to merge this plugin with core or whether I should spin up a separate repository and publish it? There is a bit of interest in it now so would be good to have a way for people to use it more easily.

@hjvedvik
Copy link
Member

@tanc We plan to have localized fields in the schema when we start working on the i18n feature. Localized fields will be an object with each property matching a language code. And the GraphQL resolver will automatically pick the value from the current language while executing the query. I'm not sure when we will implement it yet. So we can publish this plugin as it is now and do a breaking change to support localized fields when that time comes. Or what do you think?

@u12206050 Yes, I agree. We might move source plugins to their own repositories sometime soon.

@smokeyfro
Copy link
Contributor

Hi Tanc,

I'm trying to show related items from another collection using a collection link field type in Cockpit and belongsTo in my query, but struggling to get it to work. @hjvedvik tried to assist, but it seems like the collections link is not being handled correctly by the plugin. Is there anything on my end I need to do to get the collections linking properly?

@tanc
Copy link
Member Author

tanc commented Sep 2, 2019

Sorry I'm away on holiday for a couple of weeks so won't be able to help for a while

@a-kriya
Copy link

a-kriya commented Oct 26, 2019

Does not look like @tanc has had any public activity on GH for the last couple months, and this PR looks like it's been in a fairly good state since March. Can it be considered to publish the work here for now, and resolve the issue with collection link field type mentioned by @smokeyfro above in a later patch? Any other alternative to make this work easier to consume?

@Tummerhore
Copy link

Any news on this, @tanc, @hjvedvik? I would absolutely love to see this as a plugin.

@tanc
Copy link
Member Author

tanc commented Jun 29, 2020

I've been on sabbatical and not really engaged with tech for a while (bliss!) but I'm needing to build some sites so I'm back. I've spun this off into it's own repo and published it on NPM: https://www.npmjs.com/package/@tanc00/gridsome-source-cockpit

I'll close this pull request and we can continue fixing and developing here: https://github.com/tanc/gridsome-cockpit-source

@tanc tanc closed this Jun 29, 2020
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.

None yet

9 participants