Open Bielik20 opened 4 years ago
Do you have a CodeSandbox with what you're trying to do here? I'm trying to visualize it, but just not seeing it.
I don't have CodeSandbox at hand but I can show it on pictures.
So, when selecting a resource (header) you want it to only show that resource's items, right? Clicking again should show the other resources. Does that sound right? Just trying to fully understand your use case.
Yes, that is exactly the use case. I did it with very dirty workaround and I hope to remove it. It is clearly something with DragAndDrop
, because it works fine without it.
I've written a few different component overrides, but never messed with the resource header before. As far as I can tell though, reading through the code I'm not seeing where the hoc does anything specific with that component.
I also use the DnD hoc, and will be doing some stuff with resources in a future iteration of my work. Can't give you any clues now, but if I find something I'll post back (but, unfortunately, it won't be any time soon)
Thank you, in the mean time I will post my workaround for anyone who stumbles opon this issue:
export function useResourceToggle<TResource>(
resources: TResource[],
): [TResource[], (resource: TResource) => void] {
const [selected, setSelected] = useState<TResource | null>(null);
const selector = (resource: TResource) => {
setSelected(selected ? null : resource);
};
return [
(selected ? [selected] : resources).map((res) => {
// @ts-ignore
res.__toggle = () => selector(res);
return res;
}),
selector,
];
}
It is dirty and ugly but it works. You must use __toggle
method on a resource to toggle, not the returned selector
callback.
Do you want to request a feature or report a bug?
bug
What's the current behavior?
resourceHeader
doesn't update properly inDragAndDrop
Calendar. I have extracted simplified snipped from my code:resourceToggle
function insideresourceHeader
doesn't update. This results in inability to resetselected
. In other wordsselected
will always bynull
whenresourceToggle
is called from withinresourceHeader
.This happens only with
DragAndDrop
plugin. Without it everything works fine.What's the expected behavior?
resourceHeader
should be updated properly.