Skip to content

Commit

Permalink
Merge branch 'master' into migrate-to-typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
rboixaderg committed Jan 26, 2024
2 parents 20b7bf5 + e502969 commit 11d0436
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 13 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.

6 changes: 5 additions & 1 deletion e2e/vite_example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ function App() {
<Layout auth={auth} onLogout={onLogout}>
{isLogged && (
<Guillotina
locale={navigator.language || 'en'}
locale={
['ca', 'en', 'es'].includes(navigator.language)
? navigator.language
: 'en'
}
auth={auth}
url={currentSchema}
registry={{
Expand Down
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.25.2",
"version": "0.26.0",
"repository": {
"type": "git",
"url": "[email protected]:guillotinaweb/guillotina_react.git"
Expand Down
42 changes: 39 additions & 3 deletions src/guillo-gmi/components/behaviors/iworkflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ItemModel } from '../../models'
import { defineMessages, useIntl } from 'react-intl'
import { useEffect, useState } from 'react'

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 +38,7 @@ export function IWorkflow() {
const [definition, setDefinition] = useState(undefined)
const [workflowAction, setWorkflowAction] = 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 +75,33 @@ export function IWorkflow() {
Ctx.refresh()
setWorkflowAction(null)
}
const getStateTitle = () => {
if (vocabulary.data?.items?.length > 0) {
const vocabularyValue = vocabulary.data.items.find(
(item) => item.token === currentState
)
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
}

if (definition === undefined) return null

return (
Expand All @@ -92,10 +122,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 +144,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.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,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 11d0436

Please sign in to comment.