Skip to content

Commit e3d9e09

Browse files
committed
feat: Highlighter
1 parent 39f9a64 commit e3d9e09

File tree

10 files changed

+55
-12
lines changed

10 files changed

+55
-12
lines changed

packages/components/src/entry-input-layout.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled from 'styled-components'
44
import { Spacings } from './spacing'
55
import { FontSizes } from './font-size'
66
import { BorderRadii } from './border-radius'
7+
import Highlighter from './highlighter'
78

89
const ActionWrapper = styled.div`
910
display: flex;
@@ -118,13 +119,6 @@ const TextWrapper = styled(ValueBase)`
118119
padding-left: 0;
119120
`
120121

121-
const Text = styled.p`
122-
margin: 0;
123-
padding: 0;
124-
white-space: pre-wrap;
125-
word-break: break-word;
126-
`
127-
128122
const Time = styled(ValueBase)`
129123
width: 100px;
130124
text-align: right;
@@ -193,17 +187,19 @@ interface EntryInputLayoutProps extends HTMLAttributes<HTMLElement>, EntryContai
193187
text: string
194188
time: string
195189
actions: JSX.Element
190+
term: string
196191
clickHandler: React.Dispatch<React.SetStateAction<boolean>>
197192
}
198193

199-
export const EntryInputLayout: React.FC<EntryInputLayoutProps> = ({ text, time, actions, clickHandler, ...rest }) => {
194+
export const EntryInputLayout: React.FC<EntryInputLayoutProps> = ({ text, time, actions, term, clickHandler, ...rest }) => {
195+
console.log(term)
200196
return (
201197
<>
202198
<StyledEntryContainer {...rest}>
203199
<StyledEntryValueWrapper>
204200
<StyledInputWrapper onClick={() => clickHandler(true)}>
205201
<TextWrapper>
206-
<Text>{text}</Text>
202+
<Highlighter term={term}>{text}</Highlighter>
207203
</TextWrapper>
208204
<Time>{time}</Time>
209205
</StyledInputWrapper>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
interface highlighterProps {
3+
term: string
4+
children: string
5+
}
6+
7+
const Highlighter: React.FC<highlighterProps> = ({term, children}) => {
8+
if (!term) {
9+
return (
10+
<>{children}</>
11+
)
12+
}
13+
const regex = new RegExp(`(${term})`, 'gi');
14+
const parts = children.split(regex);
15+
console.log(parts)
16+
17+
return(
18+
<>
19+
<div>test</div>
20+
{parts.map((part: string, index: number)=>
21+
regex.test(part) ? (
22+
<span key={index} style={{margin: 0, backgroundColor: "rgb(84 198 247)", padding: 0, whiteSpace: "pre-wrap", wordBreak: "break-word", fontWeight: "bold"}}>
23+
{part}
24+
</span>
25+
) : (part)
26+
)}
27+
</>
28+
)
29+
}
30+
31+
export default Highlighter

packages/frontend/src/components/day-input.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ interface DayInputProps {
6666
disabled?: boolean
6767
reportStatus?: ReportStatus
6868
primary?: boolean
69+
term: string
6970
updateMessageDay?: (message: string, commentId: string) => void
7071
updateMessageEntry?: (
7172
message: string,
@@ -86,6 +87,7 @@ const DayInput: React.FunctionComponent<DayInputProps> = ({
8687
primary,
8788
updateMessageDay,
8889
updateMessageEntry,
90+
term,
8991
}) => {
9092
const { getTotalMinutes } = useDayHelper()
9193
const { addToast } = useToastContext()
@@ -232,6 +234,7 @@ const DayInput: React.FunctionComponent<DayInputProps> = ({
232234
}
233235
>
234236
<EntriesInput
237+
term={term}
235238
handleStatusChange={handleStatusChange}
236239
day={day}
237240
reportStatus={reportStatus ?? ReportStatus.Todo}

packages/frontend/src/components/entries-input.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { useToastContext } from '../hooks/use-toast-context'
2020
import { useDayHelper } from '../helper/day-helper'
2121

2222
interface EntriesInputProps {
23+
term: string
2324
day?: Pick<Day, 'id' | 'date'> & {
2425
entries: (Pick<Entry, 'id' | 'text' | 'time' | 'orderId'> & {
2526
comments: (Pick<Comment, 'id' | 'text' | 'published'> & {
@@ -49,6 +50,7 @@ const EntriesInput: React.FC<EntriesInputProps> = ({
4950
handleStatusChange,
5051
trainee,
5152
updateMessage,
53+
term,
5254
}) => {
5355
const [createEntryMutation] = useCreateEntryMutation()
5456
const { addToast } = useToastContext()
@@ -107,6 +109,7 @@ const EntriesInput: React.FC<EntriesInputProps> = ({
107109
.sort((a, b) => a.orderId - b.orderId)
108110
.map((entry) => (
109111
<EntryInput
112+
term={term}
110113
handleStatusChange={handleStatusChange}
111114
key={entry.id}
112115
disabled={disabled}

packages/frontend/src/components/entry-input.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ interface EntryDisplayFieldProps {
5353
showContextMenu?: string
5454
setShowContextMenu?: React.Dispatch<React.SetStateAction<string>>
5555
updateMessage?: (message: string, commentId: string) => void
56+
term: string
5657
}
5758

5859
const EntryInput: React.FC<EntryDisplayFieldProps> = ({
@@ -65,6 +66,7 @@ const EntryInput: React.FC<EntryDisplayFieldProps> = ({
6566
showContextMenu,
6667
setShowContextMenu,
6768
updateMessage,
69+
term,
6870
}) => {
6971
const { loading, data } = useEntryInputDataQuery()
7072

@@ -301,6 +303,7 @@ const EntryInput: React.FC<EntryDisplayFieldProps> = ({
301303
<TextTimeInput autoFocus entry={entry} onDelete={handleDelete} onSave={handleSave} />
302304
) : (
303305
<EntryInputLayout
306+
term={term}
304307
clickable
305308
disabled={disabled}
306309
draggable={!disabled}

packages/frontend/src/pages/archive-page.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ const ArchivePage: React.FunctionComponent = () => {
123123

124124
const [allChecked, setAllChecked] = React.useState(false)
125125
const [selectedTrainee, setSelectedTrainee] = React.useState<string | undefined>(undefined)
126+
const [term, setTerm] = React.useState<string | undefined>(undefined)
126127

127128
const getArchivedReports = React.useCallback(() => {
128129
if (!data) return []
@@ -215,6 +216,8 @@ const ArchivePage: React.FunctionComponent = () => {
215216
let weekEnd: number | undefined = undefined
216217
let searchText: string | undefined = undefined
217218

219+
setTerm(value)
220+
218221
const yearMatch = yearMonthRegex.exec(value)
219222
if (yearMonthRegex.test(value) && yearMatch) {
220223
year = parseInt(yearMatch[1], 10)
@@ -346,8 +349,8 @@ const ArchivePage: React.FunctionComponent = () => {
346349

347350
const link =
348351
data?.currentUser?.__typename === UserTypeEnum.Trainer
349-
? `/report/${traineeId}/${year}/${week}`
350-
: `/report/${year}/${week}`
352+
? `/report/${traineeId}/${year}/${week}/${term ? term: ""}`
353+
: `/report/${year}/${week}/${term ? term: ""}`
351354

352355
return (
353356
<StyledArchiveTableRow key={report.id}>

packages/frontend/src/pages/dashboard-page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const DashboardPage: React.FunctionComponent = () => {
6363
<Container overflow={'visible'}>
6464
<DayInput
6565
primary
66+
term=""
6667
heading={getTodayHeading()}
6768
reportStatus={reportForYearAndWeek?.status}
6869
day={day}

packages/frontend/src/pages/report-page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import { useReportHelper } from '../helper/report-helper'
4545
const ReportPage: React.FunctionComponent = () => {
4646
const navigate = useNavigate()
4747
const { getFinishedDays } = useReportHelper()
48-
const { trainee, year, week } = useParams()
48+
const { trainee, year, week, term } = useParams()
4949

5050
const variables: ReportPageDataQueryVariables = {
5151
year: parseInt(year ?? '', 10),
@@ -282,6 +282,7 @@ const ReportPage: React.FunctionComponent = () => {
282282
{report?.days.map((day) => (
283283
<StyledTopBorderWrapper key={day.id}>
284284
<DayInput
285+
term={term ? term : ""}
285286
day={day}
286287
disabled={reportArchived || reportReview || day.status === DayStatusEnum.Holiday}
287288
reportStatus={report.status}

packages/frontend/src/pages/report-review-page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ const ReportReviewPage: React.FunctionComponent = () => {
388388
<>
389389
{day.entries.map((entry, entryIndex) => (
390390
<EntryInput
391+
term=""
391392
key={entryIndex}
392393
entry={entry}
393394
day={day}

packages/frontend/src/routes.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const AppRoutes: React.FunctionComponent<RoutesProps> = ({ currentUser }) => {
7171
<>
7272
<Route path="/" element={<DashboardPage />} />
7373
<Route path="/archive" element={<ArchivePage />} />
74+
<Route path="/report/:year/:week/:term" element={<ReportPage />} />
7475
<Route path="/report/:year/:week" element={<ReportPage />} />
7576
<Route path="/report/missing" element={<MissingPage />} />
7677
<Route path="/alexa" element={<AlexaPage />} />

0 commit comments

Comments
 (0)