From e3d9e09d37b73cd2c8ef63762c22a1ff6b4a57b7 Mon Sep 17 00:00:00 2001 From: maxn92 Date: Fri, 17 Oct 2025 14:16:39 +0200 Subject: [PATCH 1/2] feat: Highlighter --- .../components/src/entry-input-layout.tsx | 14 +++------ packages/components/src/highlighter.tsx | 31 +++++++++++++++++++ .../frontend/src/components/day-input.tsx | 3 ++ .../frontend/src/components/entries-input.tsx | 3 ++ .../frontend/src/components/entry-input.tsx | 3 ++ packages/frontend/src/pages/archive-page.tsx | 7 +++-- .../frontend/src/pages/dashboard-page.tsx | 1 + packages/frontend/src/pages/report-page.tsx | 3 +- .../frontend/src/pages/report-review-page.tsx | 1 + packages/frontend/src/routes.tsx | 1 + 10 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 packages/components/src/highlighter.tsx diff --git a/packages/components/src/entry-input-layout.tsx b/packages/components/src/entry-input-layout.tsx index 71a502a5..e615d4d4 100644 --- a/packages/components/src/entry-input-layout.tsx +++ b/packages/components/src/entry-input-layout.tsx @@ -4,6 +4,7 @@ import styled from 'styled-components' import { Spacings } from './spacing' import { FontSizes } from './font-size' import { BorderRadii } from './border-radius' +import Highlighter from './highlighter' const ActionWrapper = styled.div` display: flex; @@ -118,13 +119,6 @@ const TextWrapper = styled(ValueBase)` padding-left: 0; ` -const Text = styled.p` - margin: 0; - padding: 0; - white-space: pre-wrap; - word-break: break-word; -` - const Time = styled(ValueBase)` width: 100px; text-align: right; @@ -193,17 +187,19 @@ interface EntryInputLayoutProps extends HTMLAttributes, EntryContai text: string time: string actions: JSX.Element + term: string clickHandler: React.Dispatch> } -export const EntryInputLayout: React.FC = ({ text, time, actions, clickHandler, ...rest }) => { +export const EntryInputLayout: React.FC = ({ text, time, actions, term, clickHandler, ...rest }) => { + console.log(term) return ( <> clickHandler(true)}> - {text} + {text} diff --git a/packages/components/src/highlighter.tsx b/packages/components/src/highlighter.tsx new file mode 100644 index 00000000..347f46f8 --- /dev/null +++ b/packages/components/src/highlighter.tsx @@ -0,0 +1,31 @@ + +interface highlighterProps { + term: string + children: string +} + +const Highlighter: React.FC = ({term, children}) => { + if (!term) { + return ( + <>{children} + ) + } + const regex = new RegExp(`(${term})`, 'gi'); + const parts = children.split(regex); + console.log(parts) + + return( + <> +
test
+ {parts.map((part: string, index: number)=> + regex.test(part) ? ( + + {part} + + ) : (part) + )} + + ) +} + +export default Highlighter \ No newline at end of file diff --git a/packages/frontend/src/components/day-input.tsx b/packages/frontend/src/components/day-input.tsx index b9273672..8991bcad 100644 --- a/packages/frontend/src/components/day-input.tsx +++ b/packages/frontend/src/components/day-input.tsx @@ -66,6 +66,7 @@ interface DayInputProps { disabled?: boolean reportStatus?: ReportStatus primary?: boolean + term: string updateMessageDay?: (message: string, commentId: string) => void updateMessageEntry?: ( message: string, @@ -86,6 +87,7 @@ const DayInput: React.FunctionComponent = ({ primary, updateMessageDay, updateMessageEntry, + term, }) => { const { getTotalMinutes } = useDayHelper() const { addToast } = useToastContext() @@ -232,6 +234,7 @@ const DayInput: React.FunctionComponent = ({ } > & { entries: (Pick & { comments: (Pick & { @@ -49,6 +50,7 @@ const EntriesInput: React.FC = ({ handleStatusChange, trainee, updateMessage, + term, }) => { const [createEntryMutation] = useCreateEntryMutation() const { addToast } = useToastContext() @@ -107,6 +109,7 @@ const EntriesInput: React.FC = ({ .sort((a, b) => a.orderId - b.orderId) .map((entry) => ( > updateMessage?: (message: string, commentId: string) => void + term: string } const EntryInput: React.FC = ({ @@ -65,6 +66,7 @@ const EntryInput: React.FC = ({ showContextMenu, setShowContextMenu, updateMessage, + term, }) => { const { loading, data } = useEntryInputDataQuery() @@ -301,6 +303,7 @@ const EntryInput: React.FC = ({ ) : ( { const [allChecked, setAllChecked] = React.useState(false) const [selectedTrainee, setSelectedTrainee] = React.useState(undefined) + const [term, setTerm] = React.useState(undefined) const getArchivedReports = React.useCallback(() => { if (!data) return [] @@ -215,6 +216,8 @@ const ArchivePage: React.FunctionComponent = () => { let weekEnd: number | undefined = undefined let searchText: string | undefined = undefined + setTerm(value) + const yearMatch = yearMonthRegex.exec(value) if (yearMonthRegex.test(value) && yearMatch) { year = parseInt(yearMatch[1], 10) @@ -346,8 +349,8 @@ const ArchivePage: React.FunctionComponent = () => { const link = data?.currentUser?.__typename === UserTypeEnum.Trainer - ? `/report/${traineeId}/${year}/${week}` - : `/report/${year}/${week}` + ? `/report/${traineeId}/${year}/${week}/${term ? term: ""}` + : `/report/${year}/${week}/${term ? term: ""}` return ( diff --git a/packages/frontend/src/pages/dashboard-page.tsx b/packages/frontend/src/pages/dashboard-page.tsx index 58ff6483..2394ed52 100644 --- a/packages/frontend/src/pages/dashboard-page.tsx +++ b/packages/frontend/src/pages/dashboard-page.tsx @@ -63,6 +63,7 @@ const DashboardPage: React.FunctionComponent = () => { { const navigate = useNavigate() const { getFinishedDays } = useReportHelper() - const { trainee, year, week } = useParams() + const { trainee, year, week, term } = useParams() const variables: ReportPageDataQueryVariables = { year: parseInt(year ?? '', 10), @@ -282,6 +282,7 @@ const ReportPage: React.FunctionComponent = () => { {report?.days.map((day) => ( { <> {day.entries.map((entry, entryIndex) => ( = ({ currentUser }) => { <> } /> } /> + } /> } /> } /> } /> From b6293265cd90c760b4d9805180a4f39406128b54 Mon Sep 17 00:00:00 2001 From: maxn92 Date: Fri, 17 Oct 2025 14:34:39 +0200 Subject: [PATCH 2/2] chore: Format --- .../components/src/entry-input-layout.tsx | 9 ++++- packages/components/src/highlighter.tsx | 35 ++++++++++++------- .../frontend/src/components/entries-input.tsx | 2 +- packages/frontend/src/pages/archive-page.tsx | 6 ++-- packages/frontend/src/pages/report-page.tsx | 2 +- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/packages/components/src/entry-input-layout.tsx b/packages/components/src/entry-input-layout.tsx index e615d4d4..203f3a7f 100644 --- a/packages/components/src/entry-input-layout.tsx +++ b/packages/components/src/entry-input-layout.tsx @@ -191,7 +191,14 @@ interface EntryInputLayoutProps extends HTMLAttributes, EntryContai clickHandler: React.Dispatch> } -export const EntryInputLayout: React.FC = ({ text, time, actions, term, clickHandler, ...rest }) => { +export const EntryInputLayout: React.FC = ({ + text, + time, + actions, + term, + clickHandler, + ...rest +}) => { console.log(term) return ( <> diff --git a/packages/components/src/highlighter.tsx b/packages/components/src/highlighter.tsx index 347f46f8..838eb51f 100644 --- a/packages/components/src/highlighter.tsx +++ b/packages/components/src/highlighter.tsx @@ -1,31 +1,40 @@ - interface highlighterProps { term: string children: string } -const Highlighter: React.FC = ({term, children}) => { +const Highlighter: React.FC = ({ term, children }) => { if (!term) { - return ( - <>{children} - ) + return <>{children} } - const regex = new RegExp(`(${term})`, 'gi'); - const parts = children.split(regex); + const regex = new RegExp(`(${term})`, 'gi') + const parts = children.split(regex) console.log(parts) - return( + return ( <> -
test
- {parts.map((part: string, index: number)=> +
test
+ {parts.map((part: string, index: number) => regex.test(part) ? ( - + {part} - ) : (part) + ) : ( + part + ) )} ) } -export default Highlighter \ No newline at end of file +export default Highlighter diff --git a/packages/frontend/src/components/entries-input.tsx b/packages/frontend/src/components/entries-input.tsx index 85755b06..96b8192c 100644 --- a/packages/frontend/src/components/entries-input.tsx +++ b/packages/frontend/src/components/entries-input.tsx @@ -109,7 +109,7 @@ const EntriesInput: React.FC = ({ .sort((a, b) => a.orderId - b.orderId) .map((entry) => ( { let weekEnd: number | undefined = undefined let searchText: string | undefined = undefined - setTerm(value) + setTerm(value) const yearMatch = yearMonthRegex.exec(value) if (yearMonthRegex.test(value) && yearMatch) { @@ -349,8 +349,8 @@ const ArchivePage: React.FunctionComponent = () => { const link = data?.currentUser?.__typename === UserTypeEnum.Trainer - ? `/report/${traineeId}/${year}/${week}/${term ? term: ""}` - : `/report/${year}/${week}/${term ? term: ""}` + ? `/report/${traineeId}/${year}/${week}/${term ? term : ''}` + : `/report/${year}/${week}/${term ? term : ''}` return ( diff --git a/packages/frontend/src/pages/report-page.tsx b/packages/frontend/src/pages/report-page.tsx index dd185f27..0d22bffa 100644 --- a/packages/frontend/src/pages/report-page.tsx +++ b/packages/frontend/src/pages/report-page.tsx @@ -282,7 +282,7 @@ const ReportPage: React.FunctionComponent = () => { {report?.days.map((day) => (