UNPKG

@git-temporal/git-temporal-react

Version:

<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

62 lines (61 loc) 3.31 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importDefault(require("react")); const react_redux_1 = require("react-redux"); const actions_1 = require("app/actions"); const ActionTypes_1 = require("app/actions/ActionTypes"); const commits_1 = require("app/selectors/commits"); const stateVars_1 = require("app/selectors/stateVars"); const ExtendingList_1 = require("app/components/ExtendingList"); const CommitCard_1 = require("app/components/CommitCard"); const CommitsActionMenu_1 = __importDefault(require("./CommitsActionMenu")); const CollapsibleGroup_1 = require("app/components/CollapsibleGroup"); const COLLAPSIBLE_GROUP = ActionTypes_1.CollapsibleSidePanelGroups.COMMITS; exports.Commits = () => { const commits = react_redux_1.useSelector(commits_1.getFilteredSortedCommits); const highlightedCommitIds = react_redux_1.useSelector(stateVars_1.getHighlightedCommitIds); const openGroup = react_redux_1.useSelector(stateVars_1.getOpenSidePanelGroup); const isFileSelected = react_redux_1.useSelector(stateVars_1.getIsFileSelected); const dispatch = react_redux_1.useDispatch(); const title = `${commits.length} Commits`; const isOpen = openGroup === COLLAPSIBLE_GROUP; return (react_1.default.createElement(CollapsibleGroup_1.CollapsibleGroup, { title: title, isOpen: isOpen, onOpenToggle: handleOpenGroupToggle }, react_1.default.createElement(CommitsActionMenu_1.default, null), react_1.default.createElement(ExtendingList_1.ExtendingList, { rowCount: commits.length, rowRenderer: renderRow }))); function handleOpenGroupToggle() { if (!isOpen) { dispatch(actions_1.setOpenSidePanelGroup(COLLAPSIBLE_GROUP)); } } function renderRow(index, key) { const commit = commits[index]; let isHighlighted = false; let isExpanded = false; if (highlightedCommitIds && highlightedCommitIds.length > 0) { isHighlighted = highlightedCommitIds.includes(commit.id); isExpanded = highlightedCommitIds[0] === commit.id; } return (react_1.default.createElement("div", { key: key }, react_1.default.createElement(CommitCard_1.CommitCard, { commit: commit, index: index, isHighlighted: isHighlighted, isExpanded: isExpanded, onClick: onCommitCardClick, onFileClick: onFileClick, hideFiles: isFileSelected }))); } function onCommitCardClick(event, commit, index) { event.stopPropagation(); let newHighlightedCommitIds = [commit.id]; if (highlightedCommitIds && highlightedCommitIds.length > 0) { const index = highlightedCommitIds.indexOf(commit.id); if (index !== -1) { newHighlightedCommitIds = newHighlightedCommitIds.concat(highlightedCommitIds .slice(0, index) .concat(highlightedCommitIds.slice(index + 1))); } } dispatch(actions_1.highlightCommits(newHighlightedCommitIds)); } function onFileClick(event, fileName) { event.stopPropagation(); dispatch(actions_1.selectPath(fileName)); } };