Skip to content

Commit a65de27

Browse files
authored
Merge pull request #1434 from wuxiaojun514/dev
#1430 - ListItemComments
2 parents c0e6dd8 + 1623d40 commit a65de27

File tree

7 files changed

+48
-4
lines changed

7 files changed

+48
-4
lines changed
30.5 KB
Loading
10.2 KB
Loading

docs/documentation/docs/controls/ListItemComments.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,29 @@ import { ListItemComments } from '@pnp/spfx-controls-react/lib/ListItemComments'
3535
label="ListItem Comments"
3636
/>
3737
```
38+
## Use "highlightedCommentId" parameter to support Comment Notification Link
39+
SharePoint will send a comment notification if someone has been ***"@"*** in the comment. This comment notification mail contains a ***Go to comment*** button.
3840

41+
![ListItemComments](../assets/ListItemComments05.png)
42+
43+
The "Go to Comment" link is like [https://xxx.sharepoint.com/sites/xxxx/Lists/MyList/DispForm.aspx?ID=1&commentId=1&e=LURoEsg5Zki4cS4SgcIG7w&at=15&CT=1674882847351&OR=OWA-NT&CID=c3a04ee0-40b5-9591-e6a4-3fac33046a64](https://xxx.sharepoint.com/sites/xxxx/Lists/MyList/DispForm.aspx?ID=1&commentId=1&e=LURoEsg5Zki4cS4SgcIG7w&at=15&CT=1674882847351&OR=OWA-NT&CID=c3a04ee0-40b5-9591-e6a4-3fac33046a64), which contains ***commentId*** in url parameter.
44+
45+
The comment whose id is commentId will be highlighted in the OOTB SharePoint List Item page.
46+
You can use ***highlightedCommentId*** to specify the comment you want to highlight in `ListItemComments` control.
47+
48+
```TypeScript
49+
<ListItemComments webUrl='{"https://contoso.sharepoint.com/sites/ThePerspective"}'
50+
listId='dfa283f4-5faf-4d54-b6b8-5bcaf2725af5'
51+
itemId={1}
52+
serviceScope={serviceScope}
53+
numberCommentsPerPage={10}
54+
highlightedCommentId={"1"}
55+
label="ListItem Comments"
56+
/>
57+
```
58+
59+
The specified comment will be highlighted with different border and background color (Use theme color).
60+
![ListItemComments](../assets/ListItemComments06.png)
3961

4062
## Implementation
4163

@@ -50,6 +72,8 @@ The `ListItemComments` control can be configured with the following properties:
5072
| webUrl | string | no | URL of the site. By default it uses the current site URL. |
5173
| label | string | no | Label for control |
5274
| numberCommentsPerPage | number | no | number of comments per page possible values 5 | 10 | 15 | 20 default 10 |
75+
| highlightedCommentId | string | no | The commend Id (e.g. "1") you want to highlight. This selected comment will show with different border and background color based on site theme |
76+
5377

5478
## MSGraph Permissions required
5579

src/controls/listItemComments/ListItemComments.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ import { Theme } from "spfx-uifabric-themes"; // Don't remove this import is nee
77
import { CommentsList } from "./components/Comments/CommentsList";
88
import { Stack } from "office-ui-fabric-react/lib/Stack";
99
import { Text } from "office-ui-fabric-react/lib/Text";
10+
1011
export interface IListItemCommentsProps {
1112
webUrl?: string;
1213
listId: string;
1314
itemId: string;
1415
serviceScope: ServiceScope;
1516
numberCommentsPerPage?: 5 | 10 | 15 | 20;
1617
label?: string;
18+
highlightedCommentId?:string;
1719
}
1820
const theme = window.__themeState__.theme;
1921
export const ListItemComments: React.FunctionComponent<IListItemCommentsProps> = (
2022
props: React.PropsWithChildren<IListItemCommentsProps>
2123
) => {
22-
const { webUrl, listId, itemId, serviceScope, numberCommentsPerPage, label } = props;
24+
const { webUrl, listId, itemId, serviceScope, numberCommentsPerPage, label,highlightedCommentId } = props;
2325

2426
if (!listId && !itemId && !serviceScope) return;
2527

@@ -34,6 +36,7 @@ export const ListItemComments: React.FunctionComponent<IListItemCommentsProps> =
3436
theme: theme,
3537
serviceScope: serviceScope,
3638
label: label,
39+
highlightedCommentId:highlightedCommentId,
3740
numberCommentsPerPage: numberCommentsPerPage,
3841
}}
3942
>

src/controls/listItemComments/common/IAppContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export interface IAppContext {
99
itemId: string;
1010
numberCommentsPerPage?: number;
1111
label?:string;
12+
highlightedCommentId?:string;
1213
}

src/controls/listItemComments/components/Comments/RenderComments.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,22 @@ import { RenderSpinner } from "./RenderSpinner";
1212
import { useListItemCommentsStyles } from "./useListItemCommentsStyles";
1313
import { useBoolean } from "@fluentui/react-hooks";
1414
import { List } from "office-ui-fabric-react/lib/List";
15-
import { ECommentAction } from "../..";
15+
import { AppContext, ECommentAction } from "../..";
1616

1717
export interface IRenderCommentsProps { }
1818

1919
export const RenderComments: React.FunctionComponent<IRenderCommentsProps> = () => {
20+
const { highlightedCommentId } = useContext(AppContext);
2021
const { listItemCommentsState, setlistItemCommentsState } = useContext(ListItemCommentsStateContext);
21-
const { documentCardStyles, itemContainerStyles, deleteButtonContainerStyles } = useListItemCommentsStyles();
22+
const { documentCardStyles,documentCardHighlightedStyles, itemContainerStyles, deleteButtonContainerStyles } = useListItemCommentsStyles();
2223
const { comments, isLoading } = listItemCommentsState;
2324

2425
const [hideDialog, { toggle: setHideDialog }] = useBoolean(true);
2526

2627
const onRenderCell = useCallback(
2728
(comment: IComment, index: number): JSX.Element => {
2829
return (
29-
<DocumentCard styles={documentCardStyles} key={index}>
30+
<DocumentCard styles={ highlightedCommentId && comment.id===highlightedCommentId? documentCardHighlightedStyles : documentCardStyles} key={index}>
3031
<Stack horizontal horizontalAlign="end" styles={deleteButtonContainerStyles}>
3132
<IconButton
3233
iconProps={{ iconName: "Delete" }}

src/controls/listItemComments/components/Comments/useListItemCommentsStyles.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface returnObjectStyles {
1616
renderUserContainerStyles: Partial<IStackStyles>;
1717
documentCardStyles: Partial<IDocumentCardStyles>;
1818
documentCardDeleteStyles: Partial<IDocumentCardStyles>;
19+
documentCardHighlightedStyles: Partial<IDocumentCardStyles>;
1920
documentCardUserStyles: Partial<IDocumentCardStyles>;
2021
configurationListClasses: any; // eslint-disable-line @typescript-eslint/no-explicit-any
2122
}
@@ -58,6 +59,19 @@ export const useListItemCommentsStyles = (): returnObjectStyles => {
5859
} as IStyle,
5960
};
6061

62+
const documentCardHighlightedStyles: Partial<IDocumentCardStyles> = {
63+
root: {
64+
marginBottom: 7,
65+
width: 322,
66+
backgroundColor: theme.themeLighter,
67+
border: "solid 3px "+theme.themePrimary,
68+
":hover": {
69+
borderColor: theme.themePrimary,
70+
borderWidth: 1,
71+
} as IStyle,
72+
} as IStyle,
73+
};
74+
6175
const documentCardDeleteStyles: Partial<IDocumentCardStyles> = {
6276
root: {
6377
marginBottom: 5,
@@ -121,6 +135,7 @@ export const useListItemCommentsStyles = (): returnObjectStyles => {
121135
renderUserContainerStyles,
122136
documentCardStyles,
123137
documentCardDeleteStyles,
138+
documentCardHighlightedStyles,
124139
documentCardUserStyles,
125140
configurationListClasses,
126141
};

0 commit comments

Comments
 (0)