Skip to content

Commit

Permalink
show name in draggable for DCE
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Aug 16, 2024
1 parent 350d923 commit 8ef24af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ export function isHistoryItem(item: object): item is HistoryItemSummary {
return item && "history_content_type" in item;
}

export function isCollectionItem(item: object): item is DCESummary {
return item && "element_type" in item;
}

type QuotaUsageResponse = components["schemas"]["UserQuotaUsage"];

/** Represents a registered user.**/
Expand Down
11 changes: 11 additions & 0 deletions client/src/utils/setDrag.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/**
* Helper to configure datatransfer for drag & drop operations
*/
import { type DCESummary, isCollectionItem } from "@/api";
import { type EventData, useEventStore } from "@/stores/eventStore";

type NamedDCESummary = DCESummary & { name: string };

export function setDrag(evt: DragEvent, data?: EventData, multiple = false) {
const eventStore = useEventStore();
if (data) {
Expand Down Expand Up @@ -36,10 +39,18 @@ export function setItemDragstart<T>(
if (selectedItems && itemIsSelected && selectionSize > 1) {
const selectedItemsObj: Record<string, T> = {};
for (const [key, value] of selectedItems) {
setCollectionElementName(value as any);
selectedItemsObj[key] = value;
}
setDrag(event, selectedItemsObj, true);
} else {
setCollectionElementName(item as any);
setDrag(event, item as any);
}
}

function setCollectionElementName<T extends NamedDCESummary>(obj: T) {
if (isCollectionItem(obj as object)) {
obj["name"] = obj.element_identifier;
}
}

0 comments on commit 8ef24af

Please sign in to comment.