feat: added translations to some of console page elements, empty view when there are 0 logs in console yet.

This commit is contained in:
Aliaksei Tratseuski 2024-04-30 02:49:06 +04:00
parent 8919a50bf3
commit 47f3d5f53c
3 changed files with 49 additions and 21 deletions

View file

@ -47,7 +47,23 @@
"console_page": {
"title": "Console",
"waiting": "Waiting for initialization…",
"copy": "Copy"
"copy": "Copy",
"historyEmpty": "No data yet",
"error":"Error",
"log":"Log",
"rest_api_request":"Rest API Request",
"rest_api_response":"Rest API Response",
"graphql_request":"GraphQL Request",
"graphql_response":"GraphQL Response",
"logged_at": "logged at: ",
"data": "Data",
"erros":"Errors",
"request_data": "Request data",
"headers": "Headers",
"response_data": "Response data",
"context": "Context",
"operation": "Operation",
"variables": "Variables"
},
"about_application_page": {
"title": "About & support",

View file

@ -10,36 +10,35 @@ extension on ConsoleLog {
if (log.uri != null) _KeyValueRow('uri', log.uri.toString()),
// headers bloc
if (log.headers?.isNotEmpty ?? false) const _SectionRow('Headers'),
if (log.headers?.isNotEmpty ?? false)
const _SectionRow('console_page.headers'),
...?log.headers?.entries
.map((final entry) => _KeyValueRow(entry.key, entry.value)),
// data bloc
const _SectionRow('Request data'),
const _SectionRow('console_page.data'),
_DataRow(log.data?.toString()),
],
(final RestApiResponseConsoleLog log) => [
if (log.method != null) _KeyValueRow('method', log.method),
if (log.uri != null) _KeyValueRow('uri', log.uri.toString()),
if (log.statusCode != null)
_KeyValueRow(
'statusCode',
log.statusCode.toString(),
),
_KeyValueRow('statusCode', log.statusCode.toString()),
// data bloc
const _SectionRow('Response data'),
const _SectionRow('console_page.response_data'),
_DataRow(log.data?.toString()),
],
(final GraphQlRequestConsoleLog log) => [
// context
const _SectionRow('Context'),
const _SectionRow('console_page.context'),
_DataRow(log.context?.toString()),
// data
if (log.operation != null) const _SectionRow('Operation'),
if (log.operation != null)
const _SectionRow('console_page.operation'),
_DataRow(log.stringifiedOperation), // errors
if (log.variables?.isNotEmpty ?? false)
const _SectionRow('Variables'),
const _SectionRow('console_page.variables'),
...?log.variables?.entries.map(
(final entry) => _KeyValueRow(
entry.key,
@ -49,10 +48,10 @@ extension on ConsoleLog {
],
(final GraphQlResponseConsoleLog log) => [
// context
const _SectionRow('Context'),
const _SectionRow('console_page.context'),
_DataRow(log.context?.toString()),
// data
if (log.data != null) const _SectionRow('Data'),
if (log.data != null) const _SectionRow('console_page.data'),
...?log.data?.entries.map(
(final entry) => _KeyValueRow(
entry.key,
@ -60,7 +59,8 @@ extension on ConsoleLog {
),
),
// errors
if (log.errors?.isNotEmpty ?? false) const _SectionRow('Errors'),
if (log.errors?.isNotEmpty ?? false)
const _SectionRow('console_page.errors'),
...?log.errors?.map(
(final entry) => _KeyValueRow(
entry.message,
@ -94,8 +94,7 @@ class ConsoleItemDialog extends StatelessWidget {
children: [
Row(
children: [
/// TODO(misterfourtytwo): maybe should add translations later
const Text('logged at: '),
Text('logged_at'.tr()),
SelectableText(
log.timeString,
style: const TextStyle(
@ -160,6 +159,7 @@ class _DataRow extends StatelessWidget {
class _SectionRow extends StatelessWidget {
const _SectionRow(this.title);
final String title;
@override
@ -175,7 +175,7 @@ class _SectionRow extends StatelessWidget {
),
),
child: SelectableText(
title,
title.tr(),
style: const TextStyle(
fontWeight: FontWeight.w800,
fontSize: 20,

View file

@ -78,12 +78,14 @@ class _ConsolePageState extends State<ConsolePage> {
final AsyncSnapshot<void> snapshot,
) {
if (snapshot.hasData) {
final List<ConsoleLog> messages =
final List<ConsoleLog> logs =
getIt.get<ConsoleModel>().logs;
return _ConsoleViewLoaded(
logs: messages,
);
return logs.isEmpty
? const _ConsoleViewEmpty()
: _ConsoleViewLoaded(
logs: logs,
);
}
return const _ConsoleViewLoading();
@ -115,6 +117,16 @@ class _ConsoleViewLoading extends StatelessWidget {
);
}
class _ConsoleViewEmpty extends StatelessWidget {
const _ConsoleViewEmpty();
@override
Widget build(final BuildContext context) => Align(
alignment: Alignment.topCenter,
child: Text('console_page.historyEmpty'.tr()),
);
}
class _ConsoleViewLoaded extends StatelessWidget {
const _ConsoleViewLoaded({required this.logs});