Skip to content

Commit 991d486

Browse files
authored
Merge pull request #862 from Udhay-Adithya/fix-scripts-state
fix ui state not being consistent with the original request model
2 parents e5b22a2 + 6c7c57d commit 991d486

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

lib/providers/collection_providers.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class CollectionStateNotifier
270270
ref.read(codePaneVisibleStateProvider.notifier).state = false;
271271
final defaultUriScheme = ref.read(settingsProvider).defaultUriScheme;
272272
final EnvironmentModel? originalEnvironmentModel =
273-
ref.read(selectedEnvironmentModelProvider);
273+
ref.read(activeEnvironmentModelProvider);
274274

275275
if (requestId == null || state == null) {
276276
return;
@@ -281,10 +281,11 @@ class CollectionStateNotifier
281281
return;
282282
}
283283

284-
if (requestModel != null &&
285-
!requestModel.preRequestScript.isNullOrEmpty()) {
286-
requestModel = await handlePreRequestScript(
287-
requestModel,
284+
RequestModel executionRequestModel = requestModel!.copyWith();
285+
286+
if (!requestModel.preRequestScript.isNullOrEmpty()) {
287+
executionRequestModel = await handlePreRequestScript(
288+
executionRequestModel,
288289
originalEnvironmentModel,
289290
(envModel, updatedValues) {
290291
ref
@@ -298,9 +299,9 @@ class CollectionStateNotifier
298299
);
299300
}
300301

301-
APIType apiType = requestModel!.apiType;
302+
APIType apiType = executionRequestModel.apiType;
302303
HttpRequestModel substitutedHttpRequestModel =
303-
getSubstitutedHttpRequestModel(requestModel.httpRequestModel!);
304+
getSubstitutedHttpRequestModel(executionRequestModel.httpRequestModel!);
304305

305306
// set current model's isWorking to true and update state
306307
var map = {...state!};

lib/providers/environment_providers.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ final selectedEnvironmentModelProvider =
1515
return selectedId != null ? environments![selectedId] : null;
1616
});
1717

18+
final activeEnvironmentModelProvider = StateProvider<EnvironmentModel?>((ref) {
19+
final activeId = ref.watch(activeEnvironmentIdStateProvider);
20+
final environments = ref.watch(environmentsStateNotifierProvider);
21+
if (activeId != null && environments != null) {
22+
return environments[activeId];
23+
}
24+
return null;
25+
});
26+
1827
final availableEnvironmentVariablesStateProvider =
1928
StateProvider<Map<String, List<EnvironmentVariableModel>>>((ref) {
2029
Map<String, List<EnvironmentVariableModel>> result = {};

lib/screens/history/history_widgets/his_scripts_tab.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class _ScriptsCodePaneState extends ConsumerState<HistoryScriptsTab> {
6161
crossAxisAlignment: CrossAxisAlignment.start,
6262
children: [
6363
Padding(
64-
padding: const EdgeInsets.all(8.0),
64+
padding: kP6,
6565
child: ADDropdownButton<int>(
6666
value: _selectedTabIndex,
6767
values: tabs,
@@ -75,7 +75,10 @@ class _ScriptsCodePaneState extends ConsumerState<HistoryScriptsTab> {
7575
),
7676
),
7777
Expanded(
78-
child: content[_selectedTabIndex],
78+
child: Padding(
79+
padding: kPt5o10,
80+
child: content[_selectedTabIndex],
81+
),
7982
),
8083
],
8184
);

lib/utils/pre_post_script_utils.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Future<RequestModel> handlePreRequestScript(
5959
debugPrint(
6060
"Warning: Pre-request script updated environment variables, but no active environment was selected to save them to.");
6161
}
62-
return requestModel;
62+
return newRequestModel;
6363
}
6464
return newRequestModel;
6565
}
@@ -71,7 +71,7 @@ Future<RequestModel> handlePostResponseScript(
7171
) async {
7272
final scriptResult = await executePostResponseScript(
7373
currentRequestModel: requestModel,
74-
activeEnvironment: originalEnvironmentModel?.toJson() ?? {},
74+
activeEnvironment: originalEnvironmentModel?.toJson() ?? {"values": []},
7575
);
7676

7777
final newRequestModel =

0 commit comments

Comments
 (0)