Changes to cards in notebook gallery (#422)
* added gallery changes * addressed PR comments
This commit is contained in:
parent
93cfd52e36
commit
1c0fed88c0
|
@ -38,7 +38,7 @@ export class GalleryCardComponent extends React.Component<GalleryCardComponentPr
|
|||
private static readonly cardImageHeight = 144;
|
||||
public static readonly cardHeightToWidthRatio =
|
||||
GalleryCardComponent.cardImageHeight / GalleryCardComponent.CARD_WIDTH;
|
||||
private static readonly cardDescriptionMaxChars = 88;
|
||||
private static readonly cardDescriptionMaxChars = 80;
|
||||
private static readonly cardItemGapBig = 10;
|
||||
private static readonly cardItemGapSmall = 8;
|
||||
|
||||
|
@ -105,13 +105,14 @@ export class GalleryCardComponent extends React.Component<GalleryCardComponentPr
|
|||
</Text>
|
||||
|
||||
<Text variant="small" styles={{ root: { height: 36 } }}>
|
||||
{this.props.data.description.substr(0, GalleryCardComponent.cardDescriptionMaxChars)}
|
||||
{this.renderTruncatedDescription()}
|
||||
</Text>
|
||||
|
||||
<span>
|
||||
{this.generateIconText("RedEye", this.props.data.views.toString())}
|
||||
{this.generateIconText("Download", this.props.data.downloads.toString())}
|
||||
{this.props.isFavorite !== undefined &&
|
||||
{this.props.data.views !== undefined && this.generateIconText("RedEye", this.props.data.views.toString())}
|
||||
{this.props.data.downloads !== undefined &&
|
||||
this.generateIconText("Download", this.props.data.downloads.toString())}
|
||||
{this.props.data.favorites !== undefined &&
|
||||
this.generateIconText("Heart", this.props.data.favorites.toString())}
|
||||
</span>
|
||||
</Card.Section>
|
||||
|
@ -148,6 +149,14 @@ export class GalleryCardComponent extends React.Component<GalleryCardComponentPr
|
|||
);
|
||||
}
|
||||
|
||||
private renderTruncatedDescription = (): string => {
|
||||
let truncatedDescription = this.props.data.description.substr(0, GalleryCardComponent.cardDescriptionMaxChars);
|
||||
if (this.props.data.description.length > GalleryCardComponent.cardDescriptionMaxChars) {
|
||||
truncatedDescription = `${truncatedDescription} ...`;
|
||||
}
|
||||
return truncatedDescription;
|
||||
};
|
||||
|
||||
private generateIconText = (iconName: string, text: string): JSX.Element => {
|
||||
return (
|
||||
<Text
|
||||
|
|
|
@ -31,6 +31,26 @@ export interface NotebookMetadataComponentProps {
|
|||
}
|
||||
|
||||
export class NotebookMetadataComponent extends React.Component<NotebookMetadataComponentProps> {
|
||||
private renderFavouriteButton = (): JSX.Element => {
|
||||
return (
|
||||
<Text>
|
||||
{this.props.isFavorite !== undefined ? (
|
||||
<>
|
||||
<IconButton
|
||||
iconProps={{ iconName: this.props.isFavorite ? "HeartFill" : "Heart" }}
|
||||
onClick={this.props.isFavorite ? this.props.onUnfavoriteClick : this.props.onFavoriteClick}
|
||||
/>
|
||||
{this.props.data.favorites} likes
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Icon iconName="Heart" /> {this.props.data.favorites} likes
|
||||
</>
|
||||
)}
|
||||
</Text>
|
||||
);
|
||||
};
|
||||
|
||||
public render(): JSX.Element {
|
||||
const options: Intl.DateTimeFormatOptions = {
|
||||
year: "numeric",
|
||||
|
@ -49,19 +69,7 @@ export class NotebookMetadataComponent extends React.Component<NotebookMetadataC
|
|||
</Text>
|
||||
</Stack.Item>
|
||||
|
||||
<Stack.Item>
|
||||
<Text>
|
||||
{this.props.isFavorite !== undefined && (
|
||||
<>
|
||||
<IconButton
|
||||
iconProps={{ iconName: this.props.isFavorite ? "HeartFill" : "Heart" }}
|
||||
onClick={this.props.isFavorite ? this.props.onUnfavoriteClick : this.props.onFavoriteClick}
|
||||
/>
|
||||
{this.props.data.favorites} likes
|
||||
</>
|
||||
)}
|
||||
</Text>
|
||||
</Stack.Item>
|
||||
<Stack.Item>{this.renderFavouriteButton()}</Stack.Item>
|
||||
|
||||
{this.props.downloadButtonText && (
|
||||
<Stack.Item>
|
||||
|
|
|
@ -301,9 +301,9 @@ export class PublishNotebookPaneComponent extends React.Component<PublishNoteboo
|
|||
thumbnailUrl: this.state.imageSrc,
|
||||
created: this.props.notebookCreatedDate,
|
||||
isSample: false,
|
||||
downloads: 0,
|
||||
favorites: 0,
|
||||
views: 0,
|
||||
downloads: undefined,
|
||||
favorites: undefined,
|
||||
views: undefined,
|
||||
newCellId: undefined,
|
||||
policyViolations: undefined,
|
||||
pendingScanJobIds: undefined,
|
||||
|
|
|
@ -89,8 +89,8 @@ exports[`PublishNotebookPaneComponent renders 1`] = `
|
|||
"author": "CosmosDB",
|
||||
"created": "2020-07-17T00:00:00Z",
|
||||
"description": "",
|
||||
"downloads": 0,
|
||||
"favorites": 0,
|
||||
"downloads": undefined,
|
||||
"favorites": undefined,
|
||||
"gitSha": undefined,
|
||||
"id": undefined,
|
||||
"isSample": false,
|
||||
|
@ -102,7 +102,7 @@ exports[`PublishNotebookPaneComponent renders 1`] = `
|
|||
"",
|
||||
],
|
||||
"thumbnailUrl": undefined,
|
||||
"views": 0,
|
||||
"views": undefined,
|
||||
}
|
||||
}
|
||||
showDelete={false}
|
||||
|
|
Loading…
Reference in New Issue