Skip to content

Commit

Permalink
Bug/4612 ie11 jsonptr (#4740)
Browse files Browse the repository at this point in the history
* downgrade json-ptr to v1.2.0 for ie11

* update package-lock

* switch from json-ptr to jsonpointer
  • Loading branch information
nkylstad authored Sep 8, 2020
1 parent 0cfb303 commit 2e49c9c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "altinn-app-frontend",
"version": "2.1.16",
"version": "2.1.17",
"description": "",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -31,7 +31,7 @@
"axios": "~0.20.0",
"dot-object": "~2.1.3",
"immutability-helper": "2.7.0",
"json-ptr": "~1.3.2",
"jsonpointer": "4.1.0",
"lodash.isequal": "~4.5.0",
"moment": "~2.27.0",
"react": "~16.13.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { object } from 'dot-object';
import { ILayout, ILayoutGroup } from 'src/features/form/layout';

const jsonPtr = require('json-ptr');
const JsonPointer = require('jsonpointer');

/**
* Converts the formdata in store (that is flat) to a JSON
Expand Down Expand Up @@ -41,8 +41,8 @@ export const filterFormData = (data: any, model: any): any => {
const filteredResult: any = {};
const rootKey = Object.keys(model.properties)[0];
const modelPath = model.properties[rootKey].$ref.slice(1);
const pointer = jsonPtr.create(modelPath);
const root = pointer.get(model);
const pointer = JsonPointer.compile(modelPath);
const root: any = pointer.get(model);
Object.keys(data).forEach((key: string) => {
const formDataKey = getKeyWithoutIndex(key);
const formDataRoot = formDataKey.split('.')[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getLanguageFromKey, getParsedLanguageFromKey } from 'altinn-shared/utils';
import moment from 'moment';
import Ajv from 'ajv';
import { JsonPointer } from 'json-ptr';
import { IComponentValidations, IValidations, IComponentBindingValidation, ITextResource, IValidationResult, ISchemaValidator, IRepeatingGroups } from 'src/types';
import { ILayout, ILayoutComponent, ILayoutGroup } from '../features/form/layout';
import { IValidationIssue, Severity } from '../types';
Expand All @@ -13,13 +12,15 @@ import { getKeyWithoutIndex } from './databindings';
// eslint-disable-next-line import/no-cycle
import { matchLayoutComponent } from './layout';

const JsonPointer = require('jsonpointer');

export function createValidator(schema: any): ISchemaValidator {
const ajv = new Ajv({ allErrors: true, coerceTypes: true });
ajv.addFormat('year', /^[0-9]{4}$/);
ajv.addSchema(schema, 'schema');
const rootKey = Object.keys(schema.properties)[0];
const rootElementPath = schema.properties[rootKey].$ref;
const rootPtr = JsonPointer.create(rootElementPath);
const rootPtr = JsonPointer.compile(rootElementPath.substr(1));
const rootElement = rootPtr.get(schema);
const schemaValidator: ISchemaValidator = {
validator: ajv,
Expand Down Expand Up @@ -335,18 +336,18 @@ export function getSchemaPart(dataModelPath: string[], subSchema: any, mainSchem
if (subSchema.properties && subSchema.properties[dataModelRoot] && dataModelPath && dataModelPath.length !== 0) {
const localRootElement = subSchema.properties[dataModelRoot];
if (localRootElement.$ref) {
const childSchemaPtr = JsonPointer.create(localRootElement.$ref);
const childSchemaPtr = JsonPointer.compile(localRootElement.$ref.substr(1));
return getSchemaPart(dataModelPath.slice(1), childSchemaPtr.get(mainSchema), mainSchema);
}
if (localRootElement.items && localRootElement.items.$ref) {
const childSchemaPtr = JsonPointer.create(localRootElement.items.$ref);
const childSchemaPtr = JsonPointer.compile(localRootElement.items.$ref.substr(1));
return getSchemaPart(dataModelPath.slice(1), childSchemaPtr.get(mainSchema), mainSchema);
}
return localRootElement;
}

if (subSchema.$ref) {
const ptr = JsonPointer.create(subSchema.$ref);
const ptr = JsonPointer.compile(subSchema.$ref.substr(1));
return getSchemaPart(dataModelPath.slice(1), ptr.get(mainSchema), mainSchema);
}

Expand Down

0 comments on commit 2e49c9c

Please sign in to comment.