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

Tno 2561 add keywords #1798

Merged
merged 5 commits into from
May 9, 2024
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
26 changes: 26 additions & 0 deletions app/editor/src/features/admin/filters/constants/filterColumns.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { FaRegClipboard } from 'react-icons/fa';
import { CellCheckbox, CellEllipsis, IFilterModel, ITableHookColumn } from 'tno-core';

import { handleCopyKeyWords } from '../utils/handleCopyKeyWords';
import { truncateString } from '../utils/truncateString';

export const filterColumns: ITableHookColumn<IFilterModel>[] = [
{
label: 'Name',
Expand All @@ -19,6 +23,28 @@ export const filterColumns: ITableHookColumn<IFilterModel>[] = [
width: 2,
cell: (cell) => <CellEllipsis>{cell.original.owner?.username}</CellEllipsis>,
},
{
label: 'Keywords',
accessor: 'keywords',
width: 2,
cell: (cell) => {
return (
<div className="keyword-cell">
<CellEllipsis>{truncateString(cell.original.settings?.search)}</CellEllipsis>
{cell.original.settings?.search ? (
<FaRegClipboard
className="clipboard-icon"
title="Copy keywords to clipboard"
onClick={(e) => {
e.stopPropagation();
handleCopyKeyWords(e, cell);
}}
/>
) : null}
</div>
);
},
},
{
label: 'Enabled',
accessor: 'isEnabled',
Expand Down
16 changes: 16 additions & 0 deletions app/editor/src/features/admin/filters/styled/FilterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ export const FilterList = styled.div`
max-height: calc(100% - 120px);
min-height: 200px;
}
.keyword-cell {
display: flex;
align-items: center;
position: relative;

.clipboard-icon {
opacity: 0;
transition: opacity 0.1s ease;
cursor: pointer;
margin-left: 0.5rem;
}

&:hover .clipboard-icon {
opacity: 1;
}
}
`;
11 changes: 11 additions & 0 deletions app/editor/src/features/admin/filters/utils/handleCopyKeyWords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { toast } from 'react-toastify';

export const handleCopyKeyWords = (event: any, cell: any) => {
navigator.clipboard.writeText(cell.original.settings!.search);
// animate the clipboar icon to show something happened
event.target.classList.toggle('animate');
setTimeout(() => {
event.target.classList.toggle('animate');
}, 200);
toast.success('Keywords copied to clipboard');
};
7 changes: 7 additions & 0 deletions app/editor/src/features/admin/filters/utils/truncateString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const truncateString = (str: string | undefined, num: number = 20) => {
if (!str) return '';
if (str.length > num) {
return str.slice(0, num) + '...';
}
return str;
};
22 changes: 20 additions & 2 deletions app/subscriber/src/features/my-searches/MySearches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { Action } from 'components/action';
import { SubscriberTableContainer } from 'components/table';
import React from 'react';
import { FaCheck, FaSave } from 'react-icons/fa';
import { FaBookmark, FaGear, FaPen, FaTrash } from 'react-icons/fa6';
import { FaBookmark, FaGear, FaPen, FaRegClipboard, FaTrash } from 'react-icons/fa6';
import { useNavigate } from 'react-router-dom';
import { toast } from 'react-toastify';
import { useContent, useFilters } from 'store/hooks';
import { useProfileStore } from 'store/slices';
import { Col, IFilterModel, Modal, Row, Text, useModal } from 'tno-core';

import { truncateTeaser } from '../../components/content-list/utils/truncateTeaser';
import * as styled from './styled';

/** contains a list of the user's filters, allows for edit and viewing */
Expand Down Expand Up @@ -52,14 +53,19 @@ export const MySearches = () => {
},
[editing?.id, navigate, storeFilter, storeSearchFilter],
);

const handleCopyKeywords = (keywords: any) => {
navigator.clipboard.writeText(keywords);
toast.success('Keywords copied to clipboard');
};
return (
<styled.MySearches>
<SubscriberTableContainer>
<Row className="header">
<span className="label">Search Name</span>
</Row>
{myFilters.map((filter, index) => {
const keywords = filter.settings?.search ? filter.settings.search : '';
const truncatedKeywords = truncateTeaser(keywords, 20);
return (
<Row key={filter.id} className="row">
<FaBookmark className="darker-icon link" onClick={() => handleClick(filter)} />
Expand All @@ -78,6 +84,18 @@ export const MySearches = () => {
filter.name
)}
</Col>
<Col flex="1">
{truncatedKeywords ? (
<Row className="keywords-row">
{truncatedKeywords}
<FaRegClipboard
className="copy-icon"
onClick={() => handleCopyKeywords(filter.settings?.search)}
title="Copy Keywords"
/>
</Row>
) : null}
</Col>
{editing?.id === filter.id ? (
<FaCheck onClick={() => setEditing(undefined)} />
) : (
Expand Down
17 changes: 17 additions & 0 deletions app/subscriber/src/features/my-searches/styled/MySearches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,21 @@ export const MySearches = styled(Col)`
margin: 0.25rem;
}
}

.keywords-row {
display: flex;
align-items: center;
padding: 0.5rem;
}
.copy-icon {
opacity: 0;
transition: opacity 0.1s ease;
margin-left: 1rem;
cursor: pointer;
}

.copy-icon:hover {
opacity: 1;
color: ${(props) => props.theme.css.sideBarIconHoverColor};
}
`;
Loading