PromucFlow_constructor/app/client/src/components/propertyControls/PrimaryColumnDropdownControl.tsx
albinAppsmith fbc3bd663b
feat: Migrate design system components import to design-system repo - I (#15562)
* Icon component deleted and changed the imports in refrence places

* design system package version changed

* import changes

* Delete TextInput.tsx

* Change imports

* Change single named import

* Update package

* Update package

* Delete ScrollIndicator.tsx

* Change imports

* Icon import completed

* Event type added

* Changed Button component imports

* import change button

* Button onclick type fix

* Label with Tooltip import changes

* Changed breadcrumbs import

* EmojiPicker and Emoji Reaction import changes

* AppIcon import change

* import bug fix

* Menu Item import chnages

* Icon selector imports changed

* Delete LabelWithTooltip.tsx

* Change imports across the app

* Update package version

* Update version number for design-system

* Delete Checkbox.tsx

* Remove the exports

* Add lock file for ds package update

* Change imports

* default import -> named

* Update release version

* Make arg type explicit

* Updated design-system to latest release

* Missing file mysteriously comes back and is updated accordingly

* changes design-system package version

* Add types to arguments in the onChange for text input

* onBlur type fix

* Search component in property pane

* WDS button changes reverted

* package version bumped

* conflict fix

* Remove Dropdown, change imports

* Category import fix

* fix: table icon size import

* Bump version of design system package

* Yarn lock

Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com>
2022-08-22 10:39:39 +05:30

104 lines
2.5 KiB
TypeScript

import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
import { ColumnProperties } from "widgets/TableWidget/component/Constants";
import { StyledDropDown, StyledDropDownContainer } from "./StyledControls";
import { DropdownOption } from "design-system";
import {
DSEventDetail,
DSEventTypes,
DS_EVENT,
emitInteractionAnalyticsEvent,
} from "utils/AppsmithUtils";
class PrimaryColumnDropdownControl extends BaseControl<ControlProps> {
containerRef = React.createRef<HTMLDivElement>();
componentDidMount() {
this.containerRef.current?.addEventListener(
DS_EVENT,
this.handleAdsEvent as (arg0: Event) => void,
);
}
componentWillUnmount() {
this.containerRef.current?.removeEventListener(
DS_EVENT,
this.handleAdsEvent as (arg0: Event) => void,
);
}
handleAdsEvent = (e: CustomEvent<DSEventDetail>) => {
if (
e.detail.component === "Dropdown" &&
e.detail.event === DSEventTypes.KEYPRESS
) {
emitInteractionAnalyticsEvent(this.containerRef.current, {
key: e.detail.meta.key,
});
e.stopPropagation();
}
};
render() {
// Get columns from widget properties
const columns: Record<string, ColumnProperties> = this.props
.widgetProperties.primaryColumns;
const options: any[] = [];
for (const i in columns) {
options.push({
label: columns[i].label,
id: columns[i].id,
value: i,
});
}
let defaultSelected: DropdownOption = {
label: "No selection.",
value: undefined,
};
const selected: DropdownOption = options.find(
(option) => option.value === this.props.propertyValue,
);
if (selected) {
defaultSelected = selected;
}
return (
<StyledDropDownContainer ref={this.containerRef}>
<StyledDropDown
dropdownMaxHeight="200px"
fillOptions
onSelect={this.onItemSelect}
options={options}
selected={defaultSelected}
showLabelOnly
width="100%"
/>
</StyledDropDownContainer>
);
}
onItemSelect = (
value?: string,
_option?: DropdownOption,
isUpdatedViaKeyboard?: boolean,
): void => {
if (value) {
this.updateProperty(this.props.propertyName, value, isUpdatedViaKeyboard);
}
};
static getControlType() {
return "PRIMARY_COLUMNS_DROPDOWN";
}
}
export interface PrimaryColumnDropdownControlProps extends ControlProps {
propertyValue: string;
}
export default PrimaryColumnDropdownControl;