-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tiles] add source for top event tiles (#2350)
![Screenshot 2023-03-01 at 9 04 15 AM](https://user-images.githubusercontent.com/69875368/222210884-beab0191-87c0-4aef-ab16-0ecbcb95afc1.jpg) ![Screenshot 2023-03-01 at 9 04 31 AM](https://user-images.githubusercontent.com/69875368/222210909-76bc9cc3-9b4f-49b2-924b-37da25659e2d.jpg) - Also extract out a shared footer component
- Loading branch information
1 parent
a657f66
commit dc28ed6
Showing
7 changed files
with
119 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Footer for charts in tiles. | ||
*/ | ||
|
||
import _ from "lodash"; | ||
import React from "react"; | ||
|
||
import { NL_SOURCE_REPLACEMENTS } from "../../constants/app/nl_interface_constants"; | ||
import { urlToDomain } from "../../shared/util"; | ||
import { isNlInterface } from "../../utils/nl_interface_utils"; | ||
|
||
interface ChartFooterPropType { | ||
// set of full urls of sources of the data in the chart | ||
sources: Set<string>; | ||
handleEmbed?: () => void; | ||
} | ||
|
||
/** | ||
* Gets the JSX element for displaying a list of sources. | ||
*/ | ||
function getSourcesJsx(sources: Set<string>): JSX.Element[] { | ||
if (!sources) { | ||
return null; | ||
} | ||
|
||
const sourceList: string[] = Array.from(sources); | ||
const seenSourceDomains = new Set(); | ||
const sourcesJsx = sourceList.map((source, index) => { | ||
// HACK for updating source for NL interface | ||
let processedSource = source; | ||
if (isNlInterface()) { | ||
processedSource = NL_SOURCE_REPLACEMENTS[source] || source; | ||
} | ||
const domain = urlToDomain(processedSource); | ||
if (seenSourceDomains.has(domain)) { | ||
return null; | ||
} | ||
seenSourceDomains.add(domain); | ||
return ( | ||
<span key={processedSource}> | ||
{index > 0 ? ", " : ""} | ||
<a href={processedSource}>{domain}</a> | ||
</span> | ||
); | ||
}); | ||
return sourcesJsx; | ||
} | ||
|
||
export function ChartFooter(props: ChartFooterPropType): JSX.Element { | ||
return ( | ||
<footer id="chart-container-footer"> | ||
{!_.isEmpty(props.sources) && ( | ||
<div className="sources">Data from {getSourcesJsx(props.sources)}</div> | ||
)} | ||
<div className="outlinks"> | ||
{props.handleEmbed && ( | ||
<a | ||
href="#" | ||
onClick={(event) => { | ||
event.preventDefault(); | ||
props.handleEmbed(); | ||
}} | ||
> | ||
Export | ||
</a> | ||
)} | ||
</div> | ||
</footer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters