Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Option to exclude params from request #432

Merged
merged 3 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion runtime/config-params.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export type SkyuxConfigParams = string[] | { [key: string]: boolean | { value?: any; required?: boolean } };
export type SkyuxConfigParams = string[] | {
[key: string]: boolean | {
value?: any;
required?: boolean;
excludeFromRequests?: boolean;
}
};
17 changes: 17 additions & 0 deletions runtime/params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ describe('SkyAppRuntimeConfigParams', () => {
expect(params.getUrl('https://mysite.com?c=d')).toEqual('https://mysite.com?c=d&a1=b');
});

it('should exclude certain parameters from being added to a url\'s querystring', () => {
const params: SkyAppRuntimeConfigParams = new SkyAppRuntimeConfigParams(
'?a1=b&b2=c3&z4=y',
{
'a1': true,
'b2': {
required: true
},
'z4': {
excludeFromRequests: true
}
}
);

expect(params.getUrl('https://mysite.com?c=d')).toEqual('https://mysite.com?c=d&a1=b&b2=c3');
});

it('should not add a current param if the url already has it', () => {
const params: SkyAppRuntimeConfigParams = new SkyAppRuntimeConfigParams(
'?a1=b',
Expand Down
15 changes: 14 additions & 1 deletion runtime/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ function getUrlSearchParams(url: string): URLSearchParams {
}

export class SkyAppRuntimeConfigParams {

private params: { [key: string]: string } = {};

private defaultParamValues: { [key: string]: string } = {};

private requiredParams: string[] = [];

private encodedParams: string[] = [];

private excludeFromRequestsParams: string[] = [];

constructor(
url: string,
configParams: SkyuxConfigParams
Expand Down Expand Up @@ -63,6 +69,10 @@ export class SkyAppRuntimeConfigParams {
this.params[paramName] = paramValue;
this.defaultParamValues[paramName] = paramValue;
}

if (configParam.excludeFromRequests) {
this.excludeFromRequestsParams.push(paramName);
}
}
}
}
Expand Down Expand Up @@ -178,7 +188,10 @@ export class SkyAppRuntimeConfigParams {
let joined: string[] = [];

this.getAllKeys().forEach(key => {
if (!urlSearchParams.has(key)) {
if (
this.excludeFromRequestsParams.indexOf(key) === -1 &&
!urlSearchParams.has(key)
) {
joined.push(`${key}=${encodeURIComponent(this.get(key, true))}`);
}
});
Expand Down
27 changes: 26 additions & 1 deletion skyuxconfig-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,32 @@
"type": [
"array",
"object"
]
],
"items": {
"type": "string"
},
"patternProperties": {
"^.*$": {
"type": [
"boolean",
"object"
],
"properties": {
"required": {
"description": "Indicates the parameter must be supplied to the application in order to function.",
"type": "boolean"
},
"value": {
"description": "The default value of the parameter. This value may be overridden at runtime by the query string or other future sources of parameter values."
},
"excludeFromRequests": {
"description": "Indicates whether the parameter should be excluded from the parameters automatically added to the query string of URLs requested with SkyAuthHttp.",
"type": "boolean",
"default": true
}
}
}
}
},
"plugins": {
"description": "Specifies plugins to expand on existing SKY UX Builder functionality and create new functionality.",
Expand Down
1 change: 1 addition & 0 deletions skyuxconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "./skyuxconfig-schema.json",
"mode": "advanced",
"host": {
"url": "https://host.nxt.blackbaud.com"
Expand Down