Skip to content
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
2 changes: 2 additions & 0 deletions web-console/src/components/auto-form/auto-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface Field<M> {
placeholder?: Functor<M, string>;
min?: number;
zeroMeansUndefined?: boolean;
height?: string;
disabled?: Functor<M, boolean>;
defined?: Functor<M, boolean>;
required?: Functor<M, boolean>;
Expand Down Expand Up @@ -272,6 +273,7 @@ export class AutoForm<T extends Record<string, any>> extends React.PureComponent
value={deepGet(model as any, field.name)}
onChange={(v: any) => this.fieldChange(field, v)}
placeholder={AutoForm.evaluateFunctor(field.placeholder, model, '')}
height={field.height}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`FormJsonSelector matches snapshot form json 1`] = `
<Blueprint3.FormGroup
className="form-json-selector"
>
<Blueprint3.ButtonGroup
fill={true}
>
<Blueprint3.Button
active={false}
onClick={[Function]}
text="Form"
/>
<Blueprint3.Button
active={true}
onClick={[Function]}
text="JSON"
/>
</Blueprint3.ButtonGroup>
</Blueprint3.FormGroup>
`;

exports[`FormJsonSelector matches snapshot form tab 1`] = `
<Blueprint3.FormGroup
className="form-json-selector"
>
<Blueprint3.ButtonGroup
fill={true}
>
<Blueprint3.Button
active={true}
onClick={[Function]}
text="Form"
/>
<Blueprint3.Button
active={false}
onClick={[Function]}
text="JSON"
/>
</Blueprint3.ButtonGroup>
</Blueprint3.FormGroup>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { shallow } from 'enzyme';
import React from 'react';

import { FormJsonSelector } from './form-json-selector';

describe('FormJsonSelector', () => {
it('matches snapshot form tab', () => {
const formJsonSelector = shallow(<FormJsonSelector tab="form" onChange={() => {}} />);

expect(formJsonSelector).toMatchSnapshot();
});

it('matches snapshot form json', () => {
const formJsonSelector = shallow(<FormJsonSelector tab="json" onChange={() => {}} />);

expect(formJsonSelector).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Button, ButtonGroup, FormGroup } from '@blueprintjs/core';
import React from 'react';

export type FormJsonTabs = 'form' | 'json';

export interface FormJsonSelectorProps {
tab: FormJsonTabs;
onChange: (tab: FormJsonTabs) => void;
}

export const FormJsonSelector = React.memo(function FormJsonSelector(props: FormJsonSelectorProps) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤘 I like this component!

const { tab, onChange } = props;

return (
<FormGroup className="form-json-selector">
<ButtonGroup fill>
<Button text="Form" active={tab === 'form'} onClick={() => onChange('form')} />
<Button text="JSON" active={tab === 'json'} onClick={() => onChange('json')} />
</ButtonGroup>
</FormGroup>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,10 @@ exports[`CompactionDialog matches snapshot with compactionConfig (dynamic partit
onClose={[Function]}
title="Compaction config: test1"
>
<Blueprint3.FormGroup
className="tabs"
>
<Blueprint3.ButtonGroup
fill={true}
>
<Blueprint3.Button
active={true}
onClick={[Function]}
text="Form"
/>
<Blueprint3.Button
active={false}
onClick={[Function]}
text="JSON"
/>
</Blueprint3.ButtonGroup>
</Blueprint3.FormGroup>
<Memo(FormJsonSelector)
onChange={[Function]}
tab="form"
/>
<div
className="content"
>
Expand Down Expand Up @@ -240,24 +226,10 @@ exports[`CompactionDialog matches snapshot with compactionConfig (hashed partiti
onClose={[Function]}
title="Compaction config: test1"
>
<Blueprint3.FormGroup
className="tabs"
>
<Blueprint3.ButtonGroup
fill={true}
>
<Blueprint3.Button
active={true}
onClick={[Function]}
text="Form"
/>
<Blueprint3.Button
active={false}
onClick={[Function]}
text="JSON"
/>
</Blueprint3.ButtonGroup>
</Blueprint3.FormGroup>
<Memo(FormJsonSelector)
onChange={[Function]}
tab="form"
/>
<div
className="content"
>
Expand Down Expand Up @@ -472,24 +444,10 @@ exports[`CompactionDialog matches snapshot with compactionConfig (single_dim par
onClose={[Function]}
title="Compaction config: test1"
>
<Blueprint3.FormGroup
className="tabs"
>
<Blueprint3.ButtonGroup
fill={true}
>
<Blueprint3.Button
active={true}
onClick={[Function]}
text="Form"
/>
<Blueprint3.Button
active={false}
onClick={[Function]}
text="JSON"
/>
</Blueprint3.ButtonGroup>
</Blueprint3.FormGroup>
<Memo(FormJsonSelector)
onChange={[Function]}
tab="form"
/>
<div
className="content"
>
Expand Down Expand Up @@ -704,24 +662,10 @@ exports[`CompactionDialog matches snapshot without compactionConfig 1`] = `
onClose={[Function]}
title="Compaction config: test1"
>
<Blueprint3.FormGroup
className="tabs"
>
<Blueprint3.ButtonGroup
fill={true}
>
<Blueprint3.Button
active={true}
onClick={[Function]}
text="Form"
/>
<Blueprint3.Button
active={false}
onClick={[Function]}
text="JSON"
/>
</Blueprint3.ButtonGroup>
</Blueprint3.FormGroup>
<Memo(FormJsonSelector)
onChange={[Function]}
tab="form"
/>
<div
className="content"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
height: 80vh;
}

.tabs {
.form-json-selector {
margin: 15px;
}

Expand Down
25 changes: 7 additions & 18 deletions web-console/src/dialogs/compaction-dialog/compaction-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
* limitations under the License.
*/

import { Button, ButtonGroup, Classes, Code, Dialog, FormGroup, Intent } from '@blueprintjs/core';
import { Button, Classes, Code, Dialog, Intent } from '@blueprintjs/core';
import React, { useState } from 'react';

import { AutoForm, Field, JsonInput } from '../../components';
import {
FormJsonSelector,
FormJsonTabs,
} from '../../components/form-json-selector/form-json-selector';
import { deepGet, deepSet } from '../../utils/object-change';

import './compaction-dialog.scss';

type Tabs = 'form' | 'json';

type CompactionConfig = Record<string, any>;

const COMPACTION_CONFIG_FIELDS: Field<CompactionConfig>[] = [
Expand Down Expand Up @@ -240,7 +242,7 @@ export interface CompactionDialogProps {
export const CompactionDialog = React.memo(function CompactionDialog(props: CompactionDialogProps) {
const { datasource, compactionConfig, onSave, onClose, onDelete } = props;

const [currentTab, setCurrentTab] = useState<Tabs>('form');
const [currentTab, setCurrentTab] = useState<FormJsonTabs>('form');
const [currentConfig, setCurrentConfig] = useState<CompactionConfig>(
compactionConfig || {
dataSource: datasource,
Expand All @@ -261,20 +263,7 @@ export const CompactionDialog = React.memo(function CompactionDialog(props: Comp
canOutsideClickClose={false}
title={`Compaction config: ${datasource}`}
>
<FormGroup className="tabs">
<ButtonGroup fill>
<Button
text="Form"
active={currentTab === 'form'}
onClick={() => setCurrentTab('form')}
/>
<Button
text="JSON"
active={currentTab === 'json'}
onClick={() => setCurrentTab('json')}
/>
</ButtonGroup>
</FormGroup>
<FormJsonSelector tab={currentTab} onChange={setCurrentTab} />
<div className="content">
{currentTab === 'form' ? (
<AutoForm
Expand Down
Loading