Skip to content

Commit

Permalink
Merge pull request #602 from jreyesr/feat/issue-412
Browse files Browse the repository at this point in the history
Add Select (dropdown) column type to tables
  • Loading branch information
FalkWolsky authored Jan 8, 2024
2 parents 4dbd74d + 8f6ea6f commit 5692cc6
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ProgressComp } from "./columnTypeComps/columnProgressComp";
import { RatingComp } from "./columnTypeComps/columnRatingComp";
import { BadgeStatusComp } from "./columnTypeComps/columnStatusComp";
import { ColumnTagsComp } from "./columnTypeComps/columnTagsComp";
import { ColumnSelectComp } from "./columnTypeComps/columnSelectComp";
import { SimpleTextComp } from "./columnTypeComps/simpleTextComp";
import { ColumnNumberComp } from "./columnTypeComps/ColumnNumberComp";

Expand All @@ -38,6 +39,10 @@ const actionOptions = [
label: trans("table.tag"),
value: "tag",
},
{
label: trans("table.select"),
value: "select",
},
{
label: trans("table.badgeStatus"),
value: "badgeStatus",
Expand Down Expand Up @@ -83,6 +88,7 @@ export const ColumnTypeCompMap = {
badgeStatus: BadgeStatusComp,
link: LinkComp,
tag: ColumnTagsComp,
select: ColumnSelectComp,
links: ColumnLinksComp,
image: ImageComp,
markdown: ColumnMarkdownComp,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { useState } from "react";

import { SelectUIView } from "comps/comps/selectInputComp/selectCompConstants";
import { SelectOptionControl } from "comps/controls/optionsControl";
import { StringControl } from "comps/controls/codeControl";

import { trans } from "i18n";
import { ColumnTypeCompBuilder, ColumnTypeViewFn } from "../columnTypeCompBuilder";
import { ColumnValueTooltip } from "../simpleColumnTypeComps";

const childrenMap = {
text: StringControl,
options: SelectOptionControl,
};

let options: any[] = []
const getBaseValue: ColumnTypeViewFn<typeof childrenMap, string, string> = (props) => props.text;

type SelectEditProps = {
initialValue: string;
onChange: (value: string) => void;
onChangeEnd: () => void;
options: any[];
};

const SelectEdit = (props: SelectEditProps) => {
const [currentValue, setCurrentValue] = useState(props.initialValue);

return (
<SelectUIView
value={currentValue}
options={options}
onChange={(val) => {
props.onChange(val);
setCurrentValue(val)
}}
onEvent={async (eventName)=>{
if(eventName==="blur"){
props.onChangeEnd()
}
return []
}}
// @ts-ignore
style={{}}
/>
);
};


export const ColumnSelectComp = (function () {
return new ColumnTypeCompBuilder(
childrenMap,
(props, dispatch) => {
options = props.options;
const value = props.changeValue ?? getBaseValue(props, dispatch)
return props.options.find(x => x.value === value)?.label;
},
(nodeValue) => nodeValue.text.value,
getBaseValue,
)
.setEditViewFn((props) => {
return (
<SelectEdit
initialValue={props.value}
options={options}
onChange={props.onChange}
onChangeEnd={props.onChangeEnd}
/>
)})
.setPropertyViewFn((children) => {
return (
<>
{children.text.propertyView({
label: trans("table.columnValue"),
tooltip: ColumnValueTooltip,
})}
{children.options.propertyView({
title: trans("optionsControl.optionList"),
})}
</>
);
})
.build();
})();
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ export const en = {
"link": "Link",
"links": "Links",
"tag": "Tag",
"select": "Select",
"date": "Date",
"dateTime": "Date Time",
"badgeStatus": "Status",
Expand Down

0 comments on commit 5692cc6

Please sign in to comment.