From 4fdbf058bb805ffa37ee132177f2790c958bc672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Boixader=20G=C3=BCell?= Date: Sun, 14 Jan 2024 18:20:08 +0100 Subject: [PATCH 01/20] feat: Add inputs search to editComponent --- CHANGELOG.md | 4 + e2e/cypress/integration/gmi-type-content.js | 46 +++ .../guillotina_react_app/gmi/interface.py | 19 + package.json | 2 +- .../components/behaviors/iattachment.js | 12 +- .../components/behaviors/idublincore.js | 12 +- .../components/behaviors/iimageattachment.js | 9 +- .../components/behaviors/imultiattachment.js | 9 +- .../behaviors/imultiimageattachment.js | 9 +- .../components/fields/editComponent.js | 55 ++- .../components/fields/renderField.js | 83 ++++- .../components/input/search_input.js | 135 +++++-- .../components/input/search_input_list.js | 351 ++++++++++++++++++ src/guillo-gmi/components/panel/properties.js | 10 +- src/guillo-gmi/views/groups.js | 6 +- yarn.lock | 13 +- 16 files changed, 718 insertions(+), 57 deletions(-) create mode 100644 src/guillo-gmi/components/input/search_input_list.js diff --git a/CHANGELOG.md b/CHANGELOG.md index b42291c..877bc7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +0.25.0 +------ +- feat: Add inputs search to editComponent + 0.24.1 ------ - fix: Render vocabulary field diff --git a/e2e/cypress/integration/gmi-type-content.js b/e2e/cypress/integration/gmi-type-content.js index e2ab421..c99c423 100644 --- a/e2e/cypress/integration/gmi-type-content.js +++ b/e2e/cypress/integration/gmi-type-content.js @@ -57,6 +57,52 @@ LOGIN_TYPES.forEach((loginType) => { `[data-test='${TABS_PANEL_SELECTOS.prefixTabs}-properties']` ).click() + // Modify search item + cy.get( + `[data-test='${EDITABLE_FORM_SELECTORS.prefixEditableField}-brother_gmi']` + ).click() + cy.get(`[data-test='wrapperSearchInputTest']`).click() + cy.findByText('Test GMI item 9').click() + cy.findByText('Save').click() + cy.get(NOTIFICATION_SELECTOR).should( + 'contain', + `Field brother_gmi, updated!` + ) + cy.findByText('Test GMI item 9').click() + cy.get( + `[data-test='${EDITABLE_FORM_SELECTORS.prefixEditableField}-brother_gmi']` + ).click() + cy.get(`[data-test='wrapperSearchInputTest']`).click() + cy.findByText('Test GMI item 6').click() + cy.findByText('Save').click() + cy.get(NOTIFICATION_SELECTOR).should( + 'contain', + `Field brother_gmi, updated!` + ) + + // Modify search item list + cy.get( + `[data-test='${EDITABLE_FORM_SELECTORS.prefixEditableField}-gmi_ids']` + ).click() + cy.get(`[data-test='wrapperSearchInputTest']`).click() + cy.findByText('Test GMI item 9').click() + cy.findByText('Test GMI item 7').click() + cy.get(`[data-test='wrapperSearchInputTest']`).click() + cy.findByText('Save').click() + cy.get(NOTIFICATION_SELECTOR).should('contain', `Field gmi_ids, updated!`) + cy.findByText('Test GMI item 9') + cy.findByText('Test GMI item 7') + cy.get( + `[data-test='${EDITABLE_FORM_SELECTORS.prefixEditableField}-gmi_ids']` + ).click() + cy.findAllByText('Test GMI item 9').within(() => { + cy.get('button').click() + }) + cy.findByText('Save').click() + cy.get(NOTIFICATION_SELECTOR).should('contain', `Field gmi_ids, updated!`) + cy.findByText('Test GMI item 7') + cy.findByText('Test GMI item 9').should('not.exist') + // Upload file cy.get( `[data-test='${EDITABLE_FORM_SELECTORS.prefixEditableField}-file']` diff --git a/guillotina_example/guillotina_react_app/guillotina_react_app/gmi/interface.py b/guillotina_example/guillotina_react_app/guillotina_react_app/gmi/interface.py index d7adbe2..d09872a 100644 --- a/guillotina_example/guillotina_react_app/guillotina_react_app/gmi/interface.py +++ b/guillotina_example/guillotina_react_app/guillotina_react_app/gmi/interface.py @@ -73,3 +73,22 @@ class IGMI(interfaces.IFolder): ), missing_value=[] ) + + gmi_ids = schema.List( + title="GMI list", + value_type=schema.TextLine(), + default=[], + null=True, + blank=True, + widget="search_list", + labelProperty="title", + typeNameQuery="GMI", + ) + + brother_gmi = schema.Text( + title="Brother GMI", + widget="search", + typeNameQuery="GMI", + labelProperty="title", + required=False + ) diff --git a/package.json b/package.json index d3e223c..93d4125 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.24.1", + "version": "0.25.0", "repository": { "type": "git", "url": "git@github.com:guillotinaweb/guillotina_react.git" diff --git a/src/guillo-gmi/components/behaviors/iattachment.js b/src/guillo-gmi/components/behaviors/iattachment.js index 64b15e4..e9d361c 100644 --- a/src/guillo-gmi/components/behaviors/iattachment.js +++ b/src/guillo-gmi/components/behaviors/iattachment.js @@ -2,19 +2,27 @@ import React from 'react' import { useTraversal } from '../../contexts' import { EditableField } from '../fields/editableField' import { Table } from '../ui' +import { useIntl } from 'react-intl' +import { genericMessages } from '../../locales/generic_messages' export function IAttachment({ properties, values }) { + const intl = useIntl() const Ctx = useTraversal() const modifyContent = Ctx.hasPerm('guillotina.ModifyContent') return ( {Object.keys(properties).map((key) => ( - + - + - + - + - +
{key} + {key} + {Object.keys(properties).map((key) => (
{key} + {key} + {showConfirmToDelete && ( @@ -97,7 +100,9 @@ export function IImageAttachment({ properties, values }) { )} {values['image'] && (
{intl.formatMessage(genericMessages.image)} + {intl.formatMessage(genericMessages.image)} +
{fileKeyToDelete && ( @@ -84,7 +87,9 @@ export function IMultiAttachment({ properties, values }) { {Object.keys(values['files']).map((key) => (
{key} + {key} +
{fileKeyToDelete && ( @@ -110,7 +113,9 @@ export function IMultiImageAttachment({ properties, values }) { {Object.keys(values['images']).map((key) => (
{key} + {key} +
{ - if (schema?.widget === 'textarea' || schema?.widget === 'richtext') { + const traversal = useTraversal() + + if (schema?.widget === 'search_list') { + return ( + + {rest.placeholder && ( + + )} + setValue(ev)} + queryCondition={ + schema?.queryCondition ? schema.queryCondition : 'title__in' + } + dataTest={dataTest} + path={schema.queryPath} + labelProperty={ + schema?.labelProperty ? schema.labelProperty : 'title' + } + typeNameQuery={schema?.typeNameQuery ? schema.typeNameQuery : null} + {...rest} + /> + + ) + } else if (schema?.widget === 'search') { + return ( + + {rest.placeholder && ( + + )} + setValue(ev)} + queryCondition={ + schema?.queryCondition ? schema.queryCondition : 'title__in' + } + dataTest={dataTest} + path={schema.queryPath} + labelProperty={ + schema?.labelProperty ? schema.labelProperty : 'title' + } + typeNameQuery={schema?.typeNameQuery ? schema.typeNameQuery : null} + {...rest} + /> + + ) + } else if (schema?.widget === 'textarea' || schema?.widget === 'richtext') { return (