Skip to content

Commit c67c59a

Browse files
committed
add code to errors so you can track your errors
1 parent f2d56c4 commit c67c59a

File tree

6 files changed

+104
-42
lines changed

6 files changed

+104
-42
lines changed

config/doctrine/Record.orm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<index name="date_idx" columns="status,date"/>
1212
<index name="done_idx" columns="project_id,status"/>
1313
<index name="hash_idx" columns="hash,status,date"/>
14+
<index name="code_idx" columns="status,code,date"/>
1415
</indexes>
1516
<discriminator-column name="discr" type="string"/>
1617
<discriminator-map>
@@ -26,6 +27,7 @@
2627
<field name="date" type="datetime" nullable="false"/>
2728
<field name="status" type="string" length="50"/>
2829
<field name="hash" type="string" length="32" nullable="true"/>
30+
<field name="code" type="string" length="15" nullable="true"/>
2931
<field name="metadata" type="array" nullable="true"/>
3032
<many-to-one field="project" target-entity="BugCatcher\Entity\Project">
3133
<join-column name="project_id" referenced-column-name="id" on-delete="CASCADE" nullable="false"/>

src/Entity/Record.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ abstract class Record {
2626

2727
protected ?string $hash = null;
2828

29+
protected ?string $code = null;
30+
2931

3032
#[Groups(['record:write'])]
3133
#[Assert\NotBlank(groups: ['api'])]
@@ -129,6 +131,16 @@ public function setHash(?string $hash): self {
129131
return $this;
130132
}
131133

134+
public function getCode(): ?string {
135+
return $this->code;
136+
}
137+
138+
public function setCode(?string $code): self {
139+
$this->code = $code;
140+
141+
return $this;
142+
}
143+
132144
abstract function calculateHash(): ?string;
133145

134146
abstract function getComponentName(): string;

src/Twig/Components/LogList.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ final class LogList extends AbstractController
3737
public ?DateTimeInterface $from = null;
3838
#[ExposeInTemplate]
3939
public ?DateTimeInterface $to = null;
40+
#[LiveProp(writable: true)]
41+
public string $query = '';
4042

4143
public function __construct(
4244
private readonly RecordRepository $recordRepo,
@@ -61,17 +63,24 @@ public function init(): void
6163
$projects = $this->getUser()->getActiveProjects()->toArray();
6264
}
6365
/** @var Record[] $records */
64-
$records = $this->recordRepo->createQueryBuilder("record")
65-
->where("record.status like :status")
66-
->andWhere("record INSTANCE OF :class")
67-
->andWhere("record.project IN (:projects)")
68-
->setParameter("status", $this->status . '%')
69-
->setParameter("class", $keys)
70-
->setParameter('projects',
71-
array_map(fn(Project $p) => $p->getId()->toBinary(), $projects)
72-
)
73-
->orderBy("record.date", "DESC")
74-
->setMaxResults(100)
66+
$qb = $this->recordRepo->createQueryBuilder("record")
67+
->where("record.status like :status")
68+
->andWhere("record INSTANCE OF :class")
69+
->andWhere("record.project IN (:projects)")
70+
->setParameter("status", $this->status . '%')
71+
->setParameter("class", $keys)
72+
->setParameter('projects',
73+
array_map(fn(Project $p) => $p->getId()->toBinary(), $projects)
74+
)
75+
->orderBy("record.date", "DESC")
76+
->setMaxResults(100);
77+
78+
if ($this->query) {
79+
$qb->andWhere("record.code = :query")
80+
->setParameter("query", $this->query);
81+
}
82+
83+
$records = $qb
7584
->getQuery()->getResult();
7685

7786
if ($records === []) {
Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,44 @@
11
<div{{ attributes.defaults({
2-
class:'my-3 p-3 bg-body rounded shadow-sm'
2+
class:'my-3 p-3 bg-body rounded shadow-sm'
33
}) }}>
4-
{{ this.init }}
5-
{% set logs = this.logs %}
6-
{% if logs|length %}
7-
<div class="nav justify-content-end pb-1">
8-
{% if app.request.attributes.get("project") is not null %}
9-
<a href="{{ path('bug_catcher.dashboard.index') }}" class="btn btn-primary btn-sm mx-1">
10-
<twig:ux:icon name="lucide:filter-x" width="20px" height="20px"/>
11-
{{ 'Clear filter'|trans }}
12-
</a>
13-
{% endif %}
14-
<button class="btn btn-outline-secondary btn-sm" aria-current="page"
15-
data-action="live#action"
16-
data-live-action-param="clearAll"
17-
data-live-from-param="{{ this.to|date('Y-m-d-H-i-s') }}"
18-
data-live-to-param="{{ this.from|date('Y-m-d-H-i-s') }}"
19-
>
20-
<twig:ux:icon name="game-icons:magic-broom" width="20px" height="20px"/>
21-
{{ 'Fix all'|trans }}
22-
</button>
23-
</div>
24-
<ul class="list-group">
25-
{% for log in logs %}
26-
{{ component(log.componentName, {log: log, status: status, key:log.id}) }}
27-
{% endfor %}
28-
</ul>
29-
{% else %}
30-
<h6 class="border-bottom pb-1 mb-0">Your are happy, No Errors
31-
<twig:ux:icon name="game-icons:schrodingers-cat-alive" width="30px" height="30px"/>
32-
</h6>
33-
{% endif %}
4+
{{ this.init }}
5+
{% set logs = this.logs %}
6+
{% if logs|length or query is not empty %}
7+
<div class="nav d-flex justify-content-between pb-1">
8+
<div>
9+
<input
10+
type="search"
11+
data-model="query"
12+
class="form-control form-control-sm"
13+
placeholder="{{ 'Error code'|trans }}"
14+
>
15+
</div>
16+
<div>
17+
{% if app.request.attributes.get("project") is not null %}
18+
<a href="{{ path('bug_catcher.dashboard.index') }}" class="btn btn-primary btn-sm mx-1">
19+
<twig:ux:icon name="lucide:filter-x" width="20px" height="20px"/>
20+
{{ 'Clear filter'|trans }}
21+
</a>
22+
{% endif %}
23+
<button class="btn btn-outline-secondary btn-sm" aria-current="page"
24+
data-action="live#action"
25+
data-live-action-param="clearAll"
26+
data-live-from-param="{{ this.to|date('Y-m-d-H-i-s') }}"
27+
data-live-to-param="{{ this.from|date('Y-m-d-H-i-s') }}"
28+
>
29+
<twig:ux:icon name="game-icons:magic-broom" width="20px" height="20px"/>
30+
{{ 'Fix all'|trans }}
31+
</button>
32+
</div>
33+
</div>
34+
<ul class="list-group">
35+
{% for log in logs %}
36+
{{ component(log.componentName, {log: log, status: status, key:log.id}) }}
37+
{% endfor %}
38+
</ul>
39+
{% else %}
40+
<h6 class="border-bottom pb-1 mb-0">Your are happy, No Errors
41+
<twig:ux:icon name="game-icons:schrodingers-cat-alive" width="30px" height="30px"/>
42+
</h6>
43+
{% endif %}
3444
</div>

templates/components/LogList/RecordLog.html.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<a href="{{ path('bug_catcher.dashboard.index',{project:log.project.id,status:this.status}) }}"
2323
class="badge text-bg-primary text-decoration-none">{{ log.project.name }}</a>
2424
<span class="badge text-bg-{{ status }} ">{{ log.count }}</span>
25+
{% if log.code is not empty %}
26+
<span class="badge text-bg-default text-primary border border-primary">{{ log.code }}</span>
27+
{% endif %}
2528
<div class="d-inline text-break">{{ log.message }}</div>
2629
</div>
2730
{% if is_granted('ROLE_DEVELOPER') %}

tests/Functional/Api/CronRecordTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,30 @@ public function testSendPlainRecord(): void {
3939
])
4040
->assertStatus(201);
4141
}
42+
43+
public function testSendPlainRecordWithCode(): void {
44+
[$browser] = $this->browser([]);
45+
46+
ProjectFactory::createOne([
47+
"code" => "testProject",
48+
]);
49+
50+
$browser
51+
->post("/api/record_cron", [
52+
"headers" => [
53+
"Content-Type" => "application/json",
54+
],
55+
"body" => json_encode([
56+
"level" => 500,
57+
"command" => "app:test-cron",
58+
"code" => "testCode",
59+
"lastStart" => (new DateTime("2022-01-01 10:00:00"))->format(DateTime::RFC3339_EXTENDED),
60+
"lastEnd" => (new DateTime("2022-01-01 10:00:01"))->format(DateTime::RFC3339_EXTENDED),
61+
"interval" => 360,
62+
"estimated" => 10,
63+
"projectCode" => "testProject",
64+
]),
65+
])
66+
->assertStatus(201);
67+
}
4268
}

0 commit comments

Comments
 (0)