-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileKeysDiff.jsx
More file actions
58 lines (53 loc) · 1.89 KB
/
FileKeysDiff.jsx
File metadata and controls
58 lines (53 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { useState } from "react"
import { Code, FileKeysDiffContainer, KeyWrapper } from "./style"
import ChevronIcon from "./ChevronIcon"
import PropTypes from "prop-types"
FileKeysDiff.propTypes = {
fileName: PropTypes.string,
missingKeys: PropTypes.array,
onRowClick: PropTypes.func,
}
function FileKeysDiff({ fileName, missingKeys, onRowClick }) {
const [renderLen, setRenderLen] = useState(1000)
const [isVisible, setIsVisible] = useState(true)
const [rowClicked, setRowClicked] = useState(null)
const onClickHandler = (e, item, index) => {
e.stopPropagation()
if (onRowClick) onRowClick({ fileName, ...item })
setRowClicked(index)
const timeout = setTimeout(() => {
setRowClicked(null)
clearTimeout(timeout)
}, 3000)
}
return (
<FileKeysDiffContainer className="keysDiff" isVisible={isVisible}>
<div title={fileName} className="fileTitle">
{fileName?.trunc(30)} ({Math.min(renderLen, missingKeys.length)}/{missingKeys.length})
<span
onClick={(e) => {
e.stopPropagation()
setIsVisible((prev) => !prev)
}}
className="icon"
>
<ChevronIcon right={!isVisible} />
</span>
</div>
<div className="contentList">
{missingKeys.slice(0, renderLen).map((item, i) => (
<KeyWrapper isClicked={rowClicked === i} onClick={(e) => onClickHandler(e, item, i)} key={item.keyValue + i}>
Extra key <Code title={item.keyValue}>{item.keyValue.replace(".", " > ")}</Code> in File{" "}
<Code title={fileName}>{fileName.trunc(30)}</Code>
</KeyWrapper>
))}
{missingKeys?.length > renderLen && (
<button className="loadMore" onClick={() => setRenderLen((prev) => prev + 1000)}>
LoadMore
</button>
)}
</div>
</FileKeysDiffContainer>
)
}
export default FileKeysDiff