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

EcrituresNumeriques / stylo / 15836175304

23 Jun 2025 10:08PM UTC coverage: 39.164% (-0.05%) from 39.218%
15836175304

push

github

web-flow
chore: Charge les espaces de travail avec SWR (#1635)

571 of 801 branches covered (71.29%)

Branch coverage included in aggregate %.

4 of 109 new or added lines in 4 files covered. (3.67%)

3 existing lines in 2 files now uncovered.

5615 of 14994 relevant lines covered (37.45%)

2.66 hits per line

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

0.0
/front/src/components/ArticleCreate.jsx
NEW
1
import React, { useCallback } from 'react'
×
2
import { useTranslation } from 'react-i18next'
×
3

UNCOV
4
import { useGraphQLClient } from '../helpers/graphQL'
×
NEW
5
import { useToasts } from '@geist-ui/core'
×
6

NEW
7
import { fromFormData } from '../helpers/forms.js'
×
NEW
8
import { useUserTags } from '../hooks/user.js'
×
NEW
9
import { useWorkspaces } from '../hooks/workspace.js'
×
10

NEW
11
import Checkbox from './Checkbox.jsx'
×
12
import Field from './Field.jsx'
×
NEW
13
import Alert from './molecules/Alert.jsx'
×
14
import FormActions from './molecules/FormActions.jsx'
×
NEW
15
import Loading from './molecules/Loading.jsx'
×
16

NEW
17
import { createArticle } from './Articles.graphql'
×
18

19
import checkboxStyles from './Checkbox.module.scss'
×
NEW
20
import formStyles from './field.module.scss'
×
21

22
/**
23
 * @typedef {object} ArticleCreateProps
24
 * @property {Function=} onSubmit
25
 * @property {string=} workspaceId
26
 */
27

28
/**
29
 * @param {object} props
30
 * @param {Function} props.onSubmit
31
 * @param {Function} props.onCancel
32
 * @param {string|null} props.workspaceId
33
 * @returns {React.ReactHTMLElement}
34
 */
35
export default function ArticleCreate({
×
36
  onSubmit,
×
37
  onCancel,
×
38
  workspaceId = null,
×
39
}) {
×
40
  const { t } = useTranslation()
×
41
  const { setToast } = useToasts()
×
42

43
  const { query } = useGraphQLClient()
×
44

UNCOV
45
  const handleSubmit = useCallback(async (event) => {
×
46
    event.preventDefault()
×
47
    try {
×
48
      const createArticleInput = fromFormData(event.target)
×
49
      const { createArticle: createdArticle } = await query({
×
50
        query: createArticle,
×
51
        variables: { createArticleInput },
×
52
      })
×
53
      onSubmit(createdArticle)
×
54
      setToast({
×
55
        text: t('article.create.successNotification'),
×
56
        type: 'default',
×
57
      })
×
58
    } catch (err) {
×
59
      setToast({
×
60
        text: t('article.create.errorNotification', { errMessage: err }),
×
61
        type: 'error',
×
62
      })
×
63
    }
×
64
  }, [])
×
65

66
  return (
×
67
    <section>
×
68
      <form onSubmit={handleSubmit} className={formStyles.form}>
×
69
        <Field
×
70
          autoFocus={true}
×
71
          label={t('article.createForm.titleField')}
×
72
          type="text"
×
73
          name="title"
×
74
          required={true}
×
75
        />
×
76

NEW
77
        <TagsField />
×
NEW
78
        <WorkspacesField workspaceId={workspaceId} />
×
79

80
        <FormActions
×
81
          onCancel={onCancel}
×
82
          submitButton={{
×
83
            text: t('article.createForm.buttonText'),
×
84
            title: t('article.createForm.buttonText'),
×
85
          }}
×
86
        />
×
87
      </form>
×
88
    </section>
×
89
  )
90
}
×
91

NEW
92
function WorkspacesField({ workspaceId }) {
×
NEW
93
  const { t } = useTranslation()
×
NEW
94
  const { workspaces, error, isLoading } = useWorkspaces()
×
NEW
95
  if (error) {
×
NEW
96
    return <Alert message={error.message} />
×
NEW
97
  }
×
NEW
98
  if (isLoading) {
×
NEW
99
    return <Loading />
×
NEW
100
  }
×
101

NEW
102
  if (workspaces.length > 0) {
×
NEW
103
    return (
×
NEW
104
      <div>
×
NEW
105
        <span className={formStyles.fieldLabel}>{t('workspace.title')}</span>
×
106

NEW
107
        <ul className={checkboxStyles.inlineList}>
×
NEW
108
          {workspaces.map((workspace) => (
×
NEW
109
            <li key={`selectWorkspace-${workspace._id}`}>
×
NEW
110
              <Checkbox
×
NEW
111
                name="workspaces[]"
×
NEW
112
                value={workspace._id}
×
NEW
113
                color={workspace.color}
×
NEW
114
                defaultChecked={workspaceId === workspace._id}
×
115
              >
NEW
116
                {workspace.name}
×
NEW
117
              </Checkbox>
×
NEW
118
            </li>
×
NEW
119
          ))}
×
NEW
120
        </ul>
×
NEW
121
      </div>
×
122
    )
NEW
123
  }
×
124

NEW
125
  return <></>
×
NEW
126
}
×
127

NEW
128
function TagsField() {
×
NEW
129
  const { t } = useTranslation()
×
NEW
130
  const { tags, error, isLoading } = useUserTags()
×
NEW
131
  if (error) {
×
NEW
132
    return <Alert message={error.message} />
×
NEW
133
  }
×
NEW
134
  if (isLoading) {
×
NEW
135
    return <Loading />
×
NEW
136
  }
×
137

NEW
138
  if (tags.length > 0) {
×
NEW
139
    return (
×
NEW
140
      <div>
×
NEW
141
        <span className={formStyles.fieldLabel}>
×
NEW
142
          {t('article.createForm.tagsField')}
×
NEW
143
        </span>
×
144

NEW
145
        <ul className={checkboxStyles.inlineList}>
×
NEW
146
          {tags.map((t) => (
×
NEW
147
            <li key={`selectTag-${t._id}`}>
×
NEW
148
              <Checkbox name="tags[]" value={t._id} color={t.color}>
×
NEW
149
                {t.name}
×
NEW
150
              </Checkbox>
×
NEW
151
            </li>
×
NEW
152
          ))}
×
NEW
153
        </ul>
×
NEW
154
      </div>
×
155
    )
NEW
156
  }
×
157

NEW
158
  return <></>
×
NEW
159
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc