@digi-frontend/dgate-api-documentation 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/_virtual/index3.js +1 -1
  2. package/dist/_virtual/index4.js +1 -1
  3. package/dist/_virtual/index5.js +1 -1
  4. package/dist/_virtual/index6.js +1 -1
  5. package/dist/node_modules/digitinary-ui/dist/index.js +1 -1
  6. package/dist/node_modules/digitinary-ui/dist/index.js.map +1 -1
  7. package/dist/node_modules/toposort/index.js +1 -1
  8. package/dist/node_modules/yup/index.esm.js +1 -1
  9. package/dist/src/components/InfoForm/InfoForm.js +1 -1
  10. package/dist/src/components/InfoForm/InfoForm.js.map +1 -1
  11. package/dist/src/components/MethodAccordion/MethodAccordion.js +1 -1
  12. package/dist/src/components/MethodAccordion/MethodAccordion.js.map +1 -1
  13. package/dist/src/components/table/table.js +1 -1
  14. package/dist/src/components/table/table.js.map +1 -1
  15. package/dist/src/components/table/tags-table.js +2 -0
  16. package/dist/src/components/table/tags-table.js.map +1 -0
  17. package/dist/src/constants/index.js +1 -1
  18. package/dist/src/constants/index.js.map +1 -1
  19. package/dist/src/layout/layout.js.map +1 -1
  20. package/dist/styles.css +636 -558
  21. package/dist/types/components/InfoForm/InfoForm.d.ts +3 -1
  22. package/dist/types/components/table/tags-table.d.ts +11 -0
  23. package/dist/types/constants/index.d.ts +6 -0
  24. package/dist/types/layout/layout.d.ts +1 -0
  25. package/dist/types/types/index.d.ts +18 -0
  26. package/dist/types/types/openApi.d.ts +12 -0
  27. package/package.json +2 -2
  28. package/src/components/InfoForm/InfoForm.module.scss +114 -0
  29. package/src/components/InfoForm/InfoForm.tsx +271 -51
  30. package/src/components/MethodAccordion/MethodAccordion.tsx +2 -2
  31. package/src/components/table/table.tsx +3 -3
  32. package/src/components/table/tags-table.tsx +308 -0
  33. package/src/constants/index.ts +21 -0
  34. package/src/layout/layout.tsx +1 -0
  35. package/src/types/openApi.ts +13 -0
@@ -0,0 +1,308 @@
1
+ import { useState } from 'react'
2
+ import './style.scss'
3
+ import _styles from '../InfoForm/InfoForm.module.scss'
4
+ import { Button, Input, TextArea } from 'digitinary-ui'
5
+ import Tooltip from '../Tooltip/Tooltip'
6
+ import SVGLoader from '../SVGLoader/SVGLoader'
7
+ import { AddRow, EditIcon, DeleteIcon } from '../../assets/icons'
8
+ import styles from '../MethodAccordion/MethodAccordion.module.scss'
9
+ import { useFormik } from 'formik'
10
+ import * as yup from 'yup'
11
+
12
+ const TagsTable = ({ id, headCells, data, isFormOpen, setIsFormOpen, saveNewRow, readOnly }) => {
13
+ const [text, setText] = useState('')
14
+ const [externalDesc, setExternalDesc] = useState('')
15
+ const [externalUrl, setExternalUrl] = useState('')
16
+ const [tooltipRef, setTooltipRef] = useState(null)
17
+ const [externalTooltipRefs, setExternalTooltipRefs] = useState(null)
18
+ const { values, errors, setFieldValue, isValid, submitForm, resetForm } = useFormik({
19
+ initialValues: {
20
+ name: '',
21
+ description: '',
22
+ externalDocs: {
23
+ url: '',
24
+ description: '',
25
+ },
26
+ },
27
+ validationSchema: yup.object().shape({
28
+ name: yup.string().required('Tag name is required'),
29
+ description: yup.string().optional(),
30
+ externalDocs: yup.object().optional(),
31
+ }),
32
+ onSubmit: (values) => {
33
+ setText('')
34
+ setExternalDesc('')
35
+ setExternalUrl('')
36
+ resetForm()
37
+ setIsFormOpen(false)
38
+ saveNewRow(values)
39
+ },
40
+ })
41
+ return (
42
+ <div className="tableSectionContainer">
43
+ <div className="tableContainer">
44
+ <table id={id || ''} className={`table borderRadiusTop borderRadiusBottom`}>
45
+ <thead className="tableHead">
46
+ <tr>
47
+ {headCells?.map((headCell) => (
48
+ <th
49
+ key={headCell.id}
50
+ className={`tableHeadCell ${headCell.classes || ''}`}
51
+ style={{ width: headCell.width, minWidth: headCell.minWidth }}
52
+ >
53
+ <div
54
+ className="headContainer"
55
+ data-id={`${
56
+ typeof headCell.label === 'string'
57
+ ? headCell.label.toUpperCase().replace(/[^a-zA-Z0-9]+/g, '_')
58
+ : 'UNKNOWN_LABEL'
59
+ }_COLUMN`}
60
+ >
61
+ {headCell.label}
62
+ </div>
63
+ </th>
64
+ ))}
65
+ </tr>
66
+ </thead>
67
+ <tbody className="tableBody" data-id="TABLE_BODY">
68
+ {data?.map((row, rowIndex) => {
69
+ return (
70
+ <tr key={rowIndex} data-i={rowIndex} className={`row`}>
71
+ {headCells?.map((headCell) => {
72
+ const cellContent = row[headCell.id] !== '_' && (
73
+ <div
74
+ data-id="TEXT_DESCRIPTION"
75
+ className="tableData"
76
+ style={{
77
+ width: headCell.width,
78
+ minWidth: headCell.minWidth,
79
+ }}
80
+ >
81
+ {row[headCell.id]}
82
+ </div>
83
+ )
84
+
85
+ return (
86
+ <td
87
+ key={headCell.id}
88
+ style={{
89
+ width: headCell.width,
90
+ minWidth: headCell.minWidth,
91
+ }}
92
+ >
93
+ {cellContent}
94
+ </td>
95
+ )
96
+ })}
97
+ </tr>
98
+ )
99
+ })}
100
+ {isFormOpen ? (
101
+ <tr key={''} data-i={''} className={`row`}>
102
+ <td key={'tag name'}>
103
+ <div data-id="TEXT_DESCRIPTION" className="tableData">
104
+ <Input
105
+ placeholder="Tag name"
106
+ size="large"
107
+ type="text"
108
+ onChange={(value) => {
109
+ setFieldValue('name', value)
110
+ }} // Pass the value directly
111
+ value={values.name} // Bind value to the state
112
+ disabled={readOnly}
113
+ />
114
+ </div>
115
+ </td>
116
+
117
+ <td key={'tagDescRequired'}>
118
+ <div data-id="TEXT_DESCRIPTION" className="tableData">
119
+ <div className={styles.paramDescContainer}>
120
+ <Tooltip
121
+ arrowWithBorder
122
+ placement="bottom-end"
123
+ type="function"
124
+ trigger="click"
125
+ delay={[0, 0]}
126
+ onCreate={(instance) => setTooltipRef(instance)}
127
+ content={
128
+ <div className={_styles.editDescTooltipContent}>
129
+ <p className={_styles.editDescTooltipContent_header}>Description</p>
130
+ <TextArea
131
+ value={text || values.description}
132
+ onChange={(value) => {
133
+ setText(value)
134
+ }}
135
+ disabled={readOnly}
136
+ placeholder="Describe Tag..."
137
+ />
138
+ {!readOnly && (
139
+ <Button
140
+ className={_styles.editDescTooltipContent_btn}
141
+ variant="outlined"
142
+ size="small"
143
+ onClick={() => {
144
+ setFieldValue('description', text)
145
+ tooltipRef?.hide()
146
+ }}
147
+ >
148
+ Apply
149
+ </Button>
150
+ )}
151
+ </div>
152
+ }
153
+ >
154
+ <Button
155
+ className={_styles.editDescBtn}
156
+ style={{ paddingLeft: 0 }}
157
+ variant="link"
158
+ color="action"
159
+ endIcon={<SVGLoader src={EditIcon} width="1.5rem" height="1.5rem" />}
160
+ >
161
+ {readOnly ? 'View ' : 'Add '} Description
162
+ </Button>
163
+ </Tooltip>
164
+ </div>{' '}
165
+ </div>
166
+ </td>
167
+ <td key={'tagExternal'}>
168
+ <div className="tableData">
169
+ <div className={_styles.paramDescContainer}>
170
+ <Tooltip
171
+ arrowWithBorder
172
+ placement="bottom-end"
173
+ type="function"
174
+ trigger="click"
175
+ delay={[0, 0]}
176
+ onCreate={(instance) => setExternalTooltipRefs(instance)}
177
+ content={
178
+ <div className={_styles.editDescTooltipContent}>
179
+ <p className={_styles.editDescTooltipContent_header}>
180
+ External Docs Description
181
+ </p>
182
+ <TextArea
183
+ placeholder="Describe External Doc..."
184
+ value={externalDesc || values.externalDocs.description}
185
+ disabled={readOnly}
186
+ onChange={(value) => setExternalDesc(value)}
187
+ />
188
+ <p className={_styles.editDescTooltipContent_header}>
189
+ External Docs Link
190
+ </p>
191
+ <TextArea
192
+ placeholder="External Docs Link..."
193
+ value={externalUrl || values.externalDocs.url}
194
+ disabled={readOnly}
195
+ onChange={(value) => setExternalUrl(value)}
196
+ />
197
+ {!readOnly && (
198
+ <Button
199
+ className={_styles.editDescTooltipContent_btn}
200
+ variant="outlined"
201
+ size="small"
202
+ onClick={() => {
203
+ setFieldValue(`externalDocs`, {
204
+ description: externalDesc,
205
+ url: externalUrl,
206
+ })
207
+ setExternalDesc('')
208
+ setExternalUrl('')
209
+ externalTooltipRefs?.hide()
210
+ }}
211
+ >
212
+ Apply
213
+ </Button>
214
+ )}
215
+ </div>
216
+ }
217
+ >
218
+ {readOnly ? (
219
+ <Button
220
+ className={_styles.editDescBtn}
221
+ variant="link"
222
+ color="action"
223
+ onClick={() => {
224
+ const a = document.createElement('a')
225
+ a.href = values.externalDocs?.url
226
+ a.click()
227
+ }}
228
+ >
229
+ {values?.externalDocs?.description
230
+ ? values?.externalDocs?.description?.substring(0, 12)
231
+ : '-'}
232
+ {values?.externalDocs?.description &&
233
+ values?.externalDocs?.description?.length > 12
234
+ ? '...'
235
+ : ''}
236
+ </Button>
237
+ ) : (
238
+ <Button
239
+ className={_styles.editDescBtn}
240
+ variant="link"
241
+ color="action"
242
+ endIcon={<SVGLoader src={EditIcon} width="1.5rem" height="1.5rem" />}
243
+ >
244
+ {readOnly ? 'View ' : 'Add '} External Docs Link
245
+ </Button>
246
+ )}
247
+ </Tooltip>
248
+ <div className={_styles.paramDescContainer_separator}></div>
249
+ {!readOnly && (
250
+ <Button
251
+ className={_styles.deleteParamBtn}
252
+ variant="link"
253
+ color="error"
254
+ endIcon={
255
+ <SVGLoader src={DeleteIcon} width="1.125rem" height="1.125rem" />
256
+ }
257
+ onClick={() => {
258
+ resetForm()
259
+ setText('')
260
+ setIsFormOpen(false)
261
+ }} // Correctly delete the new row
262
+ />
263
+ )}
264
+
265
+ {!readOnly && (
266
+ <Button
267
+ className={_styles.deleteParamBtn}
268
+ variant="link"
269
+ color="success"
270
+ disabled={!isValid}
271
+ endIcon={<SVGLoader src={AddRow} width="0.125rem" height="0.125rem" />}
272
+ onClick={() => {
273
+ setText('')
274
+ submitForm()
275
+ }} // Save the new row when clicked
276
+ />
277
+ )}
278
+ </div>
279
+ </div>
280
+ </td>
281
+ </tr>
282
+ ) : (
283
+ <>
284
+ {!readOnly && (
285
+ <tr key={'addNew'} data-i={'addNew'} className={`row`}>
286
+ <td colSpan={5}>
287
+ <Button
288
+ variant="link"
289
+ color="primary"
290
+ onClick={() => {
291
+ setIsFormOpen((prev) => !prev)
292
+ }}
293
+ >
294
+ + Add Tag
295
+ </Button>
296
+ </td>
297
+ </tr>
298
+ )}
299
+ </>
300
+ )}
301
+ </tbody>
302
+ </table>
303
+ </div>
304
+ </div>
305
+ )
306
+ }
307
+
308
+ export default TagsTable
@@ -41,6 +41,27 @@ export const methodColorMapping = {
41
41
  },
42
42
  }
43
43
 
44
+ export const tagsTableHeaders = [
45
+ {
46
+ id: 'tagName',
47
+ label: 'Tag Name',
48
+ sortable: false,
49
+ classes:'requiredParam'
50
+ },
51
+ {
52
+ id: 'description',
53
+ label: 'Description',
54
+ sortable: false,
55
+ classes:'requiredParam'
56
+ },
57
+ {
58
+ id: 'externalDocs',
59
+ label: 'External Docs',
60
+ sortable: false,
61
+ classes:'requiredParam'
62
+ }
63
+ ]
64
+
44
65
  export const paramsTableHeaders = [
45
66
  {
46
67
  id: 'paramName',
@@ -14,6 +14,7 @@ import { methodColorMapping } from '../constants/index'
14
14
 
15
15
  interface ILayoutProps {
16
16
  openApiJson?: OpenAPIFile
17
+ handleSave?: (values: unknown) => unknown
17
18
  }
18
19
 
19
20
  const Layout = ({ openApiJson, handleSave }: ILayoutProps): JSX.Element => {
@@ -38,6 +38,19 @@ export interface OpenAPIFile {
38
38
  tags?: {
39
39
  name: string
40
40
  description?: string
41
+ externalDocs?: {
42
+ url: string
43
+ description: string
44
+ }[]
45
+ }[]
46
+ }
47
+
48
+ export interface Tags {
49
+ name: string
50
+ description?: string
51
+ externalDocs?: {
52
+ url: string
53
+ description: string
41
54
  }[]
42
55
  }
43
56