-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2809 from bcameron1231/v4-documentSets
V4 document sets
- Loading branch information
Showing
6 changed files
with
282 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,128 @@ | ||
# @pnp/graph/items | ||
|
||
Currently, there is no module in graph to access all items directly. Please, instead, default to search by path using the following methods. | ||
|
||
[![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) | ||
|
||
### Get list items | ||
|
||
```TypeScript | ||
import { Site } from "@pnp/graph/sites"; | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/list-items"; | ||
import "@pnp/graph/lists"; | ||
|
||
const sites = graph.sites.getById("{site id}"); | ||
const graph = graphfi(...); | ||
const items = const siteLists = await graph.site.getById("{site identifier}").lists.getById("{list identifier}").items(); | ||
|
||
const items = await Site(sites, "lists/{listid}/items")(); | ||
``` | ||
|
||
### Get File/Item version information | ||
|
||
```TypeScript | ||
import { Site } from "@pnp/graph/sites"; | ||
|
||
const sites = graph.sites.getById("{site id}"); | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/list-items"; | ||
import "@pnp/graph/lists"; | ||
|
||
const users = await Site(sites, "lists/{listid}/items/{item id}/versions")(); | ||
const graph = graphfi(...); | ||
const itemVersions = const siteLists = await graph.site.getById("{site identifier}").lists.getById("{list identifier}").items.getById(1).versions(); | ||
|
||
``` | ||
|
||
### Get list items with fields included | ||
|
||
```TypeScript | ||
import { Site } from "@pnp/graph/sites"; | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/list-items"; | ||
import "@pnp/graph/lists"; | ||
|
||
const graph = graphfi(...); | ||
const listItems = await graph.site.getById("{site identifier}").lists.getById("{list identifier}").items..expand("fields")(); | ||
|
||
``` | ||
|
||
### Create a new list item | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/list-items"; | ||
import "@pnp/graph/lists"; | ||
|
||
const graph = graphfi(...); | ||
var newItem = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.add({ | ||
Title: "Widget", | ||
}); | ||
|
||
``` | ||
### Update a list item | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/list-items"; | ||
import "@pnp/graph/lists"; | ||
|
||
const graph = graphfi(...); | ||
var newItem = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").update({ | ||
Title: "Widget", | ||
}); | ||
|
||
``` | ||
|
||
### Delete a list item | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/list-items"; | ||
import "@pnp/graph/lists"; | ||
|
||
const graph = graphfi(...); | ||
var newItem = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").delete(); | ||
|
||
``` | ||
|
||
### Get Document Set Versions of an Item | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/list-items"; | ||
import "@pnp/graph/lists"; | ||
|
||
const graph = graphfi(...); | ||
var documentSetVersions = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions(); | ||
|
||
``` | ||
|
||
### Get Document Set Versions By Id | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/list-items"; | ||
import "@pnp/graph/lists"; | ||
|
||
const sites = graph.sites.getById("{site id}"); | ||
const graph = graphfi(...); | ||
var documentSetVersion = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.getById("{document set version id}"); | ||
|
||
``` | ||
|
||
### Create a new Document Set Version | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/list-items"; | ||
import "@pnp/graph/lists"; | ||
|
||
const graph = graphfi(...); | ||
var version = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.add({comment:"Test Comment", shouldCaptureMinorVersion: true}); | ||
|
||
``` | ||
|
||
### Restore a Document Set version | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/list-items"; | ||
import "@pnp/graph/lists"; | ||
|
||
const listItems : IList[] = await Site(sites, "lists/{site id}/items?$expand=fields")(); | ||
const graph = graphfi(...); | ||
await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.getById("{document set version id}").restore(); | ||
|
||
``` | ||
|
||
#### Hint: Note that you can just use normal [graph queries](https://developer.microsoft.com/en-us/graph/graph-explorer) in this search. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { addProp } from "@pnp/queryable"; | ||
import { DocumentSetVersions, _ListItem } from "./types.js"; | ||
|
||
declare module "./types" { | ||
interface _ListItem { | ||
readonly documentSetVersions: IDocumentSetVersions; | ||
} | ||
interface IListItem { | ||
readonly documentSetVersions: IDocumentSetVersions; | ||
} | ||
} | ||
|
||
addProp(_ListItem, "documentSetVersions", DocumentSetVersions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import "./list.js"; | ||
import "./document-sets.js"; | ||
|
||
export { | ||
ListItems, | ||
IListItems, | ||
ListItem, | ||
IListItem, | ||
IListItemAddResult, | ||
IDocumentSetVersion, | ||
DocumentSetVersion, | ||
DocumentSetVersions, | ||
IDocumentSetVersions, | ||
IDocumentSetVersionAddResult, | ||
} from "./types.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { expect } from "chai"; | ||
import "@pnp/graph/sites"; | ||
import "@pnp/graph/lists"; | ||
import { List } from "@microsoft/microsoft-graph-types"; | ||
import { ISite } from "@pnp/graph/sites"; | ||
import { getRandomString } from "@pnp/core"; | ||
import getTestingGraphSPSite from "./utilities/getTestingGraphSPSite.js"; | ||
import { pnpTest } from "../pnp-test.js"; | ||
import { IList } from "@pnp/graph/lists"; | ||
import { IListItem } from "@pnp/graph/list-item/types.js"; | ||
|
||
describe("List-Items", function () { | ||
let site: ISite; | ||
let list: IList; | ||
let item: IListItem; | ||
|
||
const sampleList: List = { | ||
displayName: "PnPGraphTestList", | ||
list: { "template": "ItemTestList-Graph" }, | ||
}; | ||
|
||
before(async function () { | ||
|
||
if (!this.pnp.settings.enableWebTests) { | ||
this.skip(); | ||
} | ||
|
||
site = await getTestingGraphSPSite(this); | ||
|
||
const props = await this.props({ | ||
displayName: getRandomString(5) + "Add", | ||
}); | ||
|
||
const listTemplate = JSON.parse(JSON.stringify(sampleList)); | ||
listTemplate.displayName += props.displayName; | ||
const list = (await site.lists.add(listTemplate)).list; | ||
|
||
// add test items. Document set can be added later | ||
if(list){ | ||
await list.items.add({Title: `Item ${getRandomString(4)}`} as any); | ||
await list.items.add({Title: `Item ${getRandomString(4)}`} as any); | ||
} | ||
|
||
}); | ||
|
||
it("items", pnpTest("3e0e16a0-5683-4c3a-aa3d-f35bb6912de1", async function () { | ||
const items = await list.items(); | ||
return expect(items).to.be.an("array") && expect(items[0]).to.haveOwnProperty("id"); | ||
})); | ||
|
||
it("getById()", pnpTest("6f9592fd-1568-4d9c-a3f5-7f45165d84f2", async function () { | ||
const itemData = await list.items.select("Id").top(1)<{ Id: number }[]>(); | ||
return expect(itemData[0].Id).is.not.null; | ||
})); | ||
|
||
it("add", pnpTest("587e280b-0342-4515-a166-1b05cee9f242", async function () { | ||
// fieldvalueset. ugh. Casting as any. | ||
const itemAdded = await list.items.add({fields: | ||
{ | ||
title: getRandomString(5) + "Add", | ||
}, | ||
} as any); | ||
|
||
return expect((itemAdded.id)).is.not.null; | ||
})); | ||
|
||
it("update", pnpTest("5766613a-51b8-4f88-ba0f-2436d160b86b", async function () { | ||
// fieldvalueset. ugh. Casting as any. | ||
const itemUpdated = await item.update({fields: | ||
{ | ||
title: getRandomString(5) + "Update", | ||
}, | ||
} as any); | ||
|
||
|
||
return expect(itemUpdated).is.not.null; | ||
})); | ||
|
||
it("delete", pnpTest("e55bf53f-1316-4e47-97c1-b0c0cdd860ef", async function () { | ||
const item = await list.items.add({fields: | ||
{ | ||
title: getRandomString(5) + "Add", | ||
}, | ||
} as any); | ||
const r = await list.items.filter(`Id eq '${item.id}'`)(); | ||
return expect(r.length).to.eq(0); | ||
})); | ||
|
||
it.skip("documentSetVersions", pnpTest("c2889ca3-0230-4c6e-879d-71cc9cd08e83", async function () { | ||
const versions = await item.documentSetVersions(); | ||
return expect(versions).to.be.an("array") && expect(versions[0]).to.haveOwnProperty("id"); | ||
})); | ||
|
||
it.skip("documentSetVersions - getById()", pnpTest("35226d93-204b-4877-9041-26e04e437914", async function () { | ||
const versions = await item.documentSetVersions(); | ||
|
||
const version = await item.documentSetVersions.getById(versions[0].id); | ||
return expect(version).to.not.be.null && expect(version).to.haveOwnProperty("id"); | ||
})); | ||
|
||
it.skip("documentSetVersions - add()", pnpTest("a192e096-fe84-4c2c-adc5-b1b9021c0031", async function () { | ||
const documentSetVersion = await item.documentSetVersions.add({comment:"Test Comment"}); | ||
return expect(documentSetVersion).to.not.be.null && expect(documentSetVersion).to.haveOwnProperty("id"); | ||
})); | ||
|
||
it.skip("documentSetVersions - restore()", pnpTest("8814b247-4087-4c87-9a8f-af997f7d8745", async function () { | ||
const restore = await item.documentSetVersions[0].restore(); | ||
return expect(restore).to.be.fulfilled; | ||
})); | ||
|
||
// Remove the test list we created | ||
after(async function () { | ||
if (list) { | ||
try { | ||
await list.delete(); | ||
} catch (err) { | ||
console.error("Cannot clean up test list"); | ||
} | ||
} | ||
return; | ||
}); | ||
|
||
}); |