Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function buildStatsLambdaUrl(base: string | null | undefined): string | null {
if (!hasRoute) {
const stage = 'prod';
const route = 'AggrgatedSp7Stats';
u = `${u.replace(/\/$/, '') }/${stage}/${route}`;
u = `${u.replace(/\/$/, '')}/${stage}/${route}`;
}
return u;
}
Expand All @@ -58,7 +58,10 @@ export const fetchContext = load<SystemInfo>(
if (systemInfo.stats_url !== null) {
let counts: StatsCounts | null = null;
try {
counts = await load<StatsCounts>('/context/stats_counts.json', 'application/json');
counts = await load<StatsCounts>(
'/context/stats_counts.json',
'application/json'
);
} catch {
// If counts fetch fails, proceed without them.
counts = null;
Expand Down Expand Up @@ -102,12 +105,13 @@ export const fetchContext = load<SystemInfo>(

const lambdaUrl = buildStatsLambdaUrl(systemInfo.stats_2_url);
if (lambdaUrl) {
await ping(formatUrl(lambdaUrl, parameters, false), { errorMode: 'silent' })
.catch(softFail);
await ping(formatUrl(lambdaUrl, parameters, false), {
errorMode: 'silent',
}).catch(softFail);
}
}

return systemInfo;
});

export const getSystemInfo = (): SystemInfo => systemInfo;
export const getSystemInfo = (): SystemInfo => systemInfo;
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,12 @@ export function DataSetMetaOverlay(): JSX.Element | null {
true
);

const navigate = useNavigate();

return typeof dataset === 'object' ? (
<WbDataSetMeta
dataset={dataset}
onChange={handleClose}
onClose={handleClose}
onDeleted={(): void => navigate('/specify/', { replace: true })}
onDeleted={handleClose}
/>
) : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import { Submit } from '../Atoms/Submit';
import type { EagerDataSet } from '../AttachmentsBulkImport/Import';
import { LoadingContext } from '../Core/Contexts';
import { getField } from '../DataModel/helpers';
import type { SpecifyResource } from '../DataModel/legacyTypes';
import { resourceEvents } from '../DataModel/resource';
import { tables } from '../DataModel/tables';
import type { Spdataset } from '../DataModel/types';
import { useTitle } from '../Molecules/AppTitle';
import { AutoGrowTextArea } from '../Molecules/AutoGrowTextArea';
import { DateElement } from '../Molecules/DateElement';
Expand Down Expand Up @@ -144,6 +147,8 @@ export function DataSetMeta({
expectedErrors: [Http.NOT_FOUND, Http.NO_CONTENT],
}).then(() => {
setIsDeleted(true);
const resource = {id: dataset.id, specifyTable: tables.Spdataset } as SpecifyResource<Spdataset>;
resourceEvents.trigger('deleted',resource);
})
);
}}
Expand Down
16 changes: 16 additions & 0 deletions specifyweb/frontend/js_src/lib/components/WorkBench/WbView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import '../../../css/workbench.css';
import type { HotTable } from '@handsontable/react';
import type Handsontable from 'handsontable';
import React from 'react';
import { useNavigate } from 'react-router-dom';

import { useUnloadProtect } from '../../hooks/navigation';
import { useBooleanState } from '../../hooks/useBooleanState';
Expand All @@ -30,6 +31,7 @@ import { Button } from '../Atoms/Button';
import { className } from '../Atoms/className';
import { Link } from '../Atoms/Link';
import { ReadOnlyContext } from '../Core/Contexts';
import { resourceEvents } from '../DataModel/resource';
import { WbActions } from '../WbActions';
import { useResults } from '../WbActions/useResults';
import type { Dataset } from '../WbPlanView/Wrapped';
Expand Down Expand Up @@ -85,6 +87,20 @@ export function WbView({
: dataset.rows,
[dataset]
);
// Switch to home page on dataset deleted if current dataset is deleted
const navigate = useNavigate();
React.useEffect(
() =>
resourceEvents.on('deleted', (resource) => {
if (
resource.specifyTable.name === 'Spdataset' &&
resource.id === dataset.id
) {
navigate('/specify/', { replace: true });
}
}),
[dataset.id]
);

const spreadsheetContainerRef = React.useRef<HTMLElement>(null);
const [hotTable, setHotTable] = React.useState<HotTable | null>(null);
Expand Down