#Extending edit view in Payload 2.0

7 messages · Page 1 of 1 (latest)

half tree
#

I'm upgrading my projects to Payload 2.0 and I'm having a problem fixing extended components. Note that code samples below are not exact copies but instead simplified to ease the explanation.

I have following code in the collection config:

const items: CollectionConfig = {
  slug: "items",
  admin: {
    components: {
      views: {
        Edit: { Default: CustomEditView },
      },
    },
  },
};

The props for component that can be passed into CollectionConfig.admin.components.views.Edit.Default are the following:

interface EditViewComponentProps {
  collection?: SanitizedCollectionConfig;
  global?: SanitizedGlobalConfig;
  user: User | null | undefined;
}

I'm extending component from module payload/components/views/Edit which have following props (combined into one interface here):

interface DefaultEditViewProps {
  action: string;
  apiURL: string;
  canAccessAdmin?: boolean;
  data: any;
  isLoading: boolean;
  onSave: (json: any) => void;
  updatedAt: string;
  user: User | null | undefined;
  collection: SanitizedCollectionConfig;
  disableActions?: boolean;
  disableLeaveWithoutSaving?: boolean;
  hasSavePermission?: boolean;
  id: string;
  initialState?: Fields;
  internalState?: Fields;
  isEditing?: boolean;
  permissions: CollectionPermission | null;
  customHeader?: React.ReactNode;
  disableRoutes?: boolean;
}

So the question is, that is there an easy way to set props required by DefaultEditView and extend it using props provided into custom EditViewComponent? It used to be so that the custom component got all the props required by the default component, but that doesn't seem to be the case anymore.

fathom matrixBOT
half tree
#

I found a way to deal with this by not extending edit view. The problem of extending edit view is still not solved, but for my use case UI field and extending list view did the trick. If you are interested in the details, see this GitHub discussion: https://github.com/payloadcms/payload/discussions/3660

GitHub

I'd want to see improvement towards reacting to permission changes in admin panel. I've had already a couple of cases where this has become a problem, but there's no perfect way to fix ...

supple parcel
#

Hey @half tree we should be able to get this buttoned up for you, I’ll take a closer look on Monday

unique isle
#

Hey @half tree and @supple parcel - how's this one going? I'm setting up a payload 2.0 project and trying to figure what's the best option for tenanting - this one looks the problem has been solved once it's updated fro 2.0

half tree
#

Hey @unique isle! As I said earlier, none of these issues are anymore a blocker for the plugin's 2.0 update. Now it's just my time that I just now have got some of.

unique isle
#

Oh awesome! Sorry, I just saw the message about Monday and was curious