@digi-frontend/dgate-api-documentation 1.0.16 → 1.0.20

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 (34) 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/toposort/index.js +1 -1
  6. package/dist/node_modules/yup/index.esm.js +1 -1
  7. package/dist/src/components/InfoForm/InfoForm.js +1 -1
  8. package/dist/src/components/InfoForm/InfoForm.js.map +1 -1
  9. package/dist/src/components/LivePreview/LivePreview.js +1 -1
  10. package/dist/src/components/LivePreview/LivePreview.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 +1 -1
  16. package/dist/src/components/table/tags-table.js.map +1 -1
  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 +1 -1
  20. package/dist/src/layout/layout.js.map +1 -1
  21. package/dist/styles.css +509 -485
  22. package/dist/types/components/MethodAccordion/MethodAccordion.d.ts +4 -2
  23. package/dist/types/constants/index.d.ts +7 -2
  24. package/package.json +2 -2
  25. package/src/components/InfoForm/InfoForm.module.scss +13 -0
  26. package/src/components/InfoForm/InfoForm.tsx +28 -17
  27. package/src/components/LivePreview/LivePreview.tsx +37 -11
  28. package/src/components/MethodAccordion/MethodAccordion.module.scss +13 -0
  29. package/src/components/MethodAccordion/MethodAccordion.tsx +60 -18
  30. package/src/components/table/style.scss +11 -0
  31. package/src/components/table/table.tsx +1 -0
  32. package/src/components/table/tags-table.tsx +2 -2
  33. package/src/constants/index.ts +0 -2
  34. package/src/layout/layout.tsx +7 -2
@@ -1,8 +1,10 @@
1
1
  import { TransformedMethod } from '../../types/layout.type';
2
- declare const MethodsAccordion: ({ method, path, setFieldValue, readOnly, }: {
2
+ import { Tags } from '@entities/openApi';
3
+ declare const MethodsAccordion: ({ method, path, setFieldValue, readOnly, tags, }: {
3
4
  method: TransformedMethod;
4
5
  path: string;
5
- setFieldValue?: (key: string, value: string) => void;
6
+ setFieldValue?: (key: string, value: string | string[]) => void;
6
7
  readOnly?: boolean;
8
+ tags: Tags[];
7
9
  }) => import("react/jsx-runtime").JSX.Element;
8
10
  export default MethodsAccordion;
@@ -40,12 +40,17 @@ export declare const methodColorMapping: {
40
40
  order: number;
41
41
  };
42
42
  };
43
- export declare const tagsTableHeaders: {
43
+ export declare const tagsTableHeaders: ({
44
44
  id: string;
45
45
  label: string;
46
46
  sortable: boolean;
47
47
  classes: string;
48
- }[];
48
+ } | {
49
+ id: string;
50
+ label: string;
51
+ sortable: boolean;
52
+ classes?: undefined;
53
+ })[];
49
54
  export declare const paramsTableHeaders: ({
50
55
  id: string;
51
56
  label: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "name": "@digi-frontend/dgate-api-documentation",
3
- "version": "1.0.16",
2
+ "name": "@digi-frontend/dgate-api-documentation",
3
+ "version": "1.0.20",
4
4
  "main": "dist/src/index.js",
5
5
  "module": "dist/src/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -55,6 +55,19 @@
55
55
  }
56
56
  }
57
57
  }
58
+
59
+ &:not(:global(.disabled)):global(.success) {
60
+ :global(.endBtnIcon) {
61
+ margin-block: auto;
62
+
63
+ svg {
64
+ width: 1.125rem;
65
+ path {
66
+ fill: #3aaa35;
67
+ }
68
+ }
69
+ }
70
+ }
58
71
  }
59
72
  }
60
73
 
@@ -36,12 +36,12 @@ const InfoForm = ({ readOnly }: { readOnly?: boolean }) => {
36
36
  }, [])
37
37
 
38
38
  useEffect(() => {
39
- setTableRecords(generateTableData(tableData))
39
+ setTableRecords(generateTableRecords(tableData))
40
40
  }, [tableData])
41
41
 
42
42
  useEffect(() => {
43
43
  if (values.tags && values.tags.length) {
44
- setTableRecords(generateTableData(values.tags))
44
+ setTableRecords(generateTableRecords(values.tags))
45
45
  setTableData(values.tags)
46
46
  }
47
47
  }, [values.tags])
@@ -77,7 +77,7 @@ const InfoForm = ({ readOnly }: { readOnly?: boolean }) => {
77
77
 
78
78
  const saveNewRow = (tag) => {
79
79
  setTableData([...tableData, tag])
80
- const oldTags = values.tags || [];
80
+ const oldTags = values.tags || []
81
81
  setFieldValue(`tags`, [...oldTags, tag])
82
82
  }
83
83
 
@@ -88,7 +88,7 @@ const InfoForm = ({ readOnly }: { readOnly?: boolean }) => {
88
88
  setOpenDeleteDialog(true)
89
89
  }
90
90
 
91
- const generateTableData = (items) => {
91
+ const generateTableRecords = (items) => {
92
92
  return items.map((item, index) => ({
93
93
  id: index,
94
94
  tagName: item.name,
@@ -131,10 +131,19 @@ const InfoForm = ({ readOnly }: { readOnly?: boolean }) => {
131
131
  </div>
132
132
  }
133
133
  >
134
- {readOnly ? (
135
- <Button className={styles.editDescBtn} variant="link" color="action">
136
- {item.description ? item.description.substring(0, 12) : '-'}
137
- {item.description && item.description.length > 12 ? '...' : ''}
134
+ {readOnly || values.tags[index].description ? (
135
+ <Button
136
+ className={styles.editDescBtn}
137
+ variant="link"
138
+ color="action"
139
+ endIcon={<SVGLoader src={EditIcon} width="1.5rem" height="1.5rem" />}
140
+ >
141
+ {values.tags[index].description
142
+ ? values.tags[index].description.substring(0, 12)
143
+ : '-'}
144
+ {values.tags[index].description && values.tags[index].description.length > 12
145
+ ? '...'
146
+ : ''}
138
147
  </Button>
139
148
  ) : (
140
149
  <Button
@@ -143,7 +152,9 @@ const InfoForm = ({ readOnly }: { readOnly?: boolean }) => {
143
152
  color="action"
144
153
  endIcon={<SVGLoader src={EditIcon} width="1.5rem" height="1.5rem" />}
145
154
  >
146
- {readOnly || item.description ? 'View Description' : 'Add Description'}
155
+ {readOnly || values.tags[index].description
156
+ ? 'View Description'
157
+ : 'Add Description'}
147
158
  </Button>
148
159
  )}
149
160
  </Tooltip>
@@ -210,22 +221,22 @@ const InfoForm = ({ readOnly }: { readOnly?: boolean }) => {
210
221
  </div>
211
222
  }
212
223
  >
213
- {readOnly ? (
224
+ {readOnly || values.tags[index].externalDocs?.description ? (
214
225
  <Button
215
226
  className={styles.editDescBtn}
216
227
  variant="link"
217
228
  color="action"
229
+ endIcon={<SVGLoader src={EditIcon} width="1.5rem" height="1.5rem" />}
218
230
  onClick={() => {
219
- const a = document.createElement('a')
220
- a.href = item.externalDocs?.url
221
- a.target="_blank"
222
- a.click()
231
+ setDescription(item.externalDocs?.description)
232
+ setURL(item.externalDocs?.url)
223
233
  }}
224
234
  >
225
- {item?.externalDocs?.description
226
- ? item?.externalDocs?.description?.substring(0, 12)
235
+ {values.tags[index].externalDocs?.description
236
+ ? values.tags[index].externalDocs?.description?.substring(0, 12)
227
237
  : '-'}
228
- {item?.externalDocs?.description && item?.externalDocs?.description?.length > 12
238
+ {values.tags[index].externalDocs?.description &&
239
+ values.tags[index].externalDocs?.description?.length > 12
229
240
  ? '...'
230
241
  : ''}
231
242
  </Button>
@@ -1,15 +1,12 @@
1
1
  import React, { useEffect, useState } from 'react'
2
2
  import styles from './LivePreview.module.scss'
3
3
  import SimpleLabelValue from '../../components/SimpleLabelValue'
4
-
5
4
  import MethodsAccordion from '../../components/MethodAccordion/MethodAccordion'
6
5
  import { TransformedOpenApi } from '../../types/transformedOpenApi'
7
6
  import { useFormikContext } from 'formik'
8
7
  import { methodColorMapping, tagsTableHeaders } from '../../constants/index'
9
8
  import TagsTable from '../table/tags-table'
10
- import { Button, TextArea } from 'digitinary-ui'
11
- import Tooltip from '../../components/Tooltip/Tooltip'
12
- import { DeleteIcon, deleteOutlinedIcon, EditIcon } from '../../assets/icons'
9
+ import { Button } from 'digitinary-ui'
13
10
 
14
11
  interface LivePreviewProps {
15
12
  transformedData?: TransformedOpenApi
@@ -69,8 +66,12 @@ const LivePreview: React.FC<LivePreviewProps> = ({ transformedData }) => {
69
66
  </a>
70
67
  ) : (
71
68
  <Button className={styles.editDescBtn} variant="link" color="action">
72
- {item.externalDocs?.description ? item.externalDocs?.description.substring(0, 12) : '-'}
73
- {item.externalDocs?.description && item.externalDocs?.description.length > 12 ? '...' : ''}
69
+ {item.externalDocs?.description
70
+ ? item.externalDocs?.description.substring(0, 12)
71
+ : '-'}
72
+ {item.externalDocs?.description && item.externalDocs?.description.length > 12
73
+ ? '...'
74
+ : ''}
74
75
  </Button>
75
76
  )}
76
77
 
@@ -120,12 +121,37 @@ const LivePreview: React.FC<LivePreviewProps> = ({ transformedData }) => {
120
121
 
121
122
  <SimpleLabelValue key={'endpoints'} label={'Endpoints '} />
122
123
  {values.paths.map((path) => (
123
- <div className={styles.methodsContainer}>
124
- {path.methods
124
+ <div className={styles.methodsContainer} key={path.path}>
125
+ {Object.entries(
126
+ path.methods
125
127
  .sort((a, b) => methodColorMapping[a.type].order + methodColorMapping[b.type].order)
126
- .map((method, methodIndex) => (
127
- <MethodsAccordion readOnly method={method} path={path.path} />
128
- ))}
128
+ .reduce((groupedMethods, method) => {
129
+ // Handle methods without tags
130
+ const tags = method.tags?.length ? method?.tags : ['default'];
131
+
132
+ tags.forEach((tag) => {
133
+ if (!groupedMethods[tag]) {
134
+ groupedMethods[tag] = [];
135
+ }
136
+ groupedMethods[tag].push(method);
137
+ });
138
+
139
+ return groupedMethods;
140
+ }, {})
141
+ ).map(([tag, methods]) => (
142
+ <div key={tag}>
143
+ <h3>{tag}</h3>
144
+ {methods?.map((method, methodIndex) => (
145
+ <MethodsAccordion
146
+ readOnly
147
+ method={method}
148
+ path={path.path}
149
+ tags={values.tags}
150
+ handleSave={() => null}
151
+ />
152
+ ))}
153
+ </div>
154
+ ))}
129
155
  </div>
130
156
  ))}
131
157
  </div>
@@ -134,6 +134,19 @@
134
134
  }
135
135
  }
136
136
  }
137
+
138
+ &:not(:global(.disabled)):global(.success) {
139
+ :global(.endBtnIcon) {
140
+ margin-block: auto;
141
+
142
+ svg {
143
+ width: 1.125rem;
144
+ path {
145
+ fill: #3aaa35;
146
+ }
147
+ }
148
+ }
149
+ }
137
150
  }
138
151
  }
139
152
  }
@@ -1,13 +1,7 @@
1
- import React, { useEffect, useState } from 'react'
2
- import { Accordion, Button, SelectGroup, Switch, TextArea } from 'digitinary-ui'
1
+ import { useEffect, useState } from 'react'
2
+ import { Accordion, Button, SelectGroup, SelectGroupV2, Switch, TextArea } from 'digitinary-ui'
3
3
  import SVGLoader from '../../components/SVGLoader/SVGLoader'
4
- import {
5
- CheckMarkSquare,
6
- DeleteIcon,
7
- DownArrowIcon,
8
- EditIcon,
9
- deleteOutlinedIcon,
10
- } from '../../assets/icons'
4
+ import { DeleteIcon, DownArrowIcon, EditIcon, deleteOutlinedIcon } from '../../assets/icons'
11
5
  import { httpStatusCodes, methodColorMapping, paramsTableHeaders } from '../../constants/index'
12
6
  import Tooltip from '../../components/Tooltip/Tooltip'
13
7
  import { TransformedMethod } from '../../types/layout.type'
@@ -17,6 +11,7 @@ import ParamterTable from '../table/table'
17
11
  import CommonDialog from '../../components/dialog'
18
12
  import JsonInput from '../../components/JsonInput/JsonInput'
19
13
  import styles from './MethodAccordion.module.scss'
14
+ import { Tags } from '@entities/openApi'
20
15
 
21
16
  const httpStatusCodeOptions = httpStatusCodes.map((code) => ({
22
17
  label: (
@@ -36,11 +31,13 @@ const MethodsAccordion = ({
36
31
  path,
37
32
  setFieldValue,
38
33
  readOnly,
34
+ tags,
39
35
  }: {
40
36
  method: TransformedMethod
41
37
  path: string
42
- setFieldValue?: (key: string, value: string) => void
38
+ setFieldValue?: (key: string, value: string | string[]) => void
43
39
  readOnly?: boolean
40
+ tags: Tags[]
44
41
  }) => {
45
42
  const [isExpanded, setIsExpanded] = useState({
46
43
  request: false,
@@ -54,7 +51,7 @@ const MethodsAccordion = ({
54
51
  const [selectedParamIndex, setSelectedParamIndex] = useState<number | null>(null)
55
52
  const [selectedParamName, setSelectedParamName] = useState<string | null>(null)
56
53
  const [tableRecords, setTableRecords] = useState()
57
-
54
+ const [selectionTags, setSelectionTags] = useState([])
58
55
  const [selectedStatusCode, setSelectedStatusCode] = useState(httpStatusCodeOptions[4])
59
56
  const currentResponse =
60
57
  method.responses.find((res) => Number(res.code) === selectedStatusCode.value) || '{}'
@@ -139,15 +136,20 @@ const MethodsAccordion = ({
139
136
  </div>
140
137
  }
141
138
  >
142
- {readOnly ? (
139
+ {readOnly || method.parameters[index].description?.length > 0 ? (
143
140
  <Button
144
141
  className={styles.editDescBtn}
145
142
  variant="link"
146
143
  color="action"
147
- // endIcon={<SVGLoader src={EditIcon} width="1.5rem" height="1.5rem" />}
144
+ endIcon={<SVGLoader src={EditIcon} width="1.5rem" height="1.5rem" />}
148
145
  >
149
- {item.description ? item.description.substring(0, 12) : '-'}
150
- {item.description && item.description.length > 12 ? '...' : ''}
146
+ {method.parameters[index].description
147
+ ? method.parameters[index].description.substring(0, 12)
148
+ : '-'}
149
+ {method.parameters[index].description &&
150
+ method.parameters[index].description.length > 12
151
+ ? '...'
152
+ : ''}
151
153
  </Button>
152
154
  ) : (
153
155
  <Button
@@ -213,6 +215,25 @@ const MethodsAccordion = ({
213
215
  }
214
216
  }, [method, path])
215
217
 
218
+ useEffect(() => {
219
+ // prepare tags selection list
220
+ if (!selectionTags.length) {
221
+ const convertedStringArray = (method?.tags || [])?.map((item) => ({
222
+ label: capitalize(item),
223
+ value: item,
224
+ }))
225
+ const mergedArray = [
226
+ ...convertedStringArray,
227
+ ...(tags || []).map((item) => ({ label: capitalize(item.name), value: item.name })),
228
+ ]
229
+
230
+ const filteredArray = mergedArray.filter(
231
+ (value, index, self) => index === self.findIndex((t) => t.value === value.value)
232
+ )
233
+ setSelectionTags(filteredArray)
234
+ }
235
+ }, [tags, method])
236
+
216
237
  return (
217
238
  <div>
218
239
  <Accordion
@@ -243,6 +264,30 @@ const MethodsAccordion = ({
243
264
  }
244
265
  children={
245
266
  <div className={styles.methodAccordionContent}>
267
+ <SelectGroup
268
+ className={styles.methodDesc}
269
+ disabled={readOnly}
270
+ placeholder="Select Tags"
271
+ label="Tags"
272
+ value={method.tags?.map((t) => ({
273
+ label: capitalize(t),
274
+ value: t,
275
+ }))}
276
+ onChange={(item) => {
277
+ setFieldValue(
278
+ 'tags',
279
+ item.map((i) => i.value)
280
+ )
281
+ }}
282
+ options={[
283
+ {
284
+ list: selectionTags,
285
+ },
286
+ ]}
287
+ isMultiple={true}
288
+ withSearch={false}
289
+ clearable={false}
290
+ />{' '}
246
291
  {!readOnly ? (
247
292
  <TextArea
248
293
  className={styles.methodDesc}
@@ -269,7 +314,6 @@ const MethodsAccordion = ({
269
314
  readOnly={readOnly}
270
315
  />
271
316
  </div>
272
-
273
317
  {method?.type !== 'get' && (
274
318
  <Accordion
275
319
  expanded={isExpanded.request}
@@ -312,7 +356,6 @@ const MethodsAccordion = ({
312
356
  }
313
357
  />
314
358
  )}
315
-
316
359
  <Accordion
317
360
  expanded={isExpanded.response}
318
361
  onChange={() => null}
@@ -341,7 +384,6 @@ const MethodsAccordion = ({
341
384
  withSearch={false}
342
385
  isMultiple={false}
343
386
  clearable={false}
344
- disabled={readOnly}
345
387
  placeholder="200"
346
388
  options={[
347
389
  {
@@ -101,6 +101,17 @@
101
101
  text-overflow: ellipsis;
102
102
  overflow: visible !important;
103
103
  }
104
+
105
+ &:nth-child(2) {
106
+ .tableData {
107
+ .customBtn .btnContentWrapper .endBtnIcon svg path,
108
+ .customBtn :link .btnContentWrapper .endBtnIcon svg path,
109
+ .customBtn :visited .btnContentWrapper .endBtnIcon svg path {
110
+ stroke-width: 0.1 !important;
111
+ fill: #12131a !important;
112
+ }
113
+ }
114
+ }
104
115
  }
105
116
 
106
117
  &:hover {
@@ -21,6 +21,7 @@ const ParamterTable = ({
21
21
  const [text, setText] = useState('')
22
22
  const [tooltipRef, setTooltipRef] = useState(null)
23
23
  const { values, errors, setFieldValue, isValid, submitForm, resetForm } = useFormik({
24
+ validateOnMount: true,
24
25
  initialValues: {
25
26
  name: '',
26
27
  in: 'Query',
@@ -16,6 +16,7 @@ const TagsTable = ({ id, headCells, data, isFormOpen, setIsFormOpen, saveNewRow,
16
16
  const [tooltipRef, setTooltipRef] = useState(null)
17
17
  const [externalTooltipRefs, setExternalTooltipRefs] = useState(null)
18
18
  const { values, errors, setFieldValue, isValid, submitForm, resetForm } = useFormik({
19
+ validateOnMount: true,
19
20
  initialValues: {
20
21
  name: '',
21
22
  description: '',
@@ -221,8 +222,7 @@ const TagsTable = ({ id, headCells, data, isFormOpen, setIsFormOpen, saveNewRow,
221
222
  variant="link"
222
223
  color="action"
223
224
  href={values.externalDocs?.url}
224
- target='_blank'
225
-
225
+ target="_blank"
226
226
  >
227
227
  {values?.externalDocs?.description
228
228
  ? values?.externalDocs?.description?.substring(0, 12)
@@ -52,13 +52,11 @@ export const tagsTableHeaders = [
52
52
  id: 'description',
53
53
  label: 'Description',
54
54
  sortable: false,
55
- classes: 'requiredParam',
56
55
  },
57
56
  {
58
57
  id: 'externalDocs',
59
58
  label: 'External Docs',
60
59
  sortable: false,
61
- classes: 'requiredParam',
62
60
  },
63
61
  ]
64
62
 
@@ -1,4 +1,4 @@
1
- import { JSX } from 'react'
1
+ import { JSX, useEffect } from 'react'
2
2
  import { Alert, Button } from 'digitinary-ui'
3
3
  import MethodsAccordion from '../components/MethodAccordion/MethodAccordion'
4
4
  import styles from './layout.module.css'
@@ -24,10 +24,14 @@ const Layout = ({ openApiJson, handleSave }: ILayoutProps): JSX.Element => {
24
24
  initialValues: structuredClone(transformedOpenApi),
25
25
  validationSchema: schemaValidation,
26
26
  validateOnMount: true,
27
- onSubmit: (values, { validateForm }) => {
27
+ onSubmit: (values, { validateForm, resetForm }) => {
28
28
  // Handle save logic
29
29
  const originalOpenApiForm = transformOpenApiObjectToOrigin(values)
30
30
  handleSave(originalOpenApiForm)
31
+ resetForm({
32
+ values: values, // You can reset it to the same values if you want
33
+ })
34
+
31
35
  validateForm(values)
32
36
  },
33
37
  })
@@ -72,6 +76,7 @@ const Layout = ({ openApiJson, handleSave }: ILayoutProps): JSX.Element => {
72
76
  )
73
77
  .map((method, methodIndex) => (
74
78
  <MethodsAccordion
79
+ tags={formik.values.tags}
75
80
  method={method}
76
81
  path={path.path}
77
82
  setFieldValue={(key, value) => {