This commit is contained in:
Hugo Bernier 2023-02-18 23:00:35 -05:00
commit 0f4a86aeab
4 changed files with 14 additions and 13 deletions

View File

@ -1,8 +1,8 @@
http://aka.ms/m365devprogramhttp://aka.ms/m365devprogramhttp://aka.ms/m365devprogramhttp://aka.ms/m365devprogram# Copy Views # Copy Views
## Summary ## Summary
This solution enables a user to copy views from one list/library to another across site collections. It can be used as a webpart on a page, or as a ListView Command Set extension. The user can select multiple views to copy to multiple target lists. This solution enables a user to copy views from one list/library to another across site collections. It can be used as a web part on a page, or as a ListView Command Set extension. The user can select multiple views to copy to multiple target lists.
![Copy Views extension](./assets/copy-views-screenshot.png) ![Copy Views extension](./assets/copy-views-screenshot.png)
@ -55,20 +55,20 @@ This sample is optimally compatible with the following environment configuration
- Use `gulp bundle --ship` & `gulp package-solution --ship` - Use `gulp bundle --ship` & `gulp package-solution --ship`
- Add the `.sppkg` to your SharePoint App Catalog - Add the `.sppkg` to your SharePoint App Catalog
> This sample can also be opened with [VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview). Visit https://aka.ms/spfx-devcontainer for further instructions. > This sample can also be opened with [VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview). Visit <https://aka.ms/spfx-devcontainer> for further instructions.
## Features ## Features
- Views can be copied from one list or library to other lists or libraries across site collections. - Views can be copied from one list or library to other lists or libraries across site collections.
- List views can only be copied to other *lists* and library views can only be copied to other *libraries*. - List views can only be copied to other *lists* and library views can only be copied to other *libraries*.
- When opening the component using the List view Command Set extension, the current site, list and view will be preselected. When opening the component from a webpart, the current site will be preselected. - When opening the component using the List view Command Set extension, the current site, list and view will be preselected. When opening the component from a webpart, the current site will be preselected.
- When copying views, the following things will be included: - When copying views, the following things will be included:
- Field references. - Field references.
- Sort and filter settings. - Sort and filter settings.
- Column formatting and view formatting. - Column formatting and view formatting.
- Fields that are not available on the target list are excluded from the copied view. The view query is cleaned of these fields so as not to break the view when columns are used to filter on. * - Fields that are not available on the target list are excluded from the copied view. The view query is cleaned of these fields so as not to break the view when columns are used to filter on. *
- Views of type 'Kanban board' and 'modern calendar' are currently **not** supported. - Views of type 'Kanban board' and 'modern calendar' are currently **not** supported.
- Views that are set to default on the source list will not automatically be set to default on the target list. The checkbox 'Set as default' will need to be used. - Views that are set to default on the source list will not automatically be set to default on the target list. The checkbox 'Set as default' will need to be used.
> *The component uses the DOM parser to parse the ViewQuery XML, and removes any filter conditions that reference fields that are not available on the target list. The component can even clean filter queries with multiple And/Or CAML-conditions. > *The component uses the DOM parser to parse the ViewQuery XML, and removes any filter conditions that reference fields that are not available on the target list. The component can even clean filter queries with multiple And/Or CAML-conditions.
@ -90,8 +90,8 @@ Finally, if you have an idea for improvement, [make a suggestion](https://github
## Disclaimer ## Disclaimer
**THIS CODE IS PROVIDED _AS IS_ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.** **THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
--- ---
<img src="https://pnptelemetry.azurewebsites.net/sp-dev-fx-webparts/samples/react-copy-views" /> <img src="https://pnptelemetry.azurewebsites.net/sp-dev-fx-webparts/samples/react-copy-views" />

View File

@ -3,7 +3,7 @@
"solution": { "solution": {
"name": "copy-views-client-side-solution", "name": "copy-views-client-side-solution",
"id": "f9a94606-ce1c-487c-ab87-550b240421de", "id": "f9a94606-ce1c-487c-ab87-550b240421de",
"version": "1.0.2.0", "version": "1.0.2.1",
"includeClientSideAssets": true, "includeClientSideAssets": true,
"skipFeatureDeployment": true, "skipFeatureDeployment": true,
"isDomainIsolated": false, "isDomainIsolated": false,

View File

@ -43,7 +43,7 @@ export class ListViewsService implements IListViewsService {
const web = Web([this._sp.web, siteUrl]); const web = Web([this._sp.web, siteUrl]);
const views = await web.lists.getById(listId).views.select("Id", "Title", "ServerRelativeUrl", "ViewType2")(); const views = await web.lists.getById(listId).views.orderBy("Title", true).select("Id", "Title", "ServerRelativeUrl", "ViewType2")();
return views.map((view: IViewInfo) => { return views.map((view: IViewInfo) => {
const viewFileName = view.ServerRelativeUrl.substring(view.ServerRelativeUrl.lastIndexOf('/') + 1); const viewFileName = view.ServerRelativeUrl.substring(view.ServerRelativeUrl.lastIndexOf('/') + 1);

View File

@ -51,7 +51,7 @@ export class ListsService implements IListsService {
"EntityTypeName ne 'FormServerTemplates'" // Exclude the Form Templates library "EntityTypeName ne 'FormServerTemplates'" // Exclude the Form Templates library
]; ];
const lists = await web.lists.expand("RootFolder").select("Id", "Title", "BaseType", "RootFolder/ServerRelativeUrl").filter(filterConditions.join(" and "))(); const lists = await web.lists.expand("RootFolder").select("Id", "Title", "BaseType", "RootFolder/ServerRelativeUrl").orderBy("Title", true).filter(filterConditions.join(" and "))();
return lists return lists
.filter(l => l.BaseType === 1 || l.BaseType === 0) .filter(l => l.BaseType === 1 || l.BaseType === 0)
@ -105,8 +105,9 @@ export class ListsService implements IListsService {
} }
}); });
// Sort on title to help list selection. Sorting on title is impossible serverside because Title is not sortable.
return mappedResults.sort((a, b) => { return mappedResults.sort((a, b) => {
if (a.siteUrl < b.siteUrl) { return -1; } else if (a.siteUrl > b.siteUrl) { return 1; } else { return 0; } if (a.title < b.title) { return -1; } else if (a.title > b.title) { return 1; } else { return 0; }
}); });
} }