mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
Try to type Item and getValue (WIP)
This commit is contained in:
parent
c9a66461e1
commit
f5b7b9267f
@ -1,11 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/restrict-plus-operands */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
/* eslint-disable @typescript-eslint/prefer-optional-chain */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
import { Children, isValidElement, useEffect, useState } from 'react'
|
||||
import { Marker, Tooltip } from 'react-leaflet'
|
||||
|
||||
@ -319,7 +314,7 @@ export const Layer = ({
|
||||
)}
|
||||
|
||||
<Tooltip offset={[0, -38]} direction='top'>
|
||||
{item.name ? item.name : getValue(item, itemNameField)}
|
||||
{item.name ? item.name : `${getValue(item, itemNameField)}`}
|
||||
</Tooltip>
|
||||
</Marker>
|
||||
)
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
export function getValue(obj, path) {
|
||||
import type { Item } from '#types/Item'
|
||||
|
||||
function getNestedValue(obj: Object, path: string) {
|
||||
re
|
||||
}
|
||||
|
||||
export function getValue(obj: Item | undefined, path: string): Item | string | undefined {
|
||||
if (!obj || typeof path !== 'string') return undefined
|
||||
|
||||
const pathArray = path.split('.') // Use a different variable for the split path
|
||||
for (let i = 0, len = pathArray.length; i < len; i++) {
|
||||
if (!obj) return undefined // Check if obj is falsy at each step
|
||||
// eslint-disable-next-line security/detect-object-injection
|
||||
obj = obj[pathArray[i]] // Dive one level deeper
|
||||
obj = obj[pathArray[i]] as Item // Dive one level deeper
|
||||
}
|
||||
return obj // Return the final value
|
||||
}
|
||||
|
||||
3
src/types/Item.d.ts
vendored
3
src/types/Item.d.ts
vendored
@ -24,8 +24,7 @@ export interface Item {
|
||||
slug?: string
|
||||
user_created?: UserItem
|
||||
image?: string
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
[key: string]: any
|
||||
group_type: string
|
||||
/* constructor(
|
||||
id: string,
|
||||
name: string,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user