Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🀠 July 18th

'Hacking' custom Document Actions πŸ˜‡

By William Iommi

A little 'hack' when you work on custom Document actions

DividerAction.ts

const DividerAction = () => {
  return {
    label: '------------------------',
    disabled: true,
  };
};

export default DividerAction;

TitleSectionAction.ts

const TitleSectionAction = () => {
  return {
    label: 'My Section',
    disabled: true,
  };
};

export default TitleSectionAction;

sanity.config.ts

import DividerAction from './DividerAction';
import TitleAction from './TitleAction';
import CustomAction1 from './CustomAction1';
import CustomAction2 from './CustomAction2';

export default defineConfig({
  // ... other configuration
  document: {
    actions: (prev, context) => {
      prev.splice(1, 0, TitleAction);
      prev.splice(2, 0, CustomAction1);
      prev.splice(3, 0, CustomAction2);
      prev.splice(4, 0, SpacerAction);
      return prev;
    },
  },
  // ... other configuration
});

I don't know if there is a better or proper way to do it but my end goal was to visually separate my custom actions from the default ones.

With this little 'hack' I'm able to have a separate section with my custom actions defined.

In sanity.config file, my custom actions start from index 1 (screenshot).

Contributor

Other schemas by author

Is your Microcopy unique?

A custom validation to check if your Microcopy documents have unique keys and values for a specific namespace.

William Iommi
Go to Is your Microcopy unique?