Sample Dev-Radar integrated with GitHub (#1164)

Co-authored-by: Saulo Oliveira <sauslash@hotmail.com>
This commit is contained in:
SharePoint Academy 2020-03-09 15:23:56 -03:00 committed by GitHub
parent 2574ddcfa1
commit fe7409419a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 18145 additions and 0 deletions

View File

@ -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

32
samples/react-dev-radar/.gitignore vendored Normal file
View File

@ -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

View File

@ -0,0 +1,12 @@
{
"@microsoft/generator-sharepoint": {
"isCreatingSolution": true,
"environment": "spo",
"version": "1.10.0",
"libraryName": "dev-radar",
"libraryId": "ff92e7ef-09b0-4bb2-add5-f09b1697b1c7",
"packageManager": "npm",
"isDomainIsolated": false,
"componentType": "webpart"
}
}

View File

@ -0,0 +1,61 @@
# Dev-Radar for SharePoint Online
## Summary
One way to find devs from the same stack near you.
## Screen
![react-dev-radar](dev-radar.png)
## Used SharePoint Framework Version
![drop](https://img.shields.io/badge/version-1.10.0-green.svg)
## Applies to
* [SharePoint Online](https:/dev.office.com/sharepoint)
## Solution
The web part Use PnPjs library and Axios
Create a list Devs with fields
```
Field Type
---------------------------
name single line
githubUsername single line
techs single line
avatarUrl single line
bio multiline
latitude single line
longitude single line
```
Solution|Author(s)
--------|---------
Dev Radar Web Part|Saulo Oliveira
## Version history
Version|Date|Comments
-------|----|--------
1.0.0|March 01, 2020|Initial release
## 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.**
---
## Minimal Path to Awesome
- Clone this repository
- in the command line run:
- `npm install`
- `gulp build`
- `gulp bundle --ship`
- `gulp package-solution --ship`
- `Add to AppCatalog and deploy`

View File

@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"home-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/home/HomeWebPart.js",
"manifest": "./src/webparts/home/HomeWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"HomeWebPartStrings": "lib/webparts/home/loc/{locale}.js"
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
"deployCdnPath": "temp/deploy"
}

View File

@ -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": "dev-radar",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,13 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "dev-radar-client-side-solution",
"id": "ff92e7ef-09b0-4bb2-add5-f09b1697b1c7",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"isDomainIsolated": false
},
"paths": {
"zippedPackage": "solution/dev-radar.sppkg"
}
}

View File

@ -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/"
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

7
samples/react-dev-radar/gulpfile.js vendored Normal file
View File

@ -0,0 +1,7 @@
'use strict';
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.initialize(require('gulp'));

17344
samples/react-dev-radar/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,47 @@
{
"name": "dev-radar",
"version": "0.0.1",
"private": true,
"main": "lib/index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@microsoft/sp-core-library": "1.10.0",
"@microsoft/sp-lodash-subset": "1.10.0",
"@microsoft/sp-office-ui-fabric-core": "1.10.0",
"@microsoft/sp-property-pane": "1.10.0",
"@microsoft/sp-webpart-base": "1.10.0",
"@pnp/common": "^1.3.7",
"@pnp/logging": "^1.3.7",
"@pnp/odata": "^1.3.7",
"@pnp/sp": "^1.3.7",
"@types/es6-promise": "0.0.33",
"@types/react": "16.8.8",
"@types/react-dom": "16.8.3",
"@types/webpack-env": "1.13.1",
"axios": "^0.19.2",
"office-ui-fabric-react": "6.189.2",
"react": "16.8.5",
"react-dom": "16.8.5"
},
"resolutions": {
"@types/react": "16.8.8"
},
"devDependencies": {
"@microsoft/sp-build-web": "1.10.0",
"@microsoft/sp-tslint-rules": "1.10.0",
"@microsoft/sp-module-interfaces": "1.10.0",
"@microsoft/sp-webpart-workbench": "1.10.0",
"@microsoft/rush-stack-compiler-3.3": "0.3.5",
"gulp": "~3.9.1",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"ajv": "~5.2.2"
}
}

View File

@ -0,0 +1 @@
// A file is required to be in the root of the /src directory by the TypeScript compiler

View File

@ -0,0 +1,27 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "4a2896ac-2d0e-4ea8-ae81-870c02cf43b6",
"alias": "HomeWebPart",
"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,
"supportedHosts": ["SharePointWebPart"],
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "Home" },
"description": { "default": "webpart inicial do dev radar" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "Home"
}
}]
}

View File

@ -0,0 +1,70 @@
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import * as strings from 'HomeWebPartStrings';
import Home from './components/Home';
import { IHomeProps } from './components/IHomeProps';
import { sp } from '@pnp/sp';
export interface IHomeWebPartProps {
description: string;
}
export default class HomeWebPart extends BaseClientSideWebPart <IHomeWebPartProps> {
public onInit(): Promise<void> {
return super.onInit().then(_ => {
sp.setup({
spfxContext: this.context
});
});
}
public render(): void {
const element: React.ReactElement<IHomeProps> = React.createElement(
Home,
{
description: this.properties.description
}
);
ReactDom.render(element, this.domElement);
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,28 @@
#app{
max-width: 1200px;
margin: 0 auto;
/*padding: 60px 30px;*/
display: flex;
flex-direction: row;
}
#app main {
margin-left: 30px;
}
@media (max-width: 1000px)
{
#app {
flex-direction: column;
}
#app main {
margin-left: 0;
margin-top: 30px;
}
#app aside {
width: 100%;
}
}

View File

@ -0,0 +1,77 @@
import * as React from 'react';
import { useState, useEffect } from 'react';
import axios from 'axios';
import './global.css';
import './App.css';
import './Sidebar.css';
import './Main.css';
import DevItem from '../DevItem';
import DevForm from '../DevForm';
import { sp } from '@pnp/sp';
export const App: React.FunctionComponent = () => {
const [devs, setDevs] = useState([]);
useEffect(() => {
async function loadDevs() {
sp.web.lists
.getByTitle("Devs")
.select("ID, name, githubUsername, techs, avatarUrl, bio")
.items.top(5000)
.get()
.then(items => {
setDevs(items);
},
(err) => {
console.log(err);
});
}
loadDevs();
}, []);
async function handleAddDev(data) {
const { github_username, techs, latitude, longitude } = data;
const apiResponse = await axios.get(`https://api.github.com/users/${github_username}`);
const { name, avatar_url, bio } = apiResponse.data;
sp.web.lists.getByTitle("Devs").items.add({
githubUsername: github_username,
name: name,
avatarUrl: avatar_url,
bio: bio,
techs: techs,
latitude: latitude,
longitude: longitude
}).then(i => {
console.log(i);
setDevs([...devs, i.data]);
},
(err) => {
console.log(err);
});
}
return (
<div id="app">
<aside>
<strong>Register</strong>
<DevForm onSubmit={handleAddDev} />
</aside>
<main>
<ul>
{devs.map(dev => (
<DevItem key={dev.ID} dev={dev} />
))}
</ul>
</main>
</div>
);
};

View File

@ -0,0 +1,16 @@
main {
flex: 1;
}
main ul {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20px;
list-style: none;
}
@media (max-width: 650px) {
main ul {
grid-template-columns: 1fr;
}
}

View File

@ -0,0 +1,14 @@
aside{
width: 320px;
background: #fff;
box-shadow: 0 0 14px 0 rgba(0, 0, 0, 0.02);
border-radius: 2px;
padding: 30px 20px;
}
aside strong {
font-size: 20px;
text-align: center;
display: block;
color: #333;
}

View File

@ -0,0 +1,18 @@
* {
margin: 0;
padding: 0;
outline: 0;
box-sizing: border-box;
}
html, body, #root{
height: 100%;
}
body{
-webkit-font-smoothing: antialiased;
}
body, imput, button{
font-family: Arial, Helvetica, sans-serif;
}

View File

@ -0,0 +1,80 @@
import * as React from 'react';
import './styles.css';
function DevForm(props) {
const { onSubmit } = props;
const [latitude, setLatitude] = React.useState('');
const [longitude, setLogintude] = React.useState('');
const [github_username, setGitHubUserName] = React.useState('');
const [techs, setTechs] = React.useState('');
React.useEffect(() => {
navigator.geolocation.getCurrentPosition(
(position) => {
const { latitude, longitude } = position.coords;
setLatitude(latitude.toString());
setLogintude(longitude.toString());
},
(err) => {
console.log(err);
},
{
timeout: 30000,
}
);
}, []);
async function handleAddDev(e) {
e.preventDefault();
await onSubmit({
github_username,
techs,
latitude,
longitude,
});
setGitHubUserName('');
setTechs('');
}
return (
<form onSubmit={handleAddDev}>
<div className="input-block">
<label htmlFor="github_username">GitHub UserName</label>
<input name="github_username" id="github_username" required
value={github_username}
onChange={e => setGitHubUserName(e.target.value)} />
</div>
<div className="input-block">
<label htmlFor="techs">Technologies</label>
<input name="techs" id="techs" required
value={techs}
onChange={e => setTechs(e.target.value)} />
</div>
<div className="input-group">
<div className="input-block">
<label htmlFor="latitude">Latitude</label>
<input type="number" name="latitude" id="latitude" required
value={latitude}
onChange={e => setLatitude(e.target.value)} />
</div>
<div className="input-block">
<label htmlFor="longitude">Longitude</label>
<input type="number" name="longitude" id="longitude" required
value={longitude}
onChange={e => setLogintude(e.target.value)} />
</div>
</div>
<button type="submit">Save</button>
</form>
);
}
export default DevForm;

View File

@ -0,0 +1,52 @@
aside form {
margin-top: 30px;
}
aside form .input-block + .input-block {
margin-top: 20px;
}
aside form .input-group {
margin-top: 20px;
display: grid;
gap: 20px;
grid-template-columns: 1fr 1fr;
}
aside form .input-group .input-block{
margin-top: 0;
}
aside form .input-block label {
color: #acacac;
font-size: 14px;
font-weight: bold;
display: block;
}
aside form .input-block input {
width: 100%;
height: 32px;
font-size: 14px;
color: #665;
border: 0;
border-bottom: 1px solid #eee;
}
aside form button[type="submit"] {
width: 100%;
border: 0;
margin-top: 30px;
background: #7d40e7;
border-radius: 2px;
padding: 15px 20px;
font-size: 16px;
font-weight: bold;
color: #fff;
cursor: pointer;
transition: background 0.5s;
}
aside form button[type="submit"]:hover {
background: #6931ca;
}

View File

@ -0,0 +1,24 @@
import * as React from 'react';
import './styles.css';
function DevItem(props) {
const { dev } = props;
return (
<li className="dev-item">
<header>
<img src={dev.avatarUrl} alt={dev.name} />
<div className="user-info">
<strong>{dev.name}</strong>
<span>{dev.techs}</span>
</div>
</header>
<p>{dev.bio}</p>
<a href={`https://github.com/${dev.githubUsername}`}>Access GitHub profile</a>
</li>
);
}
export default DevItem;

View File

@ -0,0 +1,51 @@
li.dev-item {
background: #fff;
box-shadow: 0 0 14px 0 rgba(0, 0, 0, 0.02);
border-radius: 2px;
padding: 20px;
}
li.dev-item header {
display: flex;
flex-direction: row;
align-items: center;
}
li.dev-item header img {
width: 54px;
height: 54px;
border-radius: 50%;
}
li.dev-item header .user-info{
margin-left: 10px;
}
.user-info strong {
display: block;
font-size: 16px;
color: #333;
}
.user-info span {
font-size: 13px;
color: #999;
margin-top: 2px;
}
li.dev-item p {
color: #665;
font-size: 14px;
line-height: 20px;
margin: 10px 0;
}
li.dev-item a {
color: #8e4dff;
font-size: 14px;
text-decoration: none;
}
li.dev-item a:hover {
color: #5a2ea6;
}

View File

@ -0,0 +1,15 @@
import * as React from 'react';
import { IHomeProps } from './IHomeProps';
import { escape } from '@microsoft/sp-lodash-subset';
import { App } from './AppForm/App';
export default class Home extends React.Component<IHomeProps, {}> {
public render(): React.ReactElement<IHomeProps> {
return (
<div>
<App />
</div>
);
}
}

View File

@ -0,0 +1,3 @@
export interface IHomeProps {
description: string;
}

View File

@ -0,0 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field"
}
});

View File

@ -0,0 +1,10 @@
declare interface IHomeWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'HomeWebPartStrings' {
const strings: IHomeWebPartStrings;
export = strings;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,38 @@
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.3/includes/tsconfig-web.json",
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "lib",
"inlineSources": false,
"strictNullChecks": false,
"noUnusedLocals": false,
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft"
],
"types": [
"es6-promise",
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"lib"
]
}

View File

@ -0,0 +1,30 @@
{
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
"rules": {
"class-name": false,
"export-name": false,
"forin": false,
"label-position": false,
"member-access": true,
"no-arg": false,
"no-console": false,
"no-construct": false,
"no-duplicate-variable": true,
"no-eval": false,
"no-function-expression": true,
"no-internal-module": true,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"variable-name": false,
"whitespace": false
}
}