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

adds the ability to remove websites from the dashboard #3049

Merged
merged 2 commits into from
Nov 18, 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
17 changes: 17 additions & 0 deletions src/app/(main)/dashboard/DashboardEdit.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@

.item {
padding: 5px 0;
position: relative;
}

.pinActive {
position: absolute;
top: 10px;
right: 10px;
padding: 5px;
}

.pin {
width: 20px;
height: 20px;
}

.item h1 {
Expand All @@ -26,6 +39,10 @@
background: var(--base50);
}

.websiteActive .text {
border: 1px solid var(--base800);
}

.active .text {
border-color: var(--base600);
box-shadow: 4px 4px 4px var(--base100);
Expand Down
19 changes: 17 additions & 2 deletions src/app/(main)/dashboard/DashboardEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState, useMemo, useEffect } from 'react';
import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd';
import classNames from 'classnames';
import { Button, Loading } from 'react-basics';
import Icons from 'components/icons';
import { firstBy } from 'thenby';
import useDashboard, { saveDashboard } from 'store/dashboard';
import { useMessages, useWebsites } from 'components/hooks';
Expand All @@ -11,9 +12,10 @@ const DRAG_ID = 'dashboard-website-ordering';

export function DashboardEdit({ teamId }: { teamId: string }) {
const settings = useDashboard();
const { websiteOrder } = settings;
const { websiteOrder, websiteActive } = settings;
const { formatMessage, labels } = useMessages();
const [order, setOrder] = useState(websiteOrder || []);
const [active, setActive] = useState(websiteActive || []);
const [websites, setWebsites] = useState([]);

const {
Expand Down Expand Up @@ -53,19 +55,27 @@ export function DashboardEdit({ teamId }: { teamId: string }) {
setOrder(orderedWebsites.map(website => website?.id || 0));
}

function handleActiveWebsites(id: string) {
setActive(prevActive =>
prevActive.includes(id) ? prevActive.filter(a => a !== id) : [...prevActive, id],
);
}

function handleSave() {
saveDashboard({
editing: false,
websiteOrder: order,
websiteActive: active,
});
}

function handleCancel() {
saveDashboard({ editing: false, websiteOrder });
saveDashboard({ editing: false, websiteOrder, websiteActive });
}

function handleReset() {
setOrder([]);
setActive([]);
}

if (isLoading) {
Expand Down Expand Up @@ -101,11 +111,16 @@ export function DashboardEdit({ teamId }: { teamId: string }) {
ref={provided.innerRef}
className={classNames(styles.item, {
[styles.active]: snapshot.isDragging,
[styles.websiteActive]: active.includes(id),
})}
{...provided.draggableProps}
{...provided.dragHandleProps}
onClick={() => handleActiveWebsites(id)}
>
<div className={styles.text}>
<div className={styles.pinActive}>
{active.includes(id) ? <Icons.PushPin className={styles.pin} /> : null}
</div>
<h1>{name}</h1>
<h2>{domain}</h2>
</div>
Expand Down
15 changes: 7 additions & 8 deletions src/app/(main)/websites/[websiteId]/WebsiteChartList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ export default function WebsiteChartList({
limit?: number;
}) {
const { formatMessage, labels } = useMessages();
const { websiteOrder } = useDashboard();
const { websiteOrder, websiteActive } = useDashboard();
const { renderTeamUrl } = useTeamUrl();
const { dir } = useLocale();

const ordered = useMemo(
() =>
websites
.map(website => ({ ...website, order: websiteOrder.indexOf(website.id) || 0 }))
.sort(firstBy('order')),
[websites, websiteOrder],
);
const ordered = useMemo(() => {
return websites
.filter(website => (websiteActive.length ? websiteActive.includes(website.id) : true))
.map(website => ({ ...website, order: websiteOrder.indexOf(website.id) || 0 }))
.sort(firstBy('order'));
}, [websites, websiteOrder, websiteActive]);

return (
<div>
Expand Down
8 changes: 8 additions & 0 deletions src/assets/pushpin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/components/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Moon from 'assets/moon.svg';
import Nodes from 'assets/nodes.svg';
import Overview from 'assets/overview.svg';
import Profile from 'assets/profile.svg';
import PushPin from 'assets/pushpin.svg';
import Reports from 'assets/reports.svg';
import Sun from 'assets/sun.svg';
import User from 'assets/user.svg';
Expand Down Expand Up @@ -47,6 +48,7 @@ const icons = {
Nodes,
Overview,
Profile,
PushPin,
Reports,
Sun,
User,
Expand Down
1 change: 1 addition & 0 deletions src/store/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const initialState = {
showCharts: true,
limit: DEFAULT_WEBSITE_LIMIT,
websiteOrder: [],
websiteActive: [],
editing: false,
};

Expand Down