Skip to content

Commit

Permalink
Fix: breaking change with the adaptive cards templating library (#735)
Browse files Browse the repository at this point in the history
* update adaptive card templating library

* fix breaking change

* fix linting error

* fix formatting
  • Loading branch information
ElinorW committed Oct 15, 2020
1 parent 571ef64 commit 059acb3
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"files.trimTrailingWhitespace": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.tslint": true
},
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
Expand Down
110 changes: 107 additions & 3 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 @@ -11,7 +11,7 @@
"@uifabric/react-cards": "0.109.101",
"@uifabric/styling": "7.13.1",
"adaptivecards": "1.2.3",
"adaptivecards-templating": "0.1.0-alpha.1",
"adaptivecards-templating": "1.4.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "9.0.0",
"babel-jest": "23.6.0",
Expand Down
28 changes: 17 additions & 11 deletions src/app/services/actions/adaptive-cards-action-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { IAction } from '../../../types/action';
import { IQuery } from '../../../types/query-runner';
import { lookupTemplate } from '../../utils/adaptive-cards-lookup';
import {
FETCH_ADAPTIVE_CARD_ERROR ,
FETCH_ADAPTIVE_CARD_ERROR,
FETCH_ADAPTIVE_CARD_PENDING,
FETCH_ADAPTIVE_CARD_SUCCESS
FETCH_ADAPTIVE_CARD_SUCCESS,
} from '../redux-constants';

export function getAdaptiveCardSuccess(result: string = ''): IAction {
Expand All @@ -18,20 +18,22 @@ export function getAdaptiveCardSuccess(result: string = ''): IAction {
export function getAdaptiveCardError(error: string): IAction {
return {
type: FETCH_ADAPTIVE_CARD_ERROR,
response: error
response: error,
};
}

export function getAdaptiveCardPending(): IAction {
return {
type: FETCH_ADAPTIVE_CARD_PENDING,
response: ''
response: '',
};
}

export function getAdaptiveCard(payload: string, sampleQuery: IQuery): Function {
export function getAdaptiveCard(
payload: string,
sampleQuery: IQuery
): Function {
return async (dispatch: Function) => {

if (!payload) {
// no payload so return empty result
return dispatch(getAdaptiveCardSuccess());
Expand All @@ -51,20 +53,24 @@ export function getAdaptiveCard(payload: string, sampleQuery: IQuery): Function
dispatch(getAdaptiveCardPending());

return fetch(`https://templates.adaptivecards.io/graph.microsoft.com/${templateFileName}`)
.then(resp => resp.json())
.then((resp) => resp.json())
.then((fetchResult) => {
if (fetchResult.error) {
throw (fetchResult.error);
throw fetchResult.error;
}
// create a card from the template
const template = new AdaptiveCardsTemplateAPI.Template(fetchResult);
const context = new AdaptiveCardsTemplateAPI.EvaluationContext();
context.$root = payload;
const context: AdaptiveCardsTemplateAPI.IEvaluationContext = {
$root: payload,
};
AdaptiveCardsTemplateAPI.GlobalSettings.getUndefinedFieldValueSubstitutionString = (
path: string
) => ' ';
const card = template.expand(context);
// give back the result of the card
return dispatch(getAdaptiveCardSuccess(card));
})
.catch(error => {
.catch((error) => {
// something wrong happened
return dispatch(getAdaptiveCardError(error));
});
Expand Down

0 comments on commit 059acb3

Please sign in to comment.