138 lines
3.4 KiB
JavaScript
138 lines
3.4 KiB
JavaScript
import {
|
|
AuditOutlined,
|
|
DeleteFilled,
|
|
EditFilled,
|
|
EyeInvisibleFilled,
|
|
WarningFilled,
|
|
} from "@ant-design/icons";
|
|
import { Button, Table } from "antd";
|
|
import React from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { connect } from "react-redux";
|
|
import { createStructuredSelector } from "reselect";
|
|
import { selectJobReadOnly } from "../../redux/application/application.selectors";
|
|
import { setModalContext } from "../../redux/modals/modals.actions";
|
|
import { DateTimeFormatter } from "../../utils/DateFormatter";
|
|
import NoteUpsertModal from "../note-upsert-modal/note-upsert-modal.container";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
jobRO: selectJobReadOnly,
|
|
});
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
setNoteUpsertContext: (context) =>
|
|
dispatch(setModalContext({ context: context, modal: "noteUpsert" })),
|
|
});
|
|
|
|
export function JobNotesComponent({
|
|
jobRO,
|
|
loading,
|
|
data,
|
|
refetch,
|
|
handleNoteDelete,
|
|
jobId,
|
|
setNoteUpsertContext,
|
|
deleteLoading,
|
|
}) {
|
|
const { t } = useTranslation();
|
|
|
|
const columns = [
|
|
{
|
|
title: "",
|
|
dataIndex: "icons",
|
|
key: "icons",
|
|
width: 80,
|
|
render: (text, record) => (
|
|
<span>
|
|
{record.critical ? (
|
|
<WarningFilled style={{ margin: 4, color: "red" }} />
|
|
) : null}
|
|
{record.private ? <EyeInvisibleFilled style={{ margin: 4 }} /> : null}
|
|
{record.audit ? <AuditOutlined style={{ margin: 4 }} /> : null}
|
|
</span>
|
|
),
|
|
},
|
|
{
|
|
title: t("notes.fields.text"),
|
|
dataIndex: "text",
|
|
key: "text",
|
|
ellipsis: true,
|
|
},
|
|
|
|
{
|
|
title: t("notes.fields.updatedat"),
|
|
dataIndex: "updated_at",
|
|
key: "updated_at",
|
|
defaultSortOrder: "descend",
|
|
width: 200,
|
|
sorter: (a, b) => new Date(a.updated_at) - new Date(b.updated_at),
|
|
render: (text, record) => (
|
|
<DateTimeFormatter>{record.updated_at}</DateTimeFormatter>
|
|
),
|
|
},
|
|
{
|
|
title: t("notes.fields.createdby"),
|
|
dataIndex: "created_by",
|
|
key: "created_by",
|
|
width: 200,
|
|
},
|
|
{
|
|
title: t("notes.actions.actions"),
|
|
dataIndex: "actions",
|
|
key: "actions",
|
|
width: 150,
|
|
render: (text, record) => (
|
|
<span>
|
|
<Button
|
|
loading={deleteLoading}
|
|
disabled={record.audit || jobRO}
|
|
onClick={() => handleNoteDelete(record.id)}
|
|
>
|
|
<DeleteFilled />
|
|
</Button>
|
|
<Button
|
|
disabled={record.audit || jobRO}
|
|
onClick={() => {
|
|
setNoteUpsertContext({
|
|
actions: { refetch: refetch },
|
|
context: {
|
|
jobId: jobId,
|
|
existingNote: record,
|
|
},
|
|
});
|
|
}}
|
|
>
|
|
<EditFilled />
|
|
</Button>
|
|
</span>
|
|
),
|
|
},
|
|
];
|
|
|
|
return (
|
|
<div>
|
|
<NoteUpsertModal />
|
|
<Button
|
|
onClick={() => {
|
|
setNoteUpsertContext({
|
|
actions: { refetch: refetch },
|
|
context: {
|
|
jobId: jobId,
|
|
},
|
|
});
|
|
}}
|
|
>
|
|
{t("notes.actions.new")}
|
|
</Button>
|
|
<Table
|
|
loading={loading}
|
|
pagination={{ position: "bottom" }}
|
|
columns={columns}
|
|
rowKey="id"
|
|
dataSource={data}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
export default connect(null, mapDispatchToProps)(JobNotesComponent);
|