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

🔥 Clean up forked repository #2781 #2783

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCallback, useState } from 'react'
import { type DocumentActionComponent, type SanityDocument, useClient } from 'sanity'
import DeleteTranslationDialog from './components/DeleteTranslationDialog'
import DeleteTranslationFooter from './components/DeleteTranslationFooter'
import { useDocumentInternationalizationContext } from '@equinor/document-internationalization'
import { useDocumentInternationalizationContext } from '@sanity/document-internationalization'
import { apiVersion } from '../../sanity.client'
import { defaultLanguage } from '../../languages'
import { Patch, Transaction } from '@sanity/client'
Expand Down
2 changes: 1 addition & 1 deletion sanityv3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@equinor/eds-icons": "^0.17.0",
"@reach/auto-id": "^0.18.0",
"@sanity/asset-utils": "^1.3.0",
"@equinor/document-internationalization": "^3.0.0",
"@sanity/document-internationalization": "^3.3.1",
"@sanity/client": "^6.15.14",
"@sanity/cross-dataset-duplicator": "^1.3.0",
"@sanity/icons": "^2.11.8",
Expand Down
13 changes: 12 additions & 1 deletion sanityv3/sanity.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { schemaTypes } from './schemas'
import { initialValueTemplates } from './initialValueTemplates'
import { CharCounterEditor } from './schemas/components/CharCounterEditor'
import { DeleteTranslationAction } from './actions/customDelete/DeleteTranslationAction'
import { documentInternationalization } from '@equinor/document-internationalization'
import { documentInternationalization } from '@sanity/document-internationalization'
import { FotowareAssetSource } from './plugins/asset-source-fotoware'
import { BrandmasterAssetSource } from './plugins/asset-source-brandmaster'
import { SetAndPublishAction } from './actions/CustomPublishAction'
Expand All @@ -41,6 +41,7 @@ import { LangBadge } from './schemas/components/LangBadge'
import './customStyles.css'
import { partialStudioTheme } from './studioTheme'
import { copyAction } from './actions/fieldActions/CustomCopyFieldAction'
import CustomDocumentInternationalizationMenu from './schemas/components/CustomDocumentInternationalizationMenu'

export const customTheme = buildLegacyTheme(partialStudioTheme)

Expand Down Expand Up @@ -114,6 +115,16 @@ const getConfig = (datasetParam: string, projectIdParam: string, isSecret = fals
templates: (prev: Template<any, any>[]) => [...filterTemplates(prev), ...initialValueTemplates],
},
document: {
unstable_languageFilter: (prev: DocumentActionComponent[], ctx: any) => {
const { schemaType, documentId } = ctx
return schemaTypes.map((it) => it.name).includes(schemaType) && documentId
? [
(props: any) => {
return CustomDocumentInternationalizationMenu({ ...props, documentId })
},
]
: prev
},
actions: (prev: DocumentActionComponent[], context: any) => {
if (isSecret) prev.push(ResetCrossDatasetToken)
if (i18n.schemaTypes.includes(context.schemaType)) prev.push(DeleteTranslationAction)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
DocumentInternationalizationMenu,
DocumentInternationalizationMenuProps,
} from '@sanity/document-internationalization'

import { useEffect, useRef } from 'react'
import { Role, useCurrentUser } from 'sanity'

export default function CustomDocumentInternationalizationMenu(props: DocumentInternationalizationMenuProps) {
const parentRef = useRef(null)
// Get current user
const currentUser = useCurrentUser()

const enableManageTranslation = currentUser?.roles.some((role: Role) =>
['administrator', 'developer'].includes(role.name),
)
useEffect(() => {
if (parentRef.current) {
const targetNode = document.querySelector('[data-portal]')
// Create a MutationObserver instance
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'childList') {
const buttons = targetNode?.querySelectorAll('button')
if (buttons && buttons?.length > 1 && buttons[0].innerText == 'Manage Translations') {
buttons[0].disabled = !enableManageTranslation || true
buttons[0].setAttribute('data-disabled', enableManageTranslation ? 'false' : 'true')
}
}
})
})

if (targetNode)
// Start observing the target element
observer.observe(targetNode, {
childList: true, // Watch for text/content changes
})
}
}, [])
return <div ref={parentRef}>{DocumentInternationalizationMenu(props)}</div>
}
Loading