Skip to content

Table column data mapping #653

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
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
column data mapping
  • Loading branch information
raheeliftikhar5 committed Jan 22, 2024
commit 5c225ccb2829fae464b66f8b964d9c82ec6bce0f
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CellProps } from "components/table/EditableCell";
import { DateTimeComp } from "comps/comps/tableComp/column/columnTypeComps/columnDateTimeComp";
import { ButtonComp } from "comps/comps/tableComp/column/simpleColumnTypeComps";
import { withType } from "comps/generators";
import { MultiCompBuilder, withDefault, withType } from "comps/generators";
import { trans } from "i18n";
import { Dropdown } from "lowcoder-design";
import { BooleanComp } from "./columnTypeComps/columnBooleanComp";
Expand All @@ -17,6 +17,31 @@ import { ColumnTagsComp } from "./columnTypeComps/columnTagsComp";
import { ColumnSelectComp } from "./columnTypeComps/columnSelectComp";
import { SimpleTextComp } from "./columnTypeComps/simpleTextComp";
import { ColumnNumberComp } from "./columnTypeComps/ColumnNumberComp";
import { useState } from "react";
import { dropdownControl } from "@lowcoder-ee/index.sdk";

const columnValueOptions = [
{
label: "ID",
value: "{{currentRow.id}}",
},
{
label: "Name",
value: "{{currentRow.name}}",
},
{
label: "Department",
value: "{{currentRow.department}}",
},
{
label: "Date",
value: "{{currentRow.date}}",
},
{
label: "Other",
value: "",
},
] as const;

const actionOptions = [
{
Expand Down Expand Up @@ -104,6 +129,15 @@ export type ColumnTypeKeys = keyof ColumnTypeMapType;

const TypedColumnTypeComp = withType(ColumnTypeCompMap, "text");

const childrenMap = {
comp: TypedColumnTypeComp,
valueMap: dropdownControl(columnValueOptions, "")
};

const TmpColumnTypeComp = new MultiCompBuilder(childrenMap, (props) => {
return props;
}).build();

export class ColumnTypeComp extends TypedColumnTypeComp {
override getView() {
const childView = this.children.comp.getView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ const columnFixOptions = [
},
] as const;

const columnValueOptions = [
{
label: "ID",
value: "{{currentRow.id}}",
},
{
label: "Name",
value: "{{currentRow.name}}",
},
{
label: "Department",
value: "{{currentRow.department}}",
},
{
label: "Date",
value: "{{currentRow.date}}",
},
{
label: "Other",
value: "",
},
] as const;

const cellColorLabel = trans("table.cellColor");
const CellColorTempComp = withContext(
new MultiCompBuilder({ color: ColorOrBoolCodeControl }, (props) => props.color)
Expand Down Expand Up @@ -94,6 +117,7 @@ export const columnChildrenMap = {
sortable: BoolControl,
width: NumberControl,
autoWidth: dropdownControl(columnWidthOptions, "auto"),
columnMapping: dropdownControl(columnValueOptions, ""),
render: RenderComp,
align: HorizontalAlignmentControl,
tempHide: stateComp<boolean>(false),
Expand Down Expand Up @@ -195,6 +219,21 @@ export class ColumnComp extends ColumnInitComp {
label: trans("table.columnTitle"),
placeholder: this.children.dataIndex.getView(),
})}
{this.children.columnMapping.propertyView({
label: "Data Mapping",
onChange: (value) => {
console.log(value)
const comp = this.children.render.getSelectedComp().getComp();
// let textRawData = "{{currentCell}}";
// if (comp.children.hasOwnProperty("text")) {
// textRawData = (comp.children as any).text.toJsonValue();
// }
this.children.render.dispatchChangeValueAction({
compType: columnType,
comp: { text: value },
} as any);
}
})}
{/* FIXME: cast type currently, return type of withContext should be corrected later */}
{this.children.render.getPropertyView()}
{this.children.showTitle.propertyView({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export function columnsToAntdFormat(
columnsAggrData: ColumnsAggrData,
onTableEvent: (eventName: any) => void,
): Array<CustomColumnType<RecordType>> {
console.log(columnsAggrData);
const sortMap: Map<string | undefined, SortOrder> = new Map(
sort.map((s) => [s.column, s.desc ? "descend" : "ascend"])
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ export function dropdownAbstractControl<T extends OptionsType>(
return controlItem(
{ filterText: params.label },
<DropdownPropertyView<T>
{...params}
value={this.value}
options={finalOptions}
onChange={(value) => {
console.log(value);
if (!params.disableDispatchValueChange) {
this.dispatchChangeValueAction(value);
}
params.onChange?.(value);
}}
{...params}
/>
);
}
Expand Down