This commit is contained in:
Rizky 2024-06-27 03:24:19 -07:00
parent 06c70830c9
commit 4f53547cc9
6 changed files with 27 additions and 15 deletions

View File

@ -29,9 +29,12 @@ export const TypeDropdown: FC<{
if (options instanceof Promise) {
options.then((res) => {
if (Array.isArray(res)) {
const list: any = res.map((e: any) => {
const list: any = res.map((e: any, idx: number) => {
return {
label: arg.opt_get_label(e, "list"),
label: arg.opt_get_label(e, "list", {
prev: res[idx - 1],
next: res[idx + 1],
}),
tag: arg.opt_get_label(e, "label"),
value: e.value,
data: e.data,

View File

@ -133,7 +133,7 @@ export const generateField = async (
opt__label: `\
(
row: { value: string; label: string; data?: any },
mode: "list" | "label",
mode: "list" | "label", opt: any
) => {
const cols = ${JSON.stringify(
getColumn(generateSelect(parseGenField(master.value.checked)))
@ -141,7 +141,7 @@ export const generateField = async (
const prefix = treePrefix({
//@ts-ignore
rel__feature, rel__id_parent, row, mode
rel__feature, rel__id_parent, row, mode, opt
});
if (isEditor) {

View File

@ -18,7 +18,7 @@ export const gen_label = ({
return `\
(
row: { value: string; label: string; data?: any },
mode: "list" | "label",
mode: "list" | "label", opt: any
) => {
const cols = ${JSON.stringify(cols)};
@ -28,7 +28,7 @@ export const gen_label = ({
const prefix = treePrefix({
//@ts-ignore
rel__feature, rel__id_parent, row, mode
rel__feature, rel__id_parent, row, mode, opt
});
const result = [];

View File

@ -123,7 +123,7 @@ export const genRelMany = (prop: {
const get_label = `\
(
row: { value: string; label: string; data?: any },
mode: "list" | "label",
mode: "list" | "label", opt: any
) => {
const cols = ${JSON.stringify(cols)};
@ -133,7 +133,7 @@ export const genRelMany = (prop: {
const prefix = treePrefix({
//@ts-ignore
rel__feature, rel__id_parent, row, mode
rel__feature, rel__id_parent, row, mode, opt
});
const result = [];

View File

@ -68,7 +68,11 @@ export type FieldProp = {
) =>
| { value: string; label: string }[]
| Promise<{ value: string; label: string }[]>;
opt_get_label: (row: any, mode: "list" | "label") => string;
opt_get_label: (
row: any,
mode: "list" | "label",
opt?: { next?: any; prev?: any }
) => string;
opt_get_value: (arg: {
options: { label: string; value: string; item?: string }[];
fm: FMLocal;

View File

@ -1,8 +1,10 @@
export const treePrefix = (props: any) => {
if (!props) return "";
const { rel__feature, rel__id_parent, row, mode } = props;
const { rel__feature, rel__id_parent, row, opt } = props;
if (props.mode !== "list") return "";
const next = opt?.next?.data?.__depth;
const prev = opt?.prev?.data?.__depth;
if (!rel__feature || !rel__id_parent || !row) return "";
@ -15,10 +17,16 @@ export const treePrefix = (props: any) => {
let prefix = ``;
if (is_tree && row.data && row.data.__depth) {
const cur = row.data.__depth;
let is_last = false;
if (cur !== next) {
is_last = true;
}
for (let i = 0; i < row.data.__depth; i++) {
if (i === 0) {
if (row.data.__depth === 1) {
prefix += "└";
prefix += is_last ? "└" : "├";
} else {
prefix += " ";
}
@ -26,7 +34,7 @@ export const treePrefix = (props: any) => {
if (row.data.__depth - 1 !== i) {
prefix += " ";
} else {
prefix += "└";
prefix += is_last ? "└" : "├";
}
}
}
@ -98,9 +106,6 @@ export const sortTree = (list: any, parent_key: string, pk: string) => {
}
if (parent) {
if (parent.item.id === "f43ac927-9c0d-4241-a837-c0bf1c6a5245") {
console.log(parent, item);
}
item.__depth = parent.depth + 1;
meta[item[pk]] = {