-
Notifications
You must be signed in to change notification settings - Fork 380
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 #80 from SharePoint/dev
Merge for v1.4.0 release
- Loading branch information
Showing
27 changed files
with
481 additions
and
17 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
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,71 @@ | ||
# ListPicker control | ||
|
||
This control allows you to select one or multiple available lists/libraries of the current site. | ||
|
||
Here is an example of the control: | ||
|
||
![ListPicker initial](../assets/ListPicker-initial.png) | ||
|
||
`ListPicker` single selection mode: | ||
|
||
![ListPicker single selection](../assets/ListPicker-single.png) | ||
|
||
`ListPicker` multi-selection mode | ||
|
||
![ListPicker multi selection](../assets/ListPicker-multi.png) | ||
|
||
## How to use this control in your solutions | ||
|
||
- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../#getting-started) page for more information about installing the dependency. | ||
- Import the control into your component: | ||
|
||
```TypeScript | ||
import { ListPicker } from "@pnp/spfx-controls-react/lib/ListPicker"; | ||
``` | ||
|
||
- Use the `ListPicker` control in your code as follows: | ||
|
||
```TypeScript | ||
<ListPicker context={this.props.context} | ||
label="Select your list(s)" | ||
placeHolder="Select your list(s)" | ||
baseTemplate={100} | ||
includeHidden={false} | ||
multiSelect={false} | ||
onSelectionChanged={this.onListPickerChange} /> | ||
``` | ||
|
||
- The `onSelectionChanged` change event returns the list(s) and can be implemented as follows: | ||
|
||
```TypeScript | ||
private onListPickerChange (lists: string | string[]) { | ||
console.log("Lists:", lists); | ||
} | ||
``` | ||
|
||
## Implementation | ||
|
||
The `ListPicker` control can be configured with the following properties: | ||
|
||
| Property | Type | Required | Description | | ||
| ---- | ---- | ---- | ---- | | ||
| context | WebPartContext OR ApplicationCustomizerContext | yes | The context object of the SPFx loaded webpart or customizer. | | ||
| className | string | no | If provided, additional class name to provide on the dropdown element. | | ||
| disabled | boolean | no | Whether or not the control is disabled. | | ||
| baseTemplate | number | no | The SharePoint BaseTemplate ID to filter the list options by. | | ||
| includeHidden | boolean | no | Whether or not to include hidden lists. Default is `true`. | | ||
| orderBy | LibsOrderBy | no | How to order the lists retrieved from SharePoint. | | ||
| selectedList | string OR string[] | no | Keys of the selected item(s). If you provide this, you must maintain selection state by observing onSelectionChanged events and passing a new value in when changed. | | ||
| multiSelect | boolean | no | Optional mode indicates if multi-choice selections is allowed. Default to `false`. | | ||
| label | string | no | Label to use for the control. | | ||
| placeholder | string | no | Placeholder label to show in the dropdown. | | ||
| onSelectionChanged | (newValue: string OR string[]): void | no | Callback function when the selected option changes. | | ||
|
||
Enum `LibsOrderBy` | ||
|
||
| Value | | ||
| ---- | | ||
| Id | | ||
| Title | | ||
|
||
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/ListPicker) |
72 changes: 72 additions & 0 deletions
72
docs/documentation/docs/controls/SecurityTrimmedControl.md
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,72 @@ | ||
# SecurityTrimmedControl | ||
|
||
This control is intended to be used when you want to show or hide components based on the user its permissions. The control can be used to check the user’s permissions on the current site / list were the solution is loaded, or on a remote site / list. | ||
|
||
## How to use this control in your solutions | ||
|
||
- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../#getting-started) page for more information about installing the dependency. | ||
- Import the following modules to your component: | ||
|
||
```TypeScript | ||
import { SecurityTrimmedControl } from "@pnp/spfx-controls-react/lib/SecurityTrimmedControl"; | ||
``` | ||
|
||
- You can use the `SecurityTrimmedControl` as follows in your solutions: | ||
|
||
**Checking permissions on the current site** | ||
|
||
```jsx | ||
<SecurityTrimmedControl context={this.props.context} | ||
level={PermissionLevel.currentWeb} | ||
permissions={[SPPermission.viewPages]}> | ||
{/* Specify the components to load when user has the required permissions */} | ||
</SecurityTrimmedControl> | ||
``` | ||
|
||
**Checking permissions on the current list** | ||
|
||
```jsx | ||
<SecurityTrimmedControl context={this.props.context} | ||
level={PermissionLevel.currentList} | ||
permissions={[SPPermission.addListItems]}> | ||
{/* Specify the components to load when user has the required permissions */} | ||
</SecurityTrimmedControl> | ||
``` | ||
|
||
**Checking permissions on remote site** | ||
|
||
```jsx | ||
<SecurityTrimmedControl context={this.props.context} | ||
level={PermissionLevel.remoteWeb} | ||
remoteSiteUrl="https://<tenant>.sharepoint.com/sites/<siteName>" | ||
permissions={[SPPermission.viewPages, SPPermission.addListItems]}> | ||
{/* Specify the components to load when user has the required permissions */} | ||
</SecurityTrimmedControl> | ||
``` | ||
|
||
**Checking permissions on remote list / library** | ||
|
||
```jsx | ||
<SecurityTrimmedControl context={this.props.context} | ||
level={PermissionLevel.remoteListOrLib} | ||
remoteSiteUrl="https://<tenant>.sharepoint.com/sites/<siteName>" | ||
relativeLibOrListUrl="/sites/<siteName>/<list-or-library-URL>" | ||
permissions={[SPPermission.addListItems]}> | ||
{/* Specify the components to load when user has the required permissions */} | ||
</SecurityTrimmedControl> | ||
``` | ||
|
||
## Implementation | ||
|
||
The `SecurityTrimmedControl` can be configured with the following properties: | ||
|
||
| Property | Type | Required | Description | | ||
| ---- | ---- | ---- | ---- | | ||
| context | WebPartContext or ApplicationCustomizerContext or FieldCustomizerContext or ListViewCommandSetContext | yes | Context of the web part, application customizer, field customizer, or list view command set. | | ||
| permissions | SPPermission[] | yes | The permissions to check for the user. | | ||
| level | PermissionLevel | yes | Specify where to check the user permissions: current site or list / remote site or list. | | ||
| remoteSiteUrl | string | no | The URL of the remote site. Required when you want to check permissions on remote site or list. | | ||
| relativeLibOrListUrl | string | no | The relative URL of the list or library. Required when you want to check permissions on remote list. | | ||
|
||
|
||
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/SecurityTrimmedControl) |
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
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,57 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
console.log("INFO: Adding the required localized resource configuration to the config.json file."); | ||
|
||
// Get the current directory | ||
const crntDir = path.resolve(__dirname); | ||
// Split the whole directory path | ||
let nesting = crntDir.split("/"); | ||
// Windows split | ||
if (nesting.length <= 1) { | ||
nesting = crntDir.split("\\"); | ||
} | ||
// Check if correctly splitted | ||
if (nesting.length > 0) { | ||
// Find the first node_modules folder index | ||
let idx = nesting.indexOf("node_modules"); | ||
// Check if index of the folder was found | ||
if (idx !== -1) { | ||
// Slice unnecessary nodes | ||
const nest = nesting.slice(idx); | ||
if (nest && nest.length > 0) { | ||
const paths = nest.map(m => ".."); | ||
// Get the path of the projects root location | ||
const rootDir = path.resolve(path.join(__dirname, paths.join('/'))); | ||
const fileLoc = `${rootDir}/config/config.json`; | ||
// Check if config.json file exists | ||
if (fs.existsSync(fileLoc)) { | ||
// Get the config file | ||
const config = fs.readFileSync(fileLoc, "utf8"); | ||
if (config && typeof config === "string") { | ||
const contents = JSON.parse(config); | ||
if (contents && contents.localizedResources && !contents.localizedResources.ControlStrings) { | ||
contents.localizedResources["ControlStrings"] = "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js"; | ||
// Update the file | ||
fs.writeFileSync(fileLoc, JSON.stringify(contents, null, 2)); | ||
console.log("INFO: Localized resource added."); | ||
} else { | ||
console.warn(`WARNING: it seems something is wrong with the config.json file or the "ControlStrings" reference was already set.`); | ||
} | ||
} else { | ||
console.warn("WARNING: the config.json file was not correctly retrieved."); | ||
} | ||
} else { | ||
console.warn("WARNING: the config.json file does not exist."); | ||
} | ||
} else { | ||
console.warn("WARNING: something is wrong with the installation path."); | ||
} | ||
} else { | ||
console.warn("WARNING: something when wrong during with retrieving the project its root location."); | ||
} | ||
} else { | ||
console.warn("WARNING: something is wrong with the installation path."); | ||
} |
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 @@ | ||
export * from './controls/securityTrimmedControl'; |
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
28 changes: 28 additions & 0 deletions
28
src/controls/securityTrimmedControl/ISecurityTrimmedControlProps.ts
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,28 @@ | ||
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base'; | ||
import { FieldCustomizerContext, ListViewCommandSetContext } from '@microsoft/sp-listview-extensibility'; | ||
import { WebPartContext } from '@microsoft/sp-webpart-base'; | ||
import { SPPermission } from '@microsoft/sp-page-context'; | ||
import { PermissionLevel } from '.'; | ||
|
||
export interface ISecurityTrimmedControlProps { | ||
/** | ||
* Context of the web part, application customizer, field customizer, or list view command set. | ||
*/ | ||
context: WebPartContext | ApplicationCustomizerContext | FieldCustomizerContext | ListViewCommandSetContext; | ||
/** | ||
* The permissions to check for the user. | ||
*/ | ||
permissions: SPPermission[]; | ||
/** | ||
* Specify where to check the user permissions: current site or list / remote site or list. | ||
*/ | ||
level: PermissionLevel; | ||
/** | ||
* The URL of the remote site. Required when you want to check permissions on remote site or list. | ||
*/ | ||
remoteSiteUrl?: string; | ||
/** | ||
* The relative URL of the list or library. Required when you want to check permissions on remote list. | ||
*/ | ||
relativeLibOrListUrl?: string; | ||
} |
Oops, something went wrong.