Mask preview for masked prompt tag (Closes #1412)

This commit is contained in:
Gregory Schier 2019-04-18 14:01:15 -07:00
parent c99ee30f46
commit 7c18b629de
7 changed files with 20 additions and 1 deletions

View File

@ -48,6 +48,7 @@ describe('init()', () => {
'setCookie',
'setHeader',
'setParameter',
'setUrl',
'settingDisableRenderRequestBody',
'settingEncodeUrl',
'settingSendCookies',

View File

@ -28,6 +28,10 @@ export default class BaseExtension {
return this._ext.description || 'no description';
}
getDisablePreview() {
return this._ext.disablePreview || (() => false);
}
getArgs() {
return this._ext.args || [];
}

View File

@ -79,6 +79,7 @@ export type PluginTemplateTag = {
args: Array<PluginArgument>,
name: string,
displayName: DisplayName,
disablePreview: () => boolean,
description: string,
run: (context: PluginTemplateTagContext, ...arg: Array<any>) => Promise<any> | any,
deprecated?: boolean,

View File

@ -93,6 +93,7 @@ export async function getTagDefinitions(): Promise<Array<NunjucksParsedTag>> {
name: ext.getTag(),
displayName: ext.getName(),
description: ext.getDescription(),
disablePreview: ext.getDisablePreview(),
args: ext.getArgs(),
}));
}

View File

@ -32,6 +32,9 @@ export type NunjucksParsedTag = {
name: string,
args: Array<NunjucksParsedTagArg>,
rawValue?: string,
displayName?: string,
description?: string,
disablePreview?: (Array<NunjucksParsedTagArg>) => boolean,
};
/**

View File

@ -278,6 +278,7 @@ class TagEditor extends React.PureComponent<Props, State> {
} else if (!activeTagData && !tagDefinition && this.state.activeTagData) {
activeTagData = {
name: 'custom',
displayName: 'Custom',
args: [],
rawValue: templateUtils.unTokenizeTag(this.state.activeTagData),
};
@ -598,13 +599,20 @@ class TagEditor extends React.PureComponent<Props, State> {
return null;
}
let finalPreview = preview;
if (activeTagDefinition && activeTagDefinition.disablePreview) {
finalPreview = activeTagDefinition.disablePreview(activeTagData.args)
? preview.replace(/./g, '*')
: preview;
}
let previewElement;
if (error) {
previewElement = <textarea className="danger" value={error || 'Error'} readOnly rows={5} />;
} else if (rendering) {
previewElement = <textarea value="rendering..." readOnly rows={5} />;
} else {
previewElement = <textarea value={preview || 'error'} readOnly rows={5} />;
previewElement = <textarea value={finalPreview || 'error'} readOnly rows={5} />;
}
return (

View File

@ -17,6 +17,7 @@ module.exports.templateTags = [
displayName: 'Prompt',
name: 'prompt',
description: 'prompt user for input',
disablePreview: args => args[4] && args[4].value === true,
args: [
{
displayName: 'Title',