-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add calendar widget to custom field of type date
- Loading branch information
Showing
9 changed files
with
217 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
INBOX_TITLE = '.inbox' | ||
HOME_TITLE = '.home' | ||
CTYPE_FOLDER = 'folder' | ||
CTYPE_DOCUMENT = 'document' | ||
INBOX_TITLE = ".inbox" | ||
HOME_TITLE = ".home" | ||
CTYPE_FOLDER = "folder" | ||
CTYPE_DOCUMENT = "document" | ||
DEFAULT_THUMBNAIL_SIZE = 100 # 100 pixels wide | ||
DEFAULT_PAGE_SIZE = 900 # 900 pixels wide | ||
JPG = 'jpg' | ||
PAGES = 'pages' | ||
THUMBNAILS = 'thumbnails' | ||
DOCVERS = 'docvers' | ||
OCR = 'ocr' | ||
DEFAULT_TAG_BG_COLOR = '#c41fff' | ||
DEFAULT_TAG_FG_COLOR = '#ffffff' | ||
INDEX_ADD_NODE = 'index_add_node' | ||
INDEX_ADD_DOCS = 'index_add_docs' | ||
INDEX_ADD_PAGES = 'index_add_pages' | ||
INDEX_REMOVE_NODE = 'index_remove_node' | ||
INDEX_UPDATE = 'index_update' | ||
S3_WORKER_ADD_DOC_VER = 's3_worker_add_doc_vers' | ||
S3_WORKER_REMOVE_DOC_VER = 's3_worker_remove_doc_vers' | ||
S3_WORKER_REMOVE_DOC_THUMBNAIL = 's3_worker_remove_doc_thumbnail' | ||
S3_WORKER_REMOVE_PAGE_THUMBNAIL = 's3_worker_remove_page_thumbnail' | ||
S3_WORKER_GENERATE_PREVIEW = 's3_worker_generate_preview' | ||
WORKER_OCR_DOCUMENT = 'worker_ocr_document' | ||
JPG = "jpg" | ||
PAGES = "pages" | ||
THUMBNAILS = "thumbnails" | ||
DOCVERS = "docvers" | ||
OCR = "ocr" | ||
DEFAULT_TAG_BG_COLOR = "#c41fff" | ||
DEFAULT_TAG_FG_COLOR = "#ffffff" | ||
INDEX_ADD_NODE = "index_add_node" | ||
INDEX_ADD_DOCS = "index_add_docs" | ||
INDEX_ADD_PAGES = "index_add_pages" | ||
INDEX_REMOVE_NODE = "index_remove_node" | ||
INDEX_UPDATE = "index_update" | ||
S3_WORKER_ADD_DOC_VER = "s3_worker_add_doc_vers" | ||
S3_WORKER_REMOVE_DOC_VER = "s3_worker_remove_doc_vers" | ||
S3_WORKER_REMOVE_DOC_THUMBNAIL = "s3_worker_remove_doc_thumbnail" | ||
S3_WORKER_REMOVE_PAGE_THUMBNAIL = "s3_worker_remove_page_thumbnail" | ||
S3_WORKER_GENERATE_PREVIEW = "s3_worker_generate_preview" | ||
WORKER_OCR_DOCUMENT = "worker_ocr_document" | ||
# incoming (from user) date format | ||
INCOMING_DATE_FORMAT = "%Y-%m-%d" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
ui2/src/features/document/components/customFields/CustomFieldDate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import type {DocumentCustomFieldValue} from "@/types" | ||
import {rem} from "@mantine/core" | ||
import {DatePickerInput, DateValue} from "@mantine/dates" | ||
import {IconCalendar} from "@tabler/icons-react" | ||
import dayjs from "dayjs" | ||
import {useEffect, useState} from "react" | ||
|
||
type onChangeArgs = { | ||
customField: DocumentCustomFieldValue | ||
value: string | ||
} | ||
|
||
type onChangeType = ({customField, value}: onChangeArgs) => void | ||
|
||
interface Args { | ||
customField: DocumentCustomFieldValue | ||
onChange: onChangeType | ||
} | ||
|
||
export default function CustomFieldDate({customField, onChange}: Args) { | ||
const [value, setValue] = useState<Date | null>(null) | ||
const icon = ( | ||
<IconCalendar style={{width: rem(18), height: rem(18)}} stroke={1.5} /> | ||
) | ||
|
||
useEffect(() => { | ||
if (customField.value && customField.value.length > 0) { | ||
const parts = customField.value.split("-") | ||
const year = Number(parts[0]) | ||
const month = Number(parts[1]) - 1 | ||
const day = Number(parts[2].substring(0, 2)) | ||
|
||
const date = new Date(year, month, day) | ||
setValue(date) | ||
} | ||
}, []) | ||
|
||
const onLocalChange = (value: DateValue) => { | ||
if (value) { | ||
const d = dayjs(value) | ||
const DATE_FORMAT = "YYYY-MM-DD" | ||
const strValue = d.format(DATE_FORMAT) | ||
onChange({customField, value: strValue}) | ||
} | ||
setValue(value) | ||
} | ||
|
||
return ( | ||
<DatePickerInput | ||
leftSection={icon} | ||
leftSectionPointerEvents="none" | ||
clearable | ||
// `valueFormat` will be retrieved from user preferences | ||
valueFormat="DD.MM.YYYY" | ||
label={customField.name} | ||
placeholder="Pick date" | ||
value={value} | ||
onChange={onLocalChange} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import CustomFieldDate from "./CustomFieldDate" | ||
|
||
export {CustomFieldDate} |
Oops, something went wrong.