Skip to content

Instantly share code, notes, and snippets.

View sdjnes's full-sized avatar

Sam Jones sdjnes

  • Zaragoza, Spain
View GitHub Profile
@sdjnes
sdjnes / gist:6b5a76ae08a6bf8b602e64a0fe6a092c
Created September 4, 2023 10:42
Prevent deletion of in-use resources in Payload
import payload from 'payload';
import { CollectionBeforeDeleteHook } from 'payload/types';
/**
* A very inefficient function to prevent deletion of items when they are referenced in other collections
*
* This should be replaced when Payload implement this feature natively, or provide additional data that we can use
* to implement this more efficiently.
*
* It is on their roadmap (https://github.com/payloadcms/payload/discussions/2938)
import { User } from 'payload/dist/auth';
import { Access, AccessArgs, FieldAccess } from 'payload/types';
type CheckerArgs = {
user?: User;
id?: string | number;
};
type Checker = (args: CheckerArgs) => boolean;
const isAdmin: Checker = ({ user }) => user?.role && user?.role === 'admin';
@sdjnes
sdjnes / Example.tsx
Last active June 20, 2023 09:33
Modal system idea
// To use it, you simply define a Modal and then render it
type MyComponentProps = {
description: string;
links: Array<{ href: string, label: string}>
}
const MyComponent = (props: MyComponentProps) => ...
const Page = () => {
@sdjnes
sdjnes / index.js
Created June 12, 2023 11:20
NX Set SHAs
const { Octokit } = require('@octokit/action');
const core = require('@actions/core');
const github = require('@actions/github');
const { execSync } = require('child_process');
const {
runId,
repo: { repo, owner },
eventName,
} = github.context;
@sdjnes
sdjnes / description.md
Last active March 30, 2023 12:18
@payloadcms/plugin-cloud-storage GCS adapter with local filesystem

The @payloadcms/plugin-cloud-storage allows you to upload files from Payload collections to a Google Cloud Storage bucket.

It relies on Node APIs that are not available in the browser.

The payload.config.ts is used by both the server of Payload and the frontend for the webpack build.

The GCS adapter for this plugin relies on the @google-cloud/storage which calls the Node APIs for processing and uploading files.

When you add this plugin to your payload.config.ts, and a collection uses a gcpAdapter, it will automatically extend your webpack config with the following (see: https://github.com/payloadcms/plugin-cloud-storage/blob/master/src/adapters/gcs/webpack.ts):

#!/bin/bash
GITHUB_ORG=""
GITHUB_REPO=""
# If the commit message contains [skip ci] then don't run
if [[ "$VERCEL_GIT_COMMIT_MESSAGE" == *"[skip ci]"* ]]; then
echo "⏭️ skipping ([skip ci] in commit message)"
exit 0
fi
{
"slate": {
"50": "#F8FAFC",
"100": "#F1F5F9",
"200": "#E2E8F0",
"300": "#CBD5E1",
"400": "#94A3B8",
"500": "#64748B",
"600": "#475569",
"700": "#334155",

Keybase proof

I hereby claim:

  • I am sdjnes on github.
  • I am sdjnes (https://keybase.io/sdjnes) on keybase.
  • I have a public key ASCnn76ia73Yj0u3bSoewEbihzet8qUSS0xV9HDQDrh4QQo

To claim this, I am signing this object: