-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve UX and states lifecycle
- Loading branch information
1 parent
254d251
commit f255498
Showing
20 changed files
with
467 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function isEmpty(value: string | null | undefined) { | ||
// eslint-disable-next-line no-null/no-null | ||
return value === undefined || value === null || value.trim() === '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { mapHerokuApiReleaseToHerokuRelease } from './utils' | ||
import { InternalError } from '../InternalError' | ||
|
||
import type { HerokuRelease } from './types' | ||
import type { HerokuApi } from '../../types' | ||
|
||
export class HerokuReleaseManager { | ||
#lastRelease: HerokuRelease | undefined | ||
#releases: HerokuRelease[] | ||
|
||
get lastRelease(): HerokuRelease | undefined { | ||
return this.#lastRelease | ||
} | ||
|
||
constructor(stdoutJson: string) { | ||
this.#releases = [] | ||
|
||
this.updateReleases(stdoutJson) | ||
} | ||
|
||
updateReleases(stdoutJson: string): void { | ||
try { | ||
const herokuApiReleases: HerokuApi.Release[] = JSON.parse(stdoutJson.trim()) | ||
|
||
this.#releases = herokuApiReleases.map(mapHerokuApiReleaseToHerokuRelease) | ||
} catch (err) { | ||
throw new InternalError(`An error happened while parsing:\n\`${stdoutJson}\`.`, err) | ||
} | ||
|
||
this.#updateLastRelease() | ||
} | ||
|
||
#updateLastRelease(): void { | ||
this.#lastRelease = this.#releases.filter(({ isSlugLess }) => !isSlugLess).at(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { HerokuApi } from '../../types' | ||
|
||
export interface HerokuRelease { | ||
readonly apiData: HerokuApi.Release | ||
readonly createdAt: Date | ||
readonly description: string | ||
readonly isCurrent: boolean | ||
readonly isSlugLess: boolean | ||
readonly status: HerokuApi.ReleaseStatus | ||
readonly updatedAt: Date | ||
readonly version: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { HerokuRelease } from './types' | ||
import type { HerokuApi } from '../../types' | ||
|
||
export function mapHerokuApiReleaseToHerokuRelease(herokuApiRelease: HerokuApi.Release): HerokuRelease { | ||
return Object.freeze({ | ||
apiData: Object.freeze(herokuApiRelease), | ||
createdAt: new Date(herokuApiRelease.created_at), | ||
description: herokuApiRelease.description, | ||
isCurrent: herokuApiRelease.current, | ||
// eslint-disable-next-line no-null/no-null | ||
isSlugLess: herokuApiRelease.slug === null, | ||
status: herokuApiRelease.status, | ||
updatedAt: new Date(herokuApiRelease.updated_at), | ||
version: herokuApiRelease.version, | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.