From c5aad900e30371caad4bfe38449440d68fc151b5 Mon Sep 17 00:00:00 2001 From: AmbrishRamachandiran Date: Tue, 17 Oct 2023 11:13:16 +0530 Subject: [PATCH 1/4] Adding decending sort in a bazaar plugin Signed-off-by: AmbrishRamachandiran --- .changeset/heavy-rings-play.md | 5 +++++ .../SortMethodSelector/SortMethodSelector.tsx | 3 ++- .../bazaar/src/components/SortView/SortView.tsx | 14 ++++++++++++-- plugins/bazaar/src/util/sortMethods.ts | 9 +++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 .changeset/heavy-rings-play.md diff --git a/.changeset/heavy-rings-play.md b/.changeset/heavy-rings-play.md new file mode 100644 index 0000000000..fc647f2491 --- /dev/null +++ b/.changeset/heavy-rings-play.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-bazaar': patch +--- + +Adding decending 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..e0b591732e 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, + sortByDecendingTitle, +} 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, + sortByDecendingTitle, + 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..d0680949f2 100644 --- a/plugins/bazaar/src/util/sortMethods.ts +++ b/plugins/bazaar/src/util/sortMethods.ts @@ -35,6 +35,15 @@ export const sortByTitle = (a: BazaarProject, b: BazaarProject) => { return 0; }; +export const sortByDecendingTitle = (a: BazaarProject, b: BazaarProject) => { + if (a.title < b.title) { + return 1; + } else if (a.title > b.title) { + return -1; + } + return 0; +}; + export const sortByMembers = (a: BazaarProject, b: BazaarProject) => { return b.membersCount - a.membersCount; }; From b4b5d5035017c077b2e8f74e100e275e6f8305f8 Mon Sep 17 00:00:00 2001 From: AmbrishRamachandiran Date: Tue, 17 Oct 2023 11:14:58 +0530 Subject: [PATCH 2/4] Adding decending sort in a bazaar plugin Signed-off-by: AmbrishRamachandiran --- .changeset/heavy-rings-play.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/heavy-rings-play.md b/.changeset/heavy-rings-play.md index fc647f2491..bbed4c3fa3 100644 --- a/.changeset/heavy-rings-play.md +++ b/.changeset/heavy-rings-play.md @@ -2,4 +2,4 @@ '@backstage/plugin-bazaar': patch --- -Adding decending sort in a bazaar plugin +Adding descending sort in a bazaar plugin From 9f4ae86b0c06218dc96b6cde787bcf67f34fbab3 Mon Sep 17 00:00:00 2001 From: AmbrishRamachandiran Date: Wed, 18 Oct 2023 09:44:58 +0530 Subject: [PATCH 3/4] Replaced the string compare logic with local compare Signed-off-by: AmbrishRamachandiran --- plugins/bazaar/src/util/sortMethods.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/plugins/bazaar/src/util/sortMethods.ts b/plugins/bazaar/src/util/sortMethods.ts index d0680949f2..d23ad177f1 100644 --- a/plugins/bazaar/src/util/sortMethods.ts +++ b/plugins/bazaar/src/util/sortMethods.ts @@ -27,21 +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 sortByDecendingTitle = (a: BazaarProject, b: BazaarProject) => { - if (a.title < b.title) { - return 1; - } else if (a.title > b.title) { - return -1; - } - return 0; + return b.title.localeCompare(a.title); }; export const sortByMembers = (a: BazaarProject, b: BazaarProject) => { From 138eac62fd82b1b9d330f73f91683ed4192be302 Mon Sep 17 00:00:00 2001 From: AmbrishRamachandiran Date: Wed, 18 Oct 2023 17:21:00 +0530 Subject: [PATCH 4/4] Name changes Signed-off-by: AmbrishRamachandiran --- plugins/bazaar/src/components/SortView/SortView.tsx | 4 ++-- plugins/bazaar/src/util/sortMethods.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/bazaar/src/components/SortView/SortView.tsx b/plugins/bazaar/src/components/SortView/SortView.tsx index e0b591732e..aa310ba55d 100644 --- a/plugins/bazaar/src/components/SortView/SortView.tsx +++ b/plugins/bazaar/src/components/SortView/SortView.tsx @@ -31,7 +31,7 @@ import { sortByDate, sortByMembers, sortByTitle, - sortByDecendingTitle, + sortByTitleDescending, } from '../../util/sortMethods'; import { SortMethodSelector } from '../SortMethodSelector'; import { fetchCatalogItems } from '../../util/fetchMethods'; @@ -86,7 +86,7 @@ export const SortView = (props: SortViewProps) => { const sortMethods = [ sortByDate, sortByTitle, - sortByDecendingTitle, + sortByTitleDescending, sortByMembers, ]; const [sortMethodNbr, setSortMethodNbr] = useState(0); diff --git a/plugins/bazaar/src/util/sortMethods.ts b/plugins/bazaar/src/util/sortMethods.ts index d23ad177f1..2a9b7969b3 100644 --- a/plugins/bazaar/src/util/sortMethods.ts +++ b/plugins/bazaar/src/util/sortMethods.ts @@ -30,7 +30,7 @@ export const sortByTitle = (a: BazaarProject, b: BazaarProject) => { return a.title.localeCompare(b.title); }; -export const sortByDecendingTitle = (a: BazaarProject, b: BazaarProject) => { +export const sortByTitleDescending = (a: BazaarProject, b: BazaarProject) => { return b.title.localeCompare(a.title); };