Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(Table): Add 'Combine chunks' flag to Merge/Erase modal #31

Merged
merged 1 commit into from
Apr 26, 2023
Merged
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
30 changes: 21 additions & 9 deletions packages/ui/src/ui/pages/navigation/modals/TableEraseModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import Dialog, {DialogError} from '../../../components/Dialog/Dialog';
import Dialog, {DialogError, FormApi} from '../../../components/Dialog/Dialog';
import {makeLink} from '../../../navigation/Navigation/PathEditorModal/CreateTableModal/CreateTableModal';
import {useDispatch, useSelector} from 'react-redux';
import {
Expand All @@ -14,6 +14,12 @@ import {
import {docsUrl} from '../../../config';
import UIFactory from '../../../UIFactory';

interface FormValues {
path: string;
range: string;
combine_chunks: boolean;
}

export default function TableEraseModal() {
const visible = useSelector(getNavigationTableEraseModalVisible);
const path = useSelector(getNavigationTableEraseModalPath);
Expand All @@ -23,17 +29,18 @@ export default function TableEraseModal() {
const dispatch = useDispatch();

const handleAdd = React.useCallback(
async (form: any) => {
async (form: FormApi<FormValues>) => {
try {
const {range} = form.getState().values;
const {range, combine_chunks} = form.getState().values;

const [from, to] = range?.split(':') || [];
await dispatch(
runTableErase(
path || '',
from ? Number(from) : undefined,
to ? Number(to) : undefined,
),
runTableErase({
path: path ?? '',
from: from ? Number(from) : undefined,
to: to ? Number(to) : undefined,
combine_chunks,
}),
);
} catch (e) {
setError(e);
Expand All @@ -48,7 +55,7 @@ export default function TableEraseModal() {
}, [dispatch]);

return (
<Dialog
<Dialog<FormValues>
visible={visible}
headerProps={{
title: 'Erase table rows',
Expand Down Expand Up @@ -83,6 +90,11 @@ export default function TableEraseModal() {
placeholder: '10:20',
},
},
{
name: 'combine_chunks',
type: 'tumbler',
caption: 'Combine chunks',
},
...(!error
? []
: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function TableMergeModal() {
poolTree,
chunkSize,
force_transform,
combine_chunks,
} = values;
const chunkSizeBytes = parseBytes(chunkSize);
const data_size_per_job = isNaN(chunkSizeBytes) ? undefined : chunkSizeBytes;
Expand All @@ -62,6 +63,7 @@ export default function TableMergeModal() {
pool_trees,
data_size_per_job,
force_transform,
combine_chunks,
},
Boolean,
) as any,
Expand Down Expand Up @@ -104,6 +106,7 @@ export default function TableMergeModal() {
columns: [],
force_transform: true,
poolTree: defaultPoolTree,
combine_chunks: true,
}}
fields={[
{
Expand Down Expand Up @@ -158,6 +161,11 @@ export default function TableMergeModal() {
type: 'table-chunk-size',
caption: 'Chunk size',
},
{
name: 'combine_chunks',
type: 'tumbler',
caption: 'Combine chunks',
},
{
name: 'poolTree',
type: 'pool-tree',
Expand Down Expand Up @@ -220,4 +228,5 @@ interface FormValues {
columns: Array<unknown>;
chunkSize: string;
force_transform: boolean;
combine_chunks: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ export function hideTableEraseModal() {

type EraseThunkAction = ThunkAction<any, RootState, any, any>;

export function runTableErase(path: string, from?: number, to?: number): EraseThunkAction {
export function runTableErase({
path,
from,
to,
combine_chunks,
}: {
path: string;
from?: number;
to?: number;
combine_chunks?: boolean;
}): EraseThunkAction {
return () => {
if (!path) {
throw Error('Path cannot be empty for "erase" operation');
Expand All @@ -37,12 +47,11 @@ export function runTableErase(path: string, from?: number, to?: number): EraseTh
range = `[:#${to}]`;
}

console.log({range});

return wrapApiPromiseByToaster(
yt.v3.erase({
spec: {
table_path: path + range,
combine_chunks,
},
...makeUiMarker(`${Page.NAVIGATION}:erase`),
}),
Expand Down