Skip to content

Commit 5ce62e6

Browse files
committed
Add info about contents to segments modal
1 parent 9ce987d commit 5ce62e6

File tree

4 files changed

+118
-124
lines changed

4 files changed

+118
-124
lines changed

assets/js/dashboard/segments/segment-authorship.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const SegmentAuthorship = ({
2929
owner_id,
3030
inserted_at,
3131
updated_at
32-
}: SavedSegment & { inserted_at: string; updated_at: string } & {
32+
}: SavedSegment & {
3333
className?: string
3434
}) => {
3535
const site = useSiteContext()

assets/js/dashboard/segments/segment-modals.tsx

Lines changed: 78 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
SegmentType
1111
} from './segments'
1212
import {
13-
EditSegment,
13+
EditSegmentIcon,
1414
useSegmentPrefetch,
1515
useSegmentsListQuery
1616
} from './segments-dropdown'
@@ -22,16 +22,16 @@ import { rootRoute } from '../router'
2222
import { FilterPillsList } from '../nav-menu/filter-pills-list'
2323
import classNames from 'classnames'
2424
import {
25-
EyeSlashIcon,
26-
EyeIcon,
2725
XMarkIcon,
28-
CheckIcon,
2926
ChevronUpIcon,
30-
ChevronDownIcon
31-
} from '@heroicons/react/24/solid'
27+
ChevronDownIcon,
28+
TrashIcon,
29+
CheckIcon
30+
} from '@heroicons/react/24/outline'
3231
import { FilterPill } from '../nav-menu/filter-pill'
3332
import { Filter } from '../query'
3433
import { SegmentAuthorship } from './segment-authorship'
34+
import { SegmentExpandedLocationState } from './segment-expanded-context'
3535

3636
const buttonClass =
3737
'h-12 text-md font-medium py-2 px-3 rounded border dark:border-gray-100 dark:text-gray-100'
@@ -282,38 +282,9 @@ export const UpdateSegmentModal = ({
282282
)
283283
}
284284

285-
const ExpandSegmentButton = ({
286-
className,
287-
onClick,
288-
onMouseEnter,
289-
expanded
290-
}: {
291-
className?: string
292-
onClick: () => Promise<void>
293-
onMouseEnter?: () => Promise<void>
294-
expanded: boolean
295-
}) => {
296-
return (
297-
<button
298-
className={classNames(
299-
'flex w-5 h-5 items-center justify-center fill-current hover:fill-indigo-600 ',
300-
className
301-
)}
302-
onClick={onClick}
303-
onMouseEnter={onMouseEnter}
304-
>
305-
{expanded ? (
306-
<ChevronUpIcon className="block w-4 h-4" />
307-
) : (
308-
<ChevronDownIcon className="block w-4 h-4" />
309-
)}
310-
</button>
311-
)
312-
}
313285
const SegmentRow = ({
314286
id,
315287
name,
316-
// type,
317288
toggleSelected,
318289
selected
319290
}: SavedSegment & { toggleSelected: () => void; selected: boolean }) => {
@@ -322,44 +293,53 @@ const SegmentRow = ({
322293
id
323294
})
324295
const [segmentDataVisible, setSegmentDataVisible] = useState(false)
296+
const toggleSegmentDataVisible = useCallback(async () => {
297+
setSegmentDataVisible((currentVisible) => {
298+
if (currentVisible) {
299+
return false
300+
}
301+
fetchSegment()
302+
return true
303+
})
304+
}, [fetchSegment])
325305
return (
326306
<div
327-
className="grid grid-cols-[1fr_20px_20px] shadow rounded bg-white dark:bg-gray-900 text-gray-700 dark:text-gray-300 text-sm py-3 px-3 transition-all"
307+
className="grid grid-cols-[1fr_20px] shadow rounded bg-white dark:bg-gray-900 text-gray-700 dark:text-gray-300 text-sm py-3 px-3 transition-all"
328308
onMouseEnter={prefetchSegment}
329309
>
330-
{/* <button className="block" onClick={toggleSelected}>
331-
{selected && <CheckIcon className="block w-4 h-4" />}
332-
</button> */}
333-
<div
310+
<button
311+
className="group flex justify-between text-left"
312+
onClick={toggleSegmentDataVisible}
313+
>
314+
<div
315+
className={classNames(
316+
'cursor-pointer break-all',
317+
selected && 'font-extrabold'
318+
)}
319+
>
320+
{name}
321+
</div>
322+
<div className="flex w-5 h-5 items-center">
323+
{segmentDataVisible ? (
324+
<ChevronUpIcon className="block w-4 h-4" />
325+
) : (
326+
<ChevronDownIcon className="block w-4 h-4 opacity-0 group-hover:opacity-100 transition-opacity" />
327+
)}
328+
</div>
329+
</button>
330+
331+
<button
332+
className="flex items-center justify-center w-5 h-5 group"
333+
title={selected ? 'Unselect segment' : 'Select segment'}
334334
onClick={toggleSelected}
335-
className={classNames(
336-
'cursor-pointer break-all',
337-
selected && 'font-extrabold'
338-
)}
339335
>
340-
{name}
341-
{/* <span>{' · '}</span> */}
342-
{/* <span className="text-[10px] leading">
343-
{{ personal: 'personal', site: 'site' }[type]}
344-
</span> */}
345-
</div>
346-
<ExpandSegmentButton
347-
className=""
348-
expanded={segmentDataVisible}
349-
onClick={
350-
segmentDataVisible
351-
? async () => setSegmentDataVisible(false)
352-
: async () => {
353-
setSegmentDataVisible(true)
354-
fetchSegment()
355-
}
356-
}
357-
/>
358-
<EditSegment
359-
onClick={async () => {
360-
expandSegment(data ?? (await fetchSegment()))
361-
}}
362-
/>
336+
<CheckIcon
337+
className={classNames(
338+
'w-4 h-4 block opacity-0 transition-opacity',
339+
selected ? 'opacity-100' : 'opacity-30 group-hover:opacity-100'
340+
)}
341+
/>
342+
</button>
363343

364344
{segmentDataVisible && (
365345
<div className="col-span-full mt-3">
@@ -376,7 +356,35 @@ const SegmentRow = ({
376356
) : (
377357
'loading'
378358
)}
379-
<SegmentAuthorship {...data} className="mt-3 text-xs" />
359+
{!!data && <SegmentAuthorship {...data} className="mt-3 text-xs" />}
360+
<div className="col-span-full mt-3 flex gap-x-4 gap-y-2 flex-wrap">
361+
<button
362+
className="flex gap-x-1 text-sm items-center hover:text-indigo-600 fill-current hover:fill-indigo-600"
363+
onClick={async () => {
364+
expandSegment(data ?? (await fetchSegment()))
365+
}}
366+
>
367+
<EditSegmentIcon className="block h-4 w-4" />
368+
Edit segment
369+
</button>
370+
<AppNavigationLink
371+
className="flex gap-x-1 text-sm items-center hover:text-indigo-600 fill-current hover:fill-indigo-600"
372+
path={rootRoute.path}
373+
search={(s) => s}
374+
state={
375+
{
376+
expandedSegment: data,
377+
modal: 'delete'
378+
} as SegmentExpandedLocationState
379+
}
380+
// onClick={async () => {
381+
// expandSegment(data ?? (await fetchSegment()))
382+
// }}
383+
>
384+
<TrashIcon className="block h-4 w-4" />
385+
Delete segment
386+
</AppNavigationLink>
387+
</div>
380388
</div>
381389
)}
382390
</div>
@@ -473,46 +481,22 @@ export const AllSegmentsModal = () => {
473481
/>
474482
))}
475483
{segments?.length && sliceEnd < segments.length && (
476-
<button onClick={showMore} className="button self-center ">
484+
<button onClick={showMore} className="button self-center mt-1">
477485
Show more
478486
</button>
479487
)}
480488
</>
481489
))}
482490
{!personalSegments?.length && !siteSegments?.length && (
483-
<span>
484-
No segments found.{' '}
485-
{/* {!!search?.trim().length && (
486-
<button
487-
className="inline cursor-pointer hover:text-indigo-700 dark:hover:text-indigo-500"
488-
onClick={() => setSearch('')}
489-
>
490-
{'Clear search to see all.'}
491-
</button>
492-
)} */}
493-
</span>
491+
<span>No segments found.</span>
494492
)}
495493
</div>
496-
{/* <div className="my-4 border-b border-gray-300"></div> */}
497494

498495
<div className="mt-4">
499496
<h2 className="text-l font-bold dark:text-gray-100">Selected filter</h2>
500497

501498
{!!data && !!proposedSegmentFilter && (
502499
<div className="mt-2 justify-self-start">
503-
{/* <FilterPillsList
504-
className="flex-wrap"
505-
direction="horizontal"
506-
pills={proposedSegmentFilter[2].map((c) => ({
507-
children: styledFilterText(labelsForProposedSegmentFilter, [
508-
proposedSegmentFilter[0],
509-
proposedSegmentFilter[1],
510-
[c]
511-
]),
512-
plainText: 'hi',
513-
interactive: false
514-
}))}
515-
/> */}
516500
<FilterPill
517501
interactive={false}
518502
plainText={plainFilterText(

assets/js/dashboard/segments/segments-dropdown.tsx

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @format */
22

3-
import React, { useCallback, useMemo, useState } from 'react'
3+
import React, { ReactNode, useCallback, useMemo, useState } from 'react'
44
import {
55
DropdownLinkGroup,
66
DropdownNavigationLink,
@@ -37,6 +37,11 @@ import { SegmentAuthorship } from './segment-authorship'
3737

3838
export const useSegmentsListQuery = () => {
3939
const site = useSiteContext()
40+
const { query } = useQueryContext()
41+
const segmentsFilter = query.filters.find(isSegmentFilter)
42+
const appliedSegmentIds = segmentsFilter
43+
? (segmentsFilter[2] as number[])
44+
: []
4045
return useQuery({
4146
queryKey: ['segments'],
4247
placeholderData: (previousData) => previousData,
@@ -50,18 +55,13 @@ export const useSegmentsListQuery = () => {
5055
accept: 'application/json'
5156
}
5257
}
53-
).then(
54-
(
55-
res
56-
): Promise<
57-
(SavedSegment & {
58-
owner_id: number
59-
inserted_at: string
60-
updated_at: string
61-
})[]
62-
> => res.json()
58+
).then((res): Promise<SavedSegment[]> => res.json())
59+
60+
return response.sort(
61+
(a, b) =>
62+
appliedSegmentIds.findIndex((id) => id === b.id) -
63+
appliedSegmentIds.findIndex((id) => id === a.id)
6364
)
64-
return response
6565
}
6666
})
6767
}
@@ -98,11 +98,9 @@ export const SegmentsList = ({ closeList }: { closeList: () => void }) => {
9898
modal: null
9999
} as SegmentExpandedLocationState
100100
}
101-
// onClick={closeList}
102101
>
103-
{/* <XMarkIcon className="block h-4 w-4" /> */}
104102
<ChevronLeftIcon className="block h-4 w-4"></ChevronLeftIcon>
105-
<div>Back to filters</div>
103+
<div>Cancel editing</div>
106104
</AppNavigationLink>
107105
<DropdownLinkGroup>
108106
<DropdownSubtitle className="break-all">
@@ -294,7 +292,7 @@ export const useSegmentPrefetch = ({ id }: Pick<SavedSegment, 'id'>) => {
294292
const navigate = useAppNavigate()
295293

296294
const getSegmentFn: QueryFunction<
297-
{ segment_data: SegmentData } & SavedSegment,
295+
SavedSegment & { segment_data: SegmentData },
298296
typeof queryKey
299297
> = useCallback(
300298
async ({ queryKey: [_, id] }) => {
@@ -429,12 +427,15 @@ const SegmentLink = ({
429427
actions={
430428
!canSeeActions ? null : (
431429
<>
432-
<EditSegment
433-
className="ml-2 shrink-0"
430+
<button
431+
title="Edit segment"
432+
className={classNames(iconButtonClass, 'ml-2 shrink-0')}
434433
onClick={async () =>
435434
expandSegment(data ?? (await fetchSegment()))
436435
}
437-
/>
436+
>
437+
<EditSegmentIcon className="block w-4 h-4" />
438+
</button>
438439
</>
439440
)
440441
}
@@ -444,11 +445,16 @@ const SegmentLink = ({
444445
)
445446
}
446447

448+
export const iconButtonClass =
449+
'flex items-center justify-center w-5 h-5 fill-current hover:fill-indigo-600'
450+
447451
export const EditSegment = ({
452+
children,
448453
className,
449454
onClick,
450455
onMouseEnter
451456
}: {
457+
children?: ReactNode
452458
onClick: () => Promise<void>
453459
onMouseEnter?: () => Promise<void>
454460
className?: string
@@ -462,13 +468,13 @@ export const EditSegment = ({
462468
onClick={onClick}
463469
onMouseEnter={onMouseEnter}
464470
>
465-
{/* <ChevronRightIcon className="w-4 h-4"></ChevronRightIcon> */}
466-
<EditSegmentIcon className="w-4 h-4" />
471+
{children}
472+
<EditSegmentIcon className="block w-4 h-4" />
467473
</button>
468474
)
469475
}
470476

471-
const EditSegmentIcon = ({ className }: { className?: string }) => (
477+
export const EditSegmentIcon = ({ className }: { className?: string }) => (
472478
<svg
473479
className={className}
474480
viewBox="0 0 16 16"

0 commit comments

Comments
 (0)