1.1.1 β€’ Published 3 months ago

teko-file-history v1.1.1

Weekly downloads
-
License
ISC
Repository
-
Last release
3 months ago

Teko File History

A library for creating a file history web page used for Teko system.

Installation

yarn

yarn add teko-file-history

npm

npm install teko-file-history

Preview UI

preview-ui.png

Usage

The library consists of 2 separated components: Table and Uploader

The library has its own mechanism to fetch configs from server. In order to get server config, you need to provide clientId, env and accessToken to the library. Configs from server will overwrite client config.

1. Props list

Base props

PropTypeRequired?Description
languagestringtrueCurrent language, accepted values vi, en
envstringfalseCurrent environment in uppercase, accept DEV, STAG, PROD
clientIdnumberfalseFPS client ID, if undefined, can't get FPS client config
accessTokenstringfalseAccess token with Bearer prefix, used for fetching APIs
isOverwriteDBConfigbooleanfalseOverwrite the configs from server by the component's props
classNamesobjectfalseCustom classnames for the component, detail below
tablePropsobjectfalseCustom props for the table component, detail below
uploaderPropsobjectfalseCustom props for the uploader component, detail below
downloadFilefunctionfalseCustom download function

Table props

The table component wraps Antd Table, so it will inherit Antd Table props, besides that we have:

PropTypeDefaultOverwritten by DBDescription
isShowDebugbooleantrueyesShow debug button and modal on dev and stag require env prop to work
isShowCreatedBybooleantrueyesShow created by column
isShowReloadbooleantrueyesShow reload button
tableTitlestringundefinednoTitle of the table
onReloadfunctionundefinednoReload function, required if you use your own BFF for fetching data
dateFormatstring"DD/MM/YYYY HH:mm:ss"noDate time format
orderColumnstring[]undefinednoCustomize table's column order, accept id, name, createdAt, status, progressStatus

Uploader props

The uploader component also wraps Antd Upload, similarly, we have these extra props:

PropTypeDefaultOverwritten by DBDescription
importFileTemplateUrlstringundefinedyesURL to download the import file template, if no value found, the download template button will be hidden
maxFileSizenumber5yesMaximum accepted file size in MB
inputFileTypesstring[]'xlsx'yesAccepted file types, accepted values xlsx, xls, csv
isShowUploaderbooleantrueyesShow uploader component
uploaderPositionstring'right'noUploader position, accepted values left, right
onUploadFilefunctionundefinednoCustom upload file function, triggered on confirm upload file

2. Features and their required props/ alternative usage

1. Fetching import history

  • Required props: env, clientId, accessToken
  • Alternative usage: pass dataSource and reload to tableProps

2. Download file

  • Required props: env, accessToken
  • Alternative usage: pass downloadFile to FileImportHistory

3. Upload file

  • Required props: env, clientId, accessToken
  • Alternative usage: using your own Uploader

4. Debug modal

  • Required props: env, accessToken
  • Alternative usage: hide it by setting isShowDebug to false

3. Understand about styling

The library does not have its own styling. It adds classnames to the components, and apply the style from the parent application.

You can overwrite the default classnames by passing the classNames prop to the component.

import { FileImportHistory } from 'teko-file-history';

return <FileImportHistory classNames={{ ...customClassNames }} />;

List of classNames in the library:

ClassNameTypeDefaultDescription
displayFlexstringd-flexApply display: flex
flexColumnstringflex-columnApply flex-direction: column
gapBasestringgap-baseApply gap: x x based on your application
gapHalfstringgap-halfApply gap: x x based on your application
marginBottomZerostringmb-0Apply margin-bottom: 0
marginTopHalfstringmt-halfApply margin-top: x x based on your application
marginHorizontalBasestringmx-baseApply margin-left: x and margin-right: x x based on your application
paddingHorizontalBasestringpx-baseApply padding-left: x and padding-right: x x based on your application
textErrorColorstringtext-errorApply color: #xxx text error color
textPrimaryColorstringtext-primaryApply color: #xxx primary color of the application

4. Implementation examples

1. Using full FPS flow

import { FileImportHistory } from 'teko-file-history';

return (
  /**
   * Let the component do everything πŸ€Έβ€β™‚οΈ
   * From fetching data to file handling, validation, and download 🀝
   */
  <FileImportHistory
    env={env}
    clientId={clientId}
    language={language}
    accessToken={`Bearer ${accessToken}`}
    /**
     * Customize your component like a pro πŸ€·β€β™‚οΈ
     */
    tableProps={{
      dateFormat: 'DD/MM/YYYY HH:mm:ss',
      orderColumn: ['id', 'name', 'createdAt', 'status', 'progressStatus'],
    }}
    uploaderProps={{
      importFileTemplateUrl: 'https://example.com/import-file-template.xlsx',
      maxFileSize: 5,
      inputFileTypes: ['xlsx', 'xls', 'csv'],
      onUploadFile: (file, setFile) => {
        // Your upload file logic, it got triggered when you click submit button
      },
    }}
  />
);

2. You control your own data

import { FileImportHistory } from 'teko-file-history';

return (
  <FileImportHistory
    env={env}
    language={language}
    accessToken={`Bearer ${accessToken}`}
    /**
     * Just like that, you don't have to worry about clientId anymore 🦈
     * But beware, you can't use our default uploader this way, try using onUploadFile πŸ€·β€β™‚οΈ
     */
    tableProps={{
      dataSource, // Your data πŸ€Έβ€β™‚οΈ
      pagination, // Your pagination πŸ€Έβ€β™‚οΈ
      onReload: () => {},
    }}
    uploaderProps={{
      onUploadFile: (file, setFile) => {
        // Your upload file logic, it got triggered when you click submit button
      },
    }}
  />
);

3. You only need the table thing, and you control your own data

import { FileImportHistory } from 'teko-file-history';

return (
  <FileImportHistory
    language={language}
    uploaderProps={{
      isShowUploader: false,
    }}
    tableProps={{
      dataSource, // Your data πŸ€Έβ€β™‚οΈ
      pagination, // Your pagination πŸ€Έβ€β™‚οΈ
      onReload: () => {},
    }}
    downloadFile={(url: string) => onDownloadFile(url)} // Your download function πŸ€·β€β™‚οΈ
  />
);
1.1.1

3 months ago

1.1.0

3 months ago

1.0.1

4 months ago

1.0.0

4 months ago