Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove intro end pages: intro end pages removed #271

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions admin/lib/presentation/app/localization/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"emptyDataMessage": "Data has not been loaded",
"emptyQuestionMessage": "Data cannot be exported",
"emptySubtitle":"",
"end": "End",
"enterText": "Enter text",
"export": "EXPORT",
"exportFloatingWindowTitle": "Save generated json-file with all settings to use in your app",
Expand All @@ -41,7 +40,6 @@
"input": "Input",
"inputHintText": "Enter answer here",
"inputType": "Input type",
"intro": "Intro",
"lines": "Lines",
"max": "max",
"min": "min",
Expand Down
20 changes: 4 additions & 16 deletions admin/lib/presentation/pages/builder/builder_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class BuilderCubit extends Cubit<BuilderState> {
}

void select(QuestionData data) {
if (state is EditQuestionBuilderState ||
state is ImportSuccessSurveyDataBuilderState) {
if (state is EditQuestionBuilderState ||
state is ImportSuccessSurveyDataBuilderState) {
emit(
EditQuestionBuilderState(
selectedIndex: data.index,
Expand All @@ -65,13 +65,7 @@ class BuilderCubit extends Cubit<BuilderState> {

_updateIndex(questionList);

final endPage = state.surveyData.endPage
.copyWith(index: state.surveyData.endPage.index - 1);

final surveyData = state.surveyData.copyWith(
questions: questionList,
endPage: endPage,
);
final surveyData = state.surveyData.copyWith(questions: questionList);
_sessionStorageRepository.saveSurveyData(surveyData);
emit(state.copyWith(surveyData: surveyData));
if (state.surveyData.questions.isEmpty) {
Expand All @@ -90,13 +84,7 @@ class BuilderCubit extends Cubit<BuilderState> {
final questionList = List<QuestionData>.of(state.surveyData.questions)
..add(data);

final endPage = state.surveyData.endPage
.copyWith(index: state.surveyData.endPage.index + 1);

final surveyData = state.surveyData.copyWith(
questions: questionList,
endPage: endPage,
);
final surveyData = state.surveyData.copyWith(questions: questionList);
_sessionStorageRepository.saveSurveyData(surveyData);
emit(state.copyWith(surveyData: surveyData));
select(state.surveyData.questions.last);
Expand Down
14 changes: 4 additions & 10 deletions admin/lib/presentation/pages/builder/builder_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ class _ContentState extends State<_Content>
final cubit = this.cubit(context);
final questions = cubit.state.surveyData.questions;
final index = _surveyController.pageController.page;
final question = index == questions.length
? cubit.state.surveyData.endPage
: index != null && index % 1 == 0
? questions[index.toInt()]
: null;
final question =
index != null && index % 1 == 0 ? questions[index.toInt()] : null;

if (question != null) {
cubit.select(question);
Expand Down Expand Up @@ -87,10 +84,8 @@ class _ContentState extends State<_Content>

QuestionData? _editableQuestion(BuilderState state) {
if (state is EditQuestionBuilderState) {
return state.selectedIndex == state.surveyData.endPage.index
? state.surveyData.endPage
: state.surveyData.questions
.firstWhereOrNull((q) => q.index == state.selectedIndex);
return state.surveyData.questions
.firstWhereOrNull((q) => q.index == state.selectedIndex);
} else if (state is PreviewQuestionBuilderState) {
return state.selectedQuestion;
} else {
Expand Down Expand Up @@ -164,7 +159,6 @@ class _ContentState extends State<_Content>
data: cubit.state.surveyData,
onUpdate: cubit.updateQuestions,
selectedIndex: _selectedIndex(state),
endPage: state.surveyData.endPage,
onDataUpdate: cubit.updateCommonTheme,
),
Expanded(
Expand Down
23 changes: 3 additions & 20 deletions admin/lib/presentation/utils/common_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class CommonData {
static const _secondIndex = 2;
static const _thirdIndex = 3;
static const _fourthIndex = 4;
static const _fifthIndex = 5;
static const _dividers = 10;

CommonTheme get commonTheme {
Expand All @@ -26,22 +25,21 @@ class CommonData {
SurveyData get surveyData {
return SurveyData(
questions: [
info(index: _firstIndex, title: context.localization.intro),
info(index: _firstIndex),
input(index: _secondIndex),
choice(index: _thirdIndex),
slider(index: _fourthIndex),
],
endPage: endPage(index: _fifthIndex),
commonTheme: commonTheme,
);
}

const CommonData(this.context);

InfoQuestionData info({int index = 0, String? title}) {
InfoQuestionData info({int index = 0}) {
return InfoQuestionData(
primaryButtonText: context.localization.next,
title: title ?? context.localization.info,
title: context.localization.info,
index: index,
subtitle: context.localization.emptySubtitle,
isSkip: false,
Expand Down Expand Up @@ -111,19 +109,4 @@ class CommonData {
secondaryButtonAction: const SkipQuestionAction(),
);
}

InfoQuestionData endPage({int index = 0}) {
return InfoQuestionData(
primaryButtonText: context.localization.next,
title: context.localization.end,
index: index,
subtitle: context.localization.surveyCompleted,
isSkip: false,
content: context.localization.emptyContent,
theme: const InfoQuestionTheme.common(),
secondaryButtonText: context.localization.skip,
mainButtonAction: const GoNextAction(),
secondaryButtonAction: const SkipQuestionAction(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ class QuestionList extends StatefulWidget {
final int? selectedIndex;
final SurveyData data;
final ValueChanged<SurveyData> onDataUpdate;
final InfoQuestionData endPage;
final bool isEditMode;

const QuestionList({
required this.onSelect,
required this.onAdd,
required this.data,
required this.endPage,
required this.onUpdate,
required this.onDelete,
required this.onDataUpdate,
Expand Down Expand Up @@ -103,13 +101,6 @@ class _QuestionListState extends State<QuestionList> {
question: widget.data.questions[index],
onQuestionTap: widget.onSelect,
),
_Question(
key: ValueKey(length),
index: length,
isSelected: length == widget.selectedIndex,
question: widget.endPage,
onQuestionTap: widget.onSelect,
),
],
),
cardBuilder: (_, children) {
Expand Down
6 changes: 3 additions & 3 deletions admin/test/presentation/pages/builder/buider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void main() {
expect(find.text('Survey'), findsOneWidget);
expect(find.text('Common'), findsOneWidget);
expect(find.text('Content'), findsOneWidget);
expect(find.text('Intro'), findsNWidgets(3));
expect(find.text('Info'), findsNWidgets(3));
expect(find.text('Input'), findsOneWidget);
expect(find.text('Choice'), findsOneWidget);
expect(find.text('NEXT'), findsNWidgets(2));
Expand Down Expand Up @@ -132,11 +132,11 @@ void main() {

await tester.pumpWidget(page);

await tester.longPress(find.text('Intro').first);
await tester.longPress(find.text('Info').first);
await tester.tap(find.text('Delete'));
await tester.pumpAndSettle();

expect(find.text('Intro'), findsNothing);
expect(find.text('Info'), findsNothing);

tester.binding.platformDispatcher.clearTextScaleFactorTestValue();
});
Expand Down
34 changes: 6 additions & 28 deletions admin/test/utils/shared_mocks.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ import 'package:survey_sdk/survey_sdk.dart' as _i2;
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class

class _FakeInfoQuestionData_0 extends _i1.SmartFake
implements _i2.InfoQuestionData {
_FakeInfoQuestionData_0(
class _FakeCommonTheme_0 extends _i1.SmartFake implements _i2.CommonTheme {
_FakeCommonTheme_0(
Object parent,
Invocation parentInvocation,
) : super(
Expand All @@ -38,18 +37,8 @@ class _FakeInfoQuestionData_0 extends _i1.SmartFake
);
}

class _FakeCommonTheme_1 extends _i1.SmartFake implements _i2.CommonTheme {
_FakeCommonTheme_1(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}

class _FakeSurveyData_2 extends _i1.SmartFake implements _i2.SurveyData {
_FakeSurveyData_2(
class _FakeSurveyData_1 extends _i1.SmartFake implements _i2.SurveyData {
_FakeSurveyData_1(
Object parent,
Invocation parentInvocation,
) : super(
Expand Down Expand Up @@ -166,17 +155,9 @@ class MockSurveyData extends _i1.Mock implements _i2.SurveyData {
returnValue: <_i2.QuestionData<dynamic>>[],
) as List<_i2.QuestionData<dynamic>>);
@override
_i2.InfoQuestionData get endPage => (super.noSuchMethod(
Invocation.getter(#endPage),
returnValue: _FakeInfoQuestionData_0(
this,
Invocation.getter(#endPage),
),
) as _i2.InfoQuestionData);
@override
_i2.CommonTheme get commonTheme => (super.noSuchMethod(
Invocation.getter(#commonTheme),
returnValue: _FakeCommonTheme_1(
returnValue: _FakeCommonTheme_0(
this,
Invocation.getter(#commonTheme),
),
Expand All @@ -189,7 +170,6 @@ class MockSurveyData extends _i1.Mock implements _i2.SurveyData {
@override
_i2.SurveyData copyWith({
List<_i2.QuestionData<dynamic>>? questions,
_i2.InfoQuestionData? endPage,
_i2.CommonTheme? commonTheme,
}) =>
(super.noSuchMethod(
Expand All @@ -198,18 +178,16 @@ class MockSurveyData extends _i1.Mock implements _i2.SurveyData {
[],
{
#questions: questions,
#endPage: endPage,
#commonTheme: commonTheme,
},
),
returnValue: _FakeSurveyData_2(
returnValue: _FakeSurveyData_1(
this,
Invocation.method(
#copyWith,
[],
{
#questions: questions,
#endPage: endPage,
#commonTheme: commonTheme,
},
),
Expand Down
64 changes: 1 addition & 63 deletions core/example/assets/questions.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
{
"schemeVersion": 1,
"endPage": {
"index": 5,
"title": "End",
"subtitle": "Survey is completed",
"type": "Info",
"isSkip": false,
"content": "",
"theme": {
"fill": 4294967295,
"titleColor": 4278190080,
"titleSize": 16,
"subtitleColor": 4278190080,
"subtitleSize": 12,
"primaryButtonFill": 4278190080,
"primaryButtonTextColor": 4294967295,
"primaryButtonTextSize": 12,
"primaryButtonRadius": 10,
"secondaryButtonFill": 4278190080,
"secondaryButtonTextColor": 4294967295,
"secondaryButtonTextSize": 12,
"secondaryButtonRadius": 10
},
"secondaryButtonText": "Skip",
"primaryButtonText": "NEXT",
"primaryButtonAction": {
"type": "GoNext"
},
"secondaryButtonAction": {
"type": "SkipQuestion"
}
},
"commonTheme": {
"slider": {
"index": 0,
Expand Down Expand Up @@ -201,42 +170,11 @@
"questions": [
{
"index": 1,
"title": "Intro",
"title": "Info",
"subtitle": "",
"type": "Info",
"isSkip": false,
"content": "You may simply need a single, brief answer without discussion. Other times, you may want to talk through a scenario, evaluate how well a group is learning new material or solicit feedback. The types of questions you ask directly impact the type of answer you receive.",
"theme": {
"fill": 4294967295,
"titleColor": 4278190080,
"titleSize": 16,
"subtitleColor": 4278190080,
"subtitleSize": 12,
"primaryButtonFill": 4278190080,
"primaryButtonTextColor": 4294967295,
"primaryButtonTextSize": 12,
"primaryButtonRadius": 10,
"secondaryButtonFill": 4278190080,
"secondaryButtonTextColor": 4294967295,
"secondaryButtonTextSize": 12,
"secondaryButtonRadius": 10
},
"secondaryButtonText": "Skip",
"primaryButtonText": "NEXT",
"primaryButtonAction": {
"type": "GoNext"
},
"secondaryButtonAction": {
"type": "SkipQuestion"
}
},
{
"index": 2,
"title": "Input",
"subtitle": "",
"type": "Input",
"isSkip": false,
"content": "You may simply need a single, brief answer without discussion. Other times, you may want to talk through a scenario, evaluate how well a group is learning new material or solicit feedback. The types of questions you ask directly impact the type of answer you receive.",
"theme": {
"inputFill": 4294967295,
"borderColor": 4278190080,
Expand Down
Loading