Skip to content

Commit

Permalink
Add deeplink above code block that links to the API reference for eac…
Browse files Browse the repository at this point in the history
…h request in the console (#142)

* Add deeplink to the docs for each request in the console

Signed-off-by: Snehil Shah <[email protected]>

* Move Core Logic to `autocomplete-openapi` module

Signed-off-by: Snehil Shah <[email protected]>

* Fix Failing Workflow

Signed-off-by: Snehil Shah <[email protected]>

* Refactor for 0c1f910256fb88b82875eef34a5056776d5a18f7

Signed-off-by: Snehil Shah <[email protected]>

* Refactor for a5693f7d5e811544a4fe245d630347c7b5148b0e

Signed-off-by: Snehil Shah <[email protected]>

* Format Source Code

Signed-off-by: Snehil Shah <[email protected]>

* refactor for `autocomplete-openapi=0.1.2`

Signed-off-by: Snehil Shah <[email protected]>

* fix workflow

Signed-off-by: Snehil Shah <[email protected]>

* Update src/components/EditorCommon/config/Rules.js

Co-authored-by: Kartik Gupta <[email protected]>

* Update openapi import in Rules.js to use the "raw" query parameter

---------

Signed-off-by: Snehil Shah <[email protected]>
Co-authored-by: Kartik Gupta <[email protected]>
Co-authored-by: kartik-gupta-ij <[email protected]>
  • Loading branch information
3 people authored Apr 20, 2024
1 parent 5db568c commit 4f91cba
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@uppy/react": "^3.1.2",
"@uppy/xhr-upload": "^3.3.1",
"@vitejs/plugin-react": "^4.0.0",
"autocomplete-openapi": "^0.1.1",
"autocomplete-openapi": "^0.1.2",
"axios": "^1.6.7",
"chart.js": "^4.3.0",
"chroma-js": "^2.4.2",
Expand Down
8 changes: 7 additions & 1 deletion src/components/CodeEditorWindow/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const CodeEditorWindow = ({ onChange, code, onChangeResult, setRequestCount }) =

let runBtnCommandId = null;
let beautifyBtnCommandId = null;
let docsBtnCommandId = null;

const handleEditorChange = (code) => {
onChange('code', code);
Expand Down Expand Up @@ -74,10 +75,15 @@ const CodeEditorWindow = ({ onChange, code, onChangeResult, setRequestCount }) =
''
);

docsBtnCommandId = editor.addCommand(0, async (_ctx, ...args) => {
const docsURL = args[0];
window.open(docsURL, '_blank');
});

// Register Code Lens Provider (Run Button)
lensesRef.current = monaco.languages.registerCodeLensProvider(
'custom-language',
btnconfig(runBtnCommandId, beautifyBtnCommandId)
btnconfig(runBtnCommandId, beautifyBtnCommandId, docsBtnCommandId)
);

// Listen for Mouse Postion Change
Expand Down
22 changes: 21 additions & 1 deletion src/components/EditorCommon/config/Rules.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { OpenapiDocs } from 'autocomplete-openapi/src/request-docs';
import openapi from '/openapi.json??url&raw';

const Method = ['POST', 'GET', 'PUT', 'DELETE', 'PATCH', 'HEAD'];
const DOCS_BASE_URL = 'https://qdrant.github.io/qdrant/redoc/index.html#tag/';

const apiDocs = new OpenapiDocs(JSON.parse(openapi));

export const Rules = {
Method,
Expand Down Expand Up @@ -54,7 +60,7 @@ export const options = {
},
};

export function btnconfig(commandId, beutifyCommandId) {
export function btnconfig(commandId, beutifyCommandId, docsCommandId) {
return {
// function takes model and token as arguments
provideCodeLenses: function (model) {
Expand Down Expand Up @@ -88,6 +94,20 @@ export function btnconfig(commandId, beutifyCommandId) {
arguments: [codeBlocks[i]],
},
});

const terminal = apiDocs.getRequestDocs(codeBlocks[i].blockText.split('\n')[0]);
if (terminal) {
const docsURL = DOCS_BASE_URL + terminal.tags[0] + '/operation/' + terminal.operationId;
lenses.push({
range,
id: 'DOCS',
command: {
id: docsCommandId,
title: 'DOCS',
arguments: [docsURL],
},
});
}
}

return {
Expand Down

0 comments on commit 4f91cba

Please sign in to comment.