From 5d0c1f94a13401b93681dfdb1fbde2e3045ee95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20de=20Juvigny?= <8087692+remidej@users.noreply.github.com> Date: Wed, 18 Sep 2024 05:49:14 -0400 Subject: [PATCH] fix: history fields width (#21313) * fix: history field width * fix: relations to admin:user are not fetched correctly * fix: do not link to admin users from history relation input * fix: apply shadow none everywhere --------- Co-authored-by: Alexandre Bodin --- .../src/history/components/VersionContent.tsx | 11 ++++++++-- .../components/VersionInputRenderer.tsx | 22 ++++++++++++------- .../server/src/history/services/history.ts | 12 +++++++--- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/packages/core/content-manager/admin/src/history/components/VersionContent.tsx b/packages/core/content-manager/admin/src/history/components/VersionContent.tsx index cb26b9afbb..9b64338fb6 100644 --- a/packages/core/content-manager/admin/src/history/components/VersionContent.tsx +++ b/packages/core/content-manager/admin/src/history/components/VersionContent.tsx @@ -109,7 +109,7 @@ const FormPanel = ({ panel }: { panel: EditFieldLayout[][] }) => { return ( - + @@ -132,7 +132,14 @@ const FormPanel = ({ panel }: { panel: EditFieldLayout[][] }) => { {row.map(({ size, ...field }) => { return ( - + ); diff --git a/packages/core/content-manager/admin/src/history/components/VersionInputRenderer.tsx b/packages/core/content-manager/admin/src/history/components/VersionInputRenderer.tsx index 236dbdec38..8d404879bb 100644 --- a/packages/core/content-manager/admin/src/history/components/VersionInputRenderer.tsx +++ b/packages/core/content-manager/admin/src/history/components/VersionInputRenderer.tsx @@ -7,7 +7,7 @@ import { useField, Form, } from '@strapi/admin/strapi-admin'; -import { Alert, Box, Field, Flex, Link, Tooltip } from '@strapi/design-system'; +import { Alert, Box, Field, Flex, Link, Tooltip, Typography } from '@strapi/design-system'; import { useIntl } from 'react-intl'; import { NavLink } from 'react-router-dom'; import { styled } from 'styled-components'; @@ -40,7 +40,7 @@ import type { RelationResult } from '../../services/relations'; import type { Schema } from '@strapi/types'; import type { DistributiveOmit } from 'react-redux'; -const StyledAlert = styled(Alert).attrs({ closeLabel: 'Close', onClose: () => {} })` +const StyledAlert = styled(Alert).attrs({ closeLabel: 'Close', onClose: () => {}, shadow: 'none' })` button { display: none; } @@ -107,12 +107,14 @@ const CustomRelationInput = (props: RelationsFieldProps) => { {results.map((relationData) => { // @ts-expect-error - targetModel does exist on the attribute. But it's not typed. - const href = `../${COLLECTION_TYPES}/${props.attribute.targetModel}/${relationData.documentId}`; + const { targetModel } = props.attribute; + const href = `../${COLLECTION_TYPES}/${targetModel}/${relationData.documentId}`; const label = getRelationLabel(relationData, props.mainField); + const isAdminUserRelation = targetModel === 'admin::user'; return ( { justifyContent="space-between" > - - - {label} - + + {isAdminUserRelation ? ( + {label} + ) : ( + + {label} + + )} diff --git a/packages/core/content-manager/server/src/history/services/history.ts b/packages/core/content-manager/server/src/history/services/history.ts index f979578be7..0282a6c449 100644 --- a/packages/core/content-manager/server/src/history/services/history.ts +++ b/packages/core/content-manager/server/src/history/services/history.ts @@ -64,6 +64,7 @@ const createHistoryService = ({ strapi }: { strapi: Core.Strapi }) => { const entryWithRelations = await Object.entries(entry.schema).reduce( async (currentDataWithRelations, [attributeKey, attributeSchema]) => { const attributeValue = entry.data[attributeKey]; + const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue]; @@ -105,9 +106,14 @@ const createHistoryService = ({ strapi }: { strapi: Core.Strapi }) => { return null; } - return strapi - .query('admin::user') - .findOne({ where: { id: userToPopulate.id } }); + return strapi.query('admin::user').findOne({ + where: { + ...(userToPopulate.id ? { id: userToPopulate.id } : {}), + ...(userToPopulate.documentId + ? { documentId: userToPopulate.documentId } + : {}), + }, + }); }) );