From ad0189b25307553f068c4fba1ed66e435aad22e2 Mon Sep 17 00:00:00 2001 From: Connor Finley Date: Sat, 20 Feb 2021 17:02:50 -0500 Subject: [PATCH] #11 Prevent delete/download of pages if none selected Remove daily notes filter in table, react-table filtering is too dumb and I don't have the energy right now. --- src/features/all-pages/AllPages.js | 7 +------ src/features/all-pages/PagesTable.js | 21 ++++++++++++++++----- src/features/all-pages/all-pages.scss | 10 ++++++++++ src/features/links/linksSlice.js | 1 + 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/features/all-pages/AllPages.js b/src/features/all-pages/AllPages.js index 86b0a83..acab265 100644 --- a/src/features/all-pages/AllPages.js +++ b/src/features/all-pages/AllPages.js @@ -20,8 +20,7 @@ const getData = (blocks, linksToBlocks) => { blockId: block.id, created: block.created, updated: block.updated, - mentions: linksToBlocks[block.id] || [], - dailyNote: !!block.dailyNote + mentions: linksToBlocks[block.id] || [] })) } @@ -58,10 +57,6 @@ const AllPages = props => { accessor: 'created', className: 'text-right', Cell: ({ value }) => value ? dayjs(value).format(DAILY_NOTE_DISPLAY_FORMAT) : null - }, { - Header: 'Daily Note?', - accessor: 'dailyNote', - show: false } ], [onMentionClick] diff --git a/src/features/all-pages/PagesTable.js b/src/features/all-pages/PagesTable.js index ef3e6d0..49d2380 100644 --- a/src/features/all-pages/PagesTable.js +++ b/src/features/all-pages/PagesTable.js @@ -1,7 +1,7 @@ import React from 'react' import { useSelector, useDispatch } from 'react-redux' import { useTable, useSortBy, useRowSelect } from 'react-table' -import { ChevronDown, ChevronUp, Trash, Download, Calendar3 } from 'react-bootstrap-icons' +import { ChevronDown, ChevronUp, Trash, Download } from 'react-bootstrap-icons' import { save } from '../io/io' import { serialize, flattenTreeIds } from '../block/blockModel' @@ -33,6 +33,9 @@ const PagesTable = ({ columns, data }) => { const linksToBlocks = useSelector(state => state.links.to) const downloadRows = rows => { + if (!rows.length) { + return + } const files = rows .map(row => row.original.blockId) .map(blockId => { @@ -51,6 +54,9 @@ const PagesTable = ({ columns, data }) => { * @param {object} rows - table rows */ const deleteRows = rows => { + if (!rows.length) { + return + } rows .map(row => row.original.blockId) .map(blockId => { @@ -82,7 +88,7 @@ const PagesTable = ({ columns, data }) => { rows, prepareRow, selectedFlatRows, - state: { selectedRowIds }, + state: { selectedRowIds } } = useTable( { columns, @@ -112,10 +118,15 @@ const PagesTable = ({ columns, data }) => { return ( <>
- deleteRows(selectedFlatRows)} className="mr-3" color={Object.keys(selectedRowIds).length ? 'white' : 'gray'} /> - downloadRows(selectedFlatRows)} color={Object.keys(selectedRowIds).length ? 'white' : 'gray'} /> + deleteRows(selectedFlatRows)} + className={`mr-3 all-pages__button${Object.keys(selectedRowIds).length ? ' active': ''}`} + /> + downloadRows(selectedFlatRows)} + className={`all-pages__button${Object.keys(selectedRowIds).length ? ' active': ''}`} + />
-
diff --git a/src/features/all-pages/all-pages.scss b/src/features/all-pages/all-pages.scss index 4cb4158..ddb826a 100644 --- a/src/features/all-pages/all-pages.scss +++ b/src/features/all-pages/all-pages.scss @@ -5,6 +5,16 @@ padding: 10px } +.all-pages__button { + cursor: not-allowed; + fill: gray; + + &.active { + cursor: pointer; + fill: white; + } +} + .mentions-bubble { position: relative; width: 37px; diff --git a/src/features/links/linksSlice.js b/src/features/links/linksSlice.js index 6a44cc9..9e28b15 100644 --- a/src/features/links/linksSlice.js +++ b/src/features/links/linksSlice.js @@ -73,6 +73,7 @@ const linksSlice = createSlice({ .map(destinationBlockId => { state.to[destinationBlockId] = state.to[destinationBlockId] .filter(sourceBlockId => sourceBlockId !== blockId) + return true }) } delete state.from[blockId]