-
Notifications
You must be signed in to change notification settings - Fork 22
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
Singleton with translations #6
Comments
So technically the problem is that when translating documents you are creating new ones, which conflicts with the whole singleton thing. However I did find a way around it as follows:
Some explanation to this: Let me know if this works for you! |
Thanks for getting back to me on this issue. The solution you propose is essentially the same as the default option. It is still possible to create multiple of the singleton doc and the user has to click through a secondary document list of one item. I'm trying to avoid the list view completely so clicking the content type leads directly to the page. I understand why this tricky with the intl plugin, but singletons are a very standard part of all our projects so I'll need to keep looking for a solution. Thanks again for the help |
@jdwillemse No you can still only create the one with the fixed ID (aka singleton) because the "Create new" action is fixed to the ID with this structure. However I am aware it is slightly more cumbersome. I am talking to some guys at Sanity regarding conflicts with custom desk structure but have not been able to find a resolution yet. |
@LiamMartens I'm trying to use it as you suggest up there (even though the extra pane for the single document is really weird/ugly), but I'm actually running into the issue of editor/translations-tabs not showing up on the singleton, even with your suggested solution. This is my deskStructure (the commented out part is how I would have included the singleton without the intl-plugin, ignore the base settings, these are non-i18n):
Since i18n works on other schemas in the same project and I'm using a global config with |
I guess the other way to do it is to nest all document fields into one object and throwing |
@LiamMartens @tom2strobl I am facing same issue where in, Translation tab disappears for article documents appearing 2 levels deep. Any pointers would be really helpful. PS: I have tried the approach given above but it somehow it didn't work for me.
|
I'm experiencing the same issue and I'm wondering what the solution is? Do we need to write (or overwrite) a custom component for nested objects like this? Any help pointing us in the right direction would be great @LiamMartens 👍 |
@saulhardman Sorry I have not been able to look into this deeper. I might have to update the component that's being used as it is most likely outdated according to updates Sanity has received now. I try to look at it this week. |
@ylokesh I need to have a look at this 😬 combining desk structures is a bit "hacky" at the moment Imo |
@LiamMartens no need to apologise – thanks for taking a look and let us know if there's any way we can help out. |
@ylokesh you also have the |
@tom2strobl very late answer but in your case I believe it is because of your |
@saulhardman I published a beta version |
Hi @LiamMartens, thank you very much 👍 I'll try that version out and get back to you. |
Hey @LiamMartens, just following up to confirm that the updates you made in |
Good to know @saulhardman that it works well for you! Can you share your solution in this thread please? Also, @LiamMartens it would be great to have some documentation on this use case in the documentation, as I feel it is a very common use case. |
This isn't exactly what you asked for but here's what my // deskStructure.js
import S from '@sanity/desk-tool/structure-builder'
import * as Structure from 'sanity-plugin-intl-input/lib/structure'
import SocialPreview from 'part:social-preview/component'
// import { toPlainText } from 'part:social-preview/utils'
import { BiCookie } from '@hacknug/react-icons/bi'
import {
RiTranslate, RiFileLine, RiFolderShieldLine, RiFileDownloadLine,
RiBriefcaseLine, RiArticleLine, RiUserLine, RiPriceTagLine, RiLayoutBottomLine, RiSettingsLine,
} from '@hacknug/react-icons/ri'
const pagesItems = [
{ title: 'Home', id: 'frontpage', schema: 'frontpage' },
{ title: 'About Us', id: 'about', schema: 'about' },
{ title: 'Blog', id: 'blog', schema: 'blog' },
{ title: 'Contact', id: 'contact', schema: 'contact' },
]
export const getDefaultDocumentNode = (props) => {
return (![
...pagesItems.map(({ schema }) => schema),
'blogPost', 'blogAuthor', 'blogTag',
].includes(props.schemaType))
? S.document()
: S.document().views([
...Structure.getDocumentNodeViewsForSchemaType(props.schemaType),
S.view.component(SocialPreview({
prepareFunction: ({ seo }) => ({
title: seo?.seo_text,
description: seo?.seo_desc,
ogImage: seo?.seo_image,
siteUrl: 'https://www.example.com',
}),
})).title('Social & SEO'),
])
}
export default () => {
const items = Structure.getFilteredDocumentTypeListItems()
const getLocalizedPosts = (type) => items.find((item) => [type].includes(item.spec.id)).getChild()
return S.list().title('Content').items([
...pagesItems.map(({ id, title, schema, icon = RiFileLine }) => {
return S.listItem().title(`${title} Page`).icon(icon).child(getLocalizedPosts(schema))
}),
S.divider(),
S.listItem().title('Blog Articles').icon(RiArticleLine).child(getLocalizedPosts('blogPost')),
S.listItem().title('Blog Authors').icon(RiUserLine).child(getLocalizedPosts('blogAuthor')),
S.listItem().title('Blog Tags').icon(RiPriceTagLine).child(getLocalizedPosts('blogTag')),
S.divider(),
S.listItem().title('Site Settings').icon(RiSettingsLine)
.child(S.document().schemaType('siteSettings').documentId('siteSettings').title('Site Settings')),
S.divider(),
items[0].title('Translation Manager').icon(RiTranslate),
])
} It doesn't keep the whole singleton implementation but it is okay in my case. I also ended up leaving these Only reason for this is I didn't manage to make everything work while keeping the same structure. The current implementation made it easy to keep everything I had in place pretty much the same so that's a win if you ask me. |
Hi @LiamMartens is there any update on this one? I'm using version There is a related issue on the sanity repo which seems relevant. Thanks! |
I'm trying to combine this plugin with the setup for singleton document described here. When I do this the translation tab disappears across all documents. I'm using document level translations.
Assuming the settings document needs to be translated too, how do I rewrite this to make it work?
The text was updated successfully, but these errors were encountered: