new Sample react-news-banner
This commit is contained in:
parent
4d53e080cb
commit
f396f6910f
|
@ -0,0 +1,25 @@
|
|||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
|
||||
[*]
|
||||
|
||||
# change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# we recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[{package,bower}.json]
|
||||
indent_style = space
|
||||
indent_size = 2
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2020,
|
||||
"sourceType": "module",
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"react": {
|
||||
"version": "detect"
|
||||
}
|
||||
},
|
||||
"ignorePatterns": ["*.js"],
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:react-hooks/recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:react/recommended"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
|
||||
# Build generated files
|
||||
dist
|
||||
lib
|
||||
solution
|
||||
temp
|
||||
*.sppkg
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# OSX
|
||||
.DS_Store
|
||||
|
||||
# Visual Studio files
|
||||
.ntvs_analysis.dat
|
||||
.vs
|
||||
bin
|
||||
obj
|
||||
|
||||
# Resx Generated Code
|
||||
*.resx.ts
|
||||
|
||||
# Styles Generated Code
|
||||
*.scss.ts
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"@pnp/generator-spfx": {
|
||||
"framework": "react",
|
||||
"pnpFramework": "reactjs.plus",
|
||||
"pnp-libraries": [
|
||||
"@pnp/pnpjs",
|
||||
"@pnp/spfx-property-controls",
|
||||
"spfx-uifabric-themes",
|
||||
"lodash",
|
||||
"@pnp/spfx-controls-react",
|
||||
"ouifr@7"
|
||||
],
|
||||
"pnp-ci": "no-devops",
|
||||
"pnp-vetting": [],
|
||||
"spfxenv": "onprem19",
|
||||
"pnp-testing": []
|
||||
},
|
||||
"@microsoft/generator-sharepoint": {
|
||||
"environment": "onprem19",
|
||||
"framework": "react",
|
||||
"isCreatingSolution": true,
|
||||
"version": "1.11.0",
|
||||
"libraryName": "react-banner",
|
||||
"libraryId": "e8b4422e-9b4e-431d-81d6-ebe6bae3c8a1",
|
||||
"packageManager": "npm",
|
||||
"componentType": "webpart"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
# News Banner
|
||||
|
||||
## Summary
|
||||
|
||||
This web part shows news information as a Banner, this information come from a list defined in any site, this web part can be installed on 2019, and SharePoint Online.
|
||||
|
||||
![NewsBanner](./assets/NewsBanner.png)
|
||||
![NewsBanner](./assets/NewsBanner.gif)
|
||||
|
||||
## Compatibility
|
||||
|
||||
![SPFx 1.4.1](https://img.shields.io/badge/SPFx-1.4.1-green.svg)
|
||||
![Node.js LTS 6.x | LTS 8.x](https://img.shields.io/badge/Node.js-LTS%206.x%20%7C%20LTS%208.x-green.svg)
|
||||
![SharePoint 2019 | Online](https://img.shields.io/badge/SharePoint-2019%20%7C%20Online-yellow.svg)
|
||||
![Teams No: Not designed for Microsoft Teams](https://img.shields.io/badge/Teams-No-red.svg "Not designed for Microsoft Teams")
|
||||
![Workbench Hosted: Does not work with local workbench](https://img.shields.io/badge/Workbench-Hosted-yellow.svg "Does not work with local workbench")
|
||||
|
||||
## Applies to
|
||||
|
||||
- [SharePoint Framework](https://aka.ms/spfx)
|
||||
|
||||
## Solution
|
||||
|
||||
Solution|Author(s)
|
||||
--------|---------
|
||||
react-news-banner |[João Mendes](https://github.com/joaojmendes), Storm Technology, ([@joaojmendes](https://twitter.com/joaojmendes))
|
||||
|
||||
## Version history
|
||||
|
||||
Version|Date|Comments
|
||||
-------|----|--------
|
||||
1.0|May, 2021|Initial release
|
||||
|
||||
## Prerequisites
|
||||
|
||||
No pre-requisites
|
||||
|
||||
## Minimal Path to Awesome
|
||||
|
||||
- Clone this repository
|
||||
- Ensure that you are at the solution folder
|
||||
- in the command-line run:
|
||||
- `npm install`
|
||||
- `gulp serve`
|
||||
|
||||
## Features
|
||||
|
||||
This web part shows how to use PnPjs, Office-ui-fabric-react,@pnp/spfx-controls-react, @pnp/spfx-property-controls to create an News Banner
|
||||
|
||||
This extension illustrates the following concepts:
|
||||
|
||||
## 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.**
|
||||
|
||||
## Support
|
||||
|
||||
We do not support samples, but we do use GitHub to track issues and constantly want to improve these samples.
|
||||
|
||||
If you encounter any issues while using this sample, [create a new issue](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=bug-report.yml&sample=react-organisation-chart&authors=@joaojmendes&title=react-organisation-chart%20-%20).
|
||||
|
||||
For questions regarding this sample, [create a new question](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=question.yml&sample=react-organisation-chart&authors=@joaojmendes&title=react-organisation-chart%20-%20).
|
||||
|
||||
Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=suggestion.yml&sample=react-organisation-chart&authors=@joaojmendes&title=react-organisation-chart%20-%20).
|
||||
|
||||
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/react-news-banner" />
|
Binary file not shown.
After Width: | Height: | Size: 13 MiB |
Binary file not shown.
After Width: | Height: | Size: 2.9 MiB |
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||
"version": "2.0",
|
||||
"bundles": {
|
||||
"banner-web-part": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/webparts/banner/BannerWebPart.js",
|
||||
"manifest": "./src/webparts/banner/BannerWebPart.manifest.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"externals": {},
|
||||
"localizedResources": {
|
||||
"BannerWebPartStrings": "lib/webparts/banner/loc/{locale}.js",
|
||||
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js",
|
||||
"PropertyControlStrings": "node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
|
||||
"deployCdnPath": "temp/deploy"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||
"workingDir": "./temp/deploy/",
|
||||
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||
"container": "react-banner",
|
||||
"accessKey": "<!-- ACCESS KEY -->"
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||
"solution": {
|
||||
"name": "react-banner-client-side-solution",
|
||||
"id": "e8b4422e-9b4e-431d-81d6-ebe6bae3c8a1",
|
||||
"version": "1.0.0.0",
|
||||
"includeClientSideAssets": true,
|
||||
"skipFeatureDeployment": true
|
||||
},
|
||||
"paths": {
|
||||
"zippedPackage": "solution/react-banner.sppkg"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
|
||||
"port": 4321,
|
||||
"https": true,
|
||||
"initialPage": "https://localhost:5432/workbench",
|
||||
"api": {
|
||||
"port": 5432,
|
||||
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
// gulpfile.js
|
||||
'use strict';
|
||||
|
||||
const gulp = require('gulp');
|
||||
const build = require('@microsoft/sp-build-web');
|
||||
const merge = require('webpack-merge');
|
||||
const TerserPlugin = require('terser-webpack-plugin-legacy');
|
||||
build.addSuppression(/Warning - \[sass\] The local CSS class .* is not camelCase and will not be type-safe./gi);
|
||||
|
||||
// force use of projects specified typescript version
|
||||
const typeScriptConfig = require('@microsoft/gulp-core-build-typescript/lib/TypeScriptConfiguration');
|
||||
typeScriptConfig.TypeScriptConfiguration.setTypescriptCompiler(require('typescript'));
|
||||
|
||||
// disable tslint
|
||||
build.tslint.enabled = false;
|
||||
|
||||
const eslint = require('gulp-eslint');
|
||||
|
||||
const eslintSubTask = build.subTask('eslint', function (gulp, buildOptions, done) {
|
||||
return gulp.src(['src/**/*.{ts,tsx}'])
|
||||
// eslint() attaches the lint output to the "eslint" property
|
||||
// of the file object so it can be used by other modules.
|
||||
.pipe(eslint())
|
||||
// eslint.format() outputs the lint results to the console.
|
||||
// Alternatively use eslint.formatEach() (see Docs).
|
||||
.pipe(eslint.format())
|
||||
// To have the process exit with an error code (1) on
|
||||
// lint error, return the stream and pipe to failAfterError last.
|
||||
.pipe(eslint.failAfterError());
|
||||
});
|
||||
|
||||
build.rig.addPreBuildTask(build.task('eslint-task', eslintSubTask));
|
||||
// force use of projects specified react version
|
||||
build.configureWebpack.mergeConfig({
|
||||
|
||||
additionalConfiguration: (generatedConfiguration) => {
|
||||
// force use of projects specified react version
|
||||
generatedConfiguration.externals = generatedConfiguration.externals
|
||||
.filter(name => !(["react", "react-dom"].includes(name)));
|
||||
// force use TerserPlugIn (remove UglifyJs)
|
||||
generatedConfiguration.plugins.forEach((plugin, i) => {
|
||||
if (plugin.options && plugin.options.mangle) {
|
||||
generatedConfiguration.plugins.splice(i, 1);
|
||||
generatedConfiguration = merge(generatedConfiguration, {
|
||||
plugins: [
|
||||
new TerserPlugin()
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
return generatedConfiguration;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
build.initialize(gulp);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,56 @@
|
|||
{
|
||||
"name": "react-news-banner",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build": "gulp bundle",
|
||||
"clean": "gulp clean",
|
||||
"test": "gulp test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluentui/theme": "^2.1.0",
|
||||
"@microsoft/office-ui-fabric-react-bundle": "^1.11.0",
|
||||
"@microsoft/sp-core-library": "~1.4.1",
|
||||
"@microsoft/sp-lodash-subset": "~1.4.1",
|
||||
"@microsoft/sp-office-ui-fabric-core": "^1.11.0",
|
||||
"@microsoft/sp-tslint-rules": "^1.11.0",
|
||||
"@microsoft/sp-webpart-base": "~1.4.1",
|
||||
"@pnp/common": "^1.3.11",
|
||||
"@pnp/logging": "^1.3.11",
|
||||
"@pnp/odata": "^1.3.11",
|
||||
"@pnp/sp": "^1.3.11",
|
||||
"@pnp/spfx-controls-react": "^1.21.1",
|
||||
"@pnp/spfx-property-controls": "^1.3.0",
|
||||
"@uifabric/merge-styles": "^7.19.2",
|
||||
"date-fns": "^2.21.2",
|
||||
"enhanced-resolve": "^5.8.0",
|
||||
"idb-keyval": "^5.0.5",
|
||||
"office-ui-fabric-react": "^6.214.1",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"spfx-uifabric-themes": "^0.8.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/sp-build-web": "1.4.1",
|
||||
"@microsoft/sp-module-interfaces": "1.4.1",
|
||||
"@microsoft/sp-webpart-workbench": "1.4.1",
|
||||
"@types/chai": "3.4.34",
|
||||
"@types/es6-promise": "0.0.33",
|
||||
"@types/mocha": "2.2.38",
|
||||
"@types/react": "^16.9.19",
|
||||
"@types/react-dom": "^16.9.0",
|
||||
"@types/webpack-env": "1.13.1",
|
||||
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
||||
"@typescript-eslint/parser": "^4.22.0",
|
||||
"ajv": "~5.2.2",
|
||||
"eslint": "^7.25.0",
|
||||
"eslint-plugin-react": "^7.23.2",
|
||||
"eslint-plugin-react-hooks": "^4.2.0",
|
||||
"gulp": "~3.9.1",
|
||||
"gulp-eslint": "^6.0.0",
|
||||
"terser-webpack-plugin-legacy": "^1.2.3",
|
||||
"typescript": "3.9.7",
|
||||
"webpack-merge": "^4.2.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
@import "~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss";
|
||||
|
||||
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
max-height: 550px;
|
||||
min-height: 550px;
|
||||
max-width: 100%;
|
||||
padding: 10px;
|
||||
|
||||
// box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.imageContainer {
|
||||
width: 70%;
|
||||
}
|
||||
.overlay {
|
||||
position: relative;
|
||||
background-color: white;
|
||||
opacity: 0.8;
|
||||
top: -500px;
|
||||
max-width: 320px;
|
||||
color: $ms-color-themeDark;
|
||||
|
||||
max-height: 120px;
|
||||
overflow: hidden;
|
||||
padding: 20px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.image {
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.documentCard {
|
||||
margin-bottom: 3px;
|
||||
max-width: 100%;
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
.documentCard:hover {
|
||||
background-color: $ms-color-themePrimary;
|
||||
color: $ms-color-white;
|
||||
}
|
||||
|
||||
.list {
|
||||
width: 30%;
|
||||
padding-top: 10px;
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
background-color: $ms-color-neutralLighterAlt;
|
||||
border-width: 1.2px;
|
||||
border-style: solid;
|
||||
border-color: $ms-color-neutralQuaternaryAlt;
|
||||
overflow-y:auto;
|
||||
|
||||
}
|
||||
|
||||
.list::-webkit-scrollbar-thumb {
|
||||
background-Color: $ms-color-neutralQuaternaryAlt
|
||||
}
|
||||
.list::-webkit-scrollbar {
|
||||
height: 10px;
|
||||
width: 7px;
|
||||
}
|
||||
|
||||
.row {
|
||||
@include ms-Grid-row;
|
||||
@include ms-fontColor-white;
|
||||
background-color: $ms-color-themeDark;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.column {
|
||||
@include ms-Grid-col;
|
||||
@include ms-lg10;
|
||||
@include ms-xl8;
|
||||
@include ms-xlPush2;
|
||||
@include ms-lgPush1;
|
||||
}
|
||||
|
||||
.title {
|
||||
@include ms-font-xl;
|
||||
font-weight: 700;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
width:100%;
|
||||
text-transform: uppercase;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 4;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
.title::hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.subTitle {
|
||||
@include ms-font-l;
|
||||
padding-top: 10px;
|
||||
// @include ms-fontColor-white;
|
||||
color: $ms-color-themeDark;
|
||||
font-weight: 700;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 4;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.lineSeparator {
|
||||
border-bottom: 1.3px;
|
||||
border-bottom-style: solid;
|
||||
border-bottom-color: $ms-color-neutralQuaternaryAlt;
|
||||
margin-left: 15px;
|
||||
margin-right: 15px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.subTitleNews {
|
||||
@include ms-font-m;
|
||||
// color: $ms-color-themeDark;
|
||||
font-weight: 700;
|
||||
text-overflow: ellipsis;
|
||||
font-weight: $ms-font-weight-semibold;
|
||||
font-size: $ms-font-size-m;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
vertical-align: top;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: $ms-font-size-m;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 4;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.buttonConfigure {
|
||||
// Our button
|
||||
text-decoration: none;
|
||||
height: 32px;
|
||||
|
||||
// Primary Button
|
||||
min-width: 80px;
|
||||
background-color: $ms-color-themePrimary;
|
||||
border-color: $ms-color-themePrimary;
|
||||
color: $ms-color-white;
|
||||
|
||||
// Basic Button
|
||||
outline: transparent;
|
||||
position: relative;
|
||||
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
font-size: $ms-font-size-m;
|
||||
font-weight: $ms-font-weight-regular;
|
||||
border-width: 0;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
.labelConfigure {
|
||||
color: $ms-color-themeDark;
|
||||
font-weight: $ms-font-weight-semibold;
|
||||
font-size: $ms-font-size-m;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
margin: 0 4px;
|
||||
vertical-align: top;
|
||||
display: inline-block;
|
||||
color: $ms-color-white;
|
||||
}
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
import { IBannerProps } from "./IBannerProps";
|
||||
import styles from "./Banner.module.scss";
|
||||
import * as React from "react";
|
||||
import { BannerCard } from "../BannerCard";
|
||||
import { IBannerState } from "./IBannerState";
|
||||
import { IListItem } from "../../entities/IListItem";
|
||||
import { useList } from "../../hooks/useList";
|
||||
import { reducer } from "./BannerReducer";
|
||||
import { EBannerTypes } from "./EBannerTypes";
|
||||
import { Placeholder } from '@pnp/spfx-controls-react';
|
||||
|
||||
import {
|
||||
MessageBar,
|
||||
MessageBarType,
|
||||
} from "office-ui-fabric-react/lib/MessageBar";
|
||||
import {
|
||||
Spinner,
|
||||
SpinnerSize,
|
||||
} from "office-ui-fabric-react/lib/Spinner";
|
||||
import {
|
||||
Stack,
|
||||
} from "office-ui-fabric-react/lib/Stack";
|
||||
import strings from "BannerWebPartStrings";
|
||||
|
||||
const initialState: IBannerState = {
|
||||
isLoading: false,
|
||||
items: [],
|
||||
messageError: undefined,
|
||||
selectedItem: undefined,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
export const Banner: React.FunctionComponent<IBannerProps> = (
|
||||
props: React.PropsWithChildren<IBannerProps>
|
||||
) => {
|
||||
const { selectedProperties, webpartContext } = props;
|
||||
const [state, dispatch] = React.useReducer(reducer, initialState);
|
||||
const { getItems } = useList();
|
||||
const { isLoading, items, messageError, selectedItem } = state;
|
||||
|
||||
|
||||
|
||||
|
||||
const _onSelectedItem = React.useCallback((item: IListItem) => {
|
||||
dispatch({
|
||||
type: EBannerTypes.SET_SELECTED_ITEM,
|
||||
payload: item,
|
||||
});
|
||||
},[]);
|
||||
|
||||
|
||||
React.useEffect(() => {
|
||||
(async () => {
|
||||
if (!selectedProperties.listId) return;
|
||||
try {
|
||||
|
||||
dispatch({
|
||||
type: EBannerTypes.SET_ISLOADING,
|
||||
payload: true,
|
||||
});
|
||||
|
||||
const _items = await getItems(selectedProperties);
|
||||
|
||||
dispatch({
|
||||
type: EBannerTypes.SET_ITEMS,
|
||||
payload: _items,
|
||||
});
|
||||
dispatch({
|
||||
type: EBannerTypes.SET_SELECTED_ITEM,
|
||||
payload: _items[0],
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: EBannerTypes.SET_MESSAGE,
|
||||
payload: undefined,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: EBannerTypes.SET_ISLOADING,
|
||||
payload: false,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
dispatch({
|
||||
type: EBannerTypes.SET_MESSAGE,
|
||||
payload: {
|
||||
message: "Something went worg",
|
||||
messageBarType: MessageBarType.error,
|
||||
isToShow: true,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: EBannerTypes.SET_ISLOADING,
|
||||
payload: false,
|
||||
});
|
||||
}
|
||||
})();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [selectedProperties]);
|
||||
|
||||
if (messageError?.isToShow) {
|
||||
return (
|
||||
<MessageBar messageBarType={messageError.messageBarType} isMultiline>
|
||||
{messageError?.message ?? strings.MessageErrorDefault}
|
||||
</MessageBar>
|
||||
);
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<Stack horizontal horizontalAlign="center" verticalAlign="center">
|
||||
<Spinner size={SpinnerSize.large}></Spinner>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
const {
|
||||
dateFieldName,
|
||||
descriptionFieldName,
|
||||
imageUrlFieldName,
|
||||
listId,
|
||||
sites,
|
||||
titleLink,
|
||||
} = selectedProperties;
|
||||
|
||||
if (
|
||||
!titleLink ||
|
||||
!sites ||
|
||||
!sites.length ||
|
||||
!listId ||
|
||||
!dateFieldName ||
|
||||
!descriptionFieldName ||
|
||||
!imageUrlFieldName
|
||||
) {
|
||||
return (
|
||||
<Placeholder iconName='Edit'
|
||||
iconText={strings.PlaceholderIconText}
|
||||
description={strings.PlaceHolderDescription}
|
||||
buttonLabel={strings.PlaceHolderButtonDescription}
|
||||
onConfigure={()=> {webpartContext.propertyPane.open()}} />
|
||||
);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
|
||||
<div className={styles.container}>
|
||||
<div className={styles.imageContainer}>
|
||||
|
||||
<img
|
||||
className={styles.image}
|
||||
src={selectedItem ? selectedItem.imageUrl : ""}
|
||||
width={"100%"}
|
||||
height={"100%"}
|
||||
></img>
|
||||
<div className={styles.overlay}>
|
||||
<a
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
data-interception="off"
|
||||
className={styles.title}
|
||||
href={titleLink ? selectedItem?.linkUrl : ""}
|
||||
>
|
||||
{selectedItem ? selectedItem?.title : ""}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.list}>
|
||||
{items.map((item, i) => {
|
||||
const _isSeleted: boolean = item.id === selectedItem.id;
|
||||
return (
|
||||
<div key={i}>
|
||||
{i > 0 && i < items.length ? (
|
||||
<div className={styles.lineSeparator}></div>
|
||||
) : null}
|
||||
<BannerCard
|
||||
item={item}
|
||||
isSelected={_isSeleted}
|
||||
onSeletedItem={_onSelectedItem}
|
||||
selectedProperties={selectedProperties}
|
||||
currentCultureName={
|
||||
webpartContext.pageContext.cultureInfo.currentCultureName
|
||||
}
|
||||
></BannerCard>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
import { IListItem, INotification } from "./../../entities";
|
||||
import { EBannerTypes } from "./EBannerTypes";
|
||||
import { IBannerState } from "./IBannerState";
|
||||
// Reducer
|
||||
export const reducer = (
|
||||
state: IBannerState,
|
||||
action: { type: EBannerTypes; payload: unknown }
|
||||
): IBannerState => {
|
||||
switch (action.type) {
|
||||
case EBannerTypes.SET_ITEMS:
|
||||
return { ...state, items: action.payload as IListItem[] };
|
||||
case EBannerTypes.SET_SELECTED_ITEM:
|
||||
return {
|
||||
...state,
|
||||
selectedItem: action.payload as IListItem,
|
||||
};
|
||||
case EBannerTypes.SET_ISLOADING:
|
||||
return { ...state, isLoading: action.payload as boolean };
|
||||
case EBannerTypes.SET_MESSAGE:
|
||||
return { ...state, messageError: action.payload as INotification };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,10 @@
|
|||
export enum EBannerTypes {
|
||||
"SET_SELECTED_ITEM" = "SET_SELECTED_ITEM",
|
||||
"SET_SELECTED_INDEX" = "SET_SELECTED_INDEX",
|
||||
"SET_ITEMS" = "SET_ITEMS",
|
||||
"SET_ISLOADING" ="SET_ISLOADING",
|
||||
"SET_MESSAGE" ="SET_MESSAGE",
|
||||
"SET_IS_RUNNING_ACTION" = "SET_IS_RUNNING_ACTION",
|
||||
"SET_SHOW_DIALOG" = "SET_SHOW_DIALOG",
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
/* tslint:disable */
|
||||
import { WebPartContext } from "@microsoft/sp-webpart-base";
|
||||
import { ISelectedProperties } from "../../entities/ISeletedProperties";
|
||||
|
||||
export interface IBannerProps {
|
||||
selectedProperties:ISelectedProperties;
|
||||
webpartContext: WebPartContext;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
/* tslint:disable */
|
||||
import { INotification } from "../../entities";
|
||||
import { IListItem } from "../../entities/IListItem";
|
||||
|
||||
export interface IBannerState {
|
||||
selectedItem: IListItem;
|
||||
items:IListItem[];
|
||||
isLoading: boolean;
|
||||
messageError: INotification
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
/* tslint:disable */
|
||||
export * from './Banner';
|
|
@ -0,0 +1,52 @@
|
|||
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
|
||||
|
||||
.subTitleNews {
|
||||
@include ms-font-m;
|
||||
// color: $ms-color-themeDark;
|
||||
font-weight: 700;
|
||||
text-overflow: ellipsis;
|
||||
font-weight: $ms-font-weight-semibold;
|
||||
font-size: $ms-font-size-m;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
vertical-align: top;
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
max-width: 100%;
|
||||
min-width: 0px;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: $ms-font-size-m;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 4;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
.documentCard {
|
||||
margin-bottom: 3px;
|
||||
max-width: 100%;
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
padding-bottom: 15px;
|
||||
|
||||
}
|
||||
|
||||
.documentCardSeleted {
|
||||
margin-bottom: 3px;
|
||||
max-width: 100%;
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
padding-bottom: 15px;
|
||||
background-color: $ms-color-themePrimary;
|
||||
color: $ms-color-white
|
||||
|
||||
}
|
||||
.documentCard:hover {
|
||||
background-color: $ms-color-themePrimary;
|
||||
color: $ms-color-white;
|
||||
cursor: pointer;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/* tslint:disable */
|
||||
import { format, parseISO } from "date-fns";
|
||||
import React from "react";
|
||||
import styles from "./BannerCard.module.scss";
|
||||
import { IBannerCardProps } from "./IBannerCardProps";
|
||||
|
||||
export const BannerCard: React.FunctionComponent<IBannerCardProps> = (
|
||||
props: React.PropsWithChildren<IBannerCardProps>
|
||||
) => {
|
||||
const { item, isSelected } = props;
|
||||
const _date = format(parseISO(item.publishedDate), "PPPP");
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={
|
||||
isSelected ? styles.documentCardSeleted : styles.documentCard
|
||||
}
|
||||
onClick={() => {
|
||||
props.onSeletedItem(item);
|
||||
}}
|
||||
>
|
||||
<div className={styles.subTitleNews}>{_date}</div>
|
||||
<div className={styles.description}>{item.description}</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
/* tslint:disable */
|
||||
import { IListItem } from "../../entities/IListItem";
|
||||
import { ISelectedProperties } from "../../entities/ISeletedProperties";
|
||||
|
||||
export interface IBannerCardProps {
|
||||
item: IListItem;
|
||||
isSelected: boolean;
|
||||
onSeletedItem?: (item: IListItem) => void;
|
||||
currentCultureName:string;
|
||||
selectedProperties:ISelectedProperties;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
export * from './BannerCard';
|
|
@ -0,0 +1 @@
|
|||
export * from './Banner';
|
|
@ -0,0 +1,9 @@
|
|||
/* tslint:disable */
|
||||
export interface IListItem {
|
||||
id: string;
|
||||
title:string;
|
||||
publishedDate:string;
|
||||
description:string;
|
||||
imageUrl:string;
|
||||
linkUrl:string;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import { MessageBarType } from "office-ui-fabric-react";
|
||||
|
||||
export interface INotification {
|
||||
message: string;
|
||||
messageBarType: MessageBarType;
|
||||
isToShow: boolean;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
export interface ISPColumn {
|
||||
'odata.type': string;
|
||||
'odata.id': string;
|
||||
'odata.editLink': string;
|
||||
AutoIndexed: boolean;
|
||||
CanBeDeleted: boolean;
|
||||
ClientSideComponentId: string;
|
||||
ClientSideComponentProperties?: string;
|
||||
ClientValidationFormula?: string;
|
||||
ClientValidationMessage?: string;
|
||||
CustomFormatter?: string;
|
||||
DefaultFormula?: string;
|
||||
DefaultValue?: string;
|
||||
Description: string;
|
||||
Direction: string;
|
||||
EnforceUniqueValues: boolean;
|
||||
EntityPropertyName: string;
|
||||
Filterable: boolean;
|
||||
FromBaseType: boolean;
|
||||
Group: string;
|
||||
Hidden: boolean;
|
||||
Id: string;
|
||||
Indexed: boolean;
|
||||
IndexStatus: number;
|
||||
InternalName: string;
|
||||
IsModern: boolean;
|
||||
JSLink: string;
|
||||
PinnedToFiltersPane: boolean;
|
||||
ReadOnlyField: boolean;
|
||||
Required: boolean;
|
||||
SchemaXml: string;
|
||||
Scope: string;
|
||||
Sealed: boolean;
|
||||
ShowInFiltersPane: number;
|
||||
Sortable: boolean;
|
||||
StaticName: string;
|
||||
Title: string;
|
||||
FieldTypeKind: number;
|
||||
TypeAsString: string;
|
||||
TypeDisplayName: string;
|
||||
TypeShortDescription: string;
|
||||
ValidationFormula?: string;
|
||||
ValidationMessage?: string;
|
||||
MaxLength: number;
|
||||
RichText: boolean;
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
export interface ISPList {
|
||||
'odata.metadata': string;
|
||||
'odata.type': string;
|
||||
'odata.id': string;
|
||||
'odata.etag': string;
|
||||
'odata.editLink': string;
|
||||
AllowContentTypes: boolean;
|
||||
BaseTemplate: number;
|
||||
BaseType: number;
|
||||
ContentTypesEnabled: boolean;
|
||||
CrawlNonDefaultViews: boolean;
|
||||
Created: string;
|
||||
CurrentChangeToken: CurrentChangeToken;
|
||||
DefaultContentApprovalWorkflowId: string;
|
||||
DefaultItemOpenUseListSetting: boolean;
|
||||
Description: string;
|
||||
Direction: string;
|
||||
DisableCommenting: boolean;
|
||||
DisableGridEditing: boolean;
|
||||
DocumentTemplateUrl?: string;
|
||||
DraftVersionVisibility: number;
|
||||
EnableAttachments: boolean;
|
||||
EnableFolderCreation: boolean;
|
||||
EnableMinorVersions: boolean;
|
||||
EnableModeration: boolean;
|
||||
EnableRequestSignOff: boolean;
|
||||
EnableVersioning: boolean;
|
||||
EntityTypeName: string;
|
||||
ExemptFromBlockDownloadOfNonViewableFiles: boolean;
|
||||
FileSavePostProcessingEnabled: boolean;
|
||||
ForceCheckout: boolean;
|
||||
HasExternalDataSource: boolean;
|
||||
Hidden: boolean;
|
||||
Id: string;
|
||||
ImagePath: ImagePath;
|
||||
ImageUrl: string;
|
||||
IrmEnabled: boolean;
|
||||
IrmExpire: boolean;
|
||||
IrmReject: boolean;
|
||||
IsApplicationList: boolean;
|
||||
IsCatalog: boolean;
|
||||
IsPrivate: boolean;
|
||||
ItemCount: number;
|
||||
LastItemDeletedDate: string;
|
||||
LastItemModifiedDate: string;
|
||||
LastItemUserModifiedDate: string;
|
||||
ListExperienceOptions: number;
|
||||
ListItemEntityTypeFullName: string;
|
||||
MajorVersionLimit: number;
|
||||
MajorWithMinorVersionsLimit: number;
|
||||
MultipleDataList: boolean;
|
||||
NoCrawl: boolean;
|
||||
ParentWebPath: ImagePath;
|
||||
ParentWebUrl: string;
|
||||
ParserDisabled: boolean;
|
||||
ServerTemplateCanCreateFolders: boolean;
|
||||
TemplateFeatureId: string;
|
||||
Title: string;
|
||||
}
|
||||
|
||||
interface ImagePath {
|
||||
DecodedUrl: string;
|
||||
}
|
||||
|
||||
interface CurrentChangeToken {
|
||||
StringValue: string;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
import { IPropertyFieldSite } from '@pnp/spfx-property-controls/lib/PropertyFieldSitePicker';
|
||||
|
||||
export interface ISelectedProperties {
|
||||
title: string;
|
||||
listId: string;
|
||||
sites: IPropertyFieldSite[];
|
||||
titleFieldName: string;
|
||||
dateFieldName: string;
|
||||
descriptionFieldName: string;
|
||||
imageUrlFieldName: string;
|
||||
listBasetemplate: number;
|
||||
numberItems: number;
|
||||
titleLink: string;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
export * from './IListItem';
|
||||
export * from './INotification';
|
||||
export * from './ISeletedProperties';
|
||||
export * from './ISPList';
|
||||
export * from './ISPColumn';
|
|
@ -0,0 +1,95 @@
|
|||
/* tslint:disable */
|
||||
import { Web } from "@pnp/sp";
|
||||
import { IListItem, ISPList } from "./../entities";
|
||||
import { sortBy, uniqBy } from "lodash";
|
||||
import { ISelectedProperties } from "../entities";
|
||||
import { ISPColumn } from "../entities";
|
||||
|
||||
type retrunFunctions = {
|
||||
getListColumns: (webUrl: string, listId: string) => Promise<ISPColumn[]>;
|
||||
getLists: (webUrl: string, baseTemplate: number) => Promise<ISPList[]>;
|
||||
getItems: (seletedProperties: ISelectedProperties) => Promise<IListItem[]>;
|
||||
};
|
||||
|
||||
export const useList = (): retrunFunctions => {
|
||||
// Get List Columns
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const getListColumns = async (
|
||||
webUrl: string,
|
||||
listId: string
|
||||
): Promise<ISPColumn[]> => {
|
||||
const web = new Web(webUrl);
|
||||
const _listColumnsResults: ISPColumn[] = await web.lists
|
||||
.getById(listId)
|
||||
.fields.filter("Hidden eq false")
|
||||
.get();
|
||||
|
||||
const _wColumns: ISPColumn[] = uniqBy(
|
||||
sortBy(_listColumnsResults, "Title"),
|
||||
"Title"
|
||||
);
|
||||
console.log(_wColumns);
|
||||
return _wColumns;
|
||||
};
|
||||
|
||||
const getItems = async (
|
||||
seletedProperties: ISelectedProperties
|
||||
): Promise<IListItem[]> => {
|
||||
const {
|
||||
dateFieldName,
|
||||
titleFieldName,
|
||||
descriptionFieldName,
|
||||
imageUrlFieldName,
|
||||
listId,
|
||||
numberItems,
|
||||
titleLink,
|
||||
sites,
|
||||
} = seletedProperties;
|
||||
const listItems: IListItem[] = [];
|
||||
if (!listId && !sites) return [];
|
||||
const web = new Web(sites[0].url);
|
||||
const sortField: string = dateFieldName ?? "Title";
|
||||
|
||||
const _listResults = await web.lists
|
||||
.getById(listId)
|
||||
.items.orderBy(sortField, false)
|
||||
.top(numberItems ?? 3)
|
||||
.get();
|
||||
if (_listResults && _listResults.length) {
|
||||
for (const item of _listResults) {
|
||||
listItems.push({
|
||||
id: item.ID,
|
||||
title: item[titleFieldName],
|
||||
description: item[descriptionFieldName],
|
||||
imageUrl: item[imageUrlFieldName]?.Url,
|
||||
linkUrl: item[titleLink]?.Url,
|
||||
publishedDate: item[dateFieldName],
|
||||
});
|
||||
}
|
||||
}
|
||||
return listItems;
|
||||
};
|
||||
// Get Lists
|
||||
const getLists = async (
|
||||
webUrl: string,
|
||||
baseTemplate: number
|
||||
): Promise<ISPList[]> => {
|
||||
let _filter = "Hidden eq false and ";
|
||||
if (baseTemplate === 0) {
|
||||
_filter = _filter + " BaseType ne 1";
|
||||
} else {
|
||||
_filter = _filter + " BaseType eq 1";
|
||||
}
|
||||
const web = new Web(webUrl);
|
||||
const _lists: ISPList[] = await web.lists.filter(_filter).get();
|
||||
|
||||
console.log("lists", _lists);
|
||||
return _lists;
|
||||
};
|
||||
// Return functions
|
||||
return {
|
||||
getListColumns,
|
||||
getLists,
|
||||
getItems,
|
||||
};
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "6df4111a-bb08-43b8-b4bb-718ecde1148e",
|
||||
"alias": "NewsBannerWebPart",
|
||||
"componentType": "WebPart",
|
||||
|
||||
// The "*" signifies that the version should be taken from the package.json
|
||||
"version": "*",
|
||||
"manifestVersion": 2,
|
||||
|
||||
// If true, the component can only be installed on sites where Custom Script is allowed.
|
||||
// Components that allow authors to embed arbitrary script code should set this to true.
|
||||
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
|
||||
"requiresCustomScript": false,
|
||||
|
||||
"preconfiguredEntries": [{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||
"group": { "default": "SPFx Custom WebParts" },
|
||||
"title": { "default": "Banner" },
|
||||
"description": { "default": "Show news and images" },
|
||||
"officeFabricIconFontName": "News",
|
||||
"properties": {
|
||||
"title": "News Banner"
|
||||
}
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,315 @@
|
|||
|
||||
import * as React from "react";
|
||||
import * as ReactDom from "react-dom";
|
||||
import { Version } from "@microsoft/sp-core-library";
|
||||
import {
|
||||
BaseClientSideWebPart,
|
||||
IPropertyPaneConfiguration,
|
||||
IPropertyPaneDropdownOption,
|
||||
IPropertyPaneField,
|
||||
IPropertyPaneGroup,
|
||||
IPropertyPanePage,
|
||||
PropertyPaneDropdown,
|
||||
PropertyPaneSlider,
|
||||
PropertyPaneTextField,
|
||||
} from "@microsoft/sp-webpart-base";
|
||||
|
||||
import * as strings from "BannerWebPartStrings";
|
||||
import { Banner } from "../../components/Banner";
|
||||
import { IBannerProps } from "../../components/Banner/IBannerProps";
|
||||
|
||||
import { useList } from "../../hooks/useList";
|
||||
import {
|
||||
PropertyFieldSitePicker,
|
||||
IPropertyFieldSite,
|
||||
} from "@pnp/spfx-property-controls";
|
||||
import { ISPList } from "../../entities/ISPList";
|
||||
import { sp } from "@pnp/sp";
|
||||
import { ISPColumn } from "../../entities";
|
||||
export interface IBannerWebPartProps {
|
||||
title: string;
|
||||
listId: string;
|
||||
titleFieldName: string;
|
||||
dateFieldName: string;
|
||||
descriptionFieldName: string;
|
||||
imageUrlFieldName: string;
|
||||
listBasetemplate: number;
|
||||
numberItems: number;
|
||||
sites: IPropertyFieldSite[];
|
||||
titleLink: string;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
const { getListColumns, getLists } = useList();
|
||||
|
||||
export default class BannerWebPart extends BaseClientSideWebPart<
|
||||
IBannerWebPartProps
|
||||
> {
|
||||
private textColumns: IPropertyPaneDropdownOption[] = [];
|
||||
private dateColumns: IPropertyPaneDropdownOption[] = [];
|
||||
private URLColumns: IPropertyPaneDropdownOption[] = [];
|
||||
private columns: IPropertyPaneDropdownOption[] = [];
|
||||
private lists: IPropertyPaneDropdownOption[] = [];
|
||||
|
||||
private listColumns: ISPColumn[] = [];
|
||||
|
||||
private _messageError: string = undefined;
|
||||
|
||||
protected async onInit(): Promise<void> {
|
||||
sp.setup({
|
||||
spfxContext: this.context,
|
||||
});
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
public render(): void {
|
||||
const element: React.ReactElement<IBannerProps> = React.createElement(
|
||||
Banner,
|
||||
{
|
||||
selectedProperties: {
|
||||
title: this.properties.titleFieldName,
|
||||
listId: this.properties.listId,
|
||||
titleFieldName: this.properties.titleFieldName,
|
||||
dateFieldName: this.properties.dateFieldName,
|
||||
descriptionFieldName: this.properties.descriptionFieldName,
|
||||
imageUrlFieldName: this.properties.imageUrlFieldName,
|
||||
listBasetemplate: this.properties.listBasetemplate,
|
||||
numberItems: this.properties.numberItems,
|
||||
sites: this.properties.sites,
|
||||
titleLink: this.properties.titleLink,
|
||||
},
|
||||
webpartContext: this.context,
|
||||
}
|
||||
);
|
||||
|
||||
ReactDom.render(element, this.domElement);
|
||||
}
|
||||
|
||||
protected onDispose(): void {
|
||||
ReactDom.unmountComponentAtNode(this.domElement);
|
||||
}
|
||||
|
||||
protected get dataVersion(): Version {
|
||||
return Version.parse("1.0");
|
||||
}
|
||||
|
||||
protected get disableReactivePropertyChanges():boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
private addLists = async (webUrl: string): Promise<void> => {
|
||||
try {
|
||||
this.lists = [];
|
||||
const lists: ISPList[] = await getLists(webUrl, 0);
|
||||
for (const list of lists) {
|
||||
this.lists.push({
|
||||
key: list.Id,
|
||||
text: list.Title,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
this._messageError = error.message;
|
||||
}
|
||||
};
|
||||
|
||||
protected async onPropertyPaneConfigurationStart():Promise<void> {
|
||||
if (
|
||||
this.properties.titleFieldName ||
|
||||
this.properties.descriptionFieldName ||
|
||||
this.properties.dateFieldName ||
|
||||
this.properties.imageUrlFieldName ||
|
||||
this.properties.listId ||
|
||||
(this.properties.sites && this.properties.sites.length)
|
||||
) {
|
||||
if (!this.lists.length) {
|
||||
await this.addLists(this.properties.sites[0].url);
|
||||
this.context.propertyPane.refresh();
|
||||
}
|
||||
if (!this.listColumns.length && this.properties.listId) {
|
||||
await this.addListColumns(this.properties.listId);
|
||||
this.context.propertyPane.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected async onPropertyPaneFieldChanged(
|
||||
propertyPath: string,
|
||||
oldValue: unknown,
|
||||
newValue: unknown
|
||||
):Promise<void> {
|
||||
if (propertyPath === "listId") {
|
||||
this.listColumns = [];
|
||||
console.log("listd", this.properties.listId);
|
||||
if (newValue as string === "") {
|
||||
this.properties.titleFieldName = "";
|
||||
this.properties.descriptionFieldName = "";
|
||||
this.properties.dateFieldName = "";
|
||||
this.properties.imageUrlFieldName = "";
|
||||
this.properties.titleLink = "";
|
||||
this.properties.numberItems = 6;
|
||||
this.context.propertyPane.refresh();
|
||||
return;
|
||||
} else {
|
||||
this.context.propertyPane.refresh();
|
||||
await this.addListColumns(newValue as string);
|
||||
this.context.propertyPane.refresh();
|
||||
}
|
||||
}
|
||||
if (propertyPath === "sites") {
|
||||
|
||||
const value:IPropertyFieldSite[] = newValue as IPropertyFieldSite[];
|
||||
if (value && !value.length) {
|
||||
this.properties.titleFieldName = "";
|
||||
this.properties.descriptionFieldName = "";
|
||||
this.properties.dateFieldName = "";
|
||||
this.properties.imageUrlFieldName = "";
|
||||
this.properties.listId = "";
|
||||
this.properties.titleLink = "";
|
||||
this.properties.numberItems = 6;
|
||||
this.context.propertyPane.refresh();
|
||||
return;
|
||||
} else {
|
||||
this.context.propertyPane.refresh();
|
||||
await this.addLists(value[0].url);
|
||||
this.context.propertyPane.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async addListColumns(newValue: string) {
|
||||
try {
|
||||
this.listColumns = [];
|
||||
|
||||
this.listColumns = await getListColumns(
|
||||
this.properties.sites[0].url,
|
||||
newValue
|
||||
);
|
||||
|
||||
for (const _column of this.listColumns) {
|
||||
if (
|
||||
(_column.TypeAsString === "Text" ||
|
||||
_column.TypeAsString === "Note") &&
|
||||
(_column.RichText === false || _column.RichText === undefined)
|
||||
) {
|
||||
this.textColumns.push({
|
||||
key: _column.InternalName,
|
||||
text: _column.Title,
|
||||
});
|
||||
}
|
||||
if (_column.TypeAsString === "DateTime") {
|
||||
this.dateColumns.push({
|
||||
key: _column.InternalName,
|
||||
text: _column.Title,
|
||||
});
|
||||
}
|
||||
if (_column.TypeAsString === "URL") {
|
||||
this.URLColumns.push({
|
||||
key: _column.InternalName,
|
||||
text: _column.Title,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
this._messageError = error.message;
|
||||
}
|
||||
}
|
||||
|
||||
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||
const _pages: IPropertyPanePage[] = [
|
||||
{
|
||||
header: {
|
||||
description: strings.PropertyPaneDescription,
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
groupName: strings.BasicGroupName,
|
||||
groupFields: [
|
||||
PropertyPaneTextField("title", {
|
||||
label: strings.DescriptionFieldLabel,
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
const groups: IPropertyPaneGroup = _pages[0].groups[0] as IPropertyPaneGroup;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const groupFields: IPropertyPaneField<any>[] = groups.groupFields;
|
||||
|
||||
groupFields.push(
|
||||
PropertyFieldSitePicker("sites", {
|
||||
label: "Select site",
|
||||
initialSites: this.properties.sites,
|
||||
context: this.context,
|
||||
deferredValidationTime: 500,
|
||||
multiSelect: false,
|
||||
onPropertyChange: this.onPropertyPaneFieldChanged,
|
||||
properties: this.properties,
|
||||
key: "sitesFieldId",
|
||||
})
|
||||
);
|
||||
if (this.properties.sites && this.properties.sites.length) {
|
||||
groupFields.push(
|
||||
PropertyPaneDropdown("listId", {
|
||||
label: strings.ListIdLabel,
|
||||
options: this.lists,
|
||||
selectedKey: this.properties.listId,
|
||||
})
|
||||
);
|
||||
// Show Columns
|
||||
if (this.listColumns.length) {
|
||||
groupFields.push(
|
||||
PropertyPaneDropdown("titleFieldName", {
|
||||
label: strings.TitleFieldLabel,
|
||||
options: this.textColumns,
|
||||
|
||||
selectedKey: this.properties.titleFieldName,
|
||||
})
|
||||
);
|
||||
groupFields.push(
|
||||
PropertyPaneDropdown("dateFieldName", {
|
||||
label: "Select field with published date",
|
||||
options: this.dateColumns,
|
||||
selectedKey: this.properties.dateFieldName,
|
||||
})
|
||||
);
|
||||
groupFields.push(
|
||||
PropertyPaneDropdown("descriptionFieldName", {
|
||||
label: "Select field with description",
|
||||
options: this.textColumns,
|
||||
selectedKey: this.properties.descriptionFieldName,
|
||||
})
|
||||
);
|
||||
groupFields.push(
|
||||
PropertyPaneDropdown("imageUrlFieldName", {
|
||||
label: "Select field width image url",
|
||||
options: this.URLColumns,
|
||||
selectedKey: this.properties.imageUrlFieldName,
|
||||
})
|
||||
);
|
||||
groupFields.push(
|
||||
PropertyPaneDropdown("titleLink", {
|
||||
label: "Select field for title link",
|
||||
options: this.URLColumns,
|
||||
selectedKey: this.properties.titleLink,
|
||||
})
|
||||
);
|
||||
groupFields.push(
|
||||
PropertyPaneSlider("numberItems", {
|
||||
label: "Number Items to Show",
|
||||
min: 3,
|
||||
max: 20,
|
||||
value: this.properties.numberItems
|
||||
? this.properties.numberItems
|
||||
: 3,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const _panelConfiguration: IPropertyPaneConfiguration = { pages: _pages };
|
||||
return _panelConfiguration;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
define([], function() {
|
||||
return {
|
||||
MessageErrorDefault: "Something went wrong when trying get data.",
|
||||
PlaceHolderButtonDescription: "Configure",
|
||||
PlaceHolderDescription: "Please configure Banner web part",
|
||||
PlaceholderIconText: "Configure your web part",
|
||||
"PropertyPaneDescription": "Please select List, and columns with information to show",
|
||||
"BasicGroupName": "Properties",
|
||||
"DescriptionFieldLabel": "Title",
|
||||
"ListIdLabel": "Select list",
|
||||
"TitleFieldLabel": "Select field with title",
|
||||
}
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
declare interface IBannerWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
BasicGroupName: string;
|
||||
DescriptionFieldLabel: string;
|
||||
ListIdLabel: string;
|
||||
MessageErrorDefault: string;
|
||||
PlaceHolderButtonDescription: string;
|
||||
PlaceHolderDescription: string;
|
||||
PlaceholderIconText: string;
|
||||
TitleFieldLabel: string;
|
||||
}
|
||||
|
||||
declare module 'BannerWebPartStrings' {
|
||||
const strings: IBannerWebPartStrings;
|
||||
export = strings;
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* This script updates the package-solution version analogue to the
|
||||
* the package.json file.
|
||||
*/
|
||||
|
||||
if (process.env.npm_package_version === undefined) {
|
||||
|
||||
throw 'Package version cannot be evaluated';
|
||||
|
||||
}
|
||||
|
||||
// define path to package-solution file
|
||||
const solution = './config/package-solution.json',
|
||||
teams = './teams/manifest.json';
|
||||
|
||||
// require filesystem instance
|
||||
const fs = require('fs');
|
||||
|
||||
// get next automated package version from process variable
|
||||
const nextPkgVersion = process.env.npm_package_version;
|
||||
|
||||
// make sure next build version match
|
||||
const nextVersion = nextPkgVersion.indexOf('-') === -1 ?
|
||||
nextPkgVersion : nextPkgVersion.split('-')[0];
|
||||
|
||||
// Update version in SPFx package-solution if exists
|
||||
if (fs.existsSync(solution)) {
|
||||
|
||||
// read package-solution file
|
||||
const solutionFileContent = fs.readFileSync(solution, 'UTF-8');
|
||||
// parse file as json
|
||||
const solutionContents = JSON.parse(solutionFileContent);
|
||||
|
||||
// set property of version to next version
|
||||
solutionContents.solution.version = nextVersion + '.0';
|
||||
|
||||
// save file
|
||||
fs.writeFileSync(
|
||||
solution,
|
||||
// convert file back to proper json
|
||||
JSON.stringify(solutionContents, null, 2),
|
||||
'UTF-8');
|
||||
|
||||
}
|
||||
|
||||
// Update version in teams manifest if exists
|
||||
if (fs.existsSync(teams)) {
|
||||
|
||||
// read package-solution file
|
||||
const teamsManifestContent = fs.readFileSync(teams, 'UTF-8');
|
||||
// parse file as json
|
||||
const teamsContent = JSON.parse(teamsManifestContent);
|
||||
|
||||
// set property of version to next version
|
||||
teamsContent.version = nextVersion;
|
||||
|
||||
// save file
|
||||
fs.writeFileSync(
|
||||
teams,
|
||||
// convert file back to proper json
|
||||
JSON.stringify(teamsContent, null, 2),
|
||||
'UTF-8');
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"jsx": "react",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true,
|
||||
"typeRoots": [
|
||||
"./node_modules/@types",
|
||||
"./node_modules/@microsoft"
|
||||
],
|
||||
"types": [
|
||||
"es6-promise",
|
||||
"webpack-env"
|
||||
],
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.collection"
|
||||
],
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.3/includes/tsconfig-web.json"
|
||||
}
|
Loading…
Reference in New Issue