cli-microsoft365 icon indicating copy to clipboard operation
cli-microsoft365 copied to clipboard

Enhancement: Extract commonly used functions into a shared file in page commands

Open mkm17 opened this issue 10 months ago • 6 comments

Hi, I have noticed that some functions are duplicated in page commands. The idea is to analyze them and extract them into a shared file, like Page.ts.

Here are the functions I have found so far.

_api/site?$select=Id used in

contenttype-add contenttype-field-remove contenttype field-set contenttype-set page-header-set site-admin-add

_api/web?$select=Id used in

contenttype-add contenttype-field-remove contenttype field-set contenttype-set page-header-set site-admin-add

/checkoutpage used in

page-clientsidewebpart-add page-header-set page-section-add

mkm17 avatar Mar 02 '25 11:03 mkm17

@mkm17 awesome suggestion 👍. Just to clarify before I open it up. So your idea is to create separate util methods for those functions and just reuse them in the commands you mentioned? If so do you think we could add links to those price functions to make it super clear what we want to get rid off and replace with a new util method?

Adam-it avatar Mar 07 '25 08:03 Adam-it

@Adam-it Yes, the aim is to reduce duplication, as some functions are already exported to the "util" file named Page.ts. I will compile a list of links to certain files.

mkm17 avatar Mar 09 '25 08:03 mkm17

@Adam-it Yes, the aim is to reduce duplication, as some functions are already exported to the "util" file named Page.ts. I will compile a list of links to certain files.

Thanks for the confirmation. I will open it up. In the mean time we may add those links to make this super clear

Adam-it avatar Mar 09 '25 09:03 Adam-it

Hi @Adam-it , you was right, GetSiteId, GetWebId and GetListId can be exported to spo.ts. In spo.ts there is already the getSiteId function but it is using Ms Graph endpoint.

**_api/site?$select=Id

_api/site?$select=Id used in

contenttype-add contenttype-field-remove contenttype field-set contenttype-set page-header-set site-admin-add

_api/web?$select=Id used in

contenttype-add contenttype-field-remove contenttype field-set contenttype-set page-header-set

getListId contenttype-add contenttype-field-remove contenttype-set listitem-batch-set

And this function from page.ts can be used for /checkoutpage which is used in

page-clientsidewebpart-add page-header-set page-section-add

mkm17 avatar Mar 29 '25 12:03 mkm17

Hi @Adam-it what do you think, can I make this change?

mkm17 avatar Apr 16 '25 15:04 mkm17

Hi @Adam-it what do you think, can I make this change?

Totally 👍 Thank you for the ping. I was a bit busy in other projects and I haven't notice this notify before. Sorry for that 🙏 You Rock 🤩

Adam-it avatar Apr 17 '25 05:04 Adam-it