@faasjs/ant-design 0.0.2-beta.414 → 0.0.2-beta.416

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.
package/dist/index.mjs CHANGED
@@ -24,7 +24,9 @@ var zh = {
24
24
  pageNotFound: "\u9875\u9762\u672A\u627E\u5230",
25
25
  add: "\u6DFB\u52A0",
26
26
  delete: "\u5220\u9664",
27
- required: "\u5FC5\u586B"
27
+ required: "\u5FC5\u586B",
28
+ search: "\u641C\u7D22",
29
+ reset: "\u91CD\u7F6E"
28
30
  };
29
31
  var en = {
30
32
  lang: "en",
@@ -34,7 +36,9 @@ var en = {
34
36
  pageNotFound: "Page Not Found",
35
37
  add: "Add",
36
38
  delete: "Delete",
37
- required: "is required"
39
+ required: "is required",
40
+ search: "Search",
41
+ reset: "Reset"
38
42
  };
39
43
  var common = isZH ? zh : en;
40
44
  var baseConfig = {
@@ -879,45 +883,45 @@ import {
879
883
  import {
880
884
  Table as AntdTable,
881
885
  Radio,
882
- Skeleton as Skeleton3
886
+ Skeleton as Skeleton3,
887
+ Empty
883
888
  } from "antd";
884
889
  import dayjs3 from "dayjs";
885
890
  import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
886
- import { isNil as isNil2, upperFirst as upperFirst4 } from "lodash";
891
+ import {
892
+ isNil as isNil2,
893
+ uniqBy,
894
+ upperFirst as upperFirst4
895
+ } from "lodash";
887
896
  import { FaasDataWrapper as FaasDataWrapper2 } from "@faasjs/react";
888
897
  import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
889
898
  function processValue(item, value) {
890
899
  var _a;
891
- if (typeof value !== "undefined" && value !== null) {
892
- if (item.options) {
893
- if (item.type.endsWith("[]"))
894
- return value.map((v) => {
895
- var _a2;
896
- return ((_a2 = item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
897
- });
898
- else if ([
899
- "string",
900
- "number",
901
- "boolean"
902
- ].includes(item.type))
903
- return ((_a = item.options.find((option) => option.value === value)) == null ? void 0 : _a.label) || value;
904
- }
905
- let dayjsFormat = "";
906
- if (item.type === "date")
907
- dayjsFormat = "YYYY-MM-DD";
908
- else if (item.type === "time")
909
- dayjsFormat = "YYYY-MM-DD HH:mm:ss";
910
- if (["date", "time"].includes(item.type)) {
911
- if (typeof value === "number" && value.toString().length === 10)
912
- value = value * 1e3;
913
- value = dayjs3(value).format(dayjsFormat);
914
- }
900
+ if (typeof value === "undefined" && value === null)
901
+ return /* @__PURE__ */ jsx11(Empty, {});
902
+ if (item.options) {
903
+ if (item.type.endsWith("[]"))
904
+ return value.map((v) => {
905
+ var _a2;
906
+ return ((_a2 = item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
907
+ });
908
+ else if ([
909
+ "string",
910
+ "number",
911
+ "boolean"
912
+ ].includes(item.type))
913
+ return ((_a = item.options.find((option) => option.value === value)) == null ? void 0 : _a.label) || value;
914
+ }
915
+ if (["date", "time"].includes(item.type)) {
916
+ if (typeof value === "number" && value.toString().length === 10)
917
+ value = value * 1e3;
918
+ return dayjs3(value).format(item.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss");
915
919
  }
916
920
  return value;
917
921
  }
918
922
  function Table(props) {
919
923
  const [columns, setColumns] = useState7();
920
- const config = useConfigContext();
924
+ const { common: common2 } = useConfigContext();
921
925
  useEffect5(() => {
922
926
  var _a;
923
927
  for (const item of props.items) {
@@ -936,8 +940,6 @@ function Table(props) {
936
940
  value: o.value
937
941
  }));
938
942
  }
939
- if (item.render)
940
- continue;
941
943
  if (item.children)
942
944
  delete item.children;
943
945
  if (props.extendTypes && props.extendTypes[item.type]) {
@@ -957,39 +959,185 @@ function Table(props) {
957
959
  }
958
960
  switch (item.type) {
959
961
  case "string":
960
- item.render = (value) => processValue(item, value);
961
- if (!item.onFilter)
962
+ if (!item.render)
963
+ item.render = (value) => processValue(item, value);
964
+ if (!item.onFilter) {
962
965
  item.onFilter = (value, row) => row[item.id].includes(value);
966
+ }
967
+ if (!item.filters && item.filterDropdown !== false && item.optionsType !== "auto")
968
+ item.filterDropdown = ({
969
+ setSelectedKeys,
970
+ selectedKeys,
971
+ confirm,
972
+ clearFilters
973
+ }) => /* @__PURE__ */ jsxs4("div", {
974
+ style: { padding: 8 },
975
+ children: [
976
+ /* @__PURE__ */ jsx11("input", {
977
+ value: selectedKeys[0],
978
+ onChange: (e) => setSelectedKeys(e.target.value ? [e.target.value] : []),
979
+ style: {
980
+ width: 188,
981
+ marginBottom: 8,
982
+ display: "block"
983
+ }
984
+ }),
985
+ /* @__PURE__ */ jsx11("button", {
986
+ type: "button",
987
+ onClick: () => confirm(),
988
+ style: {
989
+ width: 90,
990
+ marginRight: 8
991
+ },
992
+ children: common2.search
993
+ }),
994
+ /* @__PURE__ */ jsx11("button", {
995
+ type: "button",
996
+ onClick: () => clearFilters(),
997
+ style: { width: 90 },
998
+ children: common2.reset
999
+ })
1000
+ ]
1001
+ });
963
1002
  break;
964
1003
  case "string[]":
965
- item.render = (value) => processValue(item, value).join(", ");
1004
+ if (!item.render)
1005
+ item.render = (value) => processValue(item, value).join(", ");
966
1006
  if (!item.onFilter)
967
1007
  item.onFilter = (value, row) => row[item.id].includes(value);
1008
+ if (!item.filters && item.filterDropdown !== false)
1009
+ item.filterDropdown = ({
1010
+ setSelectedKeys,
1011
+ selectedKeys,
1012
+ confirm,
1013
+ clearFilters
1014
+ }) => /* @__PURE__ */ jsxs4("div", {
1015
+ style: { padding: 8 },
1016
+ children: [
1017
+ /* @__PURE__ */ jsx11("input", {
1018
+ value: selectedKeys[0],
1019
+ onChange: (e) => setSelectedKeys(e.target.value ? [e.target.value] : []),
1020
+ style: {
1021
+ width: 188,
1022
+ marginBottom: 8,
1023
+ display: "block"
1024
+ }
1025
+ }),
1026
+ /* @__PURE__ */ jsx11("button", {
1027
+ type: "button",
1028
+ onClick: () => confirm(),
1029
+ style: {
1030
+ width: 90,
1031
+ marginRight: 8
1032
+ },
1033
+ children: common2.search
1034
+ }),
1035
+ /* @__PURE__ */ jsx11("button", {
1036
+ type: "button",
1037
+ onClick: () => clearFilters(),
1038
+ style: { width: 90 },
1039
+ children: common2.reset
1040
+ })
1041
+ ]
1042
+ });
968
1043
  break;
969
1044
  case "number":
970
- item.render = (value) => processValue(item, value);
1045
+ if (!item.render)
1046
+ item.render = (value) => processValue(item, value);
971
1047
  if (!item.sorter)
972
1048
  item.sorter = (a, b) => a[item.id] - b[item.id];
973
1049
  if (!item.onFilter)
974
1050
  item.onFilter = (value, row) => value === row[item.id];
1051
+ if (!item.filters && item.filterDropdown !== false)
1052
+ item.filterDropdown = ({
1053
+ setSelectedKeys,
1054
+ selectedKeys,
1055
+ confirm,
1056
+ clearFilters
1057
+ }) => /* @__PURE__ */ jsxs4("div", {
1058
+ style: { padding: 8 },
1059
+ children: [
1060
+ /* @__PURE__ */ jsx11("input", {
1061
+ value: selectedKeys[0],
1062
+ onChange: (e) => setSelectedKeys(e.target.value ? [e.target.value] : []),
1063
+ style: {
1064
+ width: 188,
1065
+ marginBottom: 8,
1066
+ display: "block"
1067
+ }
1068
+ }),
1069
+ /* @__PURE__ */ jsx11("button", {
1070
+ type: "button",
1071
+ onClick: () => confirm(),
1072
+ style: {
1073
+ width: 90,
1074
+ marginRight: 8
1075
+ },
1076
+ children: common2.search
1077
+ }),
1078
+ /* @__PURE__ */ jsx11("button", {
1079
+ type: "button",
1080
+ onClick: () => clearFilters(),
1081
+ style: { width: 90 },
1082
+ children: common2.reset
1083
+ })
1084
+ ]
1085
+ });
975
1086
  break;
976
1087
  case "number[]":
977
- item.render = (value) => processValue(item, value).join(", ");
1088
+ if (!item.render)
1089
+ item.render = (value) => processValue(item, value).join(", ");
978
1090
  if (!item.onFilter)
979
1091
  item.onFilter = (value, row) => row[item.id].includes(value);
1092
+ if (!item.filters && item.filterDropdown !== false)
1093
+ item.filterDropdown = ({
1094
+ setSelectedKeys,
1095
+ selectedKeys,
1096
+ confirm,
1097
+ clearFilters
1098
+ }) => /* @__PURE__ */ jsxs4("div", {
1099
+ style: { padding: 8 },
1100
+ children: [
1101
+ /* @__PURE__ */ jsx11("input", {
1102
+ value: selectedKeys[0],
1103
+ onChange: (e) => setSelectedKeys(e.target.value ? [e.target.value] : []),
1104
+ style: {
1105
+ width: 188,
1106
+ marginBottom: 8,
1107
+ display: "block"
1108
+ }
1109
+ }),
1110
+ /* @__PURE__ */ jsx11("button", {
1111
+ type: "button",
1112
+ onClick: () => confirm(),
1113
+ style: {
1114
+ width: 90,
1115
+ marginRight: 8
1116
+ },
1117
+ children: common2.search
1118
+ }),
1119
+ /* @__PURE__ */ jsx11("button", {
1120
+ type: "button",
1121
+ onClick: () => clearFilters(),
1122
+ style: { width: 90 },
1123
+ children: common2.reset
1124
+ })
1125
+ ]
1126
+ });
980
1127
  break;
981
1128
  case "boolean":
982
- item.render = (value) => typeof value === "undefined" ? /* @__PURE__ */ jsx11(Blank, {}) : value ? /* @__PURE__ */ jsx11(CheckOutlined2, {
983
- style: {
984
- marginTop: "4px",
985
- color: "#52c41a"
986
- }
987
- }) : /* @__PURE__ */ jsx11(CloseOutlined2, {
988
- style: {
989
- marginTop: "4px",
990
- color: "#ff4d4f"
991
- }
992
- });
1129
+ if (!item.render)
1130
+ item.render = (value) => typeof value === "undefined" ? /* @__PURE__ */ jsx11(Blank, {}) : value ? /* @__PURE__ */ jsx11(CheckOutlined2, {
1131
+ style: {
1132
+ marginTop: "4px",
1133
+ color: "#52c41a"
1134
+ }
1135
+ }) : /* @__PURE__ */ jsx11(CloseOutlined2, {
1136
+ style: {
1137
+ marginTop: "4px",
1138
+ color: "#ff4d4f"
1139
+ }
1140
+ });
993
1141
  if (item.filterDropdown !== false)
994
1142
  item.filterDropdown = ({
995
1143
  setSelectedKeys,
@@ -1005,7 +1153,7 @@ function Table(props) {
1005
1153
  },
1006
1154
  children: [
1007
1155
  /* @__PURE__ */ jsx11(Radio.Button, {
1008
- children: config.common.all
1156
+ children: common2.all
1009
1157
  }),
1010
1158
  /* @__PURE__ */ jsx11(Radio.Button, {
1011
1159
  value: "true",
@@ -1027,7 +1175,7 @@ function Table(props) {
1027
1175
  }),
1028
1176
  /* @__PURE__ */ jsx11(Radio.Button, {
1029
1177
  value: "empty",
1030
- children: config.common.blank
1178
+ children: common2.blank
1031
1179
  })
1032
1180
  ]
1033
1181
  });
@@ -1046,21 +1194,24 @@ function Table(props) {
1046
1194
  };
1047
1195
  break;
1048
1196
  case "date":
1049
- item.render = (value) => processValue(item, value);
1197
+ if (!item.render)
1198
+ item.render = (value) => processValue(item, value);
1050
1199
  if (!item.onFilter)
1051
1200
  item.onFilter = (value, row) => dayjs3(row[item.id]).isSame(dayjs3(value));
1052
1201
  if (!item.sorter)
1053
1202
  item.sorter = (a, b) => dayjs3(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
1054
1203
  break;
1055
1204
  case "time":
1056
- item.render = (value) => processValue(item, value);
1205
+ if (!item.render)
1206
+ item.render = (value) => processValue(item, value);
1057
1207
  if (!item.onFilter)
1058
1208
  item.onFilter = (value, row) => dayjs3(row[item.id]).isSame(dayjs3(value));
1059
1209
  if (!item.sorter)
1060
1210
  item.sorter = (a, b) => dayjs3(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
1061
1211
  break;
1062
1212
  default:
1063
- item.render = (value) => processValue(item, value);
1213
+ if (!item.render)
1214
+ item.render = (value) => processValue(item, value);
1064
1215
  if (!item.onFilter)
1065
1216
  item.onFilter = (value, row) => value === row[item.id];
1066
1217
  break;
@@ -1068,6 +1219,23 @@ function Table(props) {
1068
1219
  }
1069
1220
  setColumns(props.items);
1070
1221
  }, [props.items]);
1222
+ useEffect5(() => {
1223
+ if (!props.dataSource || !columns)
1224
+ return;
1225
+ for (const column of columns) {
1226
+ if (column.optionsType === "auto" && !column.options && !column.filters) {
1227
+ setColumns((prev) => {
1228
+ const newColumns = [...prev];
1229
+ const index = newColumns.findIndex((item) => item.id === column.id);
1230
+ newColumns[index].filters = uniqBy(props.dataSource, column.id).map((v) => ({
1231
+ text: v[column.id],
1232
+ value: v[column.id]
1233
+ }));
1234
+ return newColumns;
1235
+ });
1236
+ }
1237
+ }
1238
+ }, [props.dataSource, columns]);
1071
1239
  if (!columns)
1072
1240
  return null;
1073
1241
  if (!props.faasData)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.2-beta.414",
3
+ "version": "0.0.2-beta.416",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -28,7 +28,7 @@
28
28
  "lodash": "*",
29
29
  "react": "*",
30
30
  "react-dom": "*",
31
- "@faasjs/react": "^0.0.2-beta.414",
31
+ "@faasjs/react": "^0.0.2-beta.416",
32
32
  "react-router-dom": "*",
33
33
  "dayjs": "*"
34
34
  },