Skip to content

Commit cdaa6d6

Browse files
authored
feat: enhance partner list functionality with sorting options
1 parent 625ed9c commit cdaa6d6

File tree

4 files changed

+62
-14
lines changed

4 files changed

+62
-14
lines changed

apps/site/components/Common/Partners/PartnersIconList/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ const PartnersIconList: FC<PartnersIconListProps> = ({
3737
const renderSponsorsAnimation = setTimeout(() => {
3838
initialRenderer.current = false;
3939

40-
setSeedList(randomPartnerList(ICON_PARTNERS, maxLength, 5, categories));
40+
setSeedList(
41+
randomPartnerList(ICON_PARTNERS, {
42+
pick: maxLength,
43+
dateSeed: 5,
44+
category: categories,
45+
})
46+
);
4147
}, 0);
4248

4349
return () => clearTimeout(renderSponsorsAnimation);

apps/site/components/Common/Partners/PartnersLogoList/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import { randomPartnerList } from '../utils';
1212
type PartnersLogoListProps = {
1313
maxLength?: number;
1414
categories?: PartnerCategory;
15+
sort?: 'name' | 'weight';
1516
};
1617

1718
const PartnersLogoList: FC<PartnersLogoListProps> = ({
1819
maxLength = 3,
20+
sort = 'weight',
1921
categories,
2022
}) => {
2123
const initialRenderer = useRef(true);
@@ -42,7 +44,14 @@ const PartnersLogoList: FC<PartnersLogoListProps> = ({
4244
const renderSponsorsAnimation = setTimeout(() => {
4345
initialRenderer.current = false;
4446

45-
setSeedList(randomPartnerList(LOGO_PARTNERS, maxLength, 5, categories));
47+
setSeedList(
48+
randomPartnerList(LOGO_PARTNERS, {
49+
pick: maxLength,
50+
dateSeed: 5,
51+
category: categories,
52+
sort: sort,
53+
})
54+
);
4655
}, 0);
4756

4857
return () => clearTimeout(renderSponsorsAnimation);

apps/site/components/Common/Partners/utils.ts

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
11
import type { PartnerCategory, Partners } from '#site/types/partners.js';
22

3-
// TODO: Implement no random list
4-
// TODO: Implement no importance of partner
53
function randomPartnerList(
64
partners: Array<Partners>,
7-
pick = 4,
8-
dateSeed = 5,
9-
category?: PartnerCategory
5+
config: {
6+
/**
7+
* Number of partners to pick from the list.
8+
* If null, all partners will be returned.
9+
*/
10+
pick?: number | null;
11+
/**
12+
* Date seed to use for the randomization.
13+
* This is used to ensure that the same partners are returned for the same date.
14+
*/
15+
dateSeed?: number;
16+
/**
17+
* Category of partners to filter by.
18+
* If not provided, all partners will be returned.
19+
*/
20+
category?: PartnerCategory;
21+
/**
22+
* Whether to randomize the partners or not.
23+
*/
24+
sort?: 'name' | 'weight' | null;
25+
}
1026
) {
27+
const { pick = 4, dateSeed = 5, category, sort = 'weight' } = config;
28+
29+
const filteredPartners = [...partners].filter(partner => {
30+
return !category || partner.categories.includes(category);
31+
});
32+
33+
if (sort === null) {
34+
return pick !== null ? filteredPartners.slice(0, pick) : filteredPartners;
35+
}
36+
37+
if (sort === 'name') {
38+
const shuffled = [...filteredPartners].sort((a, b) =>
39+
a.name.localeCompare(b.name)
40+
);
41+
42+
return pick !== null ? shuffled.slice(0, pick) : shuffled;
43+
}
44+
1145
const now = new Date();
1246
const minutes = Math.floor(now.getUTCMinutes() / dateSeed) * dateSeed;
1347

@@ -27,8 +61,7 @@ function randomPartnerList(
2761
const seed = fixedTime.getTime();
2862
const rng = mulberry32(seed);
2963

30-
const weightedPartners = partners.flatMap(partner => {
31-
if (category && !partner.categories.includes(category)) return [];
64+
const weightedPartners = filteredPartners.flatMap(partner => {
3265
const weight = partner.weight;
3366
return Array(weight).fill(partner);
3467
});

apps/site/pages/en/about/partners.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ The infrastructure partners provide important support for the Node.js project,
1818
providing hardware and machines for our continuous integration and testing processes,
1919
without we can't test and release new versions of Node.js.
2020

21-
<PartnersLogoList categories="infrastructure" maxLength={null} />
21+
<PartnersLogoList categories="infrastructure" maxLength={null} sort="name" />
2222

2323
## Security
2424

2525
The security partners help us to provide new security releases in a timely manner, ensuring
2626
properly good practices for vulnerability disclosure and remediation. Their contributions are
2727
crucial to ensure that the Node.js ecosystem remains secure and resilient against vulnerabilities.
2828

29-
<PartnersLogoList categories="security" maxLength={null} />
29+
<PartnersLogoList categories="security" maxLength={null} sort="name" />
3030

3131
## Releases
3232

3333
The release partners help us to provide new releases, ensuring that new features and improvements
3434
are delivered to the Node.js ecosystem in a timely manner. Their contributions are essential
3535
to the ongoing development and evolution of Node.js.
3636

37-
<PartnersLogoList categories="release" maxLength={null} />
37+
<PartnersLogoList categories="release" maxLength={null} sort="name" />
3838

3939
## Services
4040

4141
The service partners help us to provide a range of services that support the Node.js project.
4242
Their contributions are vital to ensuring that nodejs maintainers have access to the tools and
4343
resources they need to build and maintain this project.
4444

45-
<PartnersLogoList categories="service" maxLength={null} />
45+
<PartnersLogoList categories="service" maxLength={null} sort="name" />
4646

4747
## Supporters
4848

@@ -63,7 +63,7 @@ End-Of-Life versions, please visit [End-Of-Life Node.js Releases](/eol)
6363
> Using EOL releases through NES should be viewed as a temporary solution, the goal should always
6464
> be to upgrade to actively supported versions.
6565
66-
<PartnersLogoList categories="esp" maxLength={null} />
66+
<PartnersLogoList categories="esp" maxLength={null} sort="name" />
6767

6868
## Become a Partner
6969

0 commit comments

Comments
 (0)