Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/imodel-browser-react",
"comment": "use `hideFavoriteIcon` option to disable fetching favorite iModels",
"type": "minor"
}
],
"packageName": "@itwin/imodel-browser-react"
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const IModelGrid = (props: IModelGridProps) => {
iTwinId={props.iTwinId}
accessToken={props.accessToken}
serverEnvironmentPrefix={props.apiOverrides?.serverEnvironmentPrefix}
disabled={props.tileOverrides?.hideFavoriteIcon}
Comment thread
leo-belanger marked this conversation as resolved.
>
<ITwinGridInternal {...props} />
</IModelFavoritesProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as iModelApi from "../../utils/iModelApi";
* @param iTwinId - The ID of the iTwin for which to fetch favorites.
* @param accessToken - Access token that requires the `itwin-platform` scope. Provide a function that returns the token to prevent the token from expiring.
* @param serverEnvironmentPrefix - Optional server environment prefix.
* @param disabled - Optional flag to disable fetching of the favorites in the hook.
* @returns An object containing:
* - {Set<string>} iModelFavorites - A set of iModel IDs that are marked as favorites.
* - {function} addIModelToFavorites - A function to add an iModel to favorites.
Expand All @@ -21,7 +22,8 @@ import * as iModelApi from "../../utils/iModelApi";
export const useIModelFavorites = (
iTwinId: string | undefined,
accessToken: AccessTokenProvider | undefined,
serverEnvironmentPrefix?: "dev" | "qa" | ""
serverEnvironmentPrefix?: "dev" | "qa" | "",
disabled?: boolean
): {
iModelFavorites: Set<string>;
addIModelToFavorites: (iModelId: string) => Promise<void>;
Expand Down Expand Up @@ -91,7 +93,7 @@ export const useIModelFavorites = (
*/
const fetchIModelFavorites = async (abortSignal?: AbortSignal) => {
try {
if (!iTwinId || !accessToken) {
if (disabled || !iTwinId || !accessToken) {
Comment thread
leo-belanger marked this conversation as resolved.
setIModelFavorites(new Set());
return;
}
Expand All @@ -115,7 +117,7 @@ export const useIModelFavorites = (
return () => {
controller.abort();
};
}, [iTwinId, accessToken, serverEnvironmentPrefix]);
}, [disabled, iTwinId, accessToken, serverEnvironmentPrefix]);

return {
iModelFavorites,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,24 @@ export interface IModelFavoritesProviderProps {
accessToken?: AccessTokenProvider;
serverEnvironmentPrefix?: string;
children: React.ReactNode;
disabled?: boolean;
}

export const IModelFavoritesProvider = ({
iTwinId,
accessToken,
serverEnvironmentPrefix,
children,
disabled,
}: IModelFavoritesProviderProps) => {
const { iModelFavorites, addIModelToFavorites, removeIModelFromFavorites } =
useIModelFavorites(
iTwinId,
accessToken,
serverEnvironmentPrefix === "dev" || serverEnvironmentPrefix === "qa"
? serverEnvironmentPrefix
: undefined
: undefined,
disabled
);

const value = React.useMemo<IModelFavoritesContextValue>(
Expand Down
Loading