diff --git a/.changeset/heavy-rings-play.md b/.changeset/heavy-rings-play.md new file mode 100644 index 0000000000..bbed4c3fa3 --- /dev/null +++ b/.changeset/heavy-rings-play.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-bazaar': patch +--- + +Adding descending sort in a bazaar plugin diff --git a/plugins/bazaar/src/components/SortMethodSelector/SortMethodSelector.tsx b/plugins/bazaar/src/components/SortMethodSelector/SortMethodSelector.tsx index d29211dc44..2ce7f623d1 100644 --- a/plugins/bazaar/src/components/SortMethodSelector/SortMethodSelector.tsx +++ b/plugins/bazaar/src/components/SortMethodSelector/SortMethodSelector.tsx @@ -50,7 +50,8 @@ export const SortMethodSelector = ({ > Latest updated A-Z - Most members + Z-A + Most members ); diff --git a/plugins/bazaar/src/components/SortView/SortView.tsx b/plugins/bazaar/src/components/SortView/SortView.tsx index 46f4c64c42..aa310ba55d 100644 --- a/plugins/bazaar/src/components/SortView/SortView.tsx +++ b/plugins/bazaar/src/components/SortView/SortView.tsx @@ -27,7 +27,12 @@ import { BazaarProject } from '../../types'; import { bazaarApiRef } from '../../api'; import { Alert } from '@material-ui/lab'; import SearchBar from 'material-ui-search-bar'; -import { sortByDate, sortByMembers, sortByTitle } from '../../util/sortMethods'; +import { + sortByDate, + sortByMembers, + sortByTitle, + sortByTitleDescending, +} from '../../util/sortMethods'; import { SortMethodSelector } from '../SortMethodSelector'; import { fetchCatalogItems } from '../../util/fetchMethods'; import { parseBazaarProject } from '../../util/parseMethods'; @@ -78,7 +83,12 @@ export const SortView = (props: SortViewProps) => { const bazaarApi = useApi(bazaarApiRef); const catalogApi = useApi(catalogApiRef); const classes = useStyles(); - const sortMethods = [sortByDate, sortByTitle, sortByMembers]; + const sortMethods = [ + sortByDate, + sortByTitle, + sortByTitleDescending, + sortByMembers, + ]; const [sortMethodNbr, setSortMethodNbr] = useState(0); const [openAdd, setOpenAdd] = useState(false); const [searchValue, setSearchValue] = useState(''); diff --git a/plugins/bazaar/src/util/sortMethods.ts b/plugins/bazaar/src/util/sortMethods.ts index d7ef71c8de..2a9b7969b3 100644 --- a/plugins/bazaar/src/util/sortMethods.ts +++ b/plugins/bazaar/src/util/sortMethods.ts @@ -27,12 +27,11 @@ export const sortByDate = (a: BazaarProject, b: BazaarProject): number => { }; export const sortByTitle = (a: BazaarProject, b: BazaarProject) => { - if (a.title < b.title) { - return -1; - } else if (a.title > b.title) { - return 1; - } - return 0; + return a.title.localeCompare(b.title); +}; + +export const sortByTitleDescending = (a: BazaarProject, b: BazaarProject) => { + return b.title.localeCompare(a.title); }; export const sortByMembers = (a: BazaarProject, b: BazaarProject) => {