Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ee6e4a3
feat: update @itwin/itwinui-react to version 3.19.4 in storybook and …
arome Oct 16, 2025
5beb83c
refactor: remove unused refetch logic from useIModelFavorites and con…
arome Oct 16, 2025
05ad731
fix: ensure iTwinId is validated before fetching iModel favorites
arome Oct 16, 2025
9f9781f
Fix storybook not applying correct theme on first render
arome Oct 16, 2025
f7356d9
fix: rename internalOnClick to handleClickAndAddToRecents for clarity…
arome Oct 16, 2025
fd3fd6e
revert changes to storybook and create a separate PR for it
arome Oct 16, 2025
85b5bd4
fix: update no iTwin/iModel messages for clarity based on request type
arome Oct 16, 2025
d7bfc4e
fix: allow iTwinId to be optional in IModelFavoritesProvider and useI…
arome Oct 16, 2025
392eaae
feat: add iModel recents and favorites functionality
arome Oct 16, 2025
b014a55
fix: improve clarity of no iTwin messages for recents and favorites
arome Oct 16, 2025
f55d135
Merge branch 'main' into omar/imodel-recent
arome Oct 22, 2025
f5155c0
Update packages/modules/imodel-browser/src/containers/iModelGrid/useI…
arome Oct 22, 2025
c8155b7
Update packages/modules/imodel-browser/src/containers/iModelGrid/useI…
arome Oct 22, 2025
0789c86
Update packages/modules/imodel-browser/src/containers/iModelGrid/useI…
arome Oct 24, 2025
0d8577e
Add comment for requestType
arome Oct 24, 2025
3ee47aa
Refactor iModel recents handling by introducing addIModelToRecents ut…
arome Oct 24, 2025
30a8925
fix naming of file useIModelFavorites
arome Oct 24, 2025
dc5ac40
Refactor access token handling to use AccessTokenProvider type across…
arome Oct 24, 2025
49e2053
Update sorting logic in useIModelData and useIModelSort to improve ha…
arome Oct 24, 2025
05e862c
Refactor IModelTile to rename onClick prop to tilePropsOnClick for cl…
arome Oct 24, 2025
b50de10
Fix dependency array in useIModelSort to include enableSort for prope…
arome Oct 24, 2025
22bec73
remove unnecessary if condition in handleClick
arome Oct 24, 2025
83daffd
Add hover state and styling for favorite icon in IModelTile and ITwin…
arome Oct 24, 2025
c874b2b
Add handling for thumbnail click to invoke tilePropsOnClick or onThum…
arome Oct 24, 2025
057de9f
Implement client-side filtering for recents and favorites based on se…
arome Oct 24, 2025
ef38ce1
Refactor iModel favorites management: streamline API calls and enhanc…
arome Oct 27, 2025
751593d
Replace SvgStar with SvgApple in IModelGrid story and adjust cellOver…
arome Oct 27, 2025
735e8c6
Add disableAddToRecents prop to IModelGrid and update IModelTile clic…
arome Oct 27, 2025
28ce0e5
Remove unused import of addIModelToRecents from IModelTile
arome Oct 27, 2025
4d68802
Rename iModelApi to iModelApi-rename-fix and update imports in IModel…
arome Oct 27, 2025
5dc9eec
Refactor iModelApi: rename file and update imports in IModelGrid and …
arome Oct 27, 2025
3754455
Add hideFavoriteIcon prop to ITwinTile and IModelTile components
arome Oct 30, 2025
db2e174
Merge branch 'main' into omar/imodel-recent
arome Oct 30, 2025
5e83f1e
Add "remove iModel from recents" functionality when in recents mode
arome Nov 3, 2025
8765c0a
Merge branch 'main' into omar/imodel-recent
arome Nov 3, 2025
859429a
Use css for hover behavior instead of javascript
arome Nov 3, 2025
72946fd
Refactor: Update onThumbnailClick documentation to clarify recents be…
arome Nov 3, 2025
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": "Feat: Add iModel recents and favorites functionality",
"type": "minor"
}
],
"packageName": "@itwin/imodel-browser-react"
}
7 changes: 3 additions & 4 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { IModelTile as C, IModelTileProps } from "@itwin/imodel-browser-react";
import { SvgImodel, SvgPlaceholder } from "@itwin/itwinui-icons-react";
import { Badge, Button } from "@itwin/itwinui-react";
import { Meta, Story } from "@storybook/react/types-6-0";
import React from "react";

Expand All @@ -20,5 +22,26 @@ export const Primary = Template.bind({});
Primary.args = {
iModel: {
id: "1",
displayName: "iModel Name",
description: "iModel Description",
},
iModelOptions: [
{ key: "option-1", children: "Option 1" },
{ key: "option-2", children: "Option 2" },
],
tileProps: {
status: "positive",
isDisabled: false,
isLoading: false,
isSelected: false,
isNew: false,
badge: <Badge>Badge</Badge>,
leftIcon: <SvgPlaceholder />,
rightIcon: <SvgPlaceholder />,
buttons: [
<Button key="button-1">Button 1</Button>,
<Button key="button-2">Button 2</Button>,
],
thumbnail: <SvgImodel />,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export const Primary = Template.bind({});
Primary.args = {
iTwin: {
id: "1",
displayName: "iTwin Name",
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
.favoriteIconButton {
padding-inline: var(--iui-button-padding-block);
background-color: rgb(from var(--iui-color-background-hover) r g b / 0.7);

&:hover {
background-color: var(--iui-color-background-hover);
}

&:active {
background-color: var(--iui-color-background);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { SvgStar, SvgStarHollow } from "@itwin/itwinui-icons-react";
import { IconButton } from "@itwin/itwinui-react";
import React from "react";

import styles from "./TileFavoriteIcon.module.scss";

export interface TileFavoriteIconProps {
/** Whether the item is currently favorited */
isFavorite: boolean;
/** Callback to add the item to favorites */
onAddToFavorites: () => Promise<void>;
/** Callback to remove the item from favorites */
onRemoveFromFavorites: () => Promise<void>;
/** Accessible label for adding to favorites */
addLabel: string;
/** Accessible label for removing from favorites */
removeLabel: string;
/** Whether to hide the icon (will not hide if the item is favorited) */
hide?: boolean;
}

/**
* Reusable favorite icon button for Tile components
* Shows a star icon that can be clicked to add/remove from favorites
*/
export const TileFavoriteIcon = ({
isFavorite,
onAddToFavorites,
onRemoveFromFavorites,
addLabel,
removeLabel,
hide,
}: TileFavoriteIconProps) => {
// Don't render if hide is true and not favorited
if (hide && !isFavorite) {
return null;
}

return (
<IconButton
aria-label={isFavorite ? removeLabel : addLabel}
onClick={async () => {
isFavorite ? await onRemoveFromFavorites() : await onAddToFavorites();
}}
className={styles.favoriteIconButton}
styleType="borderless"
>
{isFavorite ? <SvgStar /> : <SvgStarHollow />}
</IconButton>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { InView } from "react-intersection-observer";
import { GridStructure } from "../../components/gridStructure/GridStructure";
import { NoResults } from "../../components/noResults/NoResults";
import {
AccessTokenProvider,
ApiOverrides,
DataStatus,
ITwinCellOverrides,
Expand Down Expand Up @@ -63,7 +64,7 @@ export interface ITwinGridStrings {

export interface ITwinGridProps {
/** Access token that requires the `itwins:read` scope. Provide a function that returns the token to prevent the token from expiring. Function must be memoized. */
accessToken?: string | (() => Promise<string>) | undefined;
accessToken?: AccessTokenProvider;
/** Type of iTwin to request */
requestType?: "favorites" | "recents" | "";
/** Sub class of iTwin, defaults to Project */
Expand Down Expand Up @@ -149,7 +150,12 @@ export const ITwinGrid = ({
tableLoadingData: "Loading...",
trialBadge: "Trial",
inactiveBadge: "Inactive",
noITwins: "No iTwin found.",
noITwins:
requestType === "recents"
? "No recent iTwins."
: requestType === "favorites"
? "No favorite iTwins."
: "No iTwin found.",
noAuthentication: "No access token provided",
error: "An error occurred",
addToFavorites: "Add to favorites",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { SvgItwin, SvgStar, SvgStarHollow } from "@itwin/itwinui-icons-react";
import { Badge, IconButton, ThemeProvider, Tile } from "@itwin/itwinui-react";
import { SvgItwin } from "@itwin/itwinui-icons-react";
import { Badge, ThemeProvider, Tile } from "@itwin/itwinui-react";
import React from "react";

import { TileFavoriteIcon } from "../../components/tileFavoriteIcon/TileFavoriteIcon";
import { ITwinFull } from "../../types";
import { _mergeStrings } from "../../utils/_apiOverrides";
import {
Expand Down Expand Up @@ -81,7 +82,7 @@ export const ITwinTile = ({
onClick,
...rest
} = tileProps ?? {};

const [isHovered, setIsHovered] = React.useState(false);
const strings = _mergeStrings(
{
trialBadge: "Trial",
Expand Down Expand Up @@ -112,6 +113,8 @@ export const ITwinTile = ({
status={status}
isDisabled={isDisabled}
style={fullWidth ? { width: "100%" } : undefined}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
{...rest}
>
<Tile.Name>
Expand All @@ -130,21 +133,18 @@ export const ITwinTile = ({
{leftIcon && <Tile.TypeIndicator>{leftIcon}</Tile.TypeIndicator>}
<Tile.QuickAction>
{rightIcon}
<IconButton
aria-label={
isFavorite
? strings.removeFromFavorites
: strings.addToFavorites
}
onClick={async () => {
isFavorite
? await removeFromFavorites?.(iTwin.id)
: await addToFavorites?.(iTwin.id);
}}
styleType="borderless"
>
{isFavorite ? <SvgStar /> : <SvgStarHollow />}
</IconButton>
{isFavorite !== undefined &&
addToFavorites &&
removeFromFavorites && (
<TileFavoriteIcon
isFavorite={isFavorite}
onAddToFavorites={() => addToFavorites(iTwin.id)}
onRemoveFromFavorites={() => removeFromFavorites(iTwin.id)}
addLabel={strings.addToFavorites}
removeLabel={strings.removeFromFavorites}
hide={!isHovered}
Comment thread
arome marked this conversation as resolved.
Outdated
/>
)}
</Tile.QuickAction>
<Tile.BadgeContainer>
{badge ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import React from "react";

import {
AccessTokenProvider,
ApiOverrides,
DataStatus,
ITwinFilterOptions,
Expand All @@ -17,7 +18,7 @@ import { useITwinFilter } from "./useITwinFilter";
export interface ProjectDataHookOptions {
requestType?: "favorites" | "recents" | "";
iTwinSubClass?: ITwinSubClass;
accessToken?: string | (() => Promise<string>) | undefined;
accessToken?: AccessTokenProvider;
apiOverrides?: ApiOverrides<ITwinFull[]>;
filterOptions?: ITwinFilterOptions;
orderbyOptions?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

import { useCallback, useEffect, useState } from "react";

import { AccessTokenProvider } from "../../types";
import { _getAPIServer } from "../../utils/_apiOverrides";

const HOOK_ABORT_ERROR =
"The fetch request was aborted by the cleanup function.";

/**
* Custom hook to manage iTwin favorites.
* @param {string | (() => Promise<string>) | undefined} accessToken - Access token that requires the `itwin-platform` scope. Provide a function that returns the token to prevent the token from expiring.
* @param {AccessTokenProvider} accessToken - Access token that requires the `itwin-platform` scope. Provide a function that returns the token to prevent the token from expiring.
* @param {ApiOverrides<ITwinFull[]>} [apiOverrides] - Optional API overrides.
* @returns {object} - An object containing:
* - {Set<string>} iTwinFavorites - A set of iTwin IDs that are marked as favorites.
Expand All @@ -22,7 +23,7 @@ const HOOK_ABORT_ERROR =
* - {function} resetShouldRefetchFavorites - A function to reset shouldRefetchFavorites back to false.
*/
export const useITwinFavorites = (
accessToken: string | (() => Promise<string>) | undefined,
accessToken: AccessTokenProvider | undefined,
serverEnvironmentPrefix?: "dev" | "qa" | ""
): {
iTwinFavorites: Set<string>;
Expand Down
Loading