Skip to content

Add Select (dropdown) column type to tables #602

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 8, 2024
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
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