ar-design 0.4.40 → 0.4.42

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.
@@ -20,7 +20,7 @@ export type Sort<T> = {
20
20
  export type SearchedParam = {
21
21
  [key: string]: FilterValue | FilterValue[];
22
22
  };
23
- export type Config<T> = {
23
+ export type Config<T extends object> = {
24
24
  locale?: Intl.LocalesArgument;
25
25
  isServerSide?: boolean;
26
26
  isProperties?: boolean;
@@ -34,14 +34,17 @@ export type Config<T> = {
34
34
  button?: boolean;
35
35
  render?: {
36
36
  styles: React.CSSProperties;
37
- element: (item: any[]) => React.JSX.Element;
37
+ element: (item: T[]) => React.JSX.Element;
38
38
  };
39
39
  };
40
40
  dnd?: {
41
41
  renderItem: React.JSX.Element;
42
42
  };
43
43
  isTreeView?: boolean;
44
- validation?: Errors<T>;
44
+ validation?: {
45
+ errors: Errors<T>;
46
+ getChangeData?: (items: T[]) => void;
47
+ };
45
48
  };
46
49
  type ImportActionType = {
47
50
  tooltip: string;
@@ -70,7 +73,7 @@ type DeleteActionType = {
70
73
  message?: string;
71
74
  onClick: () => void;
72
75
  };
73
- interface IProps<T> extends IChildren {
76
+ interface IProps<T extends object> extends IChildren {
74
77
  trackBy?: (item: T) => string;
75
78
  title?: string;
76
79
  description?: string;
@@ -1,7 +1,7 @@
1
1
  import React, { Dispatch, MutableRefObject, SetStateAction } from "react";
2
2
  import { TableColumnType } from "../../../libs/types";
3
3
  import { Config, Sort } from "./IProps";
4
- interface IProps<T> {
4
+ interface IProps<T extends object> {
5
5
  refs: {
6
6
  tableContent: MutableRefObject<HTMLDivElement | null>;
7
7
  buttons: MutableRefObject<(HTMLSpanElement | null)[]>;
@@ -1,7 +1,7 @@
1
1
  import React, { Dispatch, SetStateAction } from "react";
2
2
  import { TableColumnType } from "../../../libs/types";
3
3
  import { Config, Sort } from "./IProps";
4
- declare const MemoizedTHeadCell: <T>({ refs, states, methods, columns, config, }: {
4
+ declare const MemoizedTHeadCell: <T extends object>({ refs, states, methods, columns, config, }: {
5
5
  refs: {
6
6
  propertiesButton: React.MutableRefObject<(HTMLSpanElement | null)[]>;
7
7
  };
@@ -1,13 +1,12 @@
1
1
  import React from "react";
2
- import { Errors, TableColumnType } from "../../../../libs/types";
2
+ import { TableColumnType } from "../../../../libs/types";
3
3
  import { Config } from "../IProps";
4
- interface IProps<T> {
4
+ interface IProps<T extends object> {
5
5
  c: TableColumnType<T>;
6
6
  item: T;
7
7
  trackByValue: string;
8
8
  onEditable: (item: T, trackByValue: string, currentKey?: keyof T | null) => void;
9
- validation?: Errors<T>;
10
9
  config: Config<T>;
11
10
  }
12
- declare const Editable: <T>({ c, item, trackByValue, onEditable, validation, config }: IProps<T>) => React.JSX.Element | null;
11
+ declare const Editable: <T extends object>({ c, item, trackByValue, onEditable, config }: IProps<T>) => React.JSX.Element | null;
13
12
  export default Editable;
@@ -4,7 +4,7 @@ import Input from "../../../form/input";
4
4
  import DatePicker from "../../../form/date-picker";
5
5
  import Select from "../../../form/select";
6
6
  import { ExtractKey } from "../Helpers";
7
- const Editable = function ({ c, item, trackByValue, onEditable, validation, config }) {
7
+ const Editable = function ({ c, item, trackByValue, onEditable, config }) {
8
8
  // variables
9
9
  const key = c.key;
10
10
  const itemValue = item[c.key];
@@ -12,7 +12,8 @@ const Editable = function ({ c, item, trackByValue, onEditable, validation, conf
12
12
  const selectItems = Array.isArray(itemValue)
13
13
  ? c.editable?.options?.filter((x) => itemValue.includes(x.value))
14
14
  : [];
15
- const _vText = validation?.[`${c.key}_${trackByValue}`];
15
+ const validation = config.validation;
16
+ const _vText = validation?.errors?.[`${c.key}_${trackByValue}`];
16
17
  // states
17
18
  const [_value, setValue] = useState(itemValue);
18
19
  // useEffects
@@ -1,7 +1,7 @@
1
1
  import React, { Dispatch, SetStateAction } from "react";
2
2
  import { TableColumnType } from "../../../../libs/types";
3
3
  import { Config } from "../IProps";
4
- interface IProps<T> {
4
+ interface IProps<T extends object> {
5
5
  data: T[];
6
6
  columns: TableColumnType<T>[];
7
7
  refs: {
@@ -99,7 +99,7 @@ function TBody({ data, columns, refs, methods, states, config }) {
99
99
  return (React.createElement("div", { key: `last-before-${i}`, style: { left: `${i + 0.65}rem` }, className: "last-before" }));
100
100
  }),
101
101
  React.createElement("div", { className: "before" }))),
102
- React.isValidElement(render) ? (render) : column.editable && methods.onEditable ? (React.createElement(Editable, { c: column, item: item, trackByValue: methods.trackBy?.(item) ?? "", onEditable: methods.onEditable, validation: config.validation, config: config })) : (React.createElement("span", null, render)),
102
+ React.isValidElement(render) ? (render) : column.editable && methods.onEditable ? (React.createElement(Editable, { c: column, item: item, trackByValue: methods.trackBy?.(item) ?? "", onEditable: methods.onEditable, config: config })) : (React.createElement("span", null, render)),
103
103
  config.isTreeView && cIndex === 0 && (React.createElement("div", { className: "after" },
104
104
  React.createElement("div", { className: "circle" }))))));
105
105
  };
@@ -1,7 +1,14 @@
1
+ import { Dispatch, SetStateAction } from "react";
1
2
  import { Actions } from "../IProps";
2
3
  import React from "react";
3
4
  interface IProps {
5
+ states: {
6
+ createTrigger: {
7
+ get: boolean;
8
+ set: Dispatch<SetStateAction<boolean>>;
9
+ };
10
+ };
4
11
  actions: Actions;
5
12
  }
6
- declare const _default: React.MemoExoticComponent<({ actions }: IProps) => React.JSX.Element>;
13
+ declare const _default: React.MemoExoticComponent<({ states, actions }: IProps) => React.JSX.Element>;
7
14
  export default _default;
@@ -7,7 +7,7 @@ import Tooltip from "../../../feedback/tooltip";
7
7
  import Button from "../../../form/button";
8
8
  import { ARIcon } from "../../../icons";
9
9
  const { Row, Column } = Grid;
10
- const ActionButtons = ({ actions }) => {
10
+ const ActionButtons = ({ states, actions }) => {
11
11
  // states
12
12
  const [files, setFiles] = useState([]);
13
13
  const [formData, setFormData] = useState(undefined);
@@ -46,7 +46,12 @@ const ActionButtons = ({ actions }) => {
46
46
  React.createElement(Tooltip, { text: actions.export.tooltip },
47
47
  React.createElement(Button, { variant: "outlined", color: "blue", icon: { element: React.createElement(ARIcon, { icon: "Download", fill: "currentcolor" }) } })))),
48
48
  actions.create && (React.createElement(Tooltip, { text: actions.create.tooltip },
49
- React.createElement(Button, { variant: "outlined", color: "green", icon: { element: React.createElement(ARIcon, { icon: "Add", size: 24 }) }, onClick: actions.create.onClick }))),
49
+ React.createElement(Button, { variant: "outlined", color: "green", icon: { element: React.createElement(ARIcon, { icon: "Add", size: 24 }) }, onClick: (event) => {
50
+ if (!actions.create)
51
+ return;
52
+ actions.create.onClick(event);
53
+ states.createTrigger.set((prev) => !prev);
54
+ } }))),
50
55
  actions.delete && (React.createElement(Popover, { title: actions.delete.title ?? "Siliniyor", message: actions.delete.message ??
51
56
  "Seçtiğiniz verileri uygulamadan silebilirsiniz. Bu işlem, verilerin sistemimizden tamamen kaldırılmasını sağlar ve bu verilerle artık işlem yapılamaz.", onConfirm: (confirm) => {
52
57
  if (!confirm)
@@ -1,9 +1,15 @@
1
- import React from "react";
1
+ import React, { Dispatch, SetStateAction } from "react";
2
2
  import { Actions } from "../IProps";
3
3
  interface IProps {
4
+ states: {
5
+ createTrigger: {
6
+ get: boolean;
7
+ set: Dispatch<SetStateAction<boolean>>;
8
+ };
9
+ };
4
10
  title?: string;
5
11
  description?: string;
6
12
  actions?: Actions;
7
13
  }
8
- declare const _default: React.MemoExoticComponent<({ title, description, actions }: IProps) => React.JSX.Element>;
14
+ declare const _default: React.MemoExoticComponent<({ states, title, description, actions }: IProps) => React.JSX.Element>;
9
15
  export default _default;
@@ -1,10 +1,10 @@
1
1
  import React, { memo } from "react";
2
2
  import ActionButtons from "./ActionButtons";
3
- const Header = ({ title, description, actions }) => {
3
+ const Header = ({ states, title, description, actions }) => {
4
4
  return (React.createElement("div", { className: "header" },
5
5
  React.createElement("div", { className: "title" },
6
6
  React.createElement("h4", null, title),
7
7
  description && React.createElement("h5", null, description)),
8
- actions && React.createElement(ActionButtons, { actions: actions })));
8
+ actions && React.createElement(ActionButtons, { states: states, actions: actions })));
9
9
  };
10
10
  export default memo(Header);
@@ -49,6 +49,8 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
49
49
  // states
50
50
  const [selectAll, setSelectAll] = useState(false);
51
51
  const [showSubitems, setShowSubitems] = useState({});
52
+ // states -> Action Buttons
53
+ const [createTrigger, setCreateTrigger] = useState(false);
52
54
  // states -> Search
53
55
  const [searchedText, setSearchedText] = useState(null);
54
56
  const [_searchedParams, setSearchedParams] = useState(null);
@@ -566,9 +568,23 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
566
568
  setCurrentPage(1);
567
569
  setTimeout(() => handleScroll(), 0);
568
570
  }, [selectedPerPage]);
571
+ useEffect(() => {
572
+ if (typeof selections !== "function" && config.validation) {
573
+ const updatedData = data.map((item) => {
574
+ if (!("trackByValue" in item) && trackBy) {
575
+ return { ...item, trackByValue: trackBy(item) };
576
+ }
577
+ return item;
578
+ });
579
+ config.validation?.getChangeData?.(updatedData);
580
+ }
581
+ }, [createTrigger]);
569
582
  useEffect(() => {
570
583
  setIsMobile(window.innerWidth <= 768);
571
584
  window.addEventListener("resize", handleResize);
585
+ if (typeof selections !== "function" && config.validation) {
586
+ config.validation.getChangeData?.(data.map((d) => ({ ...d, trackByValue: trackBy?.(d) })) ?? []);
587
+ }
572
588
  return () => {
573
589
  window.removeEventListener("resize", handleResize);
574
590
  };
@@ -584,7 +600,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
584
600
  { value: FilterOperator.NotBlank, text: t("Table.Filters.Where.Input.Item.8.Text") },
585
601
  ];
586
602
  return (React.createElement("div", { ref: _tableWrapper, className: _tableClassName.map((c) => c).join(" ") },
587
- (title || description || actions || React.Children.count(children) > 0) && (React.createElement(Header, { title: title, description: description, actions: actions })),
603
+ (title || description || actions || React.Children.count(children) > 0) && (React.createElement(Header, { states: { createTrigger: { get: createTrigger, set: setCreateTrigger } }, title: title, description: description, actions: actions })),
588
604
  React.createElement("div", { ref: _tableContent, className: "content", onScroll: handleScroll },
589
605
  React.createElement("table", { ref: _innerRef },
590
606
  React.createElement("thead", null,
@@ -3,10 +3,14 @@ import { IChildren } from "../../../libs/types/IGlobalProps";
3
3
  interface IProps<TData extends object> extends IChildren {
4
4
  name: string;
5
5
  steps: StepProps[];
6
+ currentStep?: number;
6
7
  onChange: (currentStep: number) => void;
7
8
  validation?: {
8
9
  data: TData;
9
10
  rules: ValidationProperties<TData>[];
10
11
  };
12
+ config?: {
13
+ isAutomatic?: boolean;
14
+ };
11
15
  }
12
16
  export default IProps;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
2
  import IProps from "./IProps";
3
3
  import "../../../assets/css/components/navigation/steps/styles.css";
4
- declare const Steps: <T extends object>({ children, name, steps, onChange, validation }: IProps<T>) => React.JSX.Element;
4
+ declare const Steps: <T extends object>({ children, name, steps, currentStep, onChange, validation, config, }: IProps<T>) => React.JSX.Element;
5
5
  export default Steps;
@@ -5,11 +5,11 @@ import Typography from "../../data-display/typography";
5
5
  import Button from "../../form/button";
6
6
  import { useValidation } from "../../../libs/core/application/hooks";
7
7
  const { Title } = Typography;
8
- const Steps = function ({ children, name, steps = [], onChange, validation }) {
8
+ const Steps = function ({ children, name, steps = [], currentStep, onChange, validation, config, }) {
9
9
  // states
10
- const [currentStep, setCurrentStep] = useState(0);
10
+ const [_currentStep, setCurrentStep] = useState(0);
11
11
  // hooks
12
- const { errors, onSubmit, setSubmit } = useValidation(validation?.data, validation?.rules, currentStep + 1);
12
+ const { errors, onSubmit, setSubmit } = useValidation(validation?.data, validation?.rules, _currentStep + 1);
13
13
  // methods
14
14
  const getStepIconStatus = (currentStep, index) => {
15
15
  if (currentStep < index)
@@ -20,17 +20,24 @@ const Steps = function ({ children, name, steps = [], onChange, validation }) {
20
20
  };
21
21
  // useEffects
22
22
  useEffect(() => {
23
+ setCurrentStep(currentStep ?? 0);
24
+ }, [currentStep]);
25
+ useEffect(() => {
26
+ if (config?.isAutomatic)
27
+ return;
23
28
  const key = `${window.location.pathname}::${name}`;
24
29
  const stored = sessionStorage.getItem(key);
25
- setCurrentStep(stored !== null ? Number(stored) : 0);
26
- onChange?.(stored !== null ? Number(stored) : 0);
30
+ setCurrentStep(stored !== null ? Number(stored) : (currentStep ?? 0));
31
+ onChange?.(stored !== null ? Number(stored) : (currentStep ?? 0));
27
32
  }, []);
28
33
  return (React.createElement("div", { className: "ar-steps" },
29
34
  React.createElement("div", { className: "steps" }, steps.length > 0 &&
30
35
  steps.map((step, index) => {
31
36
  let itemIcon = ["item-icon"];
32
- itemIcon.push(getStepIconStatus(currentStep, index));
37
+ itemIcon.push(getStepIconStatus(_currentStep, index));
33
38
  return (React.createElement("div", { key: step.title || index, className: "item", onClick: () => {
39
+ if (config?.isAutomatic)
40
+ return;
34
41
  if (validation) {
35
42
  onSubmit((result) => {
36
43
  if (!result)
@@ -48,7 +55,7 @@ const Steps = function ({ children, name, steps = [], onChange, validation }) {
48
55
  sessionStorage.setItem(key, String(index));
49
56
  } },
50
57
  React.createElement("div", { className: itemIcon.map((c) => c).join(" ") },
51
- React.createElement("span", { className: getStepIconStatus(currentStep, index) })),
58
+ React.createElement("span", { className: getStepIconStatus(_currentStep, index) })),
52
59
  React.createElement("div", { className: "item-informations" },
53
60
  React.createElement("span", { className: "step" },
54
61
  "STEP ",
@@ -58,7 +65,7 @@ const Steps = function ({ children, name, steps = [], onChange, validation }) {
58
65
  React.createElement("div", { className: "content" },
59
66
  steps.map((step, stepIndex) => {
60
67
  return (React.createElement("div", { key: stepIndex }, React.Children.map(step.content, (child) => {
61
- if (React.isValidElement(child) && stepIndex === currentStep) {
68
+ if (React.isValidElement(child) && stepIndex === _currentStep) {
62
69
  return validation
63
70
  ? React.cloneElement(child, {
64
71
  errors: errors,
@@ -68,28 +75,28 @@ const Steps = function ({ children, name, steps = [], onChange, validation }) {
68
75
  return null;
69
76
  })));
70
77
  }),
71
- React.createElement("div", { className: "buttons" },
72
- currentStep > 0 && (React.createElement(Button, { color: "blue", onClick: () => {
78
+ !config?.isAutomatic && (React.createElement("div", { className: "buttons" },
79
+ _currentStep > 0 && (React.createElement(Button, { color: "blue", onClick: () => {
73
80
  setCurrentStep((prev) => prev - 1);
74
- onChange(currentStep - 1);
81
+ onChange(_currentStep - 1);
75
82
  } }, "Geri")),
76
83
  children && children,
77
- currentStep < steps.length - 1 && (React.createElement(Button, { color: "blue", onClick: () => {
84
+ _currentStep < steps.length - 1 && (React.createElement(Button, { color: "blue", onClick: () => {
78
85
  if (validation) {
79
86
  onSubmit((result) => {
80
87
  if (!result)
81
88
  return;
82
89
  setCurrentStep((prev) => prev + 1);
83
- onChange(currentStep + 1);
90
+ onChange(_currentStep + 1);
84
91
  setSubmit(false);
85
92
  });
86
93
  }
87
94
  else {
88
95
  setCurrentStep((prev) => prev + 1);
89
- onChange(currentStep + 1);
96
+ onChange(_currentStep + 1);
90
97
  }
91
98
  const key = `${window.location.pathname}::${name}`;
92
- sessionStorage.setItem(key, String(currentStep + 1));
93
- } }, "\u0130leri"))))));
99
+ sessionStorage.setItem(key, String(_currentStep + 1));
100
+ } }, "\u0130leri")))))));
94
101
  };
95
102
  export default Steps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.4.40",
3
+ "version": "0.4.42",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",