@duke333/builder-ui 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { BuilderApiContracts, BuilderApiClient, BuilderApiTransport } from '../api/index.js';
2
- import { P as createBuilderAdminPages, b as BuilderAdminPagesOptions, a as BuilderAdminPageContracts } from '../BuilderAdminPages-C-jaMLOa.js';
2
+ import { Q as createBuilderAdminPages, b as BuilderAdminPagesOptions, a as BuilderAdminPageContracts } from '../BuilderAdminPages-DrOrFyIX.js';
3
3
  import { BuilderHooks } from '../hooks/index.js';
4
4
  import 'react';
5
5
  import 'react-hook-form';
@@ -251,16 +251,19 @@ function builderFormEditorValuesFromEntity(form, emptyValues) {
251
251
  function builderListEditorValuesFromEntity(list, emptyValues) {
252
252
  if (!list) return emptyValues;
253
253
  const source = list.source;
254
+ const orderBy = list.schema.orderBy ? Array.isArray(list.schema.orderBy) ? list.schema.orderBy : [list.schema.orderBy] : [];
254
255
  return {
255
256
  title: list.title,
256
257
  description: list.description ?? "",
257
258
  sourceType: source?.type ?? "none",
258
259
  sourceTable: source?.type === "dbTable" ? source.tableName : BUILDER_EDITOR_NONE_VALUE,
259
260
  apiBasePath: source?.type === "apiEndpoint" ? source.basePath : "",
261
+ orderBy,
260
262
  columns: list.schema.columns.map((column) => ({
261
263
  key: column.key,
262
264
  label: column.label,
263
265
  sortable: column.sortable,
266
+ hidden: column.hidden ?? false,
264
267
  align: column.align
265
268
  })),
266
269
  triggers: valuesFromTriggers(list.triggers),
@@ -305,6 +308,7 @@ function builderListEditorColumnsFromTable(table) {
305
308
  key: column.name,
306
309
  label: column.label,
307
310
  sortable: column.sortable,
311
+ hidden: false,
308
312
  align: column.fieldType === "number" || column.fieldType === "money" ? "right" : "left"
309
313
  }));
310
314
  }
@@ -376,11 +380,19 @@ function builderFormEditorInputFromValues(values) {
376
380
  }
377
381
  function builderListEditorInputFromValues(values) {
378
382
  const source = values.sourceType === "dbTable" && values.sourceTable !== BUILDER_EDITOR_NONE_VALUE ? { type: "dbTable", tableName: values.sourceTable } : values.sourceType === "apiEndpoint" && values.apiBasePath ? { type: "apiEndpoint", basePath: values.apiBasePath } : null;
383
+ const orderBy = Array.from(
384
+ new Map(
385
+ values.orderBy.filter((rule) => rule.field && rule.field !== BUILDER_EDITOR_NONE_VALUE).map((rule) => [rule.field, rule])
386
+ ).values()
387
+ );
379
388
  return {
380
389
  title: values.title,
381
390
  description: values.description || null,
382
391
  source,
383
- schema: { columns: values.columns },
392
+ schema: {
393
+ columns: values.columns,
394
+ ...source && orderBy.length > 0 ? { orderBy } : {}
395
+ },
384
396
  triggers: values.triggers.map((trigger) => ({
385
397
  event: trigger.event,
386
398
  action: "callApi",
@@ -583,10 +595,18 @@ function createBuilderDefaultFormEditorBody(options) {
583
595
  ] }),
584
596
  sourceType === "dbTable" ? /* @__PURE__ */ jsxs("label", { style: styles.field, children: [
585
597
  /* @__PURE__ */ jsx("span", { style: styles.label, children: "Table" }),
586
- /* @__PURE__ */ jsxs("select", { style: styles.input, ...form.register("sourceTable"), children: [
587
- /* @__PURE__ */ jsx("option", { value: BUILDER_EDITOR_NONE_VALUE, children: "Select table" }),
588
- tables.map((table) => /* @__PURE__ */ jsx("option", { value: table.name, children: table.label ?? table.name }, table.name))
589
- ] })
598
+ /* @__PURE__ */ jsxs(
599
+ "select",
600
+ {
601
+ style: styles.input,
602
+ value: sourceTable,
603
+ ...form.register("sourceTable"),
604
+ children: [
605
+ /* @__PURE__ */ jsx("option", { value: BUILDER_EDITOR_NONE_VALUE, children: "Select table" }),
606
+ tables.map((table) => /* @__PURE__ */ jsx("option", { value: table.name, children: table.label ?? table.name }, table.name))
607
+ ]
608
+ }
609
+ )
590
610
  ] }) : null,
591
611
  sourceType === "apiEndpoint" ? /* @__PURE__ */ jsxs("label", { style: styles.field, children: [
592
612
  /* @__PURE__ */ jsx("span", { style: styles.label, children: "API base path" }),
@@ -844,6 +864,7 @@ function createBuilderDefaultListEditorBody(options) {
844
864
  listId,
845
865
  form,
846
866
  columnArray,
867
+ orderByArray,
847
868
  triggerArray,
848
869
  sourceType,
849
870
  sourceTable,
@@ -853,6 +874,8 @@ function createBuilderDefaultListEditorBody(options) {
853
874
  isSaving,
854
875
  importColumnsFromTable
855
876
  }) {
877
+ const selectedTable = tables.find((table) => table.name === sourceTable);
878
+ const orderByColumns = selectedTable?.columns.filter((column) => column.sortable) ?? [];
856
879
  return /* @__PURE__ */ jsxs("div", { style: styles.page, children: [
857
880
  /* @__PURE__ */ jsxs("div", { style: styles.header, children: [
858
881
  /* @__PURE__ */ jsxs("div", { children: [
@@ -885,10 +908,18 @@ function createBuilderDefaultListEditorBody(options) {
885
908
  ] }),
886
909
  sourceType === "dbTable" ? /* @__PURE__ */ jsxs("label", { style: styles.field, children: [
887
910
  /* @__PURE__ */ jsx("span", { style: styles.label, children: "Table" }),
888
- /* @__PURE__ */ jsxs("select", { style: styles.input, ...form.register("sourceTable"), children: [
889
- /* @__PURE__ */ jsx("option", { value: BUILDER_EDITOR_NONE_VALUE, children: "Select table" }),
890
- tables.map((table) => /* @__PURE__ */ jsx("option", { value: table.name, children: table.label ?? table.name }, table.name))
891
- ] })
911
+ /* @__PURE__ */ jsxs(
912
+ "select",
913
+ {
914
+ style: styles.input,
915
+ value: sourceTable,
916
+ ...form.register("sourceTable"),
917
+ children: [
918
+ /* @__PURE__ */ jsx("option", { value: BUILDER_EDITOR_NONE_VALUE, children: "Select table" }),
919
+ tables.map((table) => /* @__PURE__ */ jsx("option", { value: table.name, children: table.label ?? table.name }, table.name))
920
+ ]
921
+ }
922
+ )
892
923
  ] }) : null,
893
924
  sourceType === "apiEndpoint" ? /* @__PURE__ */ jsxs("label", { style: styles.field, children: [
894
925
  /* @__PURE__ */ jsx("span", { style: styles.label, children: "API base path" }),
@@ -906,6 +937,85 @@ function createBuilderDefaultListEditorBody(options) {
906
937
  ) }) : null
907
938
  ] })
908
939
  ] }),
940
+ /* @__PURE__ */ jsxs("section", { style: styles.section, children: [
941
+ /* @__PURE__ */ jsxs("div", { style: styles.sectionHeader, children: [
942
+ /* @__PURE__ */ jsxs("div", { children: [
943
+ /* @__PURE__ */ jsx("h2", { style: styles.sectionTitle, children: "Default ordering" }),
944
+ /* @__PURE__ */ jsx("p", { style: styles.description, children: "Rules are applied from top to bottom." })
945
+ ] }),
946
+ /* @__PURE__ */ jsx(
947
+ "button",
948
+ {
949
+ type: "button",
950
+ style: styles.button,
951
+ disabled: sourceType === "none" || orderByArray.fields.length >= 8,
952
+ onClick: () => orderByArray.append({
953
+ field: sourceType === "dbTable" ? orderByColumns[0]?.name ?? BUILDER_EDITOR_NONE_VALUE : "",
954
+ direction: "desc"
955
+ }),
956
+ children: "Add ordering"
957
+ }
958
+ )
959
+ ] }),
960
+ orderByArray.fields.length === 0 ? /* @__PURE__ */ jsx("div", { style: styles.grid, children: /* @__PURE__ */ jsx("p", { style: styles.description, children: "Automatic ordering is used." }) }) : null,
961
+ orderByArray.fields.map((rule, index) => /* @__PURE__ */ jsxs("div", { style: styles.row, children: [
962
+ sourceType === "dbTable" ? /* @__PURE__ */ jsxs("label", { style: styles.field, children: [
963
+ /* @__PURE__ */ jsx("span", { style: styles.label, children: "Order by field" }),
964
+ /* @__PURE__ */ jsxs("select", { style: styles.input, ...form.register(`orderBy.${index}.field`), children: [
965
+ /* @__PURE__ */ jsx("option", { value: BUILDER_EDITOR_NONE_VALUE, children: "Select field" }),
966
+ orderByColumns.map((column) => /* @__PURE__ */ jsx("option", { value: column.name, children: column.label }, column.name))
967
+ ] })
968
+ ] }) : /* @__PURE__ */ jsxs("label", { style: styles.field, children: [
969
+ /* @__PURE__ */ jsx("span", { style: styles.label, children: "Order by field" }),
970
+ /* @__PURE__ */ jsx(
971
+ "input",
972
+ {
973
+ style: styles.input,
974
+ placeholder: "createdAt",
975
+ ...form.register(`orderBy.${index}.field`)
976
+ }
977
+ )
978
+ ] }),
979
+ /* @__PURE__ */ jsxs("label", { style: styles.field, children: [
980
+ /* @__PURE__ */ jsx("span", { style: styles.label, children: "Direction" }),
981
+ /* @__PURE__ */ jsxs("select", { style: styles.input, ...form.register(`orderBy.${index}.direction`), children: [
982
+ /* @__PURE__ */ jsx("option", { value: "asc", children: "Ascending" }),
983
+ /* @__PURE__ */ jsx("option", { value: "desc", children: "Descending" })
984
+ ] })
985
+ ] }),
986
+ /* @__PURE__ */ jsxs("div", { style: styles.actions, children: [
987
+ /* @__PURE__ */ jsx(
988
+ "button",
989
+ {
990
+ type: "button",
991
+ style: styles.button,
992
+ disabled: index === 0,
993
+ onClick: () => orderByArray.move(index, index - 1),
994
+ children: "Move up"
995
+ }
996
+ ),
997
+ /* @__PURE__ */ jsx(
998
+ "button",
999
+ {
1000
+ type: "button",
1001
+ style: styles.button,
1002
+ disabled: index === orderByArray.fields.length - 1,
1003
+ onClick: () => orderByArray.move(index, index + 1),
1004
+ children: "Move down"
1005
+ }
1006
+ ),
1007
+ /* @__PURE__ */ jsx(
1008
+ "button",
1009
+ {
1010
+ type: "button",
1011
+ style: styles.button,
1012
+ onClick: () => orderByArray.remove(index),
1013
+ children: "Remove"
1014
+ }
1015
+ )
1016
+ ] })
1017
+ ] }, rule.id))
1018
+ ] }),
909
1019
  /* @__PURE__ */ jsxs("section", { style: styles.section, children: [
910
1020
  /* @__PURE__ */ jsxs("div", { style: styles.sectionHeader, children: [
911
1021
  /* @__PURE__ */ jsxs("div", { children: [
@@ -946,16 +1056,10 @@ function createBuilderDefaultListEditorBody(options) {
946
1056
  /* @__PURE__ */ jsx("input", { type: "checkbox", ...form.register(`columns.${index}.sortable`) }),
947
1057
  "Sortable"
948
1058
  ] }),
949
- /* @__PURE__ */ jsx(
950
- "button",
951
- {
952
- type: "button",
953
- style: styles.button,
954
- onClick: () => columnArray.remove(index),
955
- disabled: columnArray.fields.length <= 1,
956
- children: "Remove"
957
- }
958
- )
1059
+ /* @__PURE__ */ jsxs("label", { style: styles.checkboxField, children: [
1060
+ /* @__PURE__ */ jsx("input", { type: "checkbox", ...form.register(`columns.${index}.hidden`) }),
1061
+ "Hidden"
1062
+ ] })
959
1063
  ] }, column.id))
960
1064
  ] }),
961
1065
  /* @__PURE__ */ jsxs("section", { style: styles.section, children: [
@@ -1484,6 +1588,7 @@ function createBuilderListEditorPageComponent(deps) {
1484
1588
  defaultValues: deps.emptyValues
1485
1589
  });
1486
1590
  const columnArray = useFieldArray({ control: form.control, name: "columns" });
1591
+ const orderByArray = useFieldArray({ control: form.control, name: "orderBy" });
1487
1592
  const triggerArray = useFieldArray({ control: form.control, name: "triggers" });
1488
1593
  const sourceType = useWatch({ control: form.control, name: "sourceType" });
1489
1594
  const sourceTable = useWatch({ control: form.control, name: "sourceTable" });
@@ -1517,6 +1622,7 @@ function createBuilderListEditorPageComponent(deps) {
1517
1622
  listId,
1518
1623
  form,
1519
1624
  columnArray,
1625
+ orderByArray,
1520
1626
  triggerArray,
1521
1627
  sourceType,
1522
1628
  sourceTable,
@@ -1679,6 +1785,7 @@ function createBuilderAdminPages({
1679
1785
  key: "name",
1680
1786
  label: "Name",
1681
1787
  sortable: true,
1788
+ hidden: false,
1682
1789
  align: "left"
1683
1790
  };
1684
1791
  const emptyListValues = {
@@ -1687,6 +1794,7 @@ function createBuilderAdminPages({
1687
1794
  sourceType: "none",
1688
1795
  sourceTable: BUILDER_EDITOR_NONE_VALUE,
1689
1796
  apiBasePath: "",
1797
+ orderBy: [],
1690
1798
  columns: [emptyColumn],
1691
1799
  triggers: [],
1692
1800
  version: 0