From 990f837aaf436f389908746a0536a00beef08350 Mon Sep 17 00:00:00 2001 From: Maximilian Harz Date: Thu, 6 Feb 2025 12:22:38 +0100 Subject: [PATCH] Use radash.get to support deep properties in ProfileTextView --- package-lock.json | 14 ++++++++++++-- package.json | 1 + .../Profile/Subcomponents/ProfileTextView.tsx | 16 +++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index e8914733..a7b9022b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "leaflet": "^1.9.4", "leaflet.locatecontrol": "^0.79.0", "prop-types": "^15.8.1", + "radash": "^12.1.0", "react-colorful": "^5.6.1", "react-image-crop": "^10.1.8", "react-leaflet": "^4.2.1", @@ -6094,8 +6095,9 @@ }, "node_modules/lodash": { "version": "4.17.21", - "dev": true, - "license": "MIT" + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true }, "node_modules/lodash.camelcase": { "version": "4.3.0", @@ -8226,6 +8228,14 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/radash": { + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/radash/-/radash-12.1.0.tgz", + "integrity": "sha512-b0Zcf09AhqKS83btmUeYBS8tFK7XL2e3RvLmZcm0sTdF1/UUlHSsjXdCcWNxe7yfmAlPve5ym0DmKGtTzP6kVQ==", + "engines": { + "node": ">=14.18.0" + } + }, "node_modules/react": { "version": "18.3.1", "license": "MIT", diff --git a/package.json b/package.json index a9a903f0..9d048a8a 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,7 @@ "leaflet": "^1.9.4", "leaflet.locatecontrol": "^0.79.0", "prop-types": "^15.8.1", + "radash": "^12.1.0", "react-colorful": "^5.6.1", "react-image-crop": "^10.1.8", "react-leaflet": "^4.2.1", diff --git a/src/Components/Profile/Subcomponents/ProfileTextView.tsx b/src/Components/Profile/Subcomponents/ProfileTextView.tsx index a9604a69..9fc35bbb 100644 --- a/src/Components/Profile/Subcomponents/ProfileTextView.tsx +++ b/src/Components/Profile/Subcomponents/ProfileTextView.tsx @@ -1,10 +1,12 @@ +import { get } from 'radash' + import { TextView } from '#components/Map' import type { Item } from '#types/Item' export const ProfileTextView = ({ item, - dataField, + dataField = 'text', heading, hideWhenEmpty, }: { @@ -13,15 +15,19 @@ export const ProfileTextView = ({ heading: string hideWhenEmpty: boolean }) => { + const text = get(item, dataField) + + if (typeof text !== 'string') { + throw new Error('ProfileTextView: text is not a string') + } + return (
- {/* eslint-disable-next-line security/detect-object-injection */} - {!(item[dataField] === '' && hideWhenEmpty) && ( + {!(text === '' && hideWhenEmpty) && (

{heading}

)}
- {/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, security/detect-object-injection */} - +
)