Feature/routes export #29
@@ -3,6 +3,7 @@ import { ApprovalRouteApi } from '../../services/api';
|
||||
import { PortalDictionaryClient } from '../../services/portalDictionary';
|
||||
import { texts } from '../../texts';
|
||||
import { useRequestTypes } from '../../hooks/useRequestTypes';
|
||||
import { useLocalStorageState } from '../../hooks/useLocalStorageState';
|
||||
import { usePortalEmployees } from '../../hooks/usePortalEmployees';
|
||||
import { usePortalDictionaries } from '../../hooks/usePortalDictionaries';
|
||||
import { reportError } from '../../utils/errors';
|
||||
@@ -15,6 +16,10 @@ export interface IRoutesExportScreenProps {
|
||||
dictionary?: PortalDictionaryClient;
|
||||
}
|
||||
|
||||
// Выбранные типы заявок переживают перезагрузку страницы — выгрузку обычно
|
||||
// делают по одному и тому же набору типов.
|
||||
const SELECTED_STORAGE_KEY = 'approvalAdmin.routesExport.selected';
|
||||
|
||||
function download(blob: Blob, fileName: string): void {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
@@ -31,15 +36,17 @@ export const RoutesExportScreen: React.FC<IRoutesExportScreenProps> = ({ api, di
|
||||
const employees = usePortalEmployees(dictionary);
|
||||
const portalDictionaries = usePortalDictionaries(dictionary);
|
||||
|
||||
const [selected, setSelected] = React.useState<number[]>([]);
|
||||
const [storedSelected, setSelected] = useLocalStorageState<number[]>(SELECTED_STORAGE_KEY, []);
|
||||
const [isBusy, setIsBusy] = React.useState(false);
|
||||
const [error, setError] = React.useState<string | undefined>();
|
||||
|
||||
const allIds = requestTypes.items.map(rt => rt.id);
|
||||
// Удалённые с тех пор типы из сохранённого выбора не считаем.
|
||||
const selected = storedSelected.filter(id => allIds.indexOf(id) !== -1);
|
||||
const allSelected = allIds.length > 0 && allIds.every(id => selected.indexOf(id) !== -1);
|
||||
|
||||
const toggle = (id: number, checked: boolean): void =>
|
||||
setSelected(current => (checked ? [...current, id] : current.filter(x => x !== id)));
|
||||
setSelected(current => (checked ? [...current.filter(x => x !== id), id] : current.filter(x => x !== id)));
|
||||
|
||||
const runExport = (): void => {
|
||||
setError(undefined);
|
||||
|
||||
Reference in New Issue
Block a user