Skip to content
Open
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
12 changes: 12 additions & 0 deletions pkg/sqlite/performer.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ var performerSortOptions = sortOptions{
"play_count",
"random",
"rating",
"favorite",
"scenes_count",
"scenes_duration",
"scenes_size",
Expand Down Expand Up @@ -871,6 +872,17 @@ func (qb *PerformerStore) getPerformerSort(findFilter *models.FindFilterType) (s
sortQuery += qb.sortByLastOAt(direction)
case "latest_scene":
sortQuery += qb.sortByLatestScene(direction)
case "birthdate":

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't drop favorite sort option and birthdate case because they are needed for Favourite/Age column clicks.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't include these changes in the original description.

// birthdate is inversely related to age (older = lower date).
// flip direction so DESC means "oldest first".
Comment thread
slick-daddy marked this conversation as resolved.
Outdated
colName := getColumn(performerTable, "birthdate")
dir := getSortDirection(direction)
if dir == "ASC" {
dir = "DESC"
} else {
dir = "ASC"
}
sortQuery += " ORDER BY " + colName + " IS NULL, " + colName + " " + dir
default:
sortQuery += getSort(sort, direction, "performers")
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sqlite/studio.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ var studioSortOptions = sortOptions{
"images_count",
"latest_scene",
"name",
"favorite",
"scenes_count",
"scenes_duration",
"scenes_size",
Expand Down
1 change: 1 addition & 0 deletions pkg/sqlite/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ func (qb *TagStore) Query(ctx context.Context, tagFilter *models.TagFilterType,

var tagSortOptions = sortOptions{
"created_at",
"favorite",
"galleries_count",
"groups_count",
"id",
Expand Down
30 changes: 29 additions & 1 deletion ui/v2.5/src/components/Galleries/GalleryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import GalleryWallCard from "./GalleryWallCard";
import { EditGalleriesDialog } from "./EditGalleriesDialog";
import { DeleteGalleriesDialog } from "./DeleteGalleriesDialog";
import { ExportDialog } from "../Shared/ExportDialog";
import { getActiveSortColumn } from "src/utils/data";
import { GenerateDialog } from "../Dialogs/GenerateDialog";
import { GalleryListTable } from "./GalleryListTable";
import { GalleryCardGrid } from "./GalleryCardGrid";
Expand Down Expand Up @@ -56,14 +57,23 @@ import { PerformerAgeCriterionOption } from "src/models/list-filter/galleries";
import { SidebarFolderFilter } from "../List/Filters/FolderFilter";
import { ParentFolderCriterionOption } from "src/models/list-filter/criteria/folder";

const galleryColumnSortMap: Record<string, string> = {
images: "images_count",
};

const GalleryList: React.FC<{
galleries: GQL.SlimGalleryDataFragment[];
filter: ListFilterModel;
selectedIds: Set<string>;
onSelectChange: (id: string, selected: boolean, shiftKey: boolean) => void;
onSort?: (value: string) => void;
}> = PatchComponent(
"GalleryList",
({ galleries, filter, selectedIds, onSelectChange }) => {
({ galleries, filter, selectedIds, onSelectChange, onSort }) => {
const activeSortColumn = getActiveSortColumn(
galleryColumnSortMap,
filter.sortBy
);
const { configuration } = useConfigurationContext();
const showLightbox = useGalleriesLightbox();

Expand Down Expand Up @@ -101,6 +111,9 @@ const GalleryList: React.FC<{
galleries={galleries}
selectedIds={selectedIds}
onSelectChange={onSelectChange}
onSort={onSort}
sortBy={activeSortColumn}
sortDirection={filter.sortDirection}
/>
);
}
Expand Down Expand Up @@ -299,6 +312,20 @@ export const FilteredGalleryList = PatchComponent(

const { filter, setFilter } = filterState;

const onSort = useCallback(
(value: string) => {
const backendField = galleryColumnSortMap[value] ?? value;
if (filter.sortBy === backendField) {
setFilter(filter.toggleSortDirection());
} else {
const newFilter = filter.setSortBy(backendField);
newFilter.sortDirection = GQL.SortDirectionEnum.Asc;
setFilter(newFilter);
}
},
[filter, setFilter]
);

const { effectiveFilter, result, cachedResult, items, totalCount } =
queryResult;

Expand Down Expand Up @@ -523,6 +550,7 @@ export const FilteredGalleryList = PatchComponent(
galleries={items}
selectedIds={selectedIds}
onSelectChange={onSelectChange}
onSort={onSort}
/>
</LoadedContent>

Expand Down
15 changes: 15 additions & 0 deletions ui/v2.5/src/components/Galleries/GalleryListTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { Link } from "react-router-dom";
import * as GQL from "src/core/generated-graphql";
import { SortDirectionEnum } from "src/core/generated-graphql";
import NavUtils from "src/utils/navigation";
import { useIntl } from "react-intl";
import { objectTitle } from "src/core/files";
Expand All @@ -14,6 +15,9 @@ interface IGalleryListTableProps {
galleries: GQL.SlimGalleryDataFragment[];
selectedIds: Set<string>;
onSelectChange: (id: string, selected: boolean, shiftKey: boolean) => void;
onSort?: (value: string) => void;
sortBy?: string;
sortDirection?: SortDirectionEnum;
}

const TABLE_NAME = "galleries";
Expand Down Expand Up @@ -147,6 +151,7 @@ export const GalleryListTable: React.FC<IGalleryListTableProps> = (
label: string;
defaultShow?: boolean;
mandatory?: boolean;
sortable?: boolean;
render?: (
gallery: GQL.SlimGalleryDataFragment,
index: number
Expand All @@ -158,6 +163,7 @@ export const GalleryListTable: React.FC<IGalleryListTableProps> = (
value: "cover_image",
label: intl.formatMessage({ id: "cover_image" }),
defaultShow: true,
sortable: false,
render: CoverImageCell,
},
{
Expand All @@ -182,6 +188,7 @@ export const GalleryListTable: React.FC<IGalleryListTableProps> = (
{
value: "code",
label: intl.formatMessage({ id: "scene_code" }),
sortable: false,
render: (s) => <>{s.code}</>,
},
{
Expand All @@ -194,29 +201,34 @@ export const GalleryListTable: React.FC<IGalleryListTableProps> = (
value: "tags",
label: intl.formatMessage({ id: "tags" }),
defaultShow: true,
sortable: false,
render: TagCell,
},
{
value: "performers",
label: intl.formatMessage({ id: "performers" }),
defaultShow: true,
sortable: false,
render: PerformersCell,
},
{
value: "studio",
label: intl.formatMessage({ id: "studio" }),
defaultShow: true,
sortable: false,
render: StudioCell,
},
{
value: "scenes",
label: intl.formatMessage({ id: "scenes" }),
defaultShow: true,
sortable: false,
render: SceneCell,
},
{
value: "photographer",
label: intl.formatMessage({ id: "photographer" }),
sortable: false,
render: (s) => <>{s.photographer}</>,
},
{
Expand Down Expand Up @@ -265,6 +277,9 @@ export const GalleryListTable: React.FC<IGalleryListTableProps> = (
selectedIds={props.selectedIds}
onSelectChange={props.onSelectChange}
renderCell={renderCell}
onSort={props.onSort}
sortBy={props.sortBy}
sortDirection={props.sortDirection}
/>
);
};
14 changes: 9 additions & 5 deletions ui/v2.5/src/components/List/ListFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ export const PageSizeSelector: React.FC<{
);
};

export const SortByIcon: React.FC<{
sortDirection: SortDirectionEnum;
}> = ({ sortDirection }) => (
<Icon
icon={sortDirection === SortDirectionEnum.Asc ? faCaretUp : faCaretDown}
/>
);

export const SortBySelect: React.FC<{
className?: string;
sortBy: string | undefined;
Expand Down Expand Up @@ -303,11 +311,7 @@ export const SortBySelect: React.FC<{
}
>
<Button variant="secondary" onClick={onChangeSortDirection}>
<Icon
icon={
sortDirection === SortDirectionEnum.Asc ? faCaretUp : faCaretDown
}
/>
<SortByIcon sortDirection={sortDirection} />
</Button>
</OverlayTrigger>
{sortBy === "random" && (
Expand Down
42 changes: 36 additions & 6 deletions ui/v2.5/src/components/List/ListTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import React, { useMemo } from "react";
import { Table, Form } from "react-bootstrap";
import { CheckBoxSelect } from "../Shared/Select";
import cx from "classnames";
import { SortDirectionEnum } from "src/core/generated-graphql";
import { SortByIcon } from "./ListFilter";

export interface IColumn {
label: string;
value: string;
mandatory?: boolean;
sortable?: boolean;
}

export const ColumnSelector: React.FC<{
Expand Down Expand Up @@ -47,6 +50,9 @@ interface IListTableProps<T> {
selectedIds: Set<string>;
onSelectChange: (id: string, selected: boolean, shiftKey: boolean) => void;
renderCell: (column: IColumn, item: T, index: number) => React.ReactNode;
onSort?: (value: string) => void;
sortBy?: string;
sortDirection?: SortDirectionEnum;
}

export const ListTable = <T extends { id: string }>(
Expand All @@ -61,6 +67,9 @@ export const ListTable = <T extends { id: string }>(
selectedIds,
onSelectChange,
renderCell,
onSort,
sortBy,
sortDirection,
} = props;

const visibleColumns = useMemo(() => {
Expand Down Expand Up @@ -102,12 +111,33 @@ export const ListTable = <T extends { id: string }>(
};

const columnHeaders = useMemo(() => {
return visibleColumns.map((column) => (
<th key={column.value} className={`${column.value}-head`}>
{column.label}
</th>
));
}, [visibleColumns]);
return visibleColumns.map((column) => {
const isSortable = column.sortable !== false && onSort;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do sortable columns outnumber non-sortable columns? If not, then perhaps we should consider defaulting to sortable = false.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answering my own question, it appears that there's more sortable than not. I don't love defaulting to false with a name like sortable, but I don't have an alternative.

const isActive = sortBy === column.value;

return (
<th
key={column.value}
className={`${column.value}-head${isSortable ? " sortable" : ""}`}
onClick={isSortable ? () => onSort(column.value) : undefined}
style={isSortable ? { cursor: "pointer" } : undefined}
>
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
}}
>
{column.label}
{isActive && sortDirection && (
<SortByIcon sortDirection={sortDirection} />
)}
</div>
</th>
);
});
}, [visibleColumns, onSort, sortBy, sortDirection]);

return (
<div className={cx("table-list", className)}>
Expand Down
8 changes: 6 additions & 2 deletions ui/v2.5/src/components/List/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,11 @@ input[type="range"].zoom-slider {
margin-right: 0.25rem;
padding: 0.25em 0.6em;
text-align: center;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out,
border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
transition:
color 0.15s ease-in-out,
background-color 0.15s ease-in-out,
border-color 0.15s ease-in-out,
box-shadow 0.15s ease-in-out;
vertical-align: baseline;
white-space: nowrap;

Expand Down Expand Up @@ -928,6 +931,7 @@ ul.selectable-list {

.table thead th {
border: none;
padding-bottom: 0;
white-space: nowrap;
}

Expand Down
Loading
Loading