mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Merge pull request #220 from SyncrowIOT/SP-1664-FE-Sider-bar-tree-behavior-issues-on-Analytics-page
Sp 1664 fe sider bar tree behavior issues on analytics page
This commit is contained in:
@ -26,10 +26,10 @@ final class AirQualityDataLoadingStrategy implements AnalyticsDataLoadingStrateg
|
|||||||
final spaceTreeBloc = context.read<SpaceTreeBloc>();
|
final spaceTreeBloc = context.read<SpaceTreeBloc>();
|
||||||
final isSpaceSelected = spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
|
final isSpaceSelected = spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
|
||||||
|
|
||||||
if (isSpaceSelected) {
|
final hasSelectedSpaces = spaceTreeBloc.state.selectedSpaces.isNotEmpty;
|
||||||
clearData(context);
|
if (hasSelectedSpaces) clearData(context);
|
||||||
return;
|
|
||||||
}
|
if (isSpaceSelected) return;
|
||||||
|
|
||||||
spaceTreeBloc
|
spaceTreeBloc
|
||||||
..add(const SpaceTreeClearSelectionEvent())
|
..add(const SpaceTreeClearSelectionEvent())
|
||||||
@ -42,18 +42,11 @@ final class AirQualityDataLoadingStrategy implements AnalyticsDataLoadingStrateg
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void onChildSpaceSelected(
|
|
||||||
BuildContext context,
|
|
||||||
CommunityModel community,
|
|
||||||
SpaceModel child,
|
|
||||||
) {
|
|
||||||
return onSpaceSelected(context, community, child);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void clearData(BuildContext context) {
|
void clearData(BuildContext context) {
|
||||||
context.read<SpaceTreeBloc>().add(const SpaceTreeClearSelectionEvent());
|
context.read<SpaceTreeBloc>().add(
|
||||||
|
const AnalyticsClearAllSpaceTreeSelectionsEvent(),
|
||||||
|
);
|
||||||
FetchAirQualityDataHelper.clearAllData(context);
|
FetchAirQualityDataHelper.clearAllData(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,5 @@ abstract class AnalyticsDataLoadingStrategy {
|
|||||||
CommunityModel community,
|
CommunityModel community,
|
||||||
SpaceModel space,
|
SpaceModel space,
|
||||||
);
|
);
|
||||||
void onChildSpaceSelected(
|
|
||||||
BuildContext context,
|
|
||||||
CommunityModel community,
|
|
||||||
SpaceModel child,
|
|
||||||
);
|
|
||||||
void clearData(BuildContext context);
|
void clearData(BuildContext context);
|
||||||
}
|
}
|
||||||
|
@ -14,24 +14,14 @@ class EnergyManagementDataLoadingStrategy implements AnalyticsDataLoadingStrateg
|
|||||||
CommunityModel community,
|
CommunityModel community,
|
||||||
List<SpaceModel> spaces,
|
List<SpaceModel> spaces,
|
||||||
) {
|
) {
|
||||||
context.read<SpaceTreeBloc>().add(
|
final spaceTreeBloc = context.read<SpaceTreeBloc>();
|
||||||
OnCommunitySelected(
|
final isCommunitySelected =
|
||||||
community.uuid,
|
spaceTreeBloc.state.selectedCommunities.contains(community.uuid);
|
||||||
spaces,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
final spaceTreeState = context.read<SpaceTreeBloc>().state;
|
if (isCommunitySelected) {
|
||||||
if (spaceTreeState.selectedCommunities.contains(community.uuid)) {
|
|
||||||
clearData(context);
|
clearData(context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FetchEnergyManagementDataHelper.loadEnergyManagementData(
|
|
||||||
context,
|
|
||||||
communityId: community.uuid,
|
|
||||||
spaceId: spaces.isNotEmpty ? spaces.first.uuid ?? '' : '',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -40,21 +30,31 @@ class EnergyManagementDataLoadingStrategy implements AnalyticsDataLoadingStrateg
|
|||||||
CommunityModel community,
|
CommunityModel community,
|
||||||
SpaceModel space,
|
SpaceModel space,
|
||||||
) {
|
) {
|
||||||
context.read<SpaceTreeBloc>().add(
|
final spaceTreeBloc = context.read<SpaceTreeBloc>();
|
||||||
OnSpaceSelected(
|
final isSpaceSelected = spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
|
||||||
community,
|
final hasSelectedSpaces = spaceTreeBloc.state.selectedSpaces.isNotEmpty;
|
||||||
space.uuid ?? '',
|
|
||||||
space.children,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
final spaceTreeState = context.read<SpaceTreeBloc>().state;
|
if (isSpaceSelected) {
|
||||||
if (spaceTreeState.selectedCommunities.contains(community.uuid) ||
|
final firstSelectedSpace = spaceTreeBloc.state.selectedSpaces.first;
|
||||||
spaceTreeState.selectedSpaces.contains(space.uuid)) {
|
final isTheFirstSelectedSpace = firstSelectedSpace == space.uuid;
|
||||||
clearData(context);
|
if (isTheFirstSelectedSpace) {
|
||||||
|
clearData(context);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasSelectedSpaces) {
|
||||||
|
clearData(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
spaceTreeBloc.add(
|
||||||
|
OnSpaceSelected(
|
||||||
|
community,
|
||||||
|
space.uuid ?? '',
|
||||||
|
space.children,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
FetchEnergyManagementDataHelper.loadEnergyManagementData(
|
FetchEnergyManagementDataHelper.loadEnergyManagementData(
|
||||||
context,
|
context,
|
||||||
communityId: community.uuid,
|
communityId: community.uuid,
|
||||||
@ -62,18 +62,11 @@ class EnergyManagementDataLoadingStrategy implements AnalyticsDataLoadingStrateg
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void onChildSpaceSelected(
|
|
||||||
BuildContext context,
|
|
||||||
CommunityModel community,
|
|
||||||
SpaceModel child,
|
|
||||||
) {
|
|
||||||
return onSpaceSelected(context, community, child);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void clearData(BuildContext context) {
|
void clearData(BuildContext context) {
|
||||||
context.read<SpaceTreeBloc>().add(const SpaceTreeClearSelectionEvent());
|
context.read<SpaceTreeBloc>().add(
|
||||||
|
const AnalyticsClearAllSpaceTreeSelectionsEvent(),
|
||||||
|
);
|
||||||
FetchEnergyManagementDataHelper.clearAllData(context);
|
FetchEnergyManagementDataHelper.clearAllData(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,10 @@ class OccupancyDataLoadingStrategy implements AnalyticsDataLoadingStrategy {
|
|||||||
final spaceTreeBloc = context.read<SpaceTreeBloc>();
|
final spaceTreeBloc = context.read<SpaceTreeBloc>();
|
||||||
final isSpaceSelected = spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
|
final isSpaceSelected = spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
|
||||||
|
|
||||||
if (isSpaceSelected) {
|
final hasSelectedSpaces = spaceTreeBloc.state.selectedSpaces.isNotEmpty;
|
||||||
clearData(context);
|
if (hasSelectedSpaces) clearData(context);
|
||||||
return;
|
|
||||||
}
|
if (isSpaceSelected) return;
|
||||||
|
|
||||||
spaceTreeBloc
|
spaceTreeBloc
|
||||||
..add(const SpaceTreeClearSelectionEvent())
|
..add(const SpaceTreeClearSelectionEvent())
|
||||||
@ -42,18 +42,11 @@ class OccupancyDataLoadingStrategy implements AnalyticsDataLoadingStrategy {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void onChildSpaceSelected(
|
|
||||||
BuildContext context,
|
|
||||||
CommunityModel community,
|
|
||||||
SpaceModel child,
|
|
||||||
) {
|
|
||||||
return onSpaceSelected(context, community, child);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void clearData(BuildContext context) {
|
void clearData(BuildContext context) {
|
||||||
context.read<SpaceTreeBloc>().add(const SpaceTreeClearSelectionEvent());
|
context.read<SpaceTreeBloc>().add(
|
||||||
|
const AnalyticsClearAllSpaceTreeSelectionsEvent(),
|
||||||
|
);
|
||||||
FetchOccupancyDataHelper.clearAllData(context);
|
FetchOccupancyDataHelper.clearAllData(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class AnalyticsCommunitiesSidebar extends StatelessWidget {
|
|||||||
strategy.onSpaceSelected(context, community, space);
|
strategy.onSpaceSelected(context, community, space);
|
||||||
},
|
},
|
||||||
onSelectChildSpace: (community, child) {
|
onSelectChildSpace: (community, child) {
|
||||||
strategy.onChildSpaceSelected(context, community, child);
|
strategy.onSpaceSelected(context, community, child);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -24,6 +24,9 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
on<PaginationEvent>(_fetchPaginationSpaces);
|
on<PaginationEvent>(_fetchPaginationSpaces);
|
||||||
on<DebouncedSearchEvent>(_onDebouncedSearch);
|
on<DebouncedSearchEvent>(_onDebouncedSearch);
|
||||||
on<SpaceTreeClearSelectionEvent>(_onSpaceTreeClearSelectionEvent);
|
on<SpaceTreeClearSelectionEvent>(_onSpaceTreeClearSelectionEvent);
|
||||||
|
on<AnalyticsClearAllSpaceTreeSelectionsEvent>(
|
||||||
|
_onAnalyticsClearAllSpaceTreeSelectionsEvent,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Timer _timer = Timer(const Duration(microseconds: 0), () {});
|
Timer _timer = Timer(const Duration(microseconds: 0), () {});
|
||||||
|
|
||||||
@ -493,6 +496,20 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onAnalyticsClearAllSpaceTreeSelectionsEvent(
|
||||||
|
AnalyticsClearAllSpaceTreeSelectionsEvent event,
|
||||||
|
Emitter<SpaceTreeState> emit,
|
||||||
|
) async {
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
selectedCommunities: [],
|
||||||
|
selectedCommunityAndSpaces: {},
|
||||||
|
selectedSpaces: [],
|
||||||
|
soldCheck: [],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> close() async {
|
Future<void> close() async {
|
||||||
_timer.cancel();
|
_timer.cancel();
|
||||||
|
@ -112,3 +112,7 @@ class ClearCachedData extends SpaceTreeEvent {}
|
|||||||
class SpaceTreeClearSelectionEvent extends SpaceTreeEvent {
|
class SpaceTreeClearSelectionEvent extends SpaceTreeEvent {
|
||||||
const SpaceTreeClearSelectionEvent();
|
const SpaceTreeClearSelectionEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class AnalyticsClearAllSpaceTreeSelectionsEvent extends SpaceTreeEvent {
|
||||||
|
const AnalyticsClearAllSpaceTreeSelectionsEvent();
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user