initial_config_all_fields =
  (isEdit) =>
  async ({ table_id, exttable_name }) => {
    const table = Table.findOne(
      table_id ? { id: table_id } : { name: exttable_name }
    );

    const fields = table
      .getFields()
      .filter((f) => !f.primary_key && (!isEdit || !f.calculated));
    let cfg = { columns: [] };
    let aboves = [null];
    const style = {
      "margin-bottom": "1.5rem",
    };

    fields.forEach((f) => {
      if (!f.type) return;
      const flabel = {
        above: [
          null,
          {
            type: "blank",
            block: false,
            contents: f.label,
            textStyle: "",
            ...(isEdit ? { labelFor: f.name } : {}),
          },
        ],
      };
      if (
        f.is_fkey &&
        f.type !== "File" &&
        f.reftable_name !== "users" &&
        !isEdit
      ) {
        cfg.columns.push({
          type: "JoinField",
          join_field: `${f.name}.${
            f.attributes.summary_field ||
            Table.findOne(f.reftable_name)?.pk_name ||
            "id"
          }`,
        });
        aboves.push({
          widths: [2, 10],
          aligns: ["end", "start"],
          style,
          besides: [
            flabel,
            {
              above: [
                null,
                {
                  type: "join_field",
                  block: false,
                  textStyle: "",
                  join_field: `${f.name}.${f.attributes.summary_field}`,
                },
              ],
            },
          ],
        });
      } else if (f.reftable_name !== "users") {
        const fvNm = f.type.fieldviews
          ? Object.entries(f.type.fieldviews).find(
              ([nm, fv]) => fv.isEdit === isEdit
            )[0]
          : f.type === "File" && !isEdit
            ? Object.keys(getState().fileviews)[0]
            : f.type === "File" && isEdit
              ? "upload"
              : f.type === "Key"
                ? "select"
                : undefined;
        cfg.columns.push({
          field_name: f.name,
          type: "Field",
          fieldview: fvNm,
        });
        aboves.push({
          widths: [2, 10],
          aligns: ["end", "start"],
          style,
          besides: [
            flabel,
            {
              above: [
                null,
                {
                  type: "field",
                  block: false,
                  fieldview: fvNm,
                  textStyle: "",
                  field_name: f.name,
                },
              ],
            },
          ],
        });
      }
    });
    if (isEdit)
      aboves.push({
        widths: [2, 10],
        aligns: ["end", "start"],
        style,
        besides: [
          null,
          {
            type: "action",
            block: false,
            minRole: 100,
            action_name: "Save",
          },
        ],
      });
    cfg.layout = { above: aboves };
    return cfg;
  }
initial_config_all_fields Contract
@function
@returns {function}
@param isEdit