Library Panels: Don't list current panel in available panels list (#31472)

This commit is contained in:
kay delaney
2021-02-25 13:20:02 +00:00
committed by GitHub
parent ad68f3c5e6
commit 8379f36a68
2 changed files with 9 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ interface LibraryPanelViewProps {
onClickCard?: (panel: LibraryPanelDTO) => void; onClickCard?: (panel: LibraryPanelDTO) => void;
formatDate?: (dateString: DateTimeInput, format?: string) => string; formatDate?: (dateString: DateTimeInput, format?: string) => string;
showSecondaryActions?: boolean; showSecondaryActions?: boolean;
currentPanelId?: string;
} }
export const LibraryPanelsView: React.FC<LibraryPanelViewProps> = ({ export const LibraryPanelsView: React.FC<LibraryPanelViewProps> = ({
@@ -22,6 +23,7 @@ export const LibraryPanelsView: React.FC<LibraryPanelViewProps> = ({
onClickCard, onClickCard,
formatDate, formatDate,
showSecondaryActions, showSecondaryActions,
currentPanelId: currentPanel,
}) => { }) => {
const styles = useStyles(getPanelViewStyles); const styles = useStyles(getPanelViewStyles);
const [searchString, setSearchString] = useState(''); const [searchString, setSearchString] = useState('');
@@ -38,10 +40,14 @@ export const LibraryPanelsView: React.FC<LibraryPanelViewProps> = ({
const [filteredItems, setFilteredItems] = useState(libraryPanels); const [filteredItems, setFilteredItems] = useState(libraryPanels);
useDebounce( useDebounce(
() => { () => {
setFilteredItems(libraryPanels?.filter((v) => v.name.toLowerCase().includes(searchString.toLowerCase()))); setFilteredItems(
libraryPanels?.filter(
(v) => v.name.toLowerCase().includes(searchString.toLowerCase()) && v.uid !== currentPanel
)
);
}, },
300, 300,
[searchString, libraryPanels] [searchString, libraryPanels, currentPanel]
); );
const onDeletePanel = async (uid: string) => { const onDeletePanel = async (uid: string) => {

View File

@@ -59,6 +59,7 @@ export const PanelLibraryOptionsGroup: React.FC<Props> = ({ panel, dashboard })
> >
<LibraryPanelsView <LibraryPanelsView
formatDate={(dateString: string) => dashboard.formatDate(dateString, 'L')} formatDate={(dateString: string) => dashboard.formatDate(dateString, 'L')}
currentPanelId={panel.libraryPanel?.uid}
showSecondaryActions showSecondaryActions
> >
{(panel) => ( {(panel) => (