fix: refine dashboard interactions and widget options (#6597)
* fix: refine dashboard item interactions * fix board interactions and widget options * feat: improve bookmark selection * fix: address dashboard review feedback
This commit is contained in:
1 parent
b491d45fdc
commit
4505ce96c9
37 files changed
+824
-503
No files matched your search
@@ -19,13 +19,18 @@ export type ContextSpecificItem = {
|
||||
|
||||
interface SpotlightContextProps {
|
||||
items: ContextSpecificItem[];
|
||||
}
|
||||
|
||||
interface SpotlightRegistrationContextProps {
|
||||
registerItems: (key: string, results: ContextSpecificItem[]) => void;
|
||||
unregisterItems: (key: string) => void;
|
||||
}
|
||||
|
||||
const createSpotlightContext = (displayName: string) => {
|
||||
const SpotlightContext = createContext<SpotlightContextProps | null>(null);
|
||||
const SpotlightRegistrationContext = createContext<SpotlightRegistrationContextProps | null>(null);
|
||||
SpotlightContext.displayName = displayName;
|
||||
SpotlightRegistrationContext.displayName = `${displayName}Registration`;
|
||||
|
||||
const Provider = ({ children }: PropsWithChildren) => {
|
||||
const [itemsMap, setItemsMap] = useState<Map<string, { items: ContextSpecificItem[]; count: number }>>(new Map());
|
||||
@@ -51,16 +56,18 @@ const createSpotlightContext = (displayName: string) => {
|
||||
const newItemsMap = new Map(prevItems);
|
||||
newItemsMap.set(key, { items: newItemsMap.get(key)?.items ?? [], count: registrationCount - 1 });
|
||||
|
||||
return prevItems;
|
||||
return newItemsMap;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const items = useMemo(() => Array.from(itemsMap.values()).flatMap(({ items }) => items), [itemsMap]);
|
||||
const itemsContext = useMemo(() => ({ items }), [items]);
|
||||
const registration = useMemo(() => ({ registerItems, unregisterItems }), [registerItems, unregisterItems]);
|
||||
|
||||
return (
|
||||
<SpotlightContext.Provider value={{ items, registerItems, unregisterItems }}>
|
||||
{children}
|
||||
</SpotlightContext.Provider>
|
||||
<SpotlightRegistrationContext.Provider value={registration}>
|
||||
<SpotlightContext.Provider value={itemsContext}>{children}</SpotlightContext.Provider>
|
||||
</SpotlightRegistrationContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -79,7 +86,7 @@ const createSpotlightContext = (displayName: string) => {
|
||||
items: ContextSpecificItem[],
|
||||
dependencyArray: DependencyList,
|
||||
) => {
|
||||
const context = useContext(SpotlightContext);
|
||||
const context = useContext(SpotlightRegistrationContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
@@ -97,7 +104,7 @@ const createSpotlightContext = (displayName: string) => {
|
||||
context.unregisterItems(key);
|
||||
};
|
||||
// We ignore the results
|
||||
}, [...dependencyArray, key]);
|
||||
}, [...dependencyArray, context.registerItems, context.unregisterItems, key]);
|
||||
};
|
||||
|
||||
return [SpotlightContext, Provider, useSpotlightContextItems, useRegisterSpotlightContextItems] as const;
|
||||
|
||||
Reference in new issue
Block a user