Skip to content

Commit e3d9631

Browse files
committed
Initial commit
0 parents  commit e3d9631

34 files changed

+9096
-0
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DATABASE_URI=mongodb://127.0.0.1/your-database-name
2+
PAYLOAD_SECRET=YOUR_SECRET_HERE

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
/.idea/*
10+
!/.idea/runConfigurations
11+
12+
# testing
13+
/coverage
14+
15+
# next.js
16+
/.next/
17+
/out/
18+
19+
# production
20+
/build
21+
22+
# misc
23+
.DS_Store
24+
*.pem
25+
26+
# debug
27+
npm-debug.log*
28+
yarn-debug.log*
29+
yarn-error.log*
30+
31+
# local env files
32+
.env*.local
33+
34+
# vercel
35+
.vercel
36+
37+
# typescript
38+
*.tsbuildinfo
39+
next-env.d.ts
40+
41+
.env
42+
43+
/media

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
legacy-peer-deps=true

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"printWidth": 100,
5+
"semi": false
6+
}

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
3+
}

.vscode/launch.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Next.js: debug full stack",
9+
"type": "node",
10+
"request": "launch",
11+
"program": "${workspaceFolder}/node_modules/next/dist/bin/next",
12+
"runtimeArgs": ["--inspect"],
13+
"skipFiles": ["<node_internals>/**"],
14+
"serverReadyAction": {
15+
"action": "debugWithChrome",
16+
"killOnServerStop": true,
17+
"pattern": "- Local:.+(https?://.+)",
18+
"uriFormat": "%s",
19+
"webRoot": "${workspaceFolder}"
20+
},
21+
"cwd": "${workspaceFolder}"
22+
}
23+
]
24+
}

.vscode/settings.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"npm.packageManager": "pnpm",
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"[typescript]": {
5+
"editor.defaultFormatter": "esbenp.prettier-vscode",
6+
"editor.formatOnSave": true,
7+
"editor.codeActionsOnSave": {
8+
"source.fixAll.eslint": "explicit"
9+
}
10+
},
11+
"[typescriptreact]": {
12+
"editor.defaultFormatter": "esbenp.prettier-vscode",
13+
"editor.formatOnSave": true,
14+
"editor.codeActionsOnSave": {
15+
"source.fixAll.eslint": "explicit"
16+
}
17+
},
18+
"[javascript]": {
19+
"editor.defaultFormatter": "esbenp.prettier-vscode",
20+
"editor.formatOnSave": true,
21+
"editor.codeActionsOnSave": {
22+
"source.fixAll.eslint": "explicit"
23+
}
24+
},
25+
"[json]": {
26+
"editor.defaultFormatter": "esbenp.prettier-vscode",
27+
"editor.formatOnSave": true
28+
},
29+
"[jsonc]": {
30+
"editor.defaultFormatter": "esbenp.prettier-vscode",
31+
"editor.formatOnSave": true
32+
},
33+
"editor.formatOnSaveMode": "file",
34+
"typescript.tsdk": "node_modules/typescript/lib",
35+
"[javascript][typescript][typescriptreact]": {
36+
"editor.codeActionsOnSave": {
37+
"source.fixAll.eslint": "explicit"
38+
}
39+
}
40+
}

.yarnrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--install.ignore-engines true

Dockerfile

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# To use this Dockerfile, you have to set `output: 'standalone'` in your next.config.mjs file.
2+
# From https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
3+
4+
FROM node:22.12.0-alpine AS base
5+
6+
# Install dependencies only when needed
7+
FROM base AS deps
8+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
9+
RUN apk add --no-cache libc6-compat
10+
WORKDIR /app
11+
12+
# Install dependencies based on the preferred package manager
13+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
14+
RUN \
15+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
16+
elif [ -f package-lock.json ]; then npm ci; \
17+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
18+
else echo "Lockfile not found." && exit 1; \
19+
fi
20+
21+
22+
# Rebuild the source code only when needed
23+
FROM base AS builder
24+
WORKDIR /app
25+
COPY --from=deps /app/node_modules ./node_modules
26+
COPY . .
27+
28+
# Next.js collects completely anonymous telemetry data about general usage.
29+
# Learn more here: https://nextjs.org/telemetry
30+
# Uncomment the following line in case you want to disable telemetry during the build.
31+
# ENV NEXT_TELEMETRY_DISABLED 1
32+
33+
RUN \
34+
if [ -f yarn.lock ]; then yarn run build; \
35+
elif [ -f package-lock.json ]; then npm run build; \
36+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
37+
else echo "Lockfile not found." && exit 1; \
38+
fi
39+
40+
# Production image, copy all the files and run next
41+
FROM base AS runner
42+
WORKDIR /app
43+
44+
ENV NODE_ENV production
45+
# Uncomment the following line in case you want to disable telemetry during runtime.
46+
# ENV NEXT_TELEMETRY_DISABLED 1
47+
48+
RUN addgroup --system --gid 1001 nodejs
49+
RUN adduser --system --uid 1001 nextjs
50+
51+
# Remove this line if you do not have this folder
52+
COPY --from=builder /app/public ./public
53+
54+
# Set the correct permission for prerender cache
55+
RUN mkdir .next
56+
RUN chown nextjs:nodejs .next
57+
58+
# Automatically leverage output traces to reduce image size
59+
# https://nextjs.org/docs/advanced-features/output-file-tracing
60+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
61+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
62+
63+
USER nextjs
64+
65+
EXPOSE 3000
66+
67+
ENV PORT 3000
68+
69+
# server.js is created by next build from the standalone output
70+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
71+
CMD HOSTNAME="0.0.0.0" node server.js

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# List Presets Demo
2+
3+
_This feature is released and installed as a canary version. It is not yet available in the latest stable release. See package.json for exact details._
4+
5+
List Presets allow you to save and share filters, columns, and sort orders for your Collections. This is useful for reusing common or complex filtering patterns and column configurations across your team.
6+
7+
Each preset is saved as a new record in the database under the `payload-list-presets` collection. This allows for an endless number of Preset configurations, where the users of your app define the presets that are most useful to them, rather than being hard coded into the Payload Config.
8+
9+
Within the Admin Panel, List Presets are applied to the List View. When enabled, new controls are displayed for you can manage presets. Once saved, these presets are available for future use by you and your team.
10+
11+
To enable List Presets on a Collection, use the `enableListPresets` property in your Collection Config.
12+
13+
```ts
14+
import type { CollectionConfig } from 'payload'
15+
16+
export const MyCollection: CollectionConfig = {
17+
// ...
18+
// highlight-start
19+
enableListPresets: true,
20+
// highlight-end
21+
}
22+
```
23+
24+
## Access Control
25+
26+
List Presets are subject to the same Access Control patterns as the rest of Payload. This means you can use the same access control functions you are already familiar with to control who can read, update, and delete each individual preset.
27+
28+
### Default Access Control
29+
30+
By default, Payload provides a set of sensible defaults for all List Presets, but you can customize these rules to suit your needs. Those defaults are as follows:
31+
32+
- Only Me: Only the user who created the preset can read, update, and delete it.
33+
- Everyone: All users can read, update, and delete the preset.
34+
- Specific Users: Only select users can read, update, and delete the preset.
35+
36+
When a user manages a preset, these options will be available to them in the Admin Panel.
37+
38+
### Custom Access Control
39+
40+
You can also add custom access control rules to List Presets. For example, you could create a rule that only allows users with a specific role to read, update, or delete a preset.
41+
42+
#### Adding a new option
43+
44+
To add custom access control to List Presets, you'll first need to append a new option for users to select when managing a preset. Options are per operation, so you can have completely different rules for reading, updating, and deleting.
45+
46+
Each options requires a label, a value, and a list of fields that will be used to determine access. The fields are conditionally rendered only when that particular option is selected.
47+
48+
To do this, use the `listPresets.constraints` property in your Payload Config.
49+
50+
```ts
51+
import { buildConfig } from 'payload'
52+
53+
const config = buildConfig({
54+
// ...
55+
// highlight-start
56+
listPresets: {
57+
// ...
58+
constraints: {
59+
read: {
60+
label: 'Specific Roles',
61+
value: 'specificRoles,
62+
fields: [
63+
{
64+
name: 'roles',
65+
type: 'select',
66+
hasMany: true,
67+
options: [
68+
{ label: 'Admin', value: 'admin' },
69+
{ label: 'User', value: 'user' },
70+
],
71+
},
72+
],
73+
},
74+
update: {
75+
// ...
76+
},
77+
delete: {
78+
// ...
79+
},
80+
}
81+
},
82+
// highlight-end
83+
})
84+
```
85+
86+
#### Applying the new option
87+
88+
Once you've added the new option, you'll need to write specific access control rules for each operation using the fields that you've provided. Payload will automatically merge these rules with the default rules.
89+
90+
To do this, use the `listPresets.access` property in your Collection Config:
91+
92+
```ts
93+
import { buildConfig } from 'payload'
94+
95+
const config = buildConfig({
96+
// ...
97+
// highlight-start
98+
listPresets: {
99+
// ...
100+
access: {
101+
read: ({ req: { user } }) => ({
102+
'access.read.roles': {
103+
// Your fields are automatically injected into the access[operation] group
104+
in: user?.roles,
105+
},
106+
}),
107+
update: () => {
108+
// ...
109+
},
110+
delete: () => {
111+
// ...
112+
},
113+
},
114+
},
115+
// highlight-end
116+
})
117+
```
118+
119+
<Banner type="warning">
120+
**Note:**
121+
Payload injects your custom fields into the `access[operation]` group, so your rules need to reflect this.
122+
</Banner>

docker-compose.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '3'
2+
3+
services:
4+
payload:
5+
image: node:18-alpine
6+
ports:
7+
- '3000:3000'
8+
volumes:
9+
- .:/home/node/app
10+
- node_modules:/home/node/app/node_modules
11+
working_dir: /home/node/app/
12+
command: sh -c "corepack enable && corepack prepare pnpm@latest --activate && pnpm install && pnpm dev"
13+
depends_on:
14+
- mongo
15+
# - postgres
16+
env_file:
17+
- .env
18+
19+
# Ensure your DATABASE_URI uses 'mongo' as the hostname ie. mongodb://mongo/my-db-name
20+
mongo:
21+
image: mongo:latest
22+
ports:
23+
- '27017:27017'
24+
command:
25+
- --storageEngine=wiredTiger
26+
volumes:
27+
- data:/data/db
28+
logging:
29+
driver: none
30+
31+
# Uncomment the following to use postgres
32+
# postgres:
33+
# restart: always
34+
# image: postgres:latest
35+
# volumes:
36+
# - pgdata:/var/lib/postgresql/data
37+
# ports:
38+
# - "5432:5432"
39+
40+
volumes:
41+
data:
42+
# pgdata:
43+
node_modules:

0 commit comments

Comments
 (0)