Skip to content

Commit

Permalink
added scaler ui components (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
karzuo authored Sep 28, 2021
1 parent df64cb3 commit 8df17ba
Show file tree
Hide file tree
Showing 16 changed files with 1,882 additions and 3 deletions.
814 changes: 814 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { AddButton } from "./components/AddButton";
import { TableInputCard } from "./components/table_inputs/TableInputCard";
import { VariablesInputCard } from "./components/table_inputs/VariablesInputCard";
import { FeastInputGroup } from "../feast_config/components/FeastInputGroup";
import { EncodersInputGroup } from "./components/table_inputs/EncodersInputGroup";
import { Panel } from "../Panel";
import {
FeastInput,
Expand Down Expand Up @@ -108,6 +109,17 @@ export const InputPanel = ({ inputs = [], onChangeHandler, errors = {} }) => {
/>
)}

{input.encoders && (
<EncodersInputGroup
groupIndex={idx}
encoders={input.encoders}
onChangeHandler={onChangeHandler}
onDelete={onDeleteInput(idx)}
dragHandleProps={provided.dragHandleProps}
errors={errors}
/>
)}

<EuiSpacer size="s" />
</EuiFlexItem>
)}
Expand Down Expand Up @@ -141,6 +153,14 @@ export const InputPanel = ({ inputs = [], onChangeHandler, errors = {} }) => {
onClick={() => onAddInput("variables", [{}])}
/>
</EuiFlexItem>

<EuiFlexItem>
<AddButton
title="+ Add Encoders"
description="Define an encoder for encoding input columns at transformation step"
onClick={() => onAddInput("encoders", [{ name: "" }])}
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from "react";
import {
EuiFieldText,
EuiFlexGroup,
EuiFlexItem,
EuiPanel,
EuiSpacer,
EuiFormRow
} from "@elastic/eui";
import { FormLabelWithToolTip, useOnChangeHandler } from "@gojek/mlp-ui";
import { DraggableHeader } from "../../../DraggableHeader";
import { SelectEncoder } from "./SelectEncoder";
import { OrdinalEncoderInputGroup } from "./OrdinalEncoderInputGroup";

export const EncoderInputCard = ({
index = 0,
encoder,
onChangeHandler,
onDelete,
errors = {},
...props
}) => {
const { onChange } = useOnChangeHandler(onChangeHandler);

return (
<EuiPanel>
<DraggableHeader
onDelete={onDelete}
dragHandleProps={props.dragHandleProps}
/>

<EuiSpacer size="s" />

<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexItem>
<EuiFlexGroup direction="row">
<EuiFlexItem>
<EuiFormRow
label={
<FormLabelWithToolTip
label="Encoder Name *"
content="The name of encoder that will be passed in the table transformation step."
/>
}
isInvalid={!!errors.name}
error={errors.name}
display="columnCompressed"
fullWidth>
<EuiFieldText
placeholder="Encoder name"
value={encoder.name || ""}
onChange={e => onChange("name")(e.target.value)}
isInvalid={!!errors.name}
name={`name-${index}`}
fullWidth
/>
</EuiFormRow>
</EuiFlexItem>

<EuiFlexItem>
<SelectEncoder
encoderConfig={encoder}
onChangeHandler={onChangeHandler}
errors={errors}
/>
</EuiFlexItem>
</EuiFlexGroup>

<EuiSpacer size="s" />

{encoder["ordinalEncoderConfig"] !== undefined && (
<OrdinalEncoderInputGroup
index={index}
ordinalEncoderConfig={encoder.ordinalEncoderConfig}
onChangeHandler={onChangeHandler}
errors={errors}
/>
)}
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import React from "react";
import {
EuiDragDropContext,
euiDragDropReorder,
EuiDraggable,
EuiDroppable,
EuiFlexGroup,
EuiFlexItem,
EuiPanel,
EuiSpacer
} from "@elastic/eui";
import { get, useOnChangeHandler } from "@gojek/mlp-ui";
import { DraggableHeader } from "../../../DraggableHeader";
import { AddButton } from "../../../transformer/components/AddButton";
import { EncoderInputCard } from "./EncoderInputCard";

export const EncodersInputGroup = ({
groupIndex,
encoders,
onChangeHandler,
onDelete,
errors = {},
...props
}) => {
const { onChange } = useOnChangeHandler(onChangeHandler);

const onAddEncoder = () => {
onChange(`${groupIndex}.encoders`)([...encoders, { name: "" }]);
};

const onDeleteEncoder = idx => () => {
encoders.splice(idx, 1);
onChange(`${groupIndex}.encoders`)([...encoders]);
};

const onDragEnd = ({ source, destination }) => {
if (source && destination) {
const items = euiDragDropReorder(
encoders,
source.index,
destination.index
);
onChange(`${groupIndex}.encoders`)([...items]);
}
};

return (
<EuiPanel>
<DraggableHeader
onDelete={onDelete}
dragHandleProps={props.dragHandleProps}
/>

<EuiSpacer size="m" />

<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexGroup direction="column" gutterSize="s">
<EuiDragDropContext onDragEnd={onDragEnd}>
<EuiDroppable
droppableId="ENCODERS_INPUT_DROPPABLE_AREA"
spacing="m">
{encoders.map((encoder, encoderIdx) => (
<EuiDraggable
key={`${encoderIdx}`}
index={encoderIdx}
draggableId={`${encoderIdx}`}
customDragHandle={true}
disableInteractiveElementBlocking>
{provided => (
<EuiFlexItem key={`${encoderIdx}`}>
<EncoderInputCard
index={encoderIdx}
encoder={encoder}
onChangeHandler={onChange(
`${groupIndex}.encoders.${encoderIdx}`
)}
onDelete={
encoders.length > 1
? onDeleteEncoder(encoderIdx)
: undefined
}
dragHandleProps={provided.dragHandleProps}
errors={get(
errors,
`${groupIndex}.encoders.${encoderIdx}`
)}
/>
<EuiSpacer size="s" />
</EuiFlexItem>
)}
</EuiDraggable>
))}
</EuiDroppable>
</EuiDragDropContext>
</EuiFlexGroup>

<EuiFlexItem>
<AddButton
title="+ Add Another Encoder"
description="Declare a new encoder function that can be used on table transformation step."
titleSize="xs"
onClick={() => onAddEncoder()}
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from "react";
import {
EuiFormRow,
EuiFieldNumber,
EuiFlexGroup,
EuiFlexItem,
EuiText,
EuiSpacer
} from "@elastic/eui";
import { FormLabelWithToolTip, useOnChangeHandler } from "@gojek/mlp-ui";
import { SelectOrdinalValueType } from "./SelectOrdinalValueType";
import { OrdinalEncoderMapper } from "./OrdinalEncoderMapper";

export const OrdinalEncoderInputGroup = ({
index,
ordinalEncoderConfig,
onChangeHandler,
errors = {}
}) => {
const { onChange } = useOnChangeHandler(onChangeHandler);

return (
<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexItem>
<EuiFlexGroup direction="row">
<EuiFlexItem>
<EuiFormRow
label={
<FormLabelWithToolTip
label="Default Value *"
content="Default value to map to if mapping undefined"
/>
}
isInvalid={!!errors.defaultValue}
error={errors.defaultValue}
display="columnCompressed"
fullWidth>
<EuiFieldNumber
placeholder="Default value"
value={ordinalEncoderConfig.defaultValue || ""}
onChange={e =>
onChange("ordinalEncoderConfig.defaultValue")(e.target.value)
}
isInvalid={!!errors.defaultValue}
name={`defaultValue-${index}`}
fullWidth
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem>
<SelectOrdinalValueType
defaultValue={ordinalEncoderConfig.defaultValue}
valueType={ordinalEncoderConfig.targetValueType}
mapping={ordinalEncoderConfig.mapping}
onChangeHandler={onChange("ordinalEncoderConfig")}
errors={errors}
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>

<EuiSpacer size="s" />

{ordinalEncoderConfig.targetValueType && (
<EuiFlexItem>
<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexItem>
<EuiText size="xs">
<h4>Mapping *</h4>
</EuiText>
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup direction="row">
<EuiFlexItem>
<OrdinalEncoderMapper
mappings={ordinalEncoderConfig.mapping}
onChangeHandler={onChange("ordinalEncoderConfig")}
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
)}
</EuiFlexGroup>
);
};
Loading

0 comments on commit 8df17ba

Please sign in to comment.