Skip to content

Commit

Permalink
simplify status
Browse files Browse the repository at this point in the history
  • Loading branch information
lastminutediorama committed Aug 21, 2024
1 parent 0f3dd38 commit fba6383
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ <h4>Scenarios</h4>
<app-scenarios-card-list
*ngIf="activeScenarios.length > 0"
[scenarios]="activeScenarios"
[highlightedScenarioRow]="highlightedScenarioRow"
(viewScenario)="viewScenario()"
(selectScenario)="
highlightScenario($event)
Expand All @@ -207,7 +206,6 @@ <h4>Scenarios</h4>
<app-scenarios-card-list
*ngIf="archivedScenarios.length > 0"
[scenarios]="archivedScenarios"
[highlightedScenarioRow]="highlightedScenarioRow"
(viewScenario)="viewScenario()"
(selectScenario)="
highlightScenario($event)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<sg-scenario-card
*ngFor="let s of scenarios"
[selected]="highlightedScenarioRow?.id === s.id"
[name]="s.name"
[creator]="s.creator"
[areas]="s.max_treatment_area"
[created_at]="s.created_at"
[budget]="s.max_budget"
[treatmentPlansCount]="s.tx_plan_count"
[status]="s.scenario_result?.status"
[status]="s.scenario_result?.status || 'PENDING'"
(click)="clickedScenario(s)">
</sg-scenario-card>
Original file line number Diff line number Diff line change
Expand Up @@ -60,69 +60,50 @@ export class ScenarioCardComponent {
@Output() archiveScenario = new EventEmitter();
@Output() clicked = new EventEmitter();

readonly chipsStatus: Record<ScenarioResultStatus, StatusChipStatus> = {
FAILURE: 'failed',
LOADING: 'running',
NOT_STARTED: 'running',
PANIC: 'failed',
PENDING: 'running',
RUNNING: 'running',
SUCCESS: 'success',
TIMED_OUT: 'failed',
};

readonly chipLabel: Record<ScenarioResultStatus, ScenarioResultLabel> = {
FAILURE: 'Failed',
LOADING: 'Running',
NOT_STARTED: 'Running',
PANIC: 'Failed',
PENDING: 'Running',
RUNNING: 'Running',
SUCCESS: 'Done',
TIMED_OUT: 'Failed',
readonly chipsStatus: Record<
ScenarioResultStatus,
{ status: StatusChipStatus; label: ScenarioResultLabel }
> = {
FAILURE: { status: 'failed', label: 'Failed' },
LOADING: { status: 'running', label: 'Running' },
NOT_STARTED: { status: 'running', label: 'Running' },
PANIC: { status: 'failed', label: 'Failed' },
PENDING: { status: 'running', label: 'Running' },
RUNNING: { status: 'running', label: 'Running' },
SUCCESS: { status: 'success', label: 'Done' },
TIMED_OUT: { status: 'failed', label: 'Failed' },
};

hasFailed(): boolean {
if (this.status) {
return this.chipsStatus[this.status] == 'failed';
}
return false;
const failedValues = ['LOADING', 'NOT_STARTED', 'PENDING', 'RUNNING'];
return failedValues.includes(this.status);
}

isRunning(): boolean {
if (this.status) {
return this.chipsStatus[this.status] == 'running';
}
return false;
const runningValues = ['LOADING', 'NOT_STARTED', 'PENDING', 'RUNNING'];
return runningValues.includes(this.status);
}

isDone(): boolean {
if (this.status) {
return this.chipsStatus[this.status] == 'success';
}
return false;
const doneValues = ['SUCCESS'];
return doneValues.includes(this.status);
}

@HostBinding('class.disabled-content')
get disabledContent() {
return this.isRunning();
}

@HostBinding('class.selected')
get isSelected() {
return this.selected;
}

getChipStatus(): StatusChipStatus {
if (this.status) {
return this.chipsStatus[this.status];
return this.chipsStatus[this.status].status;
}
return 'failed';
}

getChipLabel(): ScenarioResultLabel {
if (this.status) {
return this.chipLabel[this.status];
return this.chipsStatus[this.status].label;
}
return 'Failed';
}
Expand Down

0 comments on commit fba6383

Please sign in to comment.