use-change-document-parser.ts


Overview

The use-change-document-parser.ts file defines a custom React hook named useChangeDocumentParser. This hook encapsulates the state management and business logic needed to display a modal dialog for changing the parser configuration of a document, and to submit updates for the document parser to the backend system.

It provides:

This hook is designed to be used in React components that allow users to update the parser configuration associated with a specific document entity. It abstracts away the modal state and request handling, promoting reuse and separation of concerns.


Exports

useChangeDocumentParser

A React custom hook that provides functionality to manage and submit changes to a document's parser configuration.

Signature

const {
  changeParserLoading,
  onChangeParserOk,
  changeParserVisible,
  hideChangeParserModal,
  showChangeParserModal,
  changeParserRecord,
} = useChangeDocumentParser();

Returned Properties

Property

Type

Description

changeParserLoading

boolean

Indicates whether the parser change request is currently being processed.

onChangeParserOk

(parserConfigInfo: IChangeParserRequestBody) => Promise<void>

Async callback to submit the parser change request for the currently selected document.

changeParserVisible

boolean

Controls visibility of the change parser modal dialog.

hideChangeParserModal

() => void

Function to hide the change parser modal dialog.

showChangeParserModal

(row: IDocumentInfo) => void

Function to show the modal and set the document record for which the parser will be changed.

changeParserRecord

IDocumentInfo

The currently selected document record for which the parser configuration is being changed.


Detailed Explanation

Internal State and Hooks

Methods

onChangeParserOk

async function onChangeParserOk(parserConfigInfo: IChangeParserRequestBody): Promise<void>
const { onChangeParserOk } = useChangeDocumentParser();

const newParserConfig = {
  parser_id: 'new-parser-123',
  parser_config: { key: 'value' },
};

onChangeParserOk(newParserConfig);

handleShowChangeParserModal

function handleShowChangeParserModal(row: IDocumentInfo): void
const { showChangeParserModal } = useChangeDocumentParser();

const selectedDocument = { id: 'doc123', title: 'Sample Document' };
showChangeParserModal(selectedDocument);

Types and Interfaces


Implementation Details


Interaction with Other Parts of the System


Example Usage in a Component

import React from 'react';
import { useChangeDocumentParser } from './use-change-document-parser';
import { DocumentTable } from './DocumentTable';
import { ChangeParserModal } from './ChangeParserModal';

const DocumentManager = () => {
  const {
    changeParserLoading,
    onChangeParserOk,
    changeParserVisible,
    hideChangeParserModal,
    showChangeParserModal,
    changeParserRecord,
  } = useChangeDocumentParser();

  return (
    <>
      <DocumentTable onEditParser={showChangeParserModal} />
      {changeParserVisible && (
        <ChangeParserModal
          visible={changeParserVisible}
          loading={changeParserLoading}
          document={changeParserRecord}
          onCancel={hideChangeParserModal}
          onOk={onChangeParserOk}
        />
      )}
    </>
  );
};

Mermaid Class Diagram

classDiagram
    class useChangeDocumentParser {
        - record: IDocumentInfo
        - changeParserVisible: boolean
        - changeParserLoading: boolean
        + onChangeParserOk(parserConfigInfo: IChangeParserRequestBody): Promise<void>
        + showChangeParserModal(row: IDocumentInfo): void
        + hideChangeParserModal(): void
    }

    useChangeDocumentParser ..> useSetDocumentParser : uses
    useChangeDocumentParser ..> useSetModalState : uses

Summary

The use-change-document-parser.ts file provides a well-encapsulated React hook that manages the UI state and business logic for changing the parser configuration of a document entity. By integrating modal state management and asynchronous submission handling, it enables clear separation of concerns and promotes reuse across components that require this functionality.