[Wordpress] Convert static classes to props (#5725)
* refactor: downloads * refactor: ratings * refactor: versions Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
@@ -48,34 +48,24 @@ function DownloadsForExtensionType(extensionType) {
|
||||
const { capt, exampleSlug } = extensionData[extensionType]
|
||||
|
||||
return class WordpressDownloads extends BaseWordpress {
|
||||
static get name() {
|
||||
return `Wordpress${capt}Downloads`
|
||||
static name = `Wordpress${capt}Downloads`
|
||||
|
||||
static category = 'downloads'
|
||||
|
||||
static route = {
|
||||
base: `wordpress/${extensionType}`,
|
||||
pattern: ':interval(dd|dw|dm|dy|dt)/:slug',
|
||||
}
|
||||
|
||||
static get category() {
|
||||
return 'downloads'
|
||||
}
|
||||
static examples = [
|
||||
{
|
||||
title: `WordPress ${capt} Downloads`,
|
||||
namedParams: { interval: 'dm', slug: exampleSlug },
|
||||
staticPreview: this.render({ interval: 'dm', downloads: 200000 }),
|
||||
},
|
||||
]
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: `wordpress/${extensionType}`,
|
||||
pattern: ':interval(dd|dw|dm|dy|dt)/:slug',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: `WordPress ${capt} Downloads`,
|
||||
namedParams: { interval: 'dm', slug: exampleSlug },
|
||||
staticPreview: this.render({ interval: 'dm', downloads: 200000 }),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static get defaultBadgeData() {
|
||||
return { label: 'downloads' }
|
||||
}
|
||||
static defaultBadgeData = { label: 'downloads' }
|
||||
|
||||
static render({ interval, downloads }) {
|
||||
const { messageSuffix } = intervalMap[interval]
|
||||
@@ -129,34 +119,24 @@ function InstallsForExtensionType(extensionType) {
|
||||
const { capt, exampleSlug } = extensionData[extensionType]
|
||||
|
||||
return class WordpressInstalls extends BaseWordpress {
|
||||
static get name() {
|
||||
return `Wordpress${capt}Installs`
|
||||
static name = `Wordpress${capt}Installs`
|
||||
|
||||
static category = 'downloads'
|
||||
|
||||
static route = {
|
||||
base: `wordpress/${extensionType}/installs`,
|
||||
pattern: ':slug',
|
||||
}
|
||||
|
||||
static get category() {
|
||||
return 'downloads'
|
||||
}
|
||||
static examples = [
|
||||
{
|
||||
title: `WordPress ${capt} Active Installs`,
|
||||
namedParams: { slug: exampleSlug },
|
||||
staticPreview: this.render({ installCount: 300000 }),
|
||||
},
|
||||
]
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: `wordpress/${extensionType}/installs`,
|
||||
pattern: ':slug',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: `WordPress ${capt} Active Installs`,
|
||||
namedParams: { slug: exampleSlug },
|
||||
staticPreview: this.render({ installCount: 300000 }),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static get defaultBadgeData() {
|
||||
return { label: 'active installs' }
|
||||
}
|
||||
static defaultBadgeData = { label: 'active installs' }
|
||||
|
||||
static render({ installCount }) {
|
||||
return {
|
||||
|
||||
@@ -16,42 +16,32 @@ const extensionData = {
|
||||
}
|
||||
|
||||
class WordpressRatingBase extends BaseWordpress {
|
||||
static get category() {
|
||||
return 'rating'
|
||||
}
|
||||
static category = 'rating'
|
||||
|
||||
static get defaultBadgeData() {
|
||||
return { label: 'rating' }
|
||||
}
|
||||
static defaultBadgeData = { label: 'rating' }
|
||||
}
|
||||
|
||||
function RatingForExtensionType(extensionType) {
|
||||
const { capt, exampleSlug } = extensionData[extensionType]
|
||||
|
||||
return class WordpressRating extends WordpressRatingBase {
|
||||
static get name() {
|
||||
return `Wordpress${capt}Rating`
|
||||
static name = `Wordpress${capt}Rating`
|
||||
|
||||
static route = {
|
||||
base: `wordpress/${extensionType}/rating`,
|
||||
pattern: ':slug',
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: `wordpress/${extensionType}/rating`,
|
||||
pattern: ':slug',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: `WordPress ${capt} Rating`,
|
||||
namedParams: { slug: exampleSlug },
|
||||
staticPreview: this.render({
|
||||
rating: 80,
|
||||
numRatings: 100,
|
||||
}),
|
||||
},
|
||||
]
|
||||
}
|
||||
static examples = [
|
||||
{
|
||||
title: `WordPress ${capt} Rating`,
|
||||
namedParams: { slug: exampleSlug },
|
||||
staticPreview: this.render({
|
||||
rating: 80,
|
||||
numRatings: 100,
|
||||
}),
|
||||
},
|
||||
]
|
||||
|
||||
static render({ rating, numRatings }) {
|
||||
const scaledAndRounded = ((rating / 100) * 5).toFixed(1)
|
||||
@@ -75,30 +65,24 @@ function StarsForExtensionType(extensionType) {
|
||||
const { capt, exampleSlug } = extensionData[extensionType]
|
||||
|
||||
return class WordpressStars extends WordpressRatingBase {
|
||||
static get name() {
|
||||
return `Wordpress${capt}Stars`
|
||||
static name = `Wordpress${capt}Stars`
|
||||
|
||||
static route = {
|
||||
base: `wordpress/${extensionType}`,
|
||||
pattern: '(stars|r)/:slug',
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: `wordpress/${extensionType}`,
|
||||
pattern: '(stars|r)/:slug',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: `WordPress ${capt} Rating`,
|
||||
pattern: 'stars/:slug',
|
||||
namedParams: { slug: exampleSlug },
|
||||
staticPreview: this.render({
|
||||
rating: 80,
|
||||
}),
|
||||
documentation: 'There is an alias <code>/r/:slug.svg</code> as well.',
|
||||
},
|
||||
]
|
||||
}
|
||||
static examples = [
|
||||
{
|
||||
title: `WordPress ${capt} Rating`,
|
||||
pattern: 'stars/:slug',
|
||||
namedParams: { slug: exampleSlug },
|
||||
staticPreview: this.render({
|
||||
rating: 80,
|
||||
}),
|
||||
documentation: 'There is an alias <code>/r/:slug.svg</code> as well.',
|
||||
},
|
||||
]
|
||||
|
||||
static render({ rating }) {
|
||||
const scaled = (rating / 100) * 5
|
||||
|
||||
@@ -17,34 +17,24 @@ function VersionForExtensionType(extensionType) {
|
||||
}[extensionType]
|
||||
|
||||
return class WordpressVersion extends BaseWordpress {
|
||||
static get name() {
|
||||
return `Wordpress${capt}Version`
|
||||
static name = `Wordpress${capt}Version`
|
||||
|
||||
static category = 'version'
|
||||
|
||||
static route = {
|
||||
base: `wordpress/${extensionType}/v`,
|
||||
pattern: ':slug',
|
||||
}
|
||||
|
||||
static get category() {
|
||||
return 'version'
|
||||
}
|
||||
static examples = [
|
||||
{
|
||||
title: `WordPress ${capt} Version`,
|
||||
namedParams: { slug: exampleSlug },
|
||||
staticPreview: this.render({ version: 2.5 }),
|
||||
},
|
||||
]
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: `wordpress/${extensionType}/v`,
|
||||
pattern: ':slug',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: `WordPress ${capt} Version`,
|
||||
namedParams: { slug: exampleSlug },
|
||||
staticPreview: this.render({ version: 2.5 }),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static get defaultBadgeData() {
|
||||
return { label: extensionType }
|
||||
}
|
||||
static defaultBadgeData = { label: extensionType }
|
||||
|
||||
static render({ version }) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user