Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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": "Fix sorting in iTwinGrid/iModelGrid table",
"type": "patch"
}
],
"packageName": "@itwin/imodel-browser-react"
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ OverrideCellData.args = {
name: (props) =>
props.value.includes("a") ? (
<div style={{ display: "flex", alignItems: "center", gap: "4px" }}>
<IconButton size="small" styleType="borderless">
<IconButton
aria-label="apple-icon"
size="small"
styleType="borderless"
>
<SvgApple />
</IconButton>
{props.value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ export interface ITwinGridProps {
filterOptions?: ITwinFilterOptions;
/**
* Set the `$orderby` parameter when fetching iTwins from the iTwin API, e.g. `displayName ASC`.
*
* This only has an effect when the `requestType` is empty - it does not apply to "favorites" or "recents".
*
* See https://developer.bentley.com/apis/itwins/operations/get-my-itwins/#odata-queries for details.
*/
orderbyOptions?: string;
Expand Down Expand Up @@ -266,6 +264,7 @@ export const ITwinGrid = ({
: strings.noITwins
}
isLoading={fetchStatus === DataStatus.Fetching}
isSortable
onBottomReached={fetchMore}
autoResetFilters={false}
autoResetSortBy={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const useITwinTableConfig = ({
id: ITwinCellColumn.Favorite,
Header: strings.tableColumnFavorites,
accessor: "id",
disableSortBy: true,
width: 70,
Cell: (props: CellProps<ITwinFull>) => {
const isFavorite = iTwinFavorites.has(props.value);
Expand Down Expand Up @@ -115,10 +116,9 @@ export const useITwinTableConfig = ({
{
id: ITwinCellColumn.LastModified,
Header: strings.tableColumnLastModified,
Comment thread
arome marked this conversation as resolved.
accessor: "createdDateTime",
maxWidth: 350,
accessor: "lastModifiedDateTime",
Cell: (props: CellProps<ITwinFull>) => {
const date = props.data[props.row.index].createdDateTime;
const date = props.data[props.row.index].lastModifiedDateTime;
return cellOverrides.LastModified
? cellOverrides.LastModified(props)
: date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ export const IModelGrid = (props: IModelGridProps) => {
serverEnvironmentPrefix={props.apiOverrides?.serverEnvironmentPrefix}
disabled={props.tileOverrides?.hideFavoriteIcon}
>
<ITwinGridInternal {...props} />
<IModelGridInternal {...props} />
</IModelFavoritesProvider>
);
};
const ITwinGridInternal = ({
const IModelGridInternal = ({
accessToken,
apiOverrides,
iModelActions,
Expand All @@ -172,31 +172,27 @@ const ITwinGridInternal = ({
disableAddToRecents = false,
}: IModelGridProps) => {
const [sort, setSort] = React.useState<IModelSortOptions>(sortOptions);
const [isSortOnTable, setIsSortOnTable] = React.useState(false);

React.useEffect(() => {
if (!isSortOnTable) {
const defaultTableSort: IModelSortOptions = {
sortType: "name",
descending: false,
};
setSort(
viewMode === "cells"
? defaultTableSort
: {
sortType: sortOptions.sortType,
descending: sortOptions.descending,
}
);
}
}, [isSortOnTable, sortOptions.descending, sortOptions.sortType, viewMode]);
setSort(
viewMode === "cells"
? {
sortType: "name",
descending: false,
Comment thread
simihartstein marked this conversation as resolved.
}
: {
sortType: sortOptions.sortType,
descending: sortOptions.descending,
}
);
}, [sortOptions.descending, sortOptions.sortType, viewMode]);

const strings = _mergeStrings(
{
tableColumnFavorites: "",
tableColumnName: "Name",
tableColumnDescription: "Description",
tableColumnLastModified: "Last Modified",
tableColumnLastModified: "Created Date",
Comment thread
arome marked this conversation as resolved.
Outdated
tableLoadingData: "Loading...",
noIModelSearch: "No results found",
noIModelSearchSubtext:
Expand Down Expand Up @@ -349,7 +345,6 @@ const ITwinGridInternal = ({
apiOverrides={tileApiOverrides}
useTileState={useIndividualState}
refetchIModels={refetchIModels}
{...cellOverrides}
{...tileOverrides}
tileProps={
tileOverrides
Expand Down Expand Up @@ -402,23 +397,6 @@ const ITwinGridInternal = ({
}
isLoading={fetchStatus === DataStatus.Fetching}
isSortable
onSort={(state) => {
const sortBy =
state.sortBy.length > 0 ? state.sortBy[0] : undefined;
setIsSortOnTable(sortBy?.id !== undefined);
if (
!sortBy ||
sortBy.desc === undefined ||
(sortBy.id !== "name" && sortBy.id !== "createdDateTime")
) {
return;
}
setSort({
sortType: sortBy.id,
descending: sortBy.desc,
});
}}
manualSortBy
onBottomReached={fetchMore}
autoResetFilters={false}
autoResetSortBy={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const useIModelTableConfig = ({
id: IModelCellColumn.Favorite,
Header: strings.tableColumnFavorites,
accessor: "id",
disableSortBy: true,
width: 70,
Cell: (props: CellProps<IModelFull>) => {
const isFavorite = favoritesContext?.favorites.has(props.value);
Expand Down Expand Up @@ -90,9 +91,11 @@ export const useIModelTableConfig = ({
maxWidth: 350,
Cell: (props: CellProps<IModelFull>) => (
<div data-tip={props.row.original.name}>
<span>
{cellOverrides.name ? cellOverrides.name(props) : props.value}
</span>
{cellOverrides.name ? (
cellOverrides.name(props)
) : (
<span>{props.value}</span>
)}
</div>
),
},
Expand All @@ -103,11 +106,11 @@ export const useIModelTableConfig = ({
disableSortBy: true,
Cell: (props: CellProps<IModelFull>) => (
<div data-tip={props.row.original.description}>
<span>
{cellOverrides.description
? cellOverrides.description(props)
: props.value}
</span>
{cellOverrides.description ? (
cellOverrides.description(props)
) : (
<span>{props.value}</span>
)}
</div>
),
},
Expand Down