Support more languages in Generate Code (#2991)

* generate languages for all targets

* change target client name

* add scroll bar

* remove debug log
This commit is contained in:
Huynh Tien 2024-09-16 01:36:06 +07:00 committed by GitHub
parent b3c72b1640
commit 7dd639192c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 49 deletions

View File

@ -8,8 +8,9 @@ const StyledWrapper = styled.div`
.generate-code-sidebar { .generate-code-sidebar {
background-color: ${(props) => props.theme.collection.environment.settings.sidebar.bg}; background-color: ${(props) => props.theme.collection.environment.settings.sidebar.bg};
border-right: solid 1px ${(props) => props.theme.collection.environment.settings.sidebar.borderRight}; border-right: solid 1px ${(props) => props.theme.collection.environment.settings.sidebar.borderRight};
min-height: 400px; max-height: 90vh;
height: 100%; height: 100%;
overflow-y: auto;
} }
.generate-code-item { .generate-code-item {

View File

@ -6,56 +6,11 @@ import { isValidUrl } from 'utils/url';
import { find, get } from 'lodash'; import { find, get } from 'lodash';
import { findEnvironmentInCollection } from 'utils/collections'; import { findEnvironmentInCollection } from 'utils/collections';
import { interpolateUrl, interpolateUrlPathParams } from 'utils/url/index'; import { interpolateUrl, interpolateUrlPathParams } from 'utils/url/index';
import { getLanguages } from 'utils/codegenerator/targets';
const languages = [
{
name: 'HTTP',
target: 'http',
client: 'http1.1'
},
{
name: 'JavaScript-Fetch',
target: 'javascript',
client: 'fetch'
},
{
name: 'Javascript-jQuery',
target: 'javascript',
client: 'jquery'
},
{
name: 'Javascript-axios',
target: 'javascript',
client: 'axios'
},
{
name: 'Python-Python3',
target: 'python',
client: 'python3'
},
{
name: 'Python-Requests',
target: 'python',
client: 'requests'
},
{
name: 'PHP',
target: 'php',
client: 'curl'
},
{
name: 'Shell-curl',
target: 'shell',
client: 'curl'
},
{
name: 'Shell-httpie',
target: 'shell',
client: 'httpie'
}
];
const GenerateCodeItem = ({ collection, item, onClose }) => { const GenerateCodeItem = ({ collection, item, onClose }) => {
const languages = getLanguages();
const environment = findEnvironmentInCollection(collection, collection.activeEnvironmentUid); const environment = findEnvironmentInCollection(collection, collection.activeEnvironmentUid);
let envVars = {}; let envVars = {};
if (environment) { if (environment) {

View File

@ -0,0 +1,23 @@
import { targets } from 'httpsnippet';
export const getLanguages = () => {
const allLanguages = [];
for (const target of Object.values(targets)) {
const { key, title } = target.info;
const clients = Object.keys(target.clientsById);
const languages =
(clients.length === 1)
? [{
name: title,
target: key,
client: clients[0]
}]
: clients.map(client => ({
name: `${title}-${client}`,
target: key,
client
}));
allLanguages.push(...languages);
}
return allLanguages;
};