Skip to content

Commit

Permalink
feat(MoodLog): remove ability to search via tags as this is already e…
Browse files Browse the repository at this point in the history
…ncapsulated by the generic search
  • Loading branch information
benji6 committed Nov 17, 2024
1 parent d933459 commit 3acaf24
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 116 deletions.
10 changes: 0 additions & 10 deletions client/src/components/pages/Mood/MoodLog/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ const createState = (props?: Partial<State>): State => ({

describe("MoodLog", () => {
describe("reducer", () => {
test("filterDescription/set", () => {
expect(
reducer(createState({ filterDescription: "foo", page: 3 }), {
payload: "bar",
type: "filterDescription/set",
}),
).toEqual(createState({ filterDescription: "bar", page: 0 }));
});

test("filterExploration/set", () => {
expect(
reducer(createState({ searchString: "foo", page: 3 }), {
Expand Down Expand Up @@ -56,7 +47,6 @@ describe("MoodLog", () => {

beforeEach(() => {
state = {
filterDescription: "foo",
searchString: "bar",
filterMood: 5,
page: 3,
Expand Down
45 changes: 2 additions & 43 deletions client/src/components/pages/Mood/MoodLog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import {
Card,
ComboBox,
Pagination,
Paper,
Select,
SubHeading,
TextField,
Toggle,
} from "eri";
import {
DESCRIPTION_MAX_LENGTH,
FIELDS,
MOOD_INTEGERS,
} from "../../../../constants";
import { FIELDS, MOOD_INTEGERS } from "../../../../constants";
import {
createDateFromLocalDateString,
defaultDict,
Expand Down Expand Up @@ -53,21 +48,12 @@ export default function MoodLog() {
);
const moodIdsByDate = useSelector(eventsSlice.selectors.moodIdsByDate);
const [localState, localDispatch] = useReducer(reducer, initialState);
const normalizedDescriptionWords = useSelector(
eventsSlice.selectors.normalizedDescriptionWords,
);
const dateNow = new Date();
const [dateTo, setDateTo] = useState(roundDateUp(dateNow));
const [dateFrom, setDateFrom] = useState(
roundDateDown(new Date(moods.allIds[0])),
);

const filterDescriptions = localState.filterDescription
.trim()
.toLowerCase()
.split(/\s+/)
.filter(Boolean);

const filterFeatureAvailable = moods.allIds.length >= 5;

let filteredMoodIds = moods.allIds;
Expand All @@ -80,19 +66,7 @@ export default function MoodLog() {
return false;

const date = new Date(mood.createdAt);
if (date < dateFrom || date > dateTo) return false;

if (filterDescriptions.length) {
const normalizedMoodDescription = mood.description?.toLowerCase();
if (
!filterDescriptions.every((description) =>
normalizedMoodDescription?.includes(description),
)
)
return false;
}

return true;
return date >= dateFrom && date <= dateTo;
});
if (localState.searchString) {
const fuse = new Fuse(filteredMoods, {
Expand Down Expand Up @@ -178,21 +152,6 @@ export default function MoodLog() {
type="search"
value={localState.searchString}
/>
<ComboBox
label={FIELDS.description.label}
supportiveText="Search for a specific mood tag"
maxLength={DESCRIPTION_MAX_LENGTH}
onChange={(e) =>
localDispatch({
payload: e.target.value,
type: "filterDescription/set",
})
}
options={normalizedDescriptionWords}
required={false}
type="search"
value={localState.filterDescription}
/>
<Select
label={FIELDS.mood.label}
onChange={(e) =>
Expand Down
5 changes: 0 additions & 5 deletions client/src/components/pages/Mood/MoodLog/moodLogReducer.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { FluxStandardAction } from "../../../../typeUtilities";

type Action =
| FluxStandardAction<"filterDescription/set", string>
| FluxStandardAction<"filterMood/clear">
| FluxStandardAction<"filterMood/set", number>
| FluxStandardAction<"page/set", number>
| FluxStandardAction<"searchString/set", string>
| FluxStandardAction<"shouldShowFilter/set", boolean>;

export interface State {
filterDescription: string;
filterMood: number | undefined;
page: number;
searchString: string;
shouldShowFilter: boolean;
}

export const initialState: State = {
filterDescription: "",
filterMood: undefined,
page: 0,
searchString: "",
Expand All @@ -26,8 +23,6 @@ export const initialState: State = {

export const reducer = (state: State, action: Action) => {
switch (action.type) {
case "filterDescription/set":
return { ...state, filterDescription: action.payload, page: 0 };
case "filterMood/clear":
return { ...state, filterMood: undefined, page: 0 };
case "filterMood/set":
Expand Down
3 changes: 2 additions & 1 deletion client/src/constants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import testIds from "./testIds";

if (!process.env.BUILD_TIME) throw Error("BUILD_TIME is undefined");
export const BUILD_TIME = process.env.BUILD_TIME;
export const DESCRIPTION_MAX_LENGTH = 32;
export const FIREBASE_CONFIG = {
apiKey: "AIzaSyDJUEfQvbke4ImRxqW5KwijugRKCzXw4BY",
appId: "1:189351604256:web:35457f768494fdf7e14c45",
Expand Down Expand Up @@ -83,6 +82,8 @@ export const TIME = {
} as const;

export const TEST_IDS = testIds;

const DESCRIPTION_MAX_LENGTH = 32;
export const FIELDS = {
dateAwoke: {
"data-test-id": TEST_IDS.dateAwokeInput,
Expand Down
42 changes: 0 additions & 42 deletions client/src/store/eventsSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1584,48 +1584,6 @@ describe("eventsSlice", () => {
});
});

test("descriptions", () => {
expect(
eventsSlice.selectors.normalizedDescriptionWords({
...initialState,
events: {
...initialState.events,
allIds: [
"2020-07-10T00:00:00.000Z",
"2020-08-10T00:00:00.000Z",
"2020-09-10T00:00:00.000Z",
"2020-09-11T00:00:00.000Z",
],
byId: {
"2020-07-10T00:00:00.000Z": {
createdAt: "2020-07-10T00:00:00.000Z",
type: "v1/moods/create",
payload: { description: "will be overridden", mood: 5 },
},
"2020-08-10T00:00:00.000Z": {
createdAt: "2020-08-10T00:00:00.000Z",
type: "v1/moods/create",
payload: { description: " pIkaChu ", mood: 5 },
},
"2020-09-10T00:00:00.000Z": {
createdAt: "2020-09-10T00:00:00.000Z",
type: "v1/moods/create",
payload: { description: " Bulbasaur Pikachu 🙂 ", mood: 5 },
},
"2020-09-11T00:00:00.000Z": {
createdAt: "2020-09-11T00:00:00.000Z",
type: "v1/moods/update",
payload: {
id: "2020-07-10T00:00:00.000Z",
description: "charmander squirtle pikachu",
},
},
},
},
}),
).toEqual(["🙂", "Bulbasaur", "Charmander", "Pikachu", "Squirtle"]);
});

describe("meanWeightInPeriod", () => {
test("when there are no events", () => {
expect(
Expand Down
15 changes: 0 additions & 15 deletions client/src/store/eventsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,21 +681,6 @@ export default createSlice({
dateToSelector,
moodsInPeriodResultFunction,
),
normalizedDescriptionWords: createSelector(
normalizedMoodsSelector,
(normalizedMoods): string[] => {
const descriptionWords = new Set<string>();
for (const id of normalizedMoods.allIds) {
const { description } = normalizedMoods.byId[id];
const normalizedWords = description
? getNormalizedWordCloudWords(description)
: [];
for (const normalizedWord of normalizedWords)
descriptionWords.add(normalizedWord);
}
return [...descriptionWords].sort((a, b) => a.localeCompare(b));
},
),
normalizedLegRaises: normalizedLegRaisesSelector,
normalizedMeditations: normalizedMeditationsSelector,
normalizedMoods: normalizedMoodsSelector,
Expand Down

0 comments on commit 3acaf24

Please sign in to comment.