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

feat: 1580 list favorite activities for consep #1771

Merged
merged 18 commits into from
Jan 14, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
* @param activity The activity or page name
*/
@Schema(description = "An object representing the request body when creating a favourite activity")
public record FavouriteActivityCreateDto(@NotNull String activity) {}
public record FavouriteActivityCreateDto(
@NotNull String activity,
@Schema(description = "Indicates whether this activity is from Consep", defaultValue = "false")
Boolean isConsep) {}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class FavouriteActivityEndpoint {
description =
"""
Creates a Favourite Activity to the logged user based on the activity
title or page name.
title or page name, with an optional isConsep flag.
""")
@ApiResponses(
value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public class FavouriteActivityEntity {
@Column(name = "update_timestamp")
private LocalDateTime updateTimestamp;

@Column(name = "is_consep", nullable = false, columnDefinition = "BOOLEAN DEFAULT FALSE")
@Schema(
description = "Defines if the favourite activity is a CONSEP activity",
example = "false")
private Boolean isConsep = false;

public FavouriteActivityEntity() {
this.highlighted = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public FavouriteActivityEntity createUserActivity(FavouriteActivityCreateDto act
activityEntity.setUserId(userId);
activityEntity.setActivity(activityDto.activity());

activityEntity.setIsConsep(activityDto.isConsep() != null ? activityDto.isConsep() : false);

FavouriteActivityEntity activityEntitySaved = favouriteActivityRepository.save(activityEntity);
SparLog.info("Activity {} created for user {}", activityDto.activity(), userId);
return activityEntitySaved;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE
spar.favourite_activity
ADD
COLUMN is_consep BOOLEAN DEFAULT FALSE NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ void createUserActivityTest() {
entity.setHighlighted(Boolean.FALSE);
when(favouriteActivityRepository.save(any())).thenReturn(entity);

FavouriteActivityCreateDto createDto = new FavouriteActivityCreateDto("CREATE_A_CLASS_SEEDLOT");
FavouriteActivityCreateDto createDto =
new FavouriteActivityCreateDto("CREATE_A_CLASS_SEEDLOT", false);
FavouriteActivityEntity entitySaved = favouriteActivityService.createUserActivity(createDto);

Assertions.assertNotNull(entitySaved);
Expand All @@ -67,7 +68,7 @@ void createUserActivityExceptionTest() {
entity.setHighlighted(Boolean.FALSE);
when(favouriteActivityRepository.save(any())).thenReturn(entity);

FavouriteActivityCreateDto createDto = new FavouriteActivityCreateDto(null);
FavouriteActivityCreateDto createDto = new FavouriteActivityCreateDto(null, false);

Exception notFoundExc =
Assertions.assertThrows(
Expand All @@ -81,7 +82,7 @@ void createUserActivityExceptionTest() {
when(favouriteActivityRepository.findAllByUserId(any())).thenReturn(userFavList);

FavouriteActivityCreateDto createAnotherDto =
new FavouriteActivityCreateDto("CREATE_A_CLASS_SEEDLOT");
new FavouriteActivityCreateDto("CREATE_A_CLASS_SEEDLOT", false);

Exception activityExists =
Assertions.assertThrows(
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Card/FavouriteCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const FavouriteCard = ({

return (
<Tile
className={favObject.highlighted ? 'fav-card-main-highlighted' : 'fav-card-main'}
className={`${favObject.highlighted ? 'fav-card-main-highlighted' : 'fav-card-main'} ${favObject.isConsep ? 'fav-card-main-consep' : 'fav-card-main-spar'}`}
onClick={() => navigate(favObject.link)}
tabIndex={0}
aria-label={`Go to ${favObject.header}`}
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/components/Card/FavouriteCard/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
align-items: flex-start;
padding: 1.25rem 1rem;
margin: 0.5rem;
width: 14.625rem;
height: 9.875rem;
background: var(--#{vars.$bcgov-prefix}-layer-02);
border: 1px solid var(--#{vars.$bcgov-prefix}-border-subtle-02);
Expand All @@ -50,6 +49,14 @@
cursor: pointer;
}

.fav-card-main-spar {
width: 14.625rem;
}

.fav-card-main-consep {
width: 18.281rem;
}

.fav-card-content {
display: inline-block;
margin-top: auto;
Expand Down
27 changes: 19 additions & 8 deletions frontend/src/components/FavouriteActivities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import useWindowSize from '../../hooks/UseWindowSize';
import './styles.scss';
import { MEDIUM_SCREEN_WIDTH } from '../../shared-constants/shared-constants';

const FavouriteActivities = () => {
interface FavouriteActivitiesProps {
isConsep: boolean;
}

const FavouriteActivities = ({ isConsep }: FavouriteActivitiesProps) => {
const windowSize = useWindowSize();

const favActQueryKey = ['favourite-activities'];
Expand All @@ -32,9 +36,11 @@ const FavouriteActivities = () => {
<Row
className={
`favourite-activities ${windowSize.innerWidth < MEDIUM_SCREEN_WIDTH
? 'favourite-activities-sm-padding' : 'favourite-activities-padding'}`
? 'favourite-activities-sm-padding' : 'favourite-activities-padding'}
${!isConsep && 'favourite-activities-with-background'}`
}
>
{!isConsep && (
<Column sm={4} md={8} lg={16} xlg={4} className="favourite-activities-title">
<h2>My favourite activities</h2>
<Subtitle text="Quick access to your favourite activities." className="favourite-activities-subtitle" />
Expand All @@ -48,7 +54,9 @@ const FavouriteActivities = () => {
</button>
</Tooltip>
</Column>
<Column sm={4} md={8} lg={16} xlg={12} className="favourite-activities-cards">
)}

<Column sm={4} md={8} lg={16} xlg={isConsep ? 16 : 12} className="favourite-activities-cards">
<Row>
{
favActQuery.isLoading
Expand All @@ -71,11 +79,14 @@ const FavouriteActivities = () => {
description="You can favourite your most used
activities by clicking on the heart icon inside each page"
/>
xiaopeng0202 marked this conversation as resolved.
Show resolved Hide resolved
) : favActQuery.data.map((favObject) => (
<FavouriteCard
key={favObject.type}
favObject={favObject}
/>
) : favActQuery.data.filter((fav) => fav.isConsep === isConsep).map((favObject) => (
xiaopeng0202 marked this conversation as resolved.
Show resolved Hide resolved
<Column>
<FavouriteCard
key={favObject.type}
favObject={favObject}
/>
</Column>

))
)
}
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/components/FavouriteActivities/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
@use '@carbon/type';

.favourite-activities {
background-color: var(--#{vars.$bcgov-prefix}-layer-01);

.favourite-activities-title {
h2 {
@include type.type-style('heading-03');
Expand Down Expand Up @@ -59,3 +57,7 @@
.favourite-activities-padding{
padding: 2rem;
}

.favourite-activities-with-background {
background-color: var(--#{vars.$bcgov-prefix}-layer-01);
}
12 changes: 8 additions & 4 deletions frontend/src/components/PageTitle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ interface PageTitleProps {
subtitle?: string | React.ReactNode;
enableFavourite?: boolean;
activity?: string;
isConsep?: boolean;
}

const PageTitle = ({
title,
subtitle,
enableFavourite,
activity
activity,
isConsep = false
}: PageTitleProps) => {
const favActQueryKey = ['favourite-activities'];
const queryClient = useQueryClient();
Expand All @@ -38,18 +40,20 @@ const PageTitle = ({
const highlightFavAct = useMutation({
mutationFn: (actObj: FavActivityPostType) => postFavAct(actObj),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: favActQueryKey });
queryClient.invalidateQueries(favActQueryKey);
}
});

const removeFavAct = useMutation({
mutationFn: (id: number) => deleteFavAct(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: favActQueryKey });
queryClient.invalidateQueries(favActQueryKey);
}
});

const thisFavAct = favActQuery?.data?.filter((act) => act.type === activity)[0];
const thisFavAct = favActQuery?.data?.filter(
(act) => act.type === activity && act.isConsep === isConsep
xiaopeng0202 marked this conversation as resolved.
Show resolved Hide resolved
)[0];

const isFavourited = thisFavAct !== undefined;

Expand Down
Loading
Loading