diff --git a/web/src/containers/Settings/internal/hooks/useAddPermission.tsx b/web/src/containers/Settings/internal/hooks/useAddPermission.tsx index f2d1761..c692bad 100644 --- a/web/src/containers/Settings/internal/hooks/useAddPermission.tsx +++ b/web/src/containers/Settings/internal/hooks/useAddPermission.tsx @@ -9,7 +9,7 @@ import { PermissionsContext } from '../../../../context/permissionsContext' import { findExistingPermission, findUpdatingPermission -} from '../../../../utils/helper' +} from '../../../../utils' const useAddPermission = () => { const { diff --git a/web/src/utils/index.ts b/web/src/utils/index.ts new file mode 100644 index 0000000..f5f22bb --- /dev/null +++ b/web/src/utils/index.ts @@ -0,0 +1,3 @@ +export * from './log' +export * from './types' +export * from './helper' diff --git a/web/src/utils/log.ts b/web/src/utils/log.ts new file mode 100644 index 0000000..a69ffe4 --- /dev/null +++ b/web/src/utils/log.ts @@ -0,0 +1,41 @@ +export const parseErrorsAndWarnings = (log: string) => { + const logLines = log.split('\n') + const errorLines: string[] = [] + const warningLines: string[] = [] + + logLines.forEach((line: string, index: number) => { + // INFO: check if content in element starts with ERROR + if (/<.*>ERROR/gm.test(line)) { + const errorLine = line.substring(line.indexOf('E'), line.length - 1) + errorLines.push(errorLine) + } + + // INFO: check if line starts with ERROR + else if (/^ERROR/gm.test(line)) { + errorLines.push(line) + + logLines[index] = + `` + + logLines[index] + + '' + } + + // INFO: check if content in element starts with WARNING + else if (/<.*>WARNING/gm.test(line)) { + const warningLine = line.substring(line.indexOf('W'), line.length - 1) + warningLines.push(warningLine) + } + + // INFO: check if line starts with WARNING + else if (/^WARNING/gm.test(line)) { + warningLines.push(line) + + logLines[index] = + `` + + logLines[index] + + '' + } + }) + + return { errors: errorLines, warnings: warningLines, logLines } +} diff --git a/web/src/utils/types.ts b/web/src/utils/types.ts index c733e23..c18cde3 100644 --- a/web/src/utils/types.ts +++ b/web/src/utils/types.ts @@ -39,3 +39,9 @@ export interface TreeNode { isFolder: boolean children: Array } + +export interface LogObject { + body: string + errors: string[] + warnings: string[] +}