From 19498363e17ec082633b69498a57162b9ae62d93 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sat, 14 Oct 2023 01:01:11 +0530 Subject: [PATCH] feat(#583): collection level docs --- .../CollectionSettings/Docs/StyledWrapper.js | 18 ++++++ .../CollectionSettings/Docs/index.js | 55 +++++++++++++++++++ .../components/CollectionSettings/index.js | 9 ++- .../ReduxStore/slices/collections/index.js | 9 ++- packages/bruno-electron/src/bru/index.js | 6 +- 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 packages/bruno-app/src/components/CollectionSettings/Docs/StyledWrapper.js create mode 100644 packages/bruno-app/src/components/CollectionSettings/Docs/index.js diff --git a/packages/bruno-app/src/components/CollectionSettings/Docs/StyledWrapper.js b/packages/bruno-app/src/components/CollectionSettings/Docs/StyledWrapper.js new file mode 100644 index 000000000..f0ffee808 --- /dev/null +++ b/packages/bruno-app/src/components/CollectionSettings/Docs/StyledWrapper.js @@ -0,0 +1,18 @@ +import styled from 'styled-components'; + +const StyledWrapper = styled.div` + div.CodeMirror { + /* todo: find a better way */ + height: calc(100vh - 240px); + + .CodeMirror-scroll { + padding-bottom: 0px; + } + } + .editing-mode { + cursor: pointer; + color: ${(props) => props.theme.colors.text.yellow}; + } +`; + +export default StyledWrapper; diff --git a/packages/bruno-app/src/components/CollectionSettings/Docs/index.js b/packages/bruno-app/src/components/CollectionSettings/Docs/index.js new file mode 100644 index 000000000..ca15cb3a5 --- /dev/null +++ b/packages/bruno-app/src/components/CollectionSettings/Docs/index.js @@ -0,0 +1,55 @@ +import 'github-markdown-css/github-markdown.css'; +import get from 'lodash/get'; +import { updateCollectionDocs } from 'providers/ReduxStore/slices/collections'; +import { useTheme } from 'providers/Theme/index'; +import { useState } from 'react'; +import { useDispatch } from 'react-redux'; +import { saveCollectionRoot } from 'providers/ReduxStore/slices/collections/actions'; +import Markdown from 'components/MarkDown'; +import CodeEditor from 'components/CodeEditor'; +import StyledWrapper from './StyledWrapper'; + +const Docs = ({ collection }) => { + const dispatch = useDispatch(); + const { storedTheme } = useTheme(); + const [isEditing, setIsEditing] = useState(false); + const docs = get(collection, 'root.docs', ''); + + const toggleViewMode = () => { + setIsEditing((prev) => !prev); + }; + + const onEdit = (value) => { + dispatch( + updateCollectionDocs({ + collectionUid: collection.uid, + docs: value + }) + ); + }; + + const onSave = () => dispatch(saveCollectionRoot(collection.uid)); + + return ( + +
+ {isEditing ? 'Preview' : 'Edit'} +
+ + {isEditing ? ( + + ) : ( + + )} +
+ ); +}; + +export default Docs; diff --git a/packages/bruno-app/src/components/CollectionSettings/index.js b/packages/bruno-app/src/components/CollectionSettings/index.js index eaf44e758..b3a1ece81 100644 --- a/packages/bruno-app/src/components/CollectionSettings/index.js +++ b/packages/bruno-app/src/components/CollectionSettings/index.js @@ -11,6 +11,7 @@ import Headers from './Headers'; import Auth from './Auth'; import Script from './Script'; import Test from './Tests'; +import Docs from './Docs'; import StyledWrapper from './StyledWrapper'; const CollectionSettings = ({ collection }) => { @@ -54,6 +55,9 @@ const CollectionSettings = ({ collection }) => { case 'proxy': { return ; } + case 'docs': { + return ; + } } }; @@ -81,8 +85,11 @@ const CollectionSettings = ({ collection }) => {
setTab('proxy')}> Proxy
+
setTab('docs')}> + Docs +
-
{getTabPanel(tab)}
+
{getTabPanel(tab)}
); }; diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index 5d6baa9d3..c5cb71f83 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -996,7 +996,6 @@ export const collectionsSlice = createSlice({ set(collection, 'root.request.script.res', action.payload.script); } }, - updateCollectionTests: (state, action) => { const collection = findCollectionByUid(state.collections, action.payload.collectionUid); @@ -1004,6 +1003,13 @@ export const collectionsSlice = createSlice({ set(collection, 'root.request.tests', action.payload.tests); } }, + updateCollectionDocs: (state, action) => { + const collection = findCollectionByUid(state.collections, action.payload.collectionUid); + + if (collection) { + set(collection, 'root.docs', action.payload.docs); + } + }, addCollectionHeader: (state, action) => { const collection = findCollectionByUid(state.collections, action.payload.collectionUid); @@ -1417,6 +1423,7 @@ export const { updateCollectionRequestScript, updateCollectionResponseScript, updateCollectionTests, + updateCollectionDocs, collectionAddFileEvent, collectionAddDirectoryEvent, collectionChangeFileEvent, diff --git a/packages/bruno-electron/src/bru/index.js b/packages/bruno-electron/src/bru/index.js index 342e1b494..de1080ac0 100644 --- a/packages/bruno-electron/src/bru/index.js +++ b/packages/bruno-electron/src/bru/index.js @@ -20,7 +20,8 @@ const collectionBruToJson = (bru) => { script: _.get(json, 'script', {}), vars: _.get(json, 'vars', {}), tests: _.get(json, 'tests', '') - } + }, + docs: _.get(json, 'docs', '') }; return transformedJson; @@ -43,7 +44,8 @@ const jsonToCollectionBru = (json) => { req: _.get(json, 'request.vars.req', []), res: _.get(json, 'request.vars.req', []) }, - tests: _.get(json, 'request.tests', '') + tests: _.get(json, 'request.tests', ''), + docs: _.get(json, 'docs', '') }; return _jsonToCollectionBru(collectionBruJson);