From 56ad1c7d60ebe1a9653f79a1757e23d76be36acb Mon Sep 17 00:00:00 2001
From: dipayanDebTheCoder
<72683956+dipayanDebTheCoder@users.noreply.github.com>
Date: Wed, 4 Nov 2020 20:10:56 +0530
Subject: [PATCH] feat(client): add show solution button in TimeLine (#40120)
* feat: add show solution button in TimeLine
* feat: added tests for CertificateSettings and TimeLine
* feat: view button only for projects
* feat: view button visible only for projects
---
.../components/profile/components/TimeLine.js | 99 +++++++++++++--
.../profile/components/TimeLine.test.js | 114 ++++++++++++++++++
.../profile/components/timeline.css | 3 +
.../src/components/settings/Certification.js | 3 +
.../components/settings/Certification.test.js | 73 +++++++++++
5 files changed, 281 insertions(+), 11 deletions(-)
create mode 100644 client/src/components/profile/components/TimeLine.test.js
create mode 100644 client/src/components/profile/components/timeline.css
diff --git a/client/src/components/profile/components/TimeLine.js b/client/src/components/profile/components/TimeLine.js
index 1551c77934..2d174f44af 100644
--- a/client/src/components/profile/components/TimeLine.js
+++ b/client/src/components/profile/components/TimeLine.js
@@ -1,10 +1,17 @@
import React, { Component, useMemo } from 'react';
import PropTypes from 'prop-types';
import format from 'date-fns/format';
-import { find, reverse, sortBy } from 'lodash';
-import { Button, Modal, Table } from '@freecodecamp/react-bootstrap';
+import { reverse, sortBy } from 'lodash';
+import {
+ Button,
+ Modal,
+ Table,
+ DropdownButton,
+ MenuItem
+} from '@freecodecamp/react-bootstrap';
import { useStaticQuery, graphql } from 'gatsby';
+import './timeline.css';
import TimelinePagination from './TimelinePagination';
import { FullWidthRow, Link } from '../../helpers';
import SolutionViewer from '../../settings/SolutionViewer';
@@ -13,6 +20,8 @@ import {
getPathFromID,
getTitleFromId
} from '../../../../../utils';
+
+import { maybeUrlRE } from '../../../utils';
import CertificationIcon from '../../../assets/icons/CertificationIcon';
// Items per page in timeline.
@@ -66,7 +75,9 @@ class TimelineInner extends Component {
this.state = {
solutionToView: null,
solutionOpen: false,
- pageNo: 1
+ pageNo: 1,
+ solution: null,
+ files: null
};
this.closeSolution = this.closeSolution.bind(this);
@@ -76,11 +87,73 @@ class TimelineInner extends Component {
this.prevPage = this.prevPage.bind(this);
this.nextPage = this.nextPage.bind(this);
this.lastPage = this.lastPage.bind(this);
+ this.renderViewButton = this.renderViewButton.bind(this);
+ }
+
+ renderViewButton(id, files, githubLink, solution) {
+ if (files && files.length) {
+ return (
+
+ );
+ } else if (githubLink) {
+ return (
+
+
+
+
+
+
+ );
+ } else if (maybeUrlRE.test(solution)) {
+ return (
+
+ );
+ } else {
+ return null;
+ }
}
renderCompletion(completed) {
const { idToNameMap, username } = this.props;
- const { id } = completed;
+ const { id, files, githubLink, solution } = completed;
const completedDate = new Date(completed.completedDate);
const { challengeTitle, challengePath, certPath } = idToNameMap.get(id);
return (
@@ -99,6 +172,7 @@ class TimelineInner extends Component {
{challengeTitle}
)}
+ {this.renderViewButton(id, files, githubLink, solution)} |
|