mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
Feature Request: Sort All Urls Alphabetically (#6352)
This commit is contained in:
parent
88a149c085
commit
061d21dede
9 changed files with 37 additions and 11 deletions
|
|
@ -31,6 +31,7 @@ import { Studio, StudioSelect } from "src/components/Studios/StudioSelect";
|
||||||
import { Scene, SceneSelect } from "src/components/Scenes/SceneSelect";
|
import { Scene, SceneSelect } from "src/components/Scenes/SceneSelect";
|
||||||
import { useTagsEdit } from "src/hooks/tagsEdit";
|
import { useTagsEdit } from "src/hooks/tagsEdit";
|
||||||
import { ScraperMenu } from "src/components/Shared/ScraperMenu";
|
import { ScraperMenu } from "src/components/Shared/ScraperMenu";
|
||||||
|
import { sortURLs } from "src/utils/url";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
gallery: Partial<GQL.GalleryDataFragment>;
|
gallery: Partial<GQL.GalleryDataFragment>;
|
||||||
|
|
@ -81,7 +82,7 @@ export const GalleryEditPanel: React.FC<IProps> = ({
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
title: gallery?.title ?? "",
|
title: gallery?.title ?? "",
|
||||||
code: gallery?.code ?? "",
|
code: gallery?.code ?? "",
|
||||||
urls: gallery?.urls ?? [],
|
urls: sortURLs(gallery?.urls ?? []),
|
||||||
date: gallery?.date ?? "",
|
date: gallery?.date ?? "",
|
||||||
photographer: gallery?.photographer ?? "",
|
photographer: gallery?.photographer ?? "",
|
||||||
studio_id: gallery?.studio?.id ?? null,
|
studio_id: gallery?.studio?.id ?? null,
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import { Studio, StudioSelect } from "src/components/Studios/StudioSelect";
|
||||||
import { useTagsEdit } from "src/hooks/tagsEdit";
|
import { useTagsEdit } from "src/hooks/tagsEdit";
|
||||||
import { Group } from "src/components/Groups/GroupSelect";
|
import { Group } from "src/components/Groups/GroupSelect";
|
||||||
import { RelatedGroupTable, IRelatedGroupEntry } from "./RelatedGroupTable";
|
import { RelatedGroupTable, IRelatedGroupEntry } from "./RelatedGroupTable";
|
||||||
|
import { sortURLs } from "src/utils/url";
|
||||||
|
|
||||||
interface IGroupEditPanel {
|
interface IGroupEditPanel {
|
||||||
group: Partial<GQL.GroupDataFragment>;
|
group: Partial<GQL.GroupDataFragment>;
|
||||||
|
|
@ -97,7 +98,7 @@ export const GroupEditPanel: React.FC<IGroupEditPanel> = ({
|
||||||
return { group_id: m.group.id, description: m.description ?? "" };
|
return { group_id: m.group.id, description: m.description ?? "" };
|
||||||
}),
|
}),
|
||||||
director: group?.director ?? "",
|
director: group?.director ?? "",
|
||||||
urls: group?.urls ?? [],
|
urls: sortURLs(group?.urls ?? []),
|
||||||
synopsis: group?.synopsis ?? "",
|
synopsis: group?.synopsis ?? "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import {
|
||||||
} from "src/components/Galleries/GallerySelect";
|
} from "src/components/Galleries/GallerySelect";
|
||||||
import { useTagsEdit } from "src/hooks/tagsEdit";
|
import { useTagsEdit } from "src/hooks/tagsEdit";
|
||||||
import { ScraperMenu } from "src/components/Shared/ScraperMenu";
|
import { ScraperMenu } from "src/components/Shared/ScraperMenu";
|
||||||
|
import { sortURLs } from "src/utils/url";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
image: GQL.ImageDataFragment;
|
image: GQL.ImageDataFragment;
|
||||||
|
|
@ -91,7 +92,7 @@ export const ImageEditPanel: React.FC<IProps> = ({
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
title: image.title ?? "",
|
title: image.title ?? "",
|
||||||
code: image.code ?? "",
|
code: image.code ?? "",
|
||||||
urls: image?.urls ?? [],
|
urls: sortURLs(image?.urls ?? []),
|
||||||
date: image?.date ?? "",
|
date: image?.date ?? "",
|
||||||
details: image.details ?? "",
|
details: image.details ?? "",
|
||||||
photographer: image.photographer ?? "",
|
photographer: image.photographer ?? "",
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ import {
|
||||||
yupUniqueStringList,
|
yupUniqueStringList,
|
||||||
} from "src/utils/yup";
|
} from "src/utils/yup";
|
||||||
import { useTagsEdit } from "src/hooks/tagsEdit";
|
import { useTagsEdit } from "src/hooks/tagsEdit";
|
||||||
|
import { sortURLs } from "src/utils/url";
|
||||||
import { CustomFieldsInput } from "src/components/Shared/CustomFields";
|
import { CustomFieldsInput } from "src/components/Shared/CustomFields";
|
||||||
import { cloneDeep } from "@apollo/client/utilities";
|
import { cloneDeep } from "@apollo/client/utilities";
|
||||||
|
|
||||||
|
|
@ -153,7 +154,7 @@ export const PerformerEditPanel: React.FC<IPerformerDetails> = ({
|
||||||
tattoos: performer.tattoos ?? "",
|
tattoos: performer.tattoos ?? "",
|
||||||
piercings: performer.piercings ?? "",
|
piercings: performer.piercings ?? "",
|
||||||
career_length: performer.career_length ?? "",
|
career_length: performer.career_length ?? "",
|
||||||
urls: performer.urls ?? [],
|
urls: sortURLs(performer.urls ?? []),
|
||||||
details: performer.details ?? "",
|
details: performer.details ?? "",
|
||||||
tag_ids: (performer.tags ?? []).map((t) => t.id),
|
tag_ids: (performer.tags ?? []).map((t) => t.id),
|
||||||
ignore_auto_tag: performer.ignore_auto_tag ?? false,
|
ignore_auto_tag: performer.ignore_auto_tag ?? false,
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ import { Group } from "src/components/Groups/GroupSelect";
|
||||||
import { useTagsEdit } from "src/hooks/tagsEdit";
|
import { useTagsEdit } from "src/hooks/tagsEdit";
|
||||||
import { ScraperMenu } from "src/components/Shared/ScraperMenu";
|
import { ScraperMenu } from "src/components/Shared/ScraperMenu";
|
||||||
import StashBoxIDSearchModal from "src/components/Shared/StashBoxIDSearchModal";
|
import StashBoxIDSearchModal from "src/components/Shared/StashBoxIDSearchModal";
|
||||||
|
import { sortURLs } from "src/utils/url";
|
||||||
|
|
||||||
const SceneScrapeDialog = lazyComponent(() => import("./SceneScrapeDialog"));
|
const SceneScrapeDialog = lazyComponent(() => import("./SceneScrapeDialog"));
|
||||||
const SceneQueryModal = lazyComponent(() => import("./SceneQueryModal"));
|
const SceneQueryModal = lazyComponent(() => import("./SceneQueryModal"));
|
||||||
|
|
@ -138,7 +139,7 @@ export const SceneEditPanel: React.FC<IProps> = ({
|
||||||
() => ({
|
() => ({
|
||||||
title: scene.title ?? "",
|
title: scene.title ?? "",
|
||||||
code: scene.code ?? "",
|
code: scene.code ?? "",
|
||||||
urls: scene.urls ?? [],
|
urls: sortURLs(scene.urls ?? []),
|
||||||
date: scene.date ?? "",
|
date: scene.date ?? "",
|
||||||
director: scene.director ?? "",
|
director: scene.director ?? "",
|
||||||
gallery_ids: (scene.galleries ?? []).map((g) => g.id),
|
gallery_ids: (scene.galleries ?? []).map((g) => g.id),
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { useMemo } from "react";
|
||||||
import { faInstagram, faTwitter } from "@fortawesome/free-brands-svg-icons";
|
import { faInstagram, faTwitter } from "@fortawesome/free-brands-svg-icons";
|
||||||
import ReactDOM from "react-dom";
|
import ReactDOM from "react-dom";
|
||||||
import { PatchComponent } from "src/patch";
|
import { PatchComponent } from "src/patch";
|
||||||
|
import { sortURLs } from "src/utils/url";
|
||||||
|
|
||||||
export const ExternalLinksButton: React.FC<{
|
export const ExternalLinksButton: React.FC<{
|
||||||
icon?: IconDefinition;
|
icon?: IconDefinition;
|
||||||
|
|
@ -16,14 +17,16 @@ export const ExternalLinksButton: React.FC<{
|
||||||
}> = PatchComponent(
|
}> = PatchComponent(
|
||||||
"ExternalLinksButton",
|
"ExternalLinksButton",
|
||||||
({ urls, icon = faLink, className = "", openIfSingle = false }) => {
|
({ urls, icon = faLink, className = "", openIfSingle = false }) => {
|
||||||
if (!urls.length) {
|
const sortedUrls = useMemo(() => sortURLs(urls), [urls]);
|
||||||
|
|
||||||
|
if (!sortedUrls.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Menu = () =>
|
const Menu = () =>
|
||||||
ReactDOM.createPortal(
|
ReactDOM.createPortal(
|
||||||
<Dropdown.Menu>
|
<Dropdown.Menu>
|
||||||
{urls.map((url) => (
|
{sortedUrls.map((url) => (
|
||||||
<Dropdown.Item
|
<Dropdown.Item
|
||||||
key={url}
|
key={url}
|
||||||
as={ExternalLink}
|
as={ExternalLink}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import React from "react";
|
import React, { useMemo } from "react";
|
||||||
import { TagLink } from "src/components/Shared/TagLink";
|
import { TagLink } from "src/components/Shared/TagLink";
|
||||||
import * as GQL from "src/core/generated-graphql";
|
import * as GQL from "src/core/generated-graphql";
|
||||||
import { DetailItem } from "src/components/Shared/DetailItem";
|
import { DetailItem } from "src/components/Shared/DetailItem";
|
||||||
import { StashIDPill } from "src/components/Shared/StashID";
|
import { StashIDPill } from "src/components/Shared/StashID";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
import { sortURLs } from "src/utils/url";
|
||||||
|
|
||||||
interface IStudioDetailsPanel {
|
interface IStudioDetailsPanel {
|
||||||
studio: GQL.StudioDataFragment;
|
studio: GQL.StudioDataFragment;
|
||||||
|
|
@ -46,14 +47,16 @@ export const StudioDetailsPanel: React.FC<IStudioDetailsPanel> = ({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sortedURLs = useMemo(() => sortURLs(studio.urls ?? []), [studio.urls]);
|
||||||
|
|
||||||
function renderURLs() {
|
function renderURLs() {
|
||||||
if (!studio.urls?.length) {
|
if (!sortedURLs.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul className="pl-0">
|
<ul className="pl-0">
|
||||||
{studio.urls.map((url) => (
|
{sortedURLs.map((url) => (
|
||||||
<li key={url}>
|
<li key={url}>
|
||||||
<a href={url} target="_blank" rel="noreferrer">
|
<a href={url} target="_blank" rel="noreferrer">
|
||||||
{url}
|
{url}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import { Studio, StudioSelect } from "../StudioSelect";
|
||||||
import { useTagsEdit } from "src/hooks/tagsEdit";
|
import { useTagsEdit } from "src/hooks/tagsEdit";
|
||||||
import { Icon } from "src/components/Shared/Icon";
|
import { Icon } from "src/components/Shared/Icon";
|
||||||
import StashBoxIDSearchModal from "src/components/Shared/StashBoxIDSearchModal";
|
import StashBoxIDSearchModal from "src/components/Shared/StashBoxIDSearchModal";
|
||||||
|
import { sortURLs } from "src/utils/url";
|
||||||
|
|
||||||
interface IStudioEditPanel {
|
interface IStudioEditPanel {
|
||||||
studio: Partial<GQL.StudioDataFragment>;
|
studio: Partial<GQL.StudioDataFragment>;
|
||||||
|
|
@ -68,7 +69,7 @@ export const StudioEditPanel: React.FC<IStudioEditPanel> = ({
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
id: studio.id,
|
id: studio.id,
|
||||||
name: studio.name ?? "",
|
name: studio.name ?? "",
|
||||||
urls: studio.urls ?? [],
|
urls: sortURLs(studio.urls ?? []),
|
||||||
details: studio.details ?? "",
|
details: studio.details ?? "",
|
||||||
parent_id: studio.parent_studio?.id ?? null,
|
parent_id: studio.parent_studio?.id ?? null,
|
||||||
aliases: studio.aliases ?? [],
|
aliases: studio.aliases ?? [],
|
||||||
|
|
|
||||||
14
ui/v2.5/src/utils/url.ts
Normal file
14
ui/v2.5/src/utils/url.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
/**
|
||||||
|
* Extracts the sortable portion of a URL by removing the protocol and www. prefix
|
||||||
|
*/
|
||||||
|
const urlSortKey = (url: string): string =>
|
||||||
|
url.toLowerCase().replace(/^(https?:\/\/)?(www\.)?/, "");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts a list of URLs alphabetically by their base URL,
|
||||||
|
* excluding the protocol (http/https) and www. prefix.
|
||||||
|
* Returns a new sorted array without mutating the original.
|
||||||
|
*/
|
||||||
|
export function sortURLs(urls: string[]): string[] {
|
||||||
|
return [...urls].sort((a, b) => urlSortKey(a).localeCompare(urlSortKey(b)));
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue