Skip to content

Commit

Permalink
fix: correct issue of data being null/empty (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolftousen authored Aug 20, 2024
1 parent 5830bbc commit db95192
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/ChangeFailureRate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ const ChangeFailureRate : React.FC<ChartProps> = (props: ChartProps) => {
const maxBarWidth = (1 / ((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24))) * 33 + "%"

const organizeData = (data: DoraRecord[]) => {
if(data.length === 0) {
if(!data || data.length === 0) {
setNoData(true)
setRepositories([])
setGraphData([])
setColors([])
setLoading(false)
return
}

const extractedData = extractChangeFailureRatePerDay(props, data)
Expand Down
6 changes: 5 additions & 1 deletion src/ChangeLeadTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ const ChangeLeadTime : React.FC<ChartProps> = (props: ChartProps) => {
const ticks = generateTicks(startDate, endDate, 5)

const organizeData = useCallback((data: DoraRecord[]) => {
if(data.length === 0) {
if(!data || data.length === 0) {
setNoData(true)
setGraphData(new Map<string, DoraRecord[]>())
setColors([])
setLoading(false)
return
}

const extractedData = extractChangeLeadTimePerRepository(data)
Expand Down
8 changes: 7 additions & 1 deletion src/DeploymentFrequency.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ const DeploymentFrequency : React.FC<ChartProps> = (props: ChartProps) => {
const maxBarWidth = (1 / ((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24))) * 33 + "%"

const organizeData = (data: DoraRecord[]) => {
if(data.length === 0) {
if(!data || data.length === 0) {
setNoData(true)
setRepositories([])
setGraphData([])
setColors([])
setLoading(false)
setMaxDeploys(0)
return
}

const [extractedData, deploys] = extractDeploymentsPerDay(props, data)
Expand Down
15 changes: 10 additions & 5 deletions src/Helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,17 @@ export const dateToUtc = (date: Date, dateOnly: boolean = true) => {
}

export const fetchData = async (props: ChartProps, onSuccess: (data: any) => void, onFailure?: (data: any) => void) => {
if(props.data) {
if(!props.api && !props.data) {
onSuccess([])
return
} else if(props.data) {
let data = props.data

if(data.records && data.records.length === 0) {
onSuccess([])
return
}

let parsedData: any = {}

if(typeof data === "string") {
Expand All @@ -236,10 +245,6 @@ export const fetchData = async (props: ChartProps, onSuccess: (data: any) => voi
return
}

if(!props.api) {
return
}

const start = props.start ? dateToUtc(props.start) : getDateDaysInPastUtc(31)
const end = props.end ? dateToUtc(props.end) : getDateDaysInPastUtc(1)

Expand Down
10 changes: 8 additions & 2 deletions src/RecoverTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ const RecoverTime: React.FC<ChartProps> = (props: ChartProps) => {
const ticks = generateTicks(startDate, endDate, 5);

const organizeData = (data: DoraRecord[]) => {
if (data.length === 0) {
setNoData(true);
if (!data || data.length === 0) {
setNoData(true)
setRepositories([])
setGraphData([])
setColors([])
setLoading(false)
setYLabel(" hrs")
return
}

const extractedData = extractAvgRecoverTimePerDay(props, data);
Expand Down

0 comments on commit db95192

Please sign in to comment.