fix: removes the dependency on parse-link-header

This commit is contained in:
Erik Jan de Wit 2020-04-02 17:21:59 +02:00 committed by Stan Silvert
parent e093fa218d
commit bbc2169127
5 changed files with 29 additions and 49 deletions

View file

@ -17,7 +17,7 @@
import * as React from 'react';
import {AxiosResponse} from 'axios';
import * as parse from 'parse-link-header';
import parse from '../../util/ParseLink';
import { Button, Level, LevelItem, Stack, StackItem, Tab, Tabs, TextInput } from '@patternfly/react-core';
@ -187,14 +187,14 @@ export class MyResourcesPage extends React.Component<MyResourcesPageProps, MyRes
private parseResourceResponse(response: AxiosResponse<Resource[]>): PaginatedResources {
const links: string = response.headers.link;
const parsed: (parse.Links | null) = parse(links);
const parsed = parse(links);
let next = '';
let prev = '';
if (parsed !== null) {
if (parsed.hasOwnProperty('next')) next = parsed.next.url;
if (parsed.hasOwnProperty('prev')) prev = parsed.prev.url;
if (parsed.next) next = parsed.next;
if (parsed.prev) prev = parsed.prev;
}
const resources = response.data;

View file

@ -0,0 +1,22 @@
export interface Links {
prev?: string;
next?: string;
}
function parse(linkHeader: string | undefined): Links {
if (!linkHeader) return {};
const links = linkHeader.split(/,\s*</);
return links.reduce<Links>((acc: Links, link: string): Links => {
const matcher = link.match(/<?([^>]*)>(.*)/);
if (!matcher) return {};
const linkUrl = matcher[1];
const rel = matcher[2].match(/\s*(.+)\s*=\s*"?([^"]+)"?/);
if (rel) {
acc[rel[2]] = linkUrl;
}
return acc;
}, {});
}
export default parse;

View file

@ -2978,7 +2978,8 @@
"object-keys": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz",
"integrity": "sha1-HEfyct8nfzsdrwYWd9nILiMixg4="
"integrity": "sha1-HEfyct8nfzsdrwYWd9nILiMixg4=",
"dev": true
},
"object.fromentries": {
"version": "2.0.0",
@ -3075,21 +3076,6 @@
"error-ex": "^1.2.0"
}
},
"parse-link-header": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parse-link-header/-/parse-link-header-1.0.1.tgz",
"integrity": "sha1-vt/g0hGK64S+deewJUGeyKYRQKc=",
"requires": {
"xtend": "~4.0.1"
},
"dependencies": {
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha1-u3J3n1+kZRhrH0OPZ0+jR/2121Q="
}
}
},
"parse-node-version": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parse-node-version/-/parse-node-version-1.0.1.tgz",
@ -3901,22 +3887,6 @@
"resolved": "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz",
"integrity": "sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI="
},
"url": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz",
"integrity": "sha1-ODjpfPxgUh63PFJajlW/3Z4uKPE=",
"requires": {
"punycode": "1.3.2",
"querystring": "0.2.0"
},
"dependencies": {
"punycode": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz",
"integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0="
}
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",

View file

@ -16,16 +16,12 @@
"@types/node": "^12.7.2",
"axios": "^0.19.0",
"moment": "^2.22.2",
"object-keys": "^1.1.1",
"parse-link-header": "^1.0.1",
"punycode": "^2.1.1",
"querystring": "^0.2.0",
"react": "^16.8.5",
"react-dom": "^16.8.5",
"react-router-dom": "^4.3.1",
"systemjs": "^0.20.17",
"systemjs-plugin-babel": "0.0.25",
"url": "^0.11.0"
"systemjs-plugin-babel": "0.0.25"
},
"devDependencies": {
"@types/parse-link-header": "^1.0.0",

View file

@ -36,14 +36,6 @@
'axios': 'npm:axios/dist/axios.min.js',
'history': 'npm:history/umd/history.min.js',
// libraries required for parse-link-header to work
'parse-link-header': 'npm:parse-link-header/index.js',
'xtend': 'npm:xtend/index.js',
'querystring': 'npm:querystring/index.js',
'url': 'npm:url/url.js',
'punycode': 'npm:punycode/punycode.js',
'object-keys': 'npm:object-keys/index.js',
},
bundles: {