Skip to content

Commit

Permalink
Initial release, doc lib and lists compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
cupo365 committed Jul 1, 2022
1 parent 6894cfd commit 15d50a2
Show file tree
Hide file tree
Showing 28 changed files with 526 additions and 268 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ lib
release
debug
temp
solution/*.sppkg

# Coverage directory used by tools like istanbul
coverage
Expand Down
2 changes: 1 addition & 1 deletion .yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"environment": "spo",
"packageManager": "npm",
"solutionName": "enhanced-power-automate-trigger",
"solutionShortDescription": "Trigger a Power Automate flow from SharePoint while selecting one or more files.",
"solutionShortDescription": "Trigger a Power Automate flow from SharePoint while selecting one or more items.",
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"componentType": "extension",
Expand Down
121 changes: 62 additions & 59 deletions README.md

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions config/package-solution.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
},
"metadata": {
"shortDescription": {
"default": "Trigger a Power Automate flow from SharePoint while selecting one or more files."
"default": "Trigger a Power Automate flow from SharePoint while selecting one or more items."
},
"longDescription": {
"default": "Trigger a Power Automate flow from SharePoint while selecting one or more files."
"default": "Trigger a Power Automate flow from SharePoint while selecting one or more items."
},
"screenshotPaths": [],
"videoUrl": "",
Expand All @@ -29,13 +29,11 @@
{
"title": "Application Extension - Deployment of custom action",
"description": "Deploys a custom action with ClientSideComponentId association",
"id": "2f4bcd0a-2956-4803-8024-911265601037",
"id": "4891fcc5-7de8-4336-aea9-0957ffeb83d4",
"version": "1.0.0.0",
"assets": {
"elementManifests": [
"elements.xml",
"ClientSideInstance.xml"
]
"elementManifests": ["elements.xml", "ClientSideInstance.xml"],
"elementFiles": ["triggerConfigListSchema.xml"]
}
}
]
Expand Down
8 changes: 4 additions & 4 deletions config/serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"https": true,
"serveConfigurations": {
"default": {
"pageUrl": "https://mkvj.sharepoint.com/sites/mkvj/Shared%20Documents/Forms/AllItems.aspx",
"pageUrl": "https://{your_SharePoint_site_here}",
"customActions": {
"543ef5be-c9cb-4b7b-bdaf-592c7be1493a": {
"817ae812-ac12-4047-accf-c9766b6a434a": {
"location": "ClientSideExtension.ListViewCommandSet.CommandBar",
"properties": {
"configListTitle": "Enhanced Power Automate Trigger Configuration"
Expand All @@ -15,9 +15,9 @@
}
},
"enhancedPowerAutomateTrigger": {
"pageUrl": "https://mkvj.sharepoint.com/sites/mkvj/Shared%20Documents/Forms/AllItems.aspx",
"pageUrl": "https://{your_SharePoint_site_here}",
"customActions": {
"543ef5be-c9cb-4b7b-bdaf-592c7be1493a": {
"817ae812-ac12-4047-accf-c9766b6a434a": {
"location": "ClientSideExtension.ListViewCommandSet.CommandBar",
"properties": {
"configListTitle": "Enhanced Power Automate Trigger Configuration"
Expand Down
113 changes: 113 additions & 0 deletions gulpfile-switch-list-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// This file is based on https://gist.github.com/estruyf/fb444cfd0de7b3aabe4cb4711ad2118b

"use strict";

const build = require("@microsoft/sp-build-web");
const gutil = require("gulp-util");
const fs = require("fs");

const elementsPath = "./sharepoint/assets/elements.xml";
const elementsSearchString = 'RegistrationId="';
const clientSideInstancePath = "./sharepoint/assets/ClientSideInstance.xml";
const clientSideInstanceSearchString = 'ListTemplateId="';
const listIdLength = 3;
const customListId = 100;
const docLibListId = 101;

build.task("switch-list-type", {
execute: (config) => {
return new Promise((resolve, reject) => {
try {
// Prepare
const listType = config.args["list"] || "list";
let elementsXML = fs.existsSync(elementsPath)
? fs.readFileSync(elementsPath).toString()
: undefined;
let clientSideInstanceXML = fs.existsSync(clientSideInstancePath)
? fs.readFileSync(clientSideInstancePath).toString()
: undefined;

if (!elementsXML) {
throw "Could not fetch the elements XML file content. Check the elements file path.";
}

if (!clientSideInstanceXML) {
throw "Could not fetch the client side instance XML file content. Check the client side instance file path.";
}

if (
listType.toLowerCase() !== "doc" &&
listType.toLowerCase() !== "list"
) {
throw "Invalid argument. Please choose either 'doc' or 'list' as an argument.";
}

// Switch list type
gutil.log(
gutil.colors.magenta(
`Switching list type to: ${
listType === "doc" ? "Document library" : "Custom list"
}`
)
);

gutil.log(
gutil.colors.yellow(
`Using list template ID: ${
listType === "doc" ? docLibListId : customListId
}`
)
);
let registrationIdStart =
elementsXML.indexOf(elementsSearchString) +
elementsSearchString.length;
let currentRegistrationId = elementsXML.substring(
registrationIdStart,
registrationIdStart + listIdLength
);
let newRegistrationId = `${elementsSearchString}${
listType === "doc" ? docLibListId : customListId
}`;

elementsXML = elementsXML.replace(
elementsSearchString + currentRegistrationId,
newRegistrationId
);

fs.writeFileSync(elementsPath, elementsXML);

let listTemplateIdStart =
clientSideInstanceXML.indexOf(clientSideInstanceSearchString) +
clientSideInstanceSearchString.length;
let currentListTemplateId = clientSideInstanceXML.substring(
listTemplateIdStart,
listTemplateIdStart + listIdLength
);
let newListTemplateId = `${clientSideInstanceSearchString}${
listType === "doc" ? docLibListId : customListId
}`;

clientSideInstanceXML = clientSideInstanceXML.replace(
clientSideInstanceSearchString + currentListTemplateId,
newListTemplateId
);

fs.writeFileSync(clientSideInstancePath, clientSideInstanceXML);

gutil.log(
gutil.colors.green(
`Successfully switched list type to: ${
listType === "doc" ? "Document library" : "Custom list"
}!`
)
);

resolve();
} catch (ex) {
gutil.log(gutil.colors.red(ex));

reject();
}
});
},
});
14 changes: 9 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
'use strict';
"use strict";

const build = require('@microsoft/sp-build-web');
const build = require("@microsoft/sp-build-web");

build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
build.addSuppression(
`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`
);

var getTasks = build.rig.getTasks;
build.rig.getTasks = function () {
var result = getTasks.call(build.rig);

result.set('serve', result.get('serve-deprecated'));
result.set("serve", result.get("serve-deprecated"));

return result;
};

build.initialize(require('gulp'));
require("./gulpfile-switch-list-type");

build.initialize(require("gulp"));
21 changes: 9 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
{
"name": "enhanced-power-automate-trigger",
"version": "0.0.1",
"version": "1.0.0",
"private": true,
"main": "lib/index.js",
"description": "Pass SharePoint page context to your embedded Power App.",
"description": "Trigger a Power Automate flow from SharePoint while selecting one or more items.",
"author": "cup o'365",
"license": "MIT",
"scripts": {
"install": "npm i",
"build": "gulp bundle",
"bundle": "gulp bundle",
"test": "gulp test",
"serve": "gulp serve",
"serve-nobrowser": "gulp serve --nobrowser",
"clean-install": "npm ci",
"clean": "gulp clean",
"bundle-ship": "gulp bundle --ship",
"package-solution": "gulp package-solution --ship"
"init": "npm ci && gulp bundle && gulp trust-dev-cert && gulp serve --nobrowser",
"run": "gulp serve --nobrowser",
"clean": "gulp clean && gulp bundle",
"switch-list-type-doc": "gulp switch-list-type --list doc",
"switch-list-type-list": "gulp switch-list-type --list list",
"package-doc": "gulp switch-list-type --list doc && gulp bundle --ship && gulp package-solution --ship",
"package-list": "gulp switch-list-type --list list && gulp bundle --ship && gulp package-solution --ship"
},
"dependencies": {
"@fluentui/react": "^8.22.0",
Expand Down
115 changes: 115 additions & 0 deletions resources/selected-listitem-output-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
[
{
"_fields": [
{
"id": {
"_guid": "82642ec8-ef9b-478f-acf9-31f7d45fbc31"
},
"internalName": "Title",
"fieldType": "Computed",
"isRequired": false,
"displayName": "Title",
"clientSideComponentId": {
"_guid": "00000000-0000-0000-0000-000000000000"
},
"clientSideComponentProperties": ""
}
],
"_values": [
[
{
"key": "ID",
"value": "1"
},
{
"key": "PermMask",
"value": "0x7fffffffffffffff"
},
{
"key": "FSObjType",
"value": "0"
},
{
"key": "UniqueId",
"value": "{30758281-57B5-44D2-877F-A837318D093F}"
},
{
"key": "ContentTypeId",
"value": "0x01009065A2AE4229A544BB9E5F5DE97BA03F0077E1F74ED448234FAC3198F205C065EC"
},
{
"key": "FileRef",
"value": "/sites/I_ontruimingsplannen/Lists/Test/1_.000"
},
{
"key": "Attachments",
"value": "0"
},
{
"key": "SMTotalSize",
"value": "182"
},
{
"key": "_CommentFlags",
"value": ""
},
{
"key": "_CommentCount",
"value": ""
},
{
"key": "Title",
"value": "Test1"
},
{
"key": "FileLeafRef",
"value": "1_.000"
},
{
"key": "Created_x0020_Date",
"value": "1;#2022-07-01 17:21:13"
},
{
"key": "Created_x0020_Date.ifnew",
"value": "1"
},
{
"key": "File_x0020_Type",
"value": ""
},
{
"key": "File_x0020_Type.mapapp",
"value": ""
},
{
"key": "HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon",
"value": ""
},
{
"key": "HTML_x0020_File_x0020_Type.File_x0020_Type.mapico",
"value": ""
},
{
"key": "ItemChildCount",
"value": "0"
},
{
"key": "FolderChildCount",
"value": "0"
},
{
"key": "ScopeId",
"value": "{B16AFEEA-604B-4A51-B5DA-9D1D7AB5FDB3}"
},
{
"key": "owshiddenversion",
"value": "1"
},
{
"key": "Restricted",
"value": ""
}
]
]
}
]
7 changes: 1 addition & 6 deletions sharepoint/assets/ClientSideInstance.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ClientSideComponentInstance
Title="EnhancedPowerAutomateTrigger"
Location="ClientSideExtension.ListViewCommandSet.CommandBar"
ListTemplateId="101"
Properties="{&quot;configListTitle&quot;:&quot;Enhanced Power Automate Trigger Configuration&quot;}"
ComponentId="543ef5be-c9cb-4b7b-bdaf-592c7be1493a" />
<ClientSideComponentInstance Title="EnhancedPowerAutomateTrigger" Location="ClientSideExtension.ListViewCommandSet.CommandBar" ListTemplateId="100" Properties="{&quot;configListTitle&quot;:&quot;Enhanced Power Automate Trigger Configuration&quot;}" ComponentId="817ae812-ac12-4047-accf-c9766b6a434a" />
</Elements>
12 changes: 4 additions & 8 deletions sharepoint/assets/elements.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Title="EnhancedPowerAutomateTrigger"
RegistrationId="101"
RegistrationType="List"
Location="ClientSideExtension.ListViewCommandSet.CommandBar"
ClientSideComponentId="543ef5be-c9cb-4b7b-bdaf-592c7be1493a"
ClientSideComponentProperties="{&quot;configListTitle&quot;:&quot;Enhanced Power Automate Trigger Configuration&quot;}">
</CustomAction>
<CustomAction Title="EnhancedPowerAutomateTrigger" RegistrationId="100" RegistrationType="List" Location="ClientSideExtension.ListViewCommandSet.CommandBar" ClientSideComponentId="817ae812-ac12-4047-accf-c9766b6a434a" ClientSideComponentProperties="{&quot;configListTitle&quot;:&quot;Enhanced Power Automate Trigger Configuration&quot;}">
</CustomAction>
<ListInstance CustomSchema="triggerConfigListSchema.xml" FeatureId="00bfea71-de22-43b2-a848-c05709900100" Title="Enhanced Power Automate Trigger Configuration" Description="" TemplateType="100" Url="Lists/EnhancedPowerAutomateTriggerConfiguration">
</ListInstance>
</Elements>
Loading

0 comments on commit 15d50a2

Please sign in to comment.