small bugfix

This commit is contained in:
Anton Tranelis 2024-03-23 15:26:27 +01:00
parent 112b600f73
commit 6857a6352c
2 changed files with 17 additions and 12 deletions

View File

@ -1,18 +1,18 @@
import * as React from "react"
import { useEffect } from "react";
import { getValue } from "../../Utils/GetValue";
import { Item, ItemsApi } from "../../types";
import { Item } from "../../types";
import { useAssetApi } from "../AppShell/hooks/useAssets";
import { useHasUserPermission } from "../Map/hooks/usePermissions";
export function LinkedItemsHeaderView({ item, unlinkCallback, itemNameField, itemAvatarField, loading }: {
export function LinkedItemsHeaderView({ item, unlinkCallback, itemNameField, itemAvatarField, loading, unlinkPermission }: {
item: Item,
unlinkCallback?: any,
itemNameField?: string,
itemAvatarField?: string,
loading?: boolean,
unlinkPermission: boolean
}) {
const assetsApi = useAssetApi();
@ -22,7 +22,11 @@ export function LinkedItemsHeaderView({ item, unlinkCallback, itemNameField, ite
const title = itemNameField ? getValue(item, itemNameField) : item.layer?.itemNameField && item && getValue(item, item.layer?.itemNameField);
useEffect(() => {
}, [item])
return (
<>
@ -41,6 +45,7 @@ export function LinkedItemsHeaderView({ item, unlinkCallback, itemNameField, ite
</div>
</div>
<div className='tw-col-span-1' onClick={(e) => e.stopPropagation()}>
{ unlinkPermission &&
<div className="tw-dropdown tw-dropdown-bottom">
<label tabIndex={0} className="tw-bg-base-100 tw-btn tw-m-1 tw-leading-3 tw-border-none tw-min-h-0 tw-h-6">
<svg xmlns="http://www.w3.org/2000/svg" className="tw-h-5 tw-w-5" viewBox="0 0 20 20" fill="currentColor">
@ -56,7 +61,7 @@ export function LinkedItemsHeaderView({ item, unlinkCallback, itemNameField, ite
</a>
</li>}
</ul>
</div>
</div>}
</div>
</div>
</>

View File

@ -30,7 +30,7 @@ export function OverlayItemProfile() {
const map = useMap();
const windowDimension = useWindowDimensions();
const [addButton, setAddButton] = useState<boolean>(false);
const [updatePermission, setUpdatePermission] = useState<boolean>(false);
const layers = useLayers();
@ -115,7 +115,7 @@ export function OverlayItemProfile() {
}, [item, items])
useEffect(() => {
item && item.user_created && hasUserPermission("items", "update", item) && setAddButton(true);
item && item.user_created && hasUserPermission("items", "update", item) && setUpdatePermission(true);
}, [item])
@ -246,7 +246,7 @@ export function OverlayItemProfile() {
if (i.type == 'project') return (
<div key={i.id} className='tw-cursor-pointer tw-card tw-border-[1px] tw-border-base-300 tw-card-body tw-shadow-xl tw-bg-base-100 tw-text-base-content tw-mx-4 tw-p-4 tw-mb-4 tw-h-fit' onClick={() => navigate('/item/' + i.id)}>
<LinkedItemsHeaderView loading={loading} item={i} unlinkCallback={unlinkItem} />
<LinkedItemsHeaderView unlinkPermission={updatePermission} loading={loading} item={i} unlinkCallback={unlinkItem} />
<div className='tw-overflow-y-auto tw-overflow-x-hidden tw-max-h-64 fade'>
<TextView truncate item={i} />
@ -272,7 +272,7 @@ export function OverlayItemProfile() {
</div>
</form> : <></>
}
{addButton && <ActionButton collection="items" item={item} existingRelations={relations} itemType={"project"} triggerItemSelected={linkItem} triggerAddButton={() => { setAddItemPopupType("project"); scroll() }} color={item.color}></ActionButton>}
{updatePermission && <ActionButton collection="items" item={item} existingRelations={relations} itemType={"project"} triggerItemSelected={linkItem} triggerAddButton={() => { setAddItemPopupType("project"); scroll() }} color={item.color}></ActionButton>}
</div>
</div>
@ -286,7 +286,7 @@ export function OverlayItemProfile() {
if (i.type == 'event') return (
<div key={i.id} className='tw-cursor-pointer tw-card tw-border-[1px] tw-border-base-300 tw-card-body tw-shadow-xl tw-bg-base-100 tw-text-base-content tw-mx-4 tw-p-6 tw-mb-4' onClick={() => navigate('/item/' + i.id)}>
<LinkedItemsHeaderView item={i} unlinkCallback={unlinkItem} loading={loading} />
<LinkedItemsHeaderView unlinkPermission={updatePermission} item={i} unlinkCallback={unlinkItem} loading={loading} />
<div className='tw-overflow-y-auto tw-overflow-x-hidden tw-max-h-64 fade'>
<StartEndView item={i}></StartEndView>
<TextView truncate item={i} />
@ -313,7 +313,7 @@ export function OverlayItemProfile() {
</div>
</form> : <></>
}
{addButton && <ActionButton collection="items" item={item} existingRelations={relations} itemType={"event"} triggerItemSelected={linkItem} triggerAddButton={() => { setAddItemPopupType("event"); scroll() }} color={item.color}></ActionButton>}
{updatePermission && <ActionButton collection="items" item={item} existingRelations={relations} itemType={"event"} triggerItemSelected={linkItem} triggerAddButton={() => { setAddItemPopupType("event"); scroll() }} color={item.color}></ActionButton>}
</div>
</div>