• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

EcrituresNumeriques / stylo / 15066626824

16 May 2025 10:41AM UTC coverage: 37.574% (-0.02%) from 37.594%
15066626824

Pull #1517

github

web-flow
Merge e05a1c169 into 607ffe7f9
Pull Request #1517: Mise à jour vers react-router@7

549 of 776 branches covered (70.75%)

Branch coverage included in aggregate %.

13 of 373 new or added lines in 28 files covered. (3.49%)

5 existing lines in 4 files now uncovered.

5319 of 14841 relevant lines covered (35.84%)

2.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/front/src/components/collaborative/CollaborativeVersions.jsx
1
import React from 'react'
×
2
import { shallowEqual, useSelector } from 'react-redux'
×
NEW
3
import { useNavigate } from 'react-router'
×
4
import { Trans, useTranslation } from 'react-i18next'
×
5
import { ArrowLeft } from 'lucide-react'
×
6

7
import Loading from '../molecules/Loading.jsx'
×
8
import Alert from '../molecules/Alert.jsx'
×
9
import Button from '../Button.jsx'
×
10
import Modal from '../Modal.jsx'
×
11
import CreateVersion from '../Write/CreateVersion.jsx'
×
12
import Version from '../molecules/Version.jsx'
×
13

14
import { useArticleVersions } from '../../hooks/article.js'
×
15
import { useModal } from '../../hooks/modal.js'
×
16
import i18n from '../../i18n.js'
×
17

18
import styles from './CollaborativeVersions.module.scss'
×
19

20
/**
21
 * @param {object} props
22
 * @param {boolean} props.showTitle
23
 * @param {() => void} props.onBack
24
 * @param {string} props.articleId
25
 * @param {string} props.selectedVersion
26
 * @returns {JSX.Element}
27
 */
28
export default function CollaborativeVersions({
×
29
  showTitle,
×
30
  onBack,
×
31
  articleId,
×
32
  selectedVersion,
×
33
}) {
×
34
  const articleWorkingCopyStatus = useSelector(
×
35
    (state) => state.articleWorkingCopy.status,
×
36
    shallowEqual
×
37
  )
×
38
  const syncing = articleWorkingCopyStatus === 'syncing'
×
NEW
39
  const navigate = useNavigate()
×
40
  const { article, isLoading, error } = useArticleVersions({ articleId })
×
41
  const articleVersions = article?.versions
×
42
  const createVersionModal = useModal()
×
43
  const { t } = useTranslation()
×
44

45
  if (isLoading) {
×
46
    return <Loading />
×
47
  }
×
48

49
  if (error) {
×
50
    return <Alert message={error.message} />
×
51
  }
×
52

53
  const title = onBack ? (
×
54
    <h2
×
55
      className={styles.title}
×
56
      onClick={onBack}
×
57
      style={{ cursor: 'pointer', userSelect: 'none' }}
×
58
    >
59
      <span onClick={onBack} style={{ display: 'flex' }}>
×
60
        <ArrowLeft style={{ strokeWidth: 3 }} />
×
61
      </span>
×
62
      <span>{t('versions.title')}</span>
×
63
    </h2>
×
64
  ) : (
65
    <h2 className={styles.title}>{t('versions.title')}</h2>
×
66
  )
67

68
  const monthYearFormat = new Intl.DateTimeFormat(i18n.language, {
×
69
    month: 'long',
×
70
    year: 'numeric',
×
71
  })
×
72

73
  function versionsPerMonth() {
×
74
    let previousVersionDate
×
75
    return articleVersions.map((version) => {
×
76
      const title =
×
77
        version.type === 'editingSessionEnded' ||
×
78
        version.type === 'collaborativeSessionEnded'
×
79
          ? t(`versions.${version.type}.text`)
×
80
          : t('versions.version.text', {
×
81
              major: version.version,
×
82
              minor: version.revision,
×
83
            })
×
84

85
      const date = new Date(version.createdAt)
×
86
      const versionItem = (
×
87
        <Version
×
88
          key={`showVersion-${version._id}`}
×
89
          date={date}
×
90
          title={title}
×
91
          description={version.message}
×
92
          type={version.type}
×
93
          creator={version.owner?.displayName || version.owner?.username}
×
94
          selected={selectedVersion === version._id}
×
95
          onClick={() => {
×
NEW
96
            navigate(`/article/${articleId}/version/${version._id}`)
×
97
          }}
×
98
        />
×
99
      )
100
      if (previousVersionDate) {
×
101
        if (
×
102
          previousVersionDate.getFullYear() !== date.getFullYear() ||
×
103
          previousVersionDate.getMonth() !== date.getMonth()
×
104
        ) {
×
105
          previousVersionDate = date
×
106
          return (
×
107
            <>
×
108
              <div className={styles.monthSeparator}>
×
109
                {monthYearFormat.format(date)}
×
110
              </div>
×
111
              {versionItem}
×
112
            </>
×
113
          )
114
        }
×
115
      }
×
116
      previousVersionDate = date
×
117
      return versionItem
×
118
    })
×
119
  }
×
120

121
  return (
×
122
    <section>
×
123
      {showTitle && title}
×
124
      <Button
×
125
        small={true}
×
126
        disabled={syncing}
×
127
        onClick={() => createVersionModal.show()}
×
128
        testId="create-version-button"
×
129
      >
130
        {t('versions.createVersion.button')}
×
131
        {syncing && <Loading label="" className={styles.loading} />}
×
132
      </Button>
×
133
      {articleVersions.length === 0 && (
×
134
        <p className={styles.info}>
×
135
          <Alert
×
136
            type={'info'}
×
137
            message={
×
138
              <Trans i18nKey="versions.explanation.text">
×
139
                <strong>All changes are automatically saved.</strong>
×
140
                <span className={styles.tip}>
×
141
                  Create a new version to keep track of particular changes.
142
                </span>
×
143
              </Trans>
×
144
            }
145
          />
×
146
        </p>
×
147
      )}
148
      <Modal
×
149
        title={t('versions.createVersion.title')}
×
150
        {...createVersionModal.bindings}
×
151
      >
152
        <CreateVersion
×
153
          articleId={article._id}
×
154
          onClose={() => createVersionModal.close()}
×
155
          onSubmit={() => createVersionModal.close()}
×
156
        />
×
157
      </Modal>
×
158
      <ul className={styles.versions} data-testid="versions">
×
159
        <Version
×
160
          date={null}
×
161
          type="workingCopy"
×
162
          title={t('versions.workingCopy.text')}
×
163
          selected={!selectedVersion}
×
164
          onClick={() => {
×
NEW
165
            navigate(`/article/${articleId}`)
×
166
          }}
×
167
        />
×
168
        {versionsPerMonth()}
×
169
      </ul>
×
170
    </section>
×
171
  )
172
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc