mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
Merged submission module code
This commit is contained in:
41
src/app/submission/utils/parseSectionErrorPaths.ts
Normal file
41
src/app/submission/utils/parseSectionErrorPaths.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { hasValue } from '../../shared/empty.util';
|
||||
|
||||
export interface SectionErrorPath {
|
||||
sectionId: string;
|
||||
fieldId?: string;
|
||||
fieldIndex?: number;
|
||||
originalPath: string;
|
||||
}
|
||||
|
||||
const regex = /([^\/]+)/g;
|
||||
// const regex = /\/sections\/(.*)\/(.*)\/(.*)/;
|
||||
const regexShort = /\/sections\/(.*)/;
|
||||
|
||||
/**
|
||||
* the following method accept an array of section path strings and return a path object
|
||||
* @param {string | string[]} path
|
||||
* @returns {SectionErrorPath[]}
|
||||
*/
|
||||
const parseSectionErrorPaths = (path: string | string[]): SectionErrorPath[] => {
|
||||
const paths = typeof path === 'string' ? [path] : path;
|
||||
|
||||
return paths.map((item) => {
|
||||
if (item.match(regex) && item.match(regex).length > 2) {
|
||||
return {
|
||||
sectionId: item.match(regex)[1],
|
||||
fieldId: item.match(regex)[2],
|
||||
fieldIndex: hasValue(item.match(regex)[3]) ? +item.match(regex)[3] : 0,
|
||||
originalPath: item,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
sectionId: item.match(regexShort)[1],
|
||||
originalPath: item,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default parseSectionErrorPaths;
|
Reference in New Issue
Block a user