mirror of
https://github.com/foss42/apidash.git
synced 2025-12-03 03:17:00 +08:00
feat: enhance EditAuthType to support read-only in history view
This commit is contained in:
@@ -39,11 +39,12 @@ class HistoryRequestPane extends ConsumerWidget {
|
|||||||
.select((value) => value?.httpRequestModel.hasQuery)) ??
|
.select((value) => value?.httpRequestModel.hasQuery)) ??
|
||||||
false;
|
false;
|
||||||
|
|
||||||
final scriptsLength = ref.watch(selectedHistoryRequestModelProvider
|
final hasAuth = ref.watch(selectedHistoryRequestModelProvider.select(
|
||||||
.select((value) => value?.preRequestScript?.length)) ??
|
(value) =>
|
||||||
ref.watch(selectedHistoryRequestModelProvider
|
value?.httpRequestModel.authModel?.type != APIAuthType.none));
|
||||||
.select((value) => value?.postRequestScript?.length)) ??
|
|
||||||
0;
|
final authModel = ref.watch(selectedHistoryRequestModelProvider
|
||||||
|
.select((value) => value?.httpRequestModel.authModel));
|
||||||
|
|
||||||
return switch (apiType) {
|
return switch (apiType) {
|
||||||
APIType.rest => RequestPane(
|
APIType.rest => RequestPane(
|
||||||
@@ -72,6 +73,10 @@ class HistoryRequestPane extends ConsumerWidget {
|
|||||||
rows: paramsMap,
|
rows: paramsMap,
|
||||||
keyName: kNameURLParam,
|
keyName: kNameURLParam,
|
||||||
),
|
),
|
||||||
|
EditAuthType(
|
||||||
|
authModel: authModel,
|
||||||
|
readOnly: true,
|
||||||
|
),
|
||||||
RequestDataTable(
|
RequestDataTable(
|
||||||
rows: headersMap,
|
rows: headersMap,
|
||||||
keyName: kNameHeader,
|
keyName: kNameHeader,
|
||||||
|
|||||||
@@ -9,22 +9,35 @@ import 'package:apidash_core/apidash_core.dart';
|
|||||||
import 'package:apidash/providers/providers.dart';
|
import 'package:apidash/providers/providers.dart';
|
||||||
|
|
||||||
class EditAuthType extends ConsumerWidget {
|
class EditAuthType extends ConsumerWidget {
|
||||||
const EditAuthType({super.key});
|
final AuthModel? authModel;
|
||||||
|
final bool readOnly;
|
||||||
|
|
||||||
|
const EditAuthType({
|
||||||
|
super.key,
|
||||||
|
this.authModel,
|
||||||
|
this.readOnly = false,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final selectedRequest = ref.read(selectedRequestModelProvider);
|
final AuthModel? currentAuthData;
|
||||||
|
final APIAuthType currentAuthType;
|
||||||
|
|
||||||
if (selectedRequest == null) {
|
if (authModel != null) {
|
||||||
return const SizedBox.shrink();
|
currentAuthData = authModel;
|
||||||
|
currentAuthType = authModel!.type;
|
||||||
|
} else {
|
||||||
|
final selectedRequest = ref.read(selectedRequestModelProvider);
|
||||||
|
if (selectedRequest == null) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentAuthType = ref.watch(
|
||||||
|
selectedRequestModelProvider.select((request) =>
|
||||||
|
request?.httpRequestModel?.authModel?.type ?? APIAuthType.none),
|
||||||
|
);
|
||||||
|
currentAuthData = selectedRequest.httpRequestModel?.authModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
final currentAuthType = ref.watch(
|
|
||||||
selectedRequestModelProvider
|
|
||||||
.select((request) => request?.authModel?.type ?? APIAuthType.none),
|
|
||||||
);
|
|
||||||
final currentAuthData = selectedRequest.authModel;
|
|
||||||
|
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
@@ -40,31 +53,53 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
height: 8,
|
height: 8,
|
||||||
),
|
),
|
||||||
ADPopupMenu<APIAuthType>(
|
if (readOnly)
|
||||||
value: currentAuthType.name.capitalize(),
|
Container(
|
||||||
values: const [
|
padding:
|
||||||
(APIAuthType.none, 'None'),
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
(APIAuthType.basic, 'Basic'),
|
decoration: BoxDecoration(
|
||||||
(APIAuthType.apiKey, 'API Key'),
|
color: Theme.of(context).colorScheme.surfaceContainerLowest,
|
||||||
(APIAuthType.bearer, 'Bearer'),
|
borderRadius: BorderRadius.circular(8),
|
||||||
(APIAuthType.jwt, 'JWT'),
|
border: Border.all(
|
||||||
(APIAuthType.digest, 'Digest'),
|
color:
|
||||||
(APIAuthType.oauth1, 'OAuth 1.0'),
|
Theme.of(context).colorScheme.outline.withOpacity(0.3),
|
||||||
(APIAuthType.oauth2, 'OAuth 2.0'),
|
),
|
||||||
],
|
),
|
||||||
tooltip: "Select Authentication Type",
|
child: Text(
|
||||||
isOutlined: true,
|
currentAuthType.name.toUpperCase(),
|
||||||
onChanged: (APIAuthType? newType) {
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
final selectedRequest = ref.read(selectedRequestModelProvider);
|
fontWeight: FontWeight.w500,
|
||||||
if (newType != null) {
|
color: Theme.of(context).colorScheme.primary,
|
||||||
ref.read(collectionStateNotifierProvider.notifier).update(
|
),
|
||||||
authData: selectedRequest?.authModel
|
),
|
||||||
?.copyWith(type: newType) ??
|
)
|
||||||
AuthModel(type: newType),
|
else
|
||||||
);
|
ADPopupMenu<APIAuthType>(
|
||||||
}
|
value: currentAuthType.name.capitalize(),
|
||||||
},
|
values: const [
|
||||||
),
|
(APIAuthType.none, 'None'),
|
||||||
|
(APIAuthType.basic, 'Basic'),
|
||||||
|
(APIAuthType.apiKey, 'API Key'),
|
||||||
|
(APIAuthType.bearer, 'Bearer'),
|
||||||
|
(APIAuthType.jwt, 'JWT'),
|
||||||
|
(APIAuthType.digest, 'Digest'),
|
||||||
|
(APIAuthType.oauth1, 'OAuth 1.0'),
|
||||||
|
(APIAuthType.oauth2, 'OAuth 2.0'),
|
||||||
|
],
|
||||||
|
tooltip: "Select Authentication Type",
|
||||||
|
isOutlined: true,
|
||||||
|
onChanged: (APIAuthType? newType) {
|
||||||
|
final selectedRequest =
|
||||||
|
ref.read(selectedRequestModelProvider);
|
||||||
|
if (newType != null) {
|
||||||
|
ref.read(collectionStateNotifierProvider.notifier).update(
|
||||||
|
authData: selectedRequest?.httpRequestModel?.authModel
|
||||||
|
?.copyWith(type: newType) ??
|
||||||
|
AuthModel(type: newType),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
const SizedBox(height: 48),
|
const SizedBox(height: 48),
|
||||||
_buildAuthFields(context, ref, currentAuthData),
|
_buildAuthFields(context, ref, currentAuthData),
|
||||||
],
|
],
|
||||||
@@ -107,9 +142,13 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
updateAuth: updateAuth,
|
updateAuth: updateAuth,
|
||||||
);
|
);
|
||||||
case APIAuthType.none:
|
case APIAuthType.none:
|
||||||
return const Text("No authentication selected.");
|
return Text(readOnly
|
||||||
|
? "No authentication was used for this request."
|
||||||
|
: "No authentication selected.");
|
||||||
default:
|
default:
|
||||||
return const Text("This auth type is not implemented yet.");
|
return Text(readOnly
|
||||||
|
? "Authentication details for ${authData?.type.name} are not yet supported in history view."
|
||||||
|
: "This auth type is not implemented yet.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user