pnp / cli-microsoft365

Manage Microsoft 365 and SharePoint Framework projects on any platform
https://aka.ms/cli-m365
MIT License
909 stars 317 forks source link

Add `Parent` property to content type command output #6329

Open milanholemans opened 1 week ago

milanholemans commented 1 week ago

Currently, we can list content types in sites and lists, but when using quite some content types that inherit from the same content type (e.g. Site Page X inherits from Site Page Y which inherits from Site Page), it can become really difficult to check which content type inherits from which. I suggest that we enhance the output with the Parent property. This way the user can easily check which content type inherits from which.


Commands to update:

API:

GET https://contoso.sharepoint.com/sites/playground/Lists('<Guid>')/ContentTypes?$expand=Parent

Since Parent returns the entire content type of the parent, I suggest we only retrieve properties Id, StringId, Name, Group.

Output would look something like this:

[
  {
    "Parent": {
        "StringId": "0x01000B1208C5D23DF",
        "Name": "Item",
        "Group": "List items",
        "Id": { "StringId": "0x01000B1208C5D23DF" },
     },
    "ClientFormCustomFormatter": "",
    "Description": "Create a new list item.",
    "DisplayFormClientSideComponentId": "",
    "DisplayFormClientSideComponentProperties": "",
    "DisplayFormTarget": 0,
    "DisplayFormTemplateName": "ListForm",
    "DisplayFormUrl": "",
    "DocumentTemplate": "",
    "DocumentTemplateUrl": "",
    "EditFormClientSideComponentId": "",
    "EditFormClientSideComponentProperties": "",
    "EditFormTarget": 0,
    "EditFormTemplateName": "ListForm",
    "EditFormUrl": "",
    "Group": "List Content Types",
    "Hidden": false,
    "Id": {
      "StringValue": "0x01000B1208C5D23DF44B9F1AEE7373DE9D5E"
    },
    "JSLink": "",
    "MobileDisplayFormUrl": "",
    "MobileEditFormUrl": "",
    "MobileNewFormUrl": "",
    "Name": "Item",
    "NewFormClientSideComponentId": null,
    "NewFormClientSideComponentProperties": "",
    "NewFormTarget": 0,
    "NewFormTemplateName": "ListForm",
    "NewFormUrl": "",
    "ReadOnly": false,
    "SchemaXml": "<ContentType ID=\"0x01000B1208C5D23DF44B9F1AEE7373DE9D5E\" Name=\"Item\" Group=\"List Content Types\" Description=\"Create a new list item.\" Version=\"0\" FeatureId=\"{695b6570-a48b-4a8e-8ea5-26ea7fc1d162}\" FeatureIds=\"{695b6570-a48b-4a8e-8ea5-26ea7fc1d162};{c94c1702-30a7-454c-be15-5a895223428d}\"><Folder TargetName=\"Item\"/><Fields><Field ID=\"{c042a256-787d-4a6f-8a8a-cf6ab767f12d}\" Type=\"Computed\" DisplayName=\"Content Type\" Name=\"ContentType\" DisplaceOnUpgrade=\"TRUE\" RenderXMLUsingPattern=\"TRUE\" Sortable=\"FALSE\" SourceID=\"http://schemas.microsoft.com/sharepoint/v3\" StaticName=\"ContentType\" Group=\"_Hidden\" PITarget=\"MicrosoftWindowsSharePointServices\" PIAttribute=\"ContentTypeID\" FromBaseType=\"TRUE\"><FieldRefs><FieldRef Name=\"ContentTypeId\"/></FieldRefs><DisplayPattern><MapToContentType><Column Name=\"ContentTypeId\"/></MapToContentType></DisplayPattern></Field><Field ID=\"{fa564e0f-0c70-4ab9-b863-0177e6ddd247}\" Type=\"Text\" Name=\"Title\" DisplayName=\"Title\" Required=\"TRUE\" SourceID=\"http://schemas.microsoft.com/sharepoint/v3\" StaticName=\"Title\" FromBaseType=\"TRUE\" ColName=\"nvarchar1\" ShowInNewForm=\"TRUE\" ShowInEditForm=\"TRUE\"/></Fields><XmlDocuments><XmlDocument NamespaceURI=\"http://schemas.microsoft.com/sharepoint/v3/contenttype/forms\"><FormTemplates xmlns=\"http://schemas.microsoft.com/sharepoint/v3/contenttype/forms\"><Display>ListForm</Display><Edit>ListForm</Edit><New>ListForm</New></FormTemplates></XmlDocument></XmlDocuments></ContentType>",
    "Scope": "/Lists/Test",
    "Sealed": false,
    "StringId": "0x01000B1208C5D23DF44B9F1AEE7373DE9D5E"
  }
]
Adam-it commented 1 week ago

I am all in on extending this the output to make other folks life easier, on the other hand I don't like when we modify the default API response to our output as then it produce some additional maintenance around that 🤔. What if we do not add it to the default output of those commands but instead add and additional option like withParent or something similar and then add this additional information to the output? Also then I would not trim the output but return the entire content type. What do you think? @pnp/cli-for-microsoft-365-maintainers any other feed on that?

milanholemans commented 1 week ago

I'm open to suggestions, but if we add a new flag for this, it will produce more maintenance than if we include it by default? No?

Adam-it commented 1 week ago

in terms of maintenance I meant that we modify the API response. If this API response would change then potentially the command breaks. If we do not modify the response or add it as a optional (when some option is defined) kind of thing then there will be no problem when API response would change in the default command run

milanholemans commented 1 week ago

But if we add properties to command output it won't break anything, right? Only if we remove stuff from the response.

Adam-it commented 1 week ago

no it does not break anything. I described a scenario that when an default API response change and our command does not return the default response but modified version of it then usually the command breaks. That is why I usually vote to return exactly the same as the API response if possible

milanholemans commented 1 week ago

We're not really changing the response. The only thing we do is add ?$expand=Parent&$select=Parent/Id,Parent/Name,... to the already existing API request.

MathijsVerbeeck commented 1 week ago

For me it makes sense to add the Parent property. I would add it by default too.

Adam-it commented 1 week ago
?$expand=Parent

ok I the original issue I thought we will just add ?$expand=Parent and trim the output in code. In this case it makes sense

appieschot commented 1 week ago

I opt for also adding the parent to the response.