Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Moved report helpers to component
Browse files Browse the repository at this point in the history
roll committed Nov 12, 2021
1 parent ab6ecd0 commit a4834ad
Showing 2 changed files with 15 additions and 18 deletions.
18 changes: 15 additions & 3 deletions src/components/ReportTask.tsx
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ import React from 'react'
import classNames from 'classnames'
import { ReportError } from './ReportError'
import { IReportTask, IReportError } from '../report'
import * as helpers from '../helpers'

export interface IReportTaskProps {
task: IReportTask
@@ -12,8 +11,8 @@ export interface IReportTaskProps {

export function ReportTask(props: IReportTaskProps) {
const { task, taskNumber, tasksCount } = props
const taskFile = helpers.removeBaseUrl(task.resource.path || '')
const splitTableFile = helpers.splitFilePath(taskFile)
const taskFile = removeBaseUrl(task.resource.path || '')
const splitTableFile = splitFilePath(taskFile)
const reportErrors = getReportErrors(task)
return (
<div className={classNames({ file: true, valid: task.valid, invalid: !task.valid })}>
@@ -57,6 +56,19 @@ export function ReportTask(props: IReportTaskProps) {

// Helpers

export function removeBaseUrl(text: string) {
return text.replace(/https:\/\/raw\.githubusercontent\.com\/\S*?\/\S*?\/\S*?\//g, '')
}

export function splitFilePath(path: string) {
const parts = path.split('/')
return {
name: parts.pop(),
base: parts.join('/'),
sep: parts.length ? '/' : '',
}
}

export function getReportErrors(task: IReportTask) {
const reportErrors: { [code: string]: IReportError } = {}
for (const error of task.errors) {
15 changes: 0 additions & 15 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -5,21 +5,6 @@ import { Table } from 'tableschema'
import { IDict } from './common'
import * as config from './config'

// General

export function removeBaseUrl(text: string) {
return text.replace(/https:\/\/raw\.githubusercontent\.com\/\S*?\/\S*?\/\S*?\//g, '')
}

export function splitFilePath(path: string) {
const parts = path.split('/')
return {
name: parts.pop(),
base: parts.join('/'),
sep: parts.length ? '/' : '',
}
}

// Schema

export async function importSchema(source?: string | File, schema?: IDict | File) {

0 comments on commit a4834ad

Please sign in to comment.