|
| 1 | +import React from "react"; |
| 2 | +import * as _ from "lodash"; |
| 3 | +import Kendra from "aws-sdk/clients/kendra"; |
| 4 | + |
| 5 | +import { isNullOrUndefined, truncateString } from "../../utils"; |
| 6 | +import "../../search.scss"; |
| 7 | + |
| 8 | +import Feedback from "./Feedback"; |
| 9 | +import { Relevance } from "../../constants"; |
| 10 | + |
| 11 | +const IgnoreFormats = ["PLAIN_TEXT"]; |
| 12 | +const MAX_URI_LENGTH = 30; |
| 13 | + |
| 14 | +interface ResultFooterProps { |
| 15 | + queryResultItem: Kendra.QueryResultItem; |
| 16 | + attributes: any; |
| 17 | + startTime: number; |
| 18 | + submitFeedback: ( |
| 19 | + relevance: Relevance, |
| 20 | + resultItem: Kendra.QueryResultItem |
| 21 | + ) => Promise<void>; |
| 22 | +} |
| 23 | + |
| 24 | +export default class ResultFooter extends React.Component< |
| 25 | + ResultFooterProps, |
| 26 | + {} |
| 27 | +> { |
| 28 | + private submitClickFeedback = () => { |
| 29 | + this.props.submitFeedback(Relevance.Click, this.props.queryResultItem); |
| 30 | + }; |
| 31 | + |
| 32 | + render() { |
| 33 | + const { attributes, queryResultItem, submitFeedback, startTime } = this.props; |
| 34 | + |
| 35 | + const fileFormatName = attributes.FileFormat |
| 36 | + ? attributes.FileFormat.StringValue |
| 37 | + : undefined; |
| 38 | + |
| 39 | + let fileFormat; |
| 40 | + if ( |
| 41 | + !isNullOrUndefined(fileFormatName) && |
| 42 | + IgnoreFormats.indexOf(fileFormatName) === -1 |
| 43 | + ) { |
| 44 | + fileFormat = ( |
| 45 | + <div className="display-inline"> |
| 46 | + {fileFormatName.toUpperCase()} |
| 47 | + <div className="file-format-divider-wrapper"> |
| 48 | + <div className="file-format-divider" /> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + ); |
| 52 | + } |
| 53 | + let sourceLink; |
| 54 | + let isYTVideo = 'ytauthor' in attributes; |
| 55 | + |
| 56 | + // BobS: Modified to enable link to PCA Call Analysis, using Uri containied in document attribute |
| 57 | + // const uri = queryResultItem.DocumentURI; |
| 58 | + let uri; |
| 59 | + let label; |
| 60 | + const pcaCallAnalysisUri = _.get(attributes, "ANALYSIS_URI.StringValue"); |
| 61 | + if (pcaCallAnalysisUri) { |
| 62 | + uri = pcaCallAnalysisUri; |
| 63 | + label = "Open Call Analysis"; |
| 64 | + } else { |
| 65 | + uri = queryResultItem.DocumentURI; |
| 66 | + label = uri; |
| 67 | + } |
| 68 | + |
| 69 | + if (uri && !_.isEmpty(uri)) { |
| 70 | + sourceLink = ( |
| 71 | + <div className="display-inline action-link"> |
| 72 | + <a |
| 73 | + href={uri} |
| 74 | + onClick={this.submitClickFeedback} |
| 75 | + target="_blank" |
| 76 | + rel="noopener noreferrer" |
| 77 | + > |
| 78 | + {truncateString(label!, MAX_URI_LENGTH)} |
| 79 | + </a> |
| 80 | + </div> |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + return ( |
| 85 | + <div className="result-footer"> |
| 86 | + <div className="footer-left-text"> |
| 87 | + {fileFormat} |
| 88 | + {sourceLink} |
| 89 | + </div> |
| 90 | + <Feedback |
| 91 | + queryResultItem={queryResultItem} |
| 92 | + submitFeedback={submitFeedback} |
| 93 | + /> |
| 94 | + </div> |
| 95 | + ); |
| 96 | + } |
| 97 | +} |
0 commit comments