-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/per-page' of github.com:payloadcms/payload
- Loading branch information
Showing
10 changed files
with
257 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
@import '../../../scss/styles.scss'; | ||
|
||
.per-page { | ||
display: flex; | ||
margin-bottom: $baseline; | ||
margin-right: 0; | ||
margin-left: auto; | ||
|
||
button { | ||
padding: base(.25) 0; | ||
line-height: base(1); | ||
background: transparent; | ||
border: 0; | ||
font-weight: 600; | ||
cursor: pointer; | ||
|
||
&:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
&:active, | ||
&:focus { | ||
outline: none; | ||
} | ||
} | ||
|
||
span { | ||
color: $color-gray; | ||
} | ||
|
||
ul { | ||
list-style: none; | ||
padding: 0; | ||
text-align: left; | ||
margin: 0; | ||
|
||
li { | ||
text-decoration: none; | ||
} | ||
|
||
a { | ||
color: $color-gray; | ||
&:visited, &:link, &:active { | ||
text-decoration: none; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useEffect, useState, useCallback } from 'react'; | ||
import qs from 'qs'; | ||
|
||
import { Link } from 'react-router-dom'; | ||
import { useConfig } from '@payloadcms/config-provider'; | ||
import { usePreferences } from '../../utilities/Preferences'; | ||
import { useSearchParams } from '../../utilities/SearchParams'; | ||
import Popup from '../Popup'; | ||
import Chevron from '../../icons/Chevron'; | ||
|
||
import './index.scss'; | ||
|
||
const baseClass = 'per-page'; | ||
type Props = { | ||
setLimit: (limit: number) => void; | ||
limit: number; | ||
} | ||
|
||
const PerPage: React.FC<Props> = ({ setLimit }) => { | ||
const { admin: { pagination: { options } } } = useConfig(); | ||
|
||
return ( | ||
<div className={baseClass}> | ||
<Popup | ||
horizontalAlign="center" | ||
button={( | ||
<div> | ||
Per Page: | ||
<Chevron /> | ||
</div> | ||
)} | ||
backgroundColor="#333333" | ||
render={({ close }) => ( | ||
<div> | ||
<ul> | ||
{options.map((limitNumber, i) => ( | ||
<li | ||
className={`${baseClass}-item`} | ||
key={i} | ||
> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
close(); | ||
setLimit(limitNumber); | ||
}} | ||
> | ||
{limitNumber} | ||
</button> | ||
</li> | ||
))} | ||
; | ||
</ul> | ||
</div> | ||
)} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PerPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* eslint-disable no-nested-ternary */ | ||
/* eslint-disable no-use-before-define */ | ||
import { compile } from 'json-schema-to-typescript'; | ||
// import fse from 'fs-extra'; | ||
import { CollectionConfig, SanitizedCollectionConfig } from '../collections/config/types'; | ||
import { SanitizedConfig } from './types'; | ||
|
||
export function generateTypes(sanitizedConfig: SanitizedConfig): void { | ||
console.log('compiling ts types'); | ||
const jsonSchema = configToJsonSchema(sanitizedConfig.collections); | ||
|
||
compile(jsonSchema, 'Config', { | ||
bannerComment: '// auto-generated by payload', | ||
unreachableDefinitions: true, | ||
}).then((compiled) => { | ||
// fse.writeFileSync('generated-types.ts', compiled); | ||
console.log('compiled', compiled); | ||
}); | ||
} | ||
|
||
function collectionToJsonSchema( | ||
collection: CollectionConfig, | ||
slugToLabel: Record<string, string>, | ||
): any { | ||
return { | ||
title: collection.labels.singular, | ||
type: 'object', | ||
properties: Object.fromEntries( | ||
collection.fields.map((field) => { | ||
const type = field.type === 'number' | ||
? { type: 'integer' } | ||
: field.type === 'relationship' | ||
? { | ||
$ref: `#/definitions/${slugToLabel[field.relationTo as string]}`, | ||
} | ||
: { type: 'string' }; | ||
const enum_ = field.type === 'select' ? { enum: field.options } : {}; | ||
const default_ = field.defaultValue ? { default: field.defaultValue } : {}; | ||
|
||
return [ | ||
field.name, | ||
{ | ||
...type, | ||
...enum_, | ||
...default_, | ||
}, | ||
]; | ||
}), | ||
), | ||
required: collection.fields | ||
.filter((field) => field.required === true) | ||
.map((field) => field.name), | ||
additionalProperties: false, | ||
}; | ||
} | ||
|
||
function configToJsonSchema(collections: SanitizedCollectionConfig[]): any { | ||
const slugToLabel = Object.fromEntries( | ||
collections.map((collection) => [ | ||
collection.slug, | ||
collection.labels.singular, | ||
]), | ||
); | ||
return { | ||
definitions: Object.fromEntries( | ||
collections.map((collection) => [ | ||
collection.labels.singular, | ||
collectionToJsonSchema(collection, slugToLabel), | ||
]), | ||
), | ||
additionalProperties: false, | ||
}; | ||
} | ||
|
||
// const result = await compile(jsonSchema, 'Config', { | ||
// bannerComment: '// auto-generated by payload', | ||
// unreachableDefinitions: true, | ||
// }); | ||
|
||
// await fse.writeFile('generated-types.ts', result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters