Skip to content

Commit

Permalink
Feat: Add possibility to translate the workflow texts
Browse files Browse the repository at this point in the history
  • Loading branch information
rboixaderg committed Jan 25, 2024
1 parent 0f6913b commit 5cb31f8
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.26.0
------
- Feat: Add possibility to translate the workflow texts

0.25.2
------
- feat: use label property to render info in search inputs and to sort elements
Expand Down
6 changes: 3 additions & 3 deletions e2e/cypress/integration/gmi-type-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,15 @@ LOGIN_TYPES.forEach((loginType) => {
)

// Modify workflow
cy.findByText(/Current state: private/)
cy.findByText(/Current state: Private/)
cy.findByText('Publish').click()
cy.findByText('Confirm').click()
cy.get(NOTIFICATION_SELECTOR).should('contain', `Great status changed!`)
cy.findByText(/Current state: public/)
cy.findByText(/Current state: Public/)
cy.findByText('Retire').click()
cy.findByText('Confirm').click()
cy.get(NOTIFICATION_SELECTOR).should('contain', `Great status changed!`)
cy.findByText(/Current state: private/)
cy.findByText(/Current state: Private/)

// Upload multiple image
cy.get(`[data-test='formMultiimageOrderedAttachmentTest']`).within(() => {
Expand Down
8 changes: 7 additions & 1 deletion e2e/vite_example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from guillotina import configure

from guillotina_react_app.workflow import guillotina_basic_with_translations

app_settings = {
"commands": {
"populate": "guillotina_react_app.commands.populate.PopulateData",
},
"workflows": {"guillotina_basic_with_translations": guillotina_basic_with_translations},
"workflows_content": {
"guillotina_react_app.gmi.interface.IGMI": "guillotina_basic",
"guillotina_react_app.gmi.interface.IGMI": "guillotina_basic_with_translations",
"guillotina_react_app.gmi.interface.IGMIBehaviors": "guillotina_simple",
},
}
Expand All @@ -21,3 +22,4 @@ def includeme(root):
configure.scan("guillotina_react_app.vocabularies")
configure.scan("guillotina_react_app.gmi")
configure.scan("guillotina_react_app.gmi_behaviors")
configure.scan("guillotina_react_app.workflow")
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
guillotina_basic_with_translations = {
"initial_state": "private",
"states": {
"private": {
"metadata": {
"title": "Private",
"translated_title": {
"en": "Private",
"ca": "Privat",
"es": "Privado",
},
},
"actions": {
"publish": {
"title": "Publish",
"metadata": {
"translated_title": {
"en": "Publish",
"ca": "Publicar",
"es": "Publicar",
},
},
"to": "public",
"check_permission": "guillotina.ReviewContent",
}
},
"set_permission": {
"roleperm": [
{
"setting": "Deny",
"role": "guillotina.Anonymous",
"permission": "guillotina.ViewContent",
},
{
"setting": "Deny",
"role": "guillotina.Anonymous",
"permission": "guillotina.AccessContent",
},
{
"setting": "Deny",
"role": "guillotina.Anonymous",
"permission": "guillotina.SearchContent",
},
]
},
},
"public": {
"metadata": {
"title": "Public",
"translated_title": {
"en": "Public",
"ca": "Públic",
"es": "Público",
},
},
"actions": {
"retire": {
"title": "Retire",
"metadata": {
"translated_title": {
"en": "Retire",
"ca": "Retirar",
"es": "Retirar",
},
},
"to": "private",
"check_permission": "guillotina.ReviewContent",
},
},
"set_permission": {
"roleperm": [
{
"setting": "AllowSingle",
"role": "guillotina.Anonymous",
"permission": "guillotina.ViewContent",
},
{
"setting": "AllowSingle",
"role": "guillotina.Anonymous",
"permission": "guillotina.AccessContent",
},
{
"setting": "AllowSingle",
"role": "guillotina.Anonymous",
"permission": "guillotina.SearchContent",
},
]
},
},
},
}
2 changes: 1 addition & 1 deletion guillotina_example/guillotina_react_app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
guillotina==7.0.0
guillotina==7.0.2
pillow==9.5
45 changes: 41 additions & 4 deletions src/guillo-gmi/components/behaviors/iworkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { Confirm } from '../modal'
import { useCrudContext } from '../../hooks/useCrudContext'
import { ItemModel } from '../../models'
import { defineMessages, useIntl } from 'react-intl'

import { useVocabulary } from '../../hooks/useVocabulary'
import { get } from '../../lib/utils'
const messages = defineMessages({
status_changed_ok: {
id: 'status_changed_ok',
Expand Down Expand Up @@ -36,6 +37,7 @@ export function IWorkflow() {
const [definition, setDefinition] = React.useState(undefined)
const [workflowAction, setWorkflowAction] = React.useState(null)
const model = new ItemModel(Ctx.context)
const vocabulary = useVocabulary('workflow_states')
const currentState =
model.item['guillotina.contrib.workflows.interfaces.IWorkflowBehavior'][
'review_state'
Expand Down Expand Up @@ -72,6 +74,35 @@ export function IWorkflow() {
Ctx.refresh()
setWorkflowAction(null)
}
const getStateTitle = () => {
console.log('getStateTitle', vocabulary)
if (vocabulary.data?.items?.length > 0) {
const vocabularyValue = vocabulary.data.items.find(
(item) => item.token === currentState
)
console.log('state title', vocabularyValue, intl.locale)
if (vocabularyValue) {
const translatedValue = get(
vocabularyValue,
`title.translated_title.${intl.locale}`,
null
)
if (translatedValue !== null) {
return translatedValue
}
const titleValue = get(
vocabularyValue,
`title.title.${intl.locale}`,
null
)
if (titleValue !== null) {
return titleValue
}
}
}
return currentState
}
console.log('Workflow log')
if (definition === undefined) return null

return (
Expand All @@ -92,10 +123,12 @@ export function IWorkflow() {
className="has-text-weight-bold"
data-test={`textInfoStatus-${currentState}`}
>
{intl.formatMessage(messages.current_state, { state: currentState })}
{intl.formatMessage(messages.current_state, {
state: getStateTitle(),
})}
</div>
</div>
{modifyContent && (
{modifyContent && definition.transitions.length > 0 && (
<div
className=" is-flex is-align-items-center has-text-weight-bold"
data-test={`textInfoStatus-${currentState}`}
Expand All @@ -112,7 +145,11 @@ export function IWorkflow() {
)
}
>
{transition.title}
{get(
transition,
`metadata.translated_title.${intl.locale}`,
transition.title
)}
</button>
)
})}
Expand Down
1 change: 0 additions & 1 deletion src/guillo-gmi/components/fields/renderField.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export const SearchRenderField = ({ schema, value, modifyContent }) => {
}, [value])

const getRenderValue = () => {
console.log('get render values', value, valuesLabels)
if (value === undefined) {
if (modifyContent) {
return DEFAULT_VALUE_EDITABLE_FIELD
Expand Down

0 comments on commit 5cb31f8

Please sign in to comment.