mirror of
https://github.com/Kong/insomnia.git
synced 2026-10-22 23:05:25 -04:00
Add folder index to request tag (Closes #1011)
This commit is contained in:
1 parent
4fec7fd9e8
commit
60f6a31a95
3 files changed
+36
-8
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import * as models from '../models/index';
|
||||
import * as templating from './index';
|
||||
import * as pluginContexts from '../plugins/context';
|
||||
import * as db from '../common/database';
|
||||
|
||||
const EMPTY_ARG = '__EMPTY_NUNJUCKS_ARG__';
|
||||
|
||||
@@ -81,8 +82,16 @@ export default class BaseExtension {
|
||||
util: {
|
||||
render: str => templating.render(str, { context: renderContext }),
|
||||
models: {
|
||||
request: { getById: models.request.getById },
|
||||
requestGroup: { getById: models.requestGroup.getById },
|
||||
request: {
|
||||
getById: models.request.getById,
|
||||
getAncestors: async request => {
|
||||
const ancestors = await db.withAncestors(request, [
|
||||
models.requestGroup.type,
|
||||
models.workspace.type
|
||||
]);
|
||||
return ancestors.filter(doc => doc._id !== request._id);
|
||||
}
|
||||
},
|
||||
workspace: { getById: models.workspace.getById },
|
||||
oAuth2Token: { getByRequestId: models.oAuth2Token.getByParentId },
|
||||
cookieJar: {
|
||||
|
||||
@@ -552,7 +552,11 @@ class TagEditor extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
const help =
|
||||
typeof argDefinition.help === 'string' ? argDefinition.help : '';
|
||||
typeof argDefinition.help === 'string' ||
|
||||
typeof argDefinition.help === 'function'
|
||||
? fnOrString(argDefinition.help, argDatas)
|
||||
: '';
|
||||
|
||||
const displayName =
|
||||
typeof argDefinition.displayName === 'string' ||
|
||||
typeof argDefinition.displayName === 'function'
|
||||
|
||||
@@ -23,7 +23,7 @@ module.exports.templateTags = [
|
||||
{
|
||||
displayName: 'Folder',
|
||||
value: 'folder',
|
||||
description: 'name of immediate parent folder (or workspace)'
|
||||
description: 'name of parent folder (or workspace)'
|
||||
},
|
||||
{
|
||||
displayName: 'URL',
|
||||
@@ -61,10 +61,17 @@ module.exports.templateTags = [
|
||||
return 'Name';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
hide: args => args[0].value !== 'folder',
|
||||
displayName: 'Parent Index',
|
||||
help:
|
||||
'Specify an index (Starting at 0) for how high up the folder tree to look',
|
||||
type: 'number'
|
||||
}
|
||||
],
|
||||
|
||||
async run(context, attribute, name) {
|
||||
async run(context, attribute, name, folderIndex) {
|
||||
const { meta } = context;
|
||||
|
||||
if (!meta.requestId || !meta.workspaceId) {
|
||||
@@ -131,10 +138,18 @@ module.exports.templateTags = [
|
||||
case 'name':
|
||||
return request.name;
|
||||
case 'folder':
|
||||
const requestGroup = await context.util.models.requestGroup.getById(
|
||||
request.parentId
|
||||
const ancestors = await context.util.models.request.getAncestors(
|
||||
request
|
||||
);
|
||||
return requestGroup ? requestGroup.name : workspace.name;
|
||||
const doc = ancestors[folderIndex || 0];
|
||||
if (!doc) {
|
||||
throw new Error(
|
||||
`Could not get folder by index ${folderIndex}. Must be between 0-${
|
||||
ancestors.length
|
||||
}`
|
||||
);
|
||||
}
|
||||
return doc ? doc.name : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user