diff --git a/package.json b/package.json
index 4e6c95f..dbf09d6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@ilb/antd-tables",
- "version": "1.0.1",
+ "version": "1.1.0",
"description": "",
"main": "index.js",
"type": "module",
@@ -10,11 +10,11 @@
"author": "ssortia",
"license": "MIT",
"dependencies": {
- "@ant-design/icons": "^4.7.0",
+ "@ant-design/icons": "^4.8.3",
"@ilb/ajvinstance": "^3.0.0",
"@ilb/antd-toasts": "^1.0.0",
"@ilb/uniformscomponentsantd": "^1.2.24",
- "react": "18.2.0",
+ "react": "18.3.1",
"antd": "^4.21.5",
"moment": "^2.29.4",
"uniforms": "^3.10.0-rc.1",
diff --git a/src/components/icons/ArchiveIcon.js b/src/components/icons/ArchiveIcon.js
new file mode 100644
index 0000000..9e049d5
--- /dev/null
+++ b/src/components/icons/ArchiveIcon.js
@@ -0,0 +1,15 @@
+import React from 'react';
+import Icon from '@ant-design/icons';
+
+const ArchiveSvg = () => (
+
+);
+const ArchiveIcon = (props) => ;
+
+export default ArchiveIcon;
diff --git a/src/components/icons/RestoreIcon.js b/src/components/icons/RestoreIcon.js
new file mode 100644
index 0000000..e50dc44
--- /dev/null
+++ b/src/components/icons/RestoreIcon.js
@@ -0,0 +1,15 @@
+import React from 'react';
+import Icon from '@ant-design/icons';
+
+const RestoreSvg = () => (
+
+);
+const RestoreIcon = (props) => ;
+
+export default RestoreIcon;
diff --git a/src/components/other/IsArchiveToggle.mjs b/src/components/other/IsArchiveToggle.mjs
new file mode 100644
index 0000000..e658ad9
--- /dev/null
+++ b/src/components/other/IsArchiveToggle.mjs
@@ -0,0 +1,41 @@
+import { Button } from "antd";
+import RestoreIcon from "../icons/RestoreIcon.js";
+import ArchiveIcon from "../icons/ArchiveIcon.js";
+
+/**
+ * @param record
+ * @param onRestore
+ * @param onArchive
+ * @param props
+ * @constructor
+ */
+export default function IsArchiveToggle({ isArchive, onRestore, onArchive, ...props }) {
+ const IconComponent = ({ type, handler }) => {
+ let icon = "Тут могла быть ваша реклама.";
+
+ if (type === "restore") {
+ icon = ;
+ }
+
+ if (type === "archive") {
+ icon = ;
+ }
+
+ return (
+
+ );
+ };
+
+ return (
+
+
+
+ );
+}
diff --git a/src/components/tables/SimpleEditableTable.js b/src/components/tables/SimpleEditableTable.js
index 4e470a2..708f0ee 100644
--- a/src/components/tables/SimpleEditableTable.js
+++ b/src/components/tables/SimpleEditableTable.js
@@ -6,12 +6,14 @@ import schemaAdapter from "../../schemaAdapter.js";
import DefaultModal from "../modals/DefaultModal.js";
import SimpleTitle from "../titles/SimpleTitle.js";
import Access from "../Access.js";
+import IsArchiveToggle from "../other/IsArchiveToggle.mjs";
/**
* @param {object} - Объект с опциями.
* @param {object} schema - Схема формы.
* @param {boolean} config.withId - Флаг включения идентификатора в таблицу
* @param {boolean} config.title - Текст заголовка таблицы.
+ * @param {boolean} config.archivable - Флаг, указывающий, что записи могут быть архивными.
* @param {*} resource - Ресурс.
* @param {*} [modalComponent=null] - Компонент модального окна
*/
@@ -67,29 +69,55 @@ const SimpleEditableTable = ({
}
};
+ const successCallback = () => {
+ Toast.success();
+ refresh();
+ return true;
+ }
+
+ const errorCallback = (err) => {
+ Toast.error(err.message);
+ return false;
+ }
+
+ const hideModal = () => {
+ setOpen(false);
+ }
+
/**
* Создание/Редактирование записи
*
* @param data
- * @returns {boolean} - корректно ли отработало сохранение
*/
const store = (data) => {
- const successCallback = () => {
- Toast.success();
- setOpen(false);
- refresh();
- return true;
+ if (editingRecord.id) {
+ return resource.update(editingRecord.id, data).then(successCallback).catch(errorCallback).finally(hideModal)
+ } else {
+ return resource.create(data).then(successCallback).catch(errorCallback).finally(hideModal)
}
+ };
- const errorCallback = (err) => {
- Toast.error(err.message);
- return false;
+ /**
+ *
+ * @param {object} record
+ * @param {int} record.id
+ * @returns {Promise}
+ */
+ const archive = async (record) => {
+ if (confirm(`Отправить "${record.title || record.name}" в архив?`)) {
+ return resource.archive(record.id).then(successCallback).catch(errorCallback);
}
+ };
- if (editingRecord.id) {
- return resource.update(editingRecord.id, data).then(successCallback).catch(errorCallback)
- } else {
- return resource.create(data).then(successCallback).catch(errorCallback)
+ /**
+ *
+ * @param {object} record
+ * @param {int} record.id
+ * @returns {Promise<*>}
+ */
+ const restore = async (record) => {
+ if (confirm(`Восстановить "${record.title || record.name}" из архива?`)) {
+ return resource.restore(record.id).then(successCallback).catch(errorCallback);
}
};
@@ -127,7 +155,7 @@ const SimpleEditableTable = ({
const actionsColumn = {
title: "Действия",
width: 100,
- render: (record) => {
+ render: (_, record) => {
return (
@@ -141,6 +169,17 @@ const SimpleEditableTable = ({
/>
+
+
+ {config.archivable && (
+ restore(record)}
+ onArchive={() => archive(record)}
+ />
+ )}
+
+