Skip to content

Commit

Permalink
refactor: display a message when no options in the filter (#3292)
Browse files Browse the repository at this point in the history
* refactor: display a message when no options

* refactor: empty text component
  • Loading branch information
hamed-musallam authored Nov 21, 2024
1 parent e9a2b0c commit 28e70a8
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 82 deletions.
32 changes: 32 additions & 0 deletions src/component/elements/EmptyText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import styled from '@emotion/styled';
import type { CSSProperties } from 'react';
import { FaRegEyeSlash } from 'react-icons/fa';

const EmptyContainer = styled.div`
display: flex;
justify-content: center;
color: #6a6a6a;
padding: 1.5rem 0;
`;

const Icon = styled(FaRegEyeSlash)`
margin: 0 10px;
font-size: 1.1rem;
`;
const Text = styled.span`
font-size: 0.8rem;
`;
interface EmptyTextProps {
text: string;
style?: { text?: CSSProperties; icon?: CSSProperties };
}

export function EmptyText(props: EmptyTextProps) {
const { text, style = { text: {}, icon: {} } } = props;
return (
<EmptyContainer>
<Icon style={style.icon} />
<Text style={style.text}>{text}</Text>
</EmptyContainer>
);
}
2 changes: 1 addition & 1 deletion src/component/hooks/useFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { Spectrum1D, Spectrum2D } from 'nmr-load-save';
import type { Filter1DEntry, Filter2DEntry } from 'nmr-processing';
import { useMemo } from 'react';

import type { ExtractFilterEntry } from '../../data/types/common/ExtractFilterEntry.js';
import type { FilterEntry } from '../../data/types/common/FilterEntry.js';

import useSpectrum from './useSpectrum.js';
import type { ExtractFilterEntry } from '../../data/types/common/ExtractFilterEntry.js';

const emptyData = { filters: {} };
type FilterReturnType<T> = T extends Filter1DEntry['name']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import type {
} from 'nmr-load-save';
import { useFormContext } from 'react-hook-form';

import { getFilterLabel } from '../../../../data/getFilterLabel.js';
import IsotopesViewer from '../../../elements/IsotopesViewer.js';
import Label from '../../../elements/Label.js';
import ReactTable from '../../../elements/ReactTable/ReactTable.js';
import type { CustomColumn } from '../../../elements/ReactTable/utility/addCustomColumn.js';
import type { WorkspaceWithSource } from '../../../reducer/preferences/preferencesReducer.js';
import { getFilterLabel } from '../../../../data/getFilterLabel.js';

function OnLoadProcessingTabContent() {
const { register, watch } = useFormContext<WorkspacePreferences>();
Expand Down
6 changes: 3 additions & 3 deletions src/component/panels/IntegralsPanel/IntegralTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SIGNAL_KINDS } from '../../../data/constants/signalsKinds.js';
import { checkIntegralKind } from '../../../data/data1d/Spectrum1D/index.js';
import { useDispatch } from '../../context/DispatchContext.js';
import { EditableColumn } from '../../elements/EditableColumn.js';
import { EmptyText } from '../../elements/EmptyText.js';
import ReactTable from '../../elements/ReactTable/ReactTable.js';
import type { CustomColumn } from '../../elements/ReactTable/utility/addCustomColumn.js';
import addCustomColumn, {
Expand All @@ -15,8 +16,7 @@ import addCustomColumn, {
import Select from '../../elements/Select.js';
import { usePanelPreferences } from '../../hooks/usePanelPreferences.js';
import { formatNumber } from '../../utility/formatNumber.js';
import NoDataForFid from '../extra/placeholder/NoDataForFid.js';
import NoTableData from '../extra/placeholder/NoTableData.js';
import { NoDataForFid } from '../extra/placeholder/NoDataForFid.js';

import type { IntegralPanelInnerProps } from './IntegralPanel.js';

Expand Down Expand Up @@ -180,7 +180,7 @@ function IntegralTable({ activeTab, data, info }: IntegralTableProps) {
}

if (!data || data.length === 0) {
return <NoTableData />;
return <EmptyText text="No data" />;
}

return <ReactTable data={data} columns={tableColumns} />;
Expand Down
6 changes: 3 additions & 3 deletions src/component/panels/PeaksPanel/PeaksTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FaEdit, FaRegTrashAlt } from 'react-icons/fa';

import { useDispatch } from '../../context/DispatchContext.js';
import { EditableColumn } from '../../elements/EditableColumn.js';
import { EmptyText } from '../../elements/EmptyText.js';
import ReactTable from '../../elements/ReactTable/ReactTable.js';
import type { ControlCustomColumn } from '../../elements/ReactTable/utility/addCustomColumn.js';
import addCustomColumn, {
Expand All @@ -13,8 +14,7 @@ import addCustomColumn, {
import { usePanelPreferences } from '../../hooks/usePanelPreferences.js';
import { EditPeakShapeModal } from '../../modal/EditPeakShapeModal.js';
import { formatNumber } from '../../utility/formatNumber.js';
import NoDataForFid from '../extra/placeholder/NoDataForFid.js';
import NoTableData from '../extra/placeholder/NoTableData.js';
import { NoDataForFid } from '../extra/placeholder/NoDataForFid.js';

import type { PeakRecord } from './PeaksPanel.js';

Expand Down Expand Up @@ -203,7 +203,7 @@ function PeaksTable({ activeTab, data, info }: PeaksTableProps) {
}

if (!data || data.length === 0) {
return <NoTableData />;
return <EmptyText text="No data" />;
}

return (
Expand Down
6 changes: 3 additions & 3 deletions src/component/panels/RangesPanel/RangesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type { Info1D } from 'nmr-processing';
import { FaLink } from 'react-icons/fa';

import { withDialog } from '../../elements/DialogManager.js';
import { EmptyText } from '../../elements/EmptyText.js';
import type { TableContextMenuProps } from '../../elements/ReactTable/ReactTable.js';
import useTableSortBy from '../../hooks/useTableSortBy.js';
import { EditRangeModal } from '../../modal/editRange/EditRangeModal.js';
import NoDataForFid from '../extra/placeholder/NoDataForFid.js';
import NoTableData from '../extra/placeholder/NoTableData.js';
import { NoDataForFid } from '../extra/placeholder/NoDataForFid.js';

import RangesTableRow from './RangesTableRow.js';
import useMapRanges from './hooks/useMapRanges.js';
Expand Down Expand Up @@ -86,7 +86,7 @@ function RangesTable({
}

if (!tableData || tableData.length === 0) {
return <NoTableData />;
return <EmptyText text="No data" />;
}

const showActions =
Expand Down
14 changes: 7 additions & 7 deletions src/component/panels/ZonesPanel/ZonesTable.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import type {
Zones1DNucleusPreferences,
Zones2DNucleusPreferences,
} from 'nmr-load-save';
import type { Info2D } from 'nmr-processing';
import type { ReactNode } from 'react';
import { FaLink } from 'react-icons/fa';

import { withDialog } from '../../elements/DialogManager.js';
import { EmptyText } from '../../elements/EmptyText.js';
import { usePanelPreferences } from '../../hooks/usePanelPreferences.js';
import useTableSortBy from '../../hooks/useTableSortBy.js';
import { EditZoneModal } from '../../modal/editZone/EditZoneModal.js';
import NoDataForFid from '../extra/placeholder/NoDataForFid.js';
import NoTableData from '../extra/placeholder/NoTableData.js';
import { NoDataForFid } from '../extra/placeholder/NoDataForFid.js';

import ZonesTableRow from './ZonesTableRow.js';
import { useMapZones } from './hooks/useMapZones.js';
import type {
Zones1DNucleusPreferences,
Zones2DNucleusPreferences,
} from 'nmr-load-save';

const tableStyle = css`
border-spacing: 0;
Expand Down Expand Up @@ -121,7 +121,7 @@ function ZonesTable({ tableData, onUnlink, nucleus, info }: ZonesTableProps) {
}

if (!tableData || tableData.length === 0) {
return <NoTableData />;
return <EmptyText text="No data" />;
}

return (
Expand Down
4 changes: 2 additions & 2 deletions src/component/panels/databasePanel/DatabasePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useChartData } from '../../context/ChartContext.js';
import { useDispatch } from '../../context/DispatchContext.js';
import { usePreferences } from '../../context/PreferencesContext.js';
import { useToaster } from '../../context/ToasterContext.js';
import { EmptyText } from '../../elements/EmptyText.js';
import { useFormatNumberByNucleus } from '../../hooks/useFormatNumberByNucleus.js';
import useSpectraByActiveNucleus from '../../hooks/useSpectraPerNucleus.js';
import { options } from '../../toolbar/ToolTypes.js';
Expand All @@ -31,7 +32,6 @@ import { exportAsJSON } from '../../utility/export.js';
import nucleusToString from '../../utility/nucleusToString.js';
import { PanelNoData } from '../PanelNoData.js';
import { tablePanelStyle } from '../extra/BasicPanelStyle.js';
import NoTableData from '../extra/placeholder/NoTableData.js';
import type { SettingsRef } from '../extra/utilities/settingImperativeHandle.js';
import PreferencesHeader from '../header/PreferencesHeader.js';

Expand Down Expand Up @@ -418,7 +418,7 @@ function DatabasePanelInner({
onSave={saveHandler}
/>
) : (
<NoTableData
<EmptyText
text={
databases && databases?.length > 0
? 'Please select a database'
Expand Down
6 changes: 3 additions & 3 deletions src/component/panels/extra/placeholder/NoDataForFid.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NoTableData from './NoTableData.js';
import { EmptyText } from '../../../elements/EmptyText.js';

export default function NoDataForFid() {
return <NoTableData text="Not available for FID" />;
export function NoDataForFid() {
return <EmptyText text="Not available for FID" />;
}
26 changes: 0 additions & 26 deletions src/component/panels/extra/placeholder/NoTableData.tsx

This file was deleted.

40 changes: 9 additions & 31 deletions src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ import styled from '@emotion/styled';
import { v4 } from '@lukeed/uuid';
import { Filters1D, Filters2D } from 'nmr-processing';
import { memo, useEffect, useRef, useState } from 'react';
import { FaRegEyeSlash, FaRegTrashAlt } from 'react-icons/fa';
import { FaRegTrashAlt } from 'react-icons/fa';
import { ObjectInspector } from 'react-inspector';
import { Button } from 'react-science/ui';

import { getFilterLabel } from '../../../../data/getFilterLabel.js';
import type { FilterEntry as BaseFilterEntry } from '../../../../data/types/common/FilterEntry.js';
import { useChartData } from '../../../context/ChartContext.js';
import { useDispatch } from '../../../context/DispatchContext.js';
import { useToaster } from '../../../context/ToasterContext.js';
import type { AlertButton } from '../../../elements/Alert.js';
import { useAlert } from '../../../elements/Alert.js';
import { EmptyText } from '../../../elements/EmptyText.js';
import { Sections } from '../../../elements/Sections.js';
import useSpectraByActiveNucleus from '../../../hooks/useSpectraPerNucleus.js';
import useSpectrum from '../../../hooks/useSpectrum.js';

import { filterOptionPanels } from './index.js';
import { getFilterLabel } from '../../../../data/getFilterLabel.js';

const nonRemovableFilters = new Set<BaseFilterEntry['name']>([
'digitalFilter',
Expand Down Expand Up @@ -248,7 +249,7 @@ function FiltersInner(props: FiltersInnerProps) {
}

if (filtersList?.length === 0) {
return <EmptyFilters />;
return <EmptyText text="No Filters" />;
}

function handleClose() {
Expand Down Expand Up @@ -296,7 +297,11 @@ function FiltersInner(props: FiltersInnerProps) {
/>
) : (
<Sections.Body>
<ObjectInspector data={error || value} />
{value && Object.keys(value).length > 0 ? (
<ObjectInspector data={value} />
) : (
<EmptyText text=" No options available" />
)}
</Sections.Body>
)}
</Sections.Item>
Expand All @@ -321,30 +326,3 @@ export function FiltersSectionsPanel() {

return <MemoizedFilters {...{ filters, spectraCounter, activeFilterID }} />;
}

const EmptyContainer = styled.div`
display: flex;
justify-content: center;
color: #6a6a6a;
padding: 10px 0;
`;

export function EmptyFilters() {
return (
<EmptyContainer>
<FaRegEyeSlash
style={{
margin: '0px 10px',
fontSize: '16px',
}}
/>
<span
style={{
fontSize: '11px',
}}
>
No Filters
</span>
</EmptyContainer>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Fragment, useMemo } from 'react';
import type { SpectraAnalysisData } from '../../../data/data1d/multipleSpectraAnalysis.js';
import { usePreferences } from '../../context/PreferencesContext.js';
import { useSortSpectra } from '../../context/SortSpectraContext.js';
import { EmptyText } from '../../elements/EmptyText.js';
import ReactTable from '../../elements/ReactTable/ReactTable.js';
import type { CustomColumn } from '../../elements/ReactTable/utility/addCustomColumn.js';
import addCustomColumn from '../../elements/ReactTable/utility/addCustomColumn.js';
import { useFormatNumberByNucleus } from '../../hooks/useFormatNumberByNucleus.js';
import { usePanelPreferences } from '../../hooks/usePanelPreferences.js';
import evaluate from '../../utility/Evaluate.js';
import NoTableData from '../extra/placeholder/NoTableData.js';

import AnalysisCell from './base/AnalysisCell.js';
import AnalysisColumnHeader from './base/AnalysisColumnHeader.js';
Expand Down Expand Up @@ -152,7 +152,7 @@ function MultipleSpectraAnalysisTable({
/>
</Fragment>
) : (
<NoTableData />
<EmptyText text="No data" />
);
}

Expand Down
1 change: 1 addition & 0 deletions src/data/getFilterLabel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Filters1D, Filters2D } from 'nmr-processing';

import type { FilterEntry } from './types/common/FilterEntry.js';

export function getFilterLabel(name: FilterEntry['name']): string {
Expand Down

0 comments on commit 28e70a8

Please sign in to comment.