From 144ee586285ca6a22fba6d5e5201779b26b97423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Boixader=20G=C3=BCell?= Date: Mon, 8 Jan 2024 08:32:35 +0100 Subject: [PATCH 1/3] chore: gitignore, logs --- .gitignore | 4 +++- e2e/vite_example/src/App.tsx | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index db5a0fc..00b5868 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,6 @@ e2e/example/.next # Guillotina .python-version *.egg-info -__pycache__ \ No newline at end of file +__pycache__ + +.vscode \ No newline at end of file diff --git a/e2e/vite_example/src/App.tsx b/e2e/vite_example/src/App.tsx index 6c81d70..8d1de09 100644 --- a/e2e/vite_example/src/App.tsx +++ b/e2e/vite_example/src/App.tsx @@ -127,7 +127,6 @@ function App() { return null } - console.log('language', navigator.language) return ( From c4ce6124a240b4956a907b99a850877b915069cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Boixader=20G=C3=BCell?= Date: Mon, 8 Jan 2024 08:32:58 +0100 Subject: [PATCH 2/3] fix: render vocabulary field, error hooks --- .../components/fields/renderField.js | 73 +++++++++++++------ src/guillo-gmi/components/index.js | 1 + 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/guillo-gmi/components/fields/renderField.js b/src/guillo-gmi/components/fields/renderField.js index 7517388..1d2e3c1 100644 --- a/src/guillo-gmi/components/fields/renderField.js +++ b/src/guillo-gmi/components/fields/renderField.js @@ -1,15 +1,16 @@ import React from 'react' import { DownloadField } from './downloadField' +import { useIntl } from 'react-intl' import { useVocabulary } from '../../hooks/useVocabulary' import { get } from '../../lib/utils' -import { useIntl } from 'react-intl' + const plain = ['string', 'number', 'boolean'] -export function RenderField({ value, Widget }) { +export function RenderField({ value, Widget, schema }) { if (value === null || value === undefined) return '' if (Widget) { - return + return } const type = typeof value @@ -40,13 +41,52 @@ const FieldValue = ({ field, value }) => ( ) -export function RenderFieldComponent({ schema, field, val, modifyContent }) { - const intl = useIntl() - const DEFAULT_VALUE_EDITABLE_FIELD = intl.formatMessage({ +const DEFAULT_VALUE_NO_EDITABLE_FIELD = ' -- ' +const getDefaultValueEditableField = (intl) => { + return intl.formatMessage({ id: 'default_value_editable_field', defaultMessage: 'Click to edit', }) - const DEFAULT_VALUE_NO_EDITABLE_FIELD = ' -- ' +} + +export const VocabularyRenderField = ({ schema, value, modifyContent }) => { + const intl = useIntl() + const DEFAULT_VALUE_EDITABLE_FIELD = getDefaultValueEditableField(intl) + + const vocabularyName = schema?.items?.vocabularyName || schema?.vocabularyName + const vocabulary = useVocabulary(vocabularyName) + + const getRenderProps = () => { + const renderProps = { + value: + value ?? + (modifyContent + ? DEFAULT_VALUE_EDITABLE_FIELD + : DEFAULT_VALUE_NO_EDITABLE_FIELD), + } + + if (schema?.vocabularyName) { + const vocabularyValue = get(vocabulary, 'data.items', []).find( + (item) => item.token === value + ) + renderProps['value'] = vocabularyValue?.title ?? '' + } else { + renderProps['value'] = (renderProps['value'] ?? []).map((value) => { + return ( + get(vocabulary, 'data.items', []).find((item) => item.token === value) + ?.title ?? '' + ) + }) + } + + return renderProps + } + return +} + +export function RenderFieldComponent({ schema, field, val, modifyContent }) { + const intl = useIntl() + const DEFAULT_VALUE_EDITABLE_FIELD = getDefaultValueEditableField(intl) const getRenderProps = () => { const renderProps = { @@ -67,23 +107,8 @@ export function RenderFieldComponent({ schema, field, val, modifyContent }) { } else if (val && schema?.type === 'datetime') { renderProps['value'] = new Date(val).toLocaleString() } else if (schema?.items?.vocabularyName || schema?.vocabularyName) { - const vocabularyName = - schema?.items?.vocabularyName || schema?.vocabularyName - const vocabulary = useVocabulary(vocabularyName) - if (schema?.vocabularyName) { - const vocabularyValue = get(vocabulary, 'data.items', []).find( - (item) => item.token === val - ) - renderProps['value'] = vocabularyValue?.title ?? '' - } else { - renderProps['value'] = (renderProps['value'] ?? []).map((value) => { - return ( - get(vocabulary, 'data.items', []).find( - (item) => item.token === value - )?.title ?? '' - ) - }) - } + renderProps['Widget'] = VocabularyRenderField + renderProps['schema'] = schema } return renderProps diff --git a/src/guillo-gmi/components/index.js b/src/guillo-gmi/components/index.js index 2fdba3b..cd64220 100644 --- a/src/guillo-gmi/components/index.js +++ b/src/guillo-gmi/components/index.js @@ -17,6 +17,7 @@ export * from './input/dropdown' export * from './fields/editableField' export * from './fields/renderField' export * from './fields/downloadField' +export * from './fields/editComponent' export * from './behaviors/iattachment' export * from './behaviors/imultiattachment' From d198c0642e9d70a9674b43e26ae5738453a57a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Boixader=20G=C3=BCell?= Date: Mon, 8 Jan 2024 08:59:35 +0100 Subject: [PATCH 3/3] chore: version, changelog --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5ee058..b42291c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +0.24.1 +------ +- fix: Render vocabulary field + 0.24.0 ------ - feat: Implement and update some guillotina behaviors diff --git a/package.json b/package.json index bd3559e..d3e223c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.24.0", + "version": "0.24.1", "repository": { "type": "git", "url": "git@github.com:guillotinaweb/guillotina_react.git"