Fixed bugs for react-star-ratings
This commit is contained in:
parent
19d2775130
commit
eb67d0e68d
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||||
"solution": {
|
"solution": {
|
||||||
"name": "ratings-client-side-solution",
|
"name": "ratings",
|
||||||
"id": "1fac5bb8-6a05-4c52-aee3-496f6921ac1a",
|
"id": "1fac5bb8-6a05-4c52-aee3-496f6921ac1a",
|
||||||
"version": "1.0.0.0",
|
"version": "1.0.0.0",
|
||||||
"includeClientSideAssets": true,
|
"includeClientSideAssets": true,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ratings",
|
"name": "ratings",
|
||||||
"version": "0.0.1",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ratings",
|
"name": "ratings",
|
||||||
"version": "0.0.1",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
TooltipHost
|
TooltipHost
|
||||||
} from '@fluentui/react';
|
} from '@fluentui/react';
|
||||||
import styles from './Ratings.module.scss';
|
import styles from './Ratings.module.scss';
|
||||||
|
import * as strings from 'RatingsWebPartStrings';
|
||||||
import { IRatingsProps } from './IRatingsProps';
|
import { IRatingsProps } from './IRatingsProps';
|
||||||
import SPHttpClientService from '../services/SPHttpClientService';
|
import SPHttpClientService from '../services/SPHttpClientService';
|
||||||
import '../extensions/Map';
|
import '../extensions/Map';
|
||||||
|
@ -21,8 +22,6 @@ interface IRatings {
|
||||||
|
|
||||||
export const Ratings = ({ context, properties }: IRatingsProps) => {
|
export const Ratings = ({ context, properties }: IRatingsProps) => {
|
||||||
|
|
||||||
console.log(properties);
|
|
||||||
|
|
||||||
const ratingStyles = React.useMemo(() => (props: IRatingStyleProps): Partial<IRatingStyles> => ({
|
const ratingStyles = React.useMemo(() => (props: IRatingStyleProps): Partial<IRatingStyles> => ({
|
||||||
root: {
|
root: {
|
||||||
selectors: {
|
selectors: {
|
||||||
|
@ -81,11 +80,11 @@ export const Ratings = ({ context, properties }: IRatingsProps) => {
|
||||||
const ratings = await service.getRatings();
|
const ratings = await service.getRatings();
|
||||||
const rating = ratings.get(user.LoginName);
|
const rating = ratings.get(user.LoginName);
|
||||||
const count = ratings.size;
|
const count = ratings.size;
|
||||||
const sum = ratings.values().reduce((current, prev) => prev + current);
|
const sum = ratings.values().reduce((current, prev) => prev + current, 0);
|
||||||
return {
|
return {
|
||||||
rating: rating,
|
rating: rating,
|
||||||
count: count,
|
count: count,
|
||||||
average: sum / count
|
average: count ? sum / count : 0
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
@ -134,8 +133,8 @@ export const Ratings = ({ context, properties }: IRatingsProps) => {
|
||||||
)
|
)
|
||||||
: (
|
: (
|
||||||
<div className={styles.flex}>
|
<div className={styles.flex}>
|
||||||
<span>Rate this page: </span>
|
<span>{strings.RateThisPageLabel}: </span>
|
||||||
<TooltipHost content={`Average: ${value.average}, Count: ${value.count}`}>
|
<TooltipHost content={`${strings.AverageLabel}: ${value.average}, ${strings.CountLabel}: ${value.count}`}>
|
||||||
<Rating
|
<Rating
|
||||||
allowZeroStars
|
allowZeroStars
|
||||||
rating={value.rating}
|
rating={value.rating}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
define([], function() {
|
define([], function() {
|
||||||
return {
|
return {
|
||||||
"PropertyPaneDescription": "Youn can rate site pages.",
|
"PropertyPaneDescription": "You can rate site pages.",
|
||||||
"ActiveColorLabel": "Active Color",
|
"ActiveColorLabel": "Active Color",
|
||||||
"InactiveColorLabel": "Inactive Color"
|
"InactiveColorLabel": "Inactive Color",
|
||||||
|
"RateThisPageLabel": "Rate this page",
|
||||||
|
"AverageLabel": "Average",
|
||||||
|
"CountLabel": "Count"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
define([], function() {
|
||||||
|
return {
|
||||||
|
"PropertyPaneDescription": "サイトのページを評価することができます。",
|
||||||
|
"ActiveColorLabel": "アクティブな色",
|
||||||
|
"InactiveColorLabel": "非アクティブな色",
|
||||||
|
"RateThisPageLabel": "このページの評価",
|
||||||
|
"AverageLabel": "平均",
|
||||||
|
"CountLabel": "件数"
|
||||||
|
}
|
||||||
|
});
|
|
@ -2,6 +2,9 @@ declare interface IRatingsWebPartStrings {
|
||||||
PropertyPaneDescription: string;
|
PropertyPaneDescription: string;
|
||||||
ActiveColorLabel: string;
|
ActiveColorLabel: string;
|
||||||
InactiveColorLabel: string;
|
InactiveColorLabel: string;
|
||||||
|
RateThisPageLabel: string;
|
||||||
|
AverageLabel: string;
|
||||||
|
CountLabel: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'RatingsWebPartStrings' {
|
declare module 'RatingsWebPartStrings' {
|
||||||
|
|
Loading…
Reference in New Issue