|
@@ -1,15 +1,17 @@
|
|
-import { useEffect, useRef, useState } from 'react';
|
|
|
|
|
|
+import { MouseEventHandler, useEffect, useRef, useState } from 'react';
|
|
import { TrashSvg } from '$app/components/_shared/svg/TrashSvg';
|
|
import { TrashSvg } from '$app/components/_shared/svg/TrashSvg';
|
|
import { FieldTypeIcon } from '$app/components/_shared/EditRow/FieldTypeIcon';
|
|
import { FieldTypeIcon } from '$app/components/_shared/EditRow/FieldTypeIcon';
|
|
import { FieldTypeName } from '$app/components/_shared/EditRow/FieldTypeName';
|
|
import { FieldTypeName } from '$app/components/_shared/EditRow/FieldTypeName';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { TypeOptionController } from '$app/stores/effects/database/field/type_option/type_option_controller';
|
|
import { TypeOptionController } from '$app/stores/effects/database/field/type_option/type_option_controller';
|
|
import { Some } from 'ts-results';
|
|
import { Some } from 'ts-results';
|
|
-import { FieldInfo } from '$app/stores/effects/database/field/field_controller';
|
|
|
|
|
|
+import { FieldController, FieldInfo } from '$app/stores/effects/database/field/field_controller';
|
|
import { MoreSvg } from '$app/components/_shared/svg/MoreSvg';
|
|
import { MoreSvg } from '$app/components/_shared/svg/MoreSvg';
|
|
import { useAppSelector } from '$app/stores/store';
|
|
import { useAppSelector } from '$app/stores/store';
|
|
import { CellIdentifier } from '$app/stores/effects/database/cell/cell_bd_svc';
|
|
import { CellIdentifier } from '$app/stores/effects/database/cell/cell_bd_svc';
|
|
import { PopupWindow } from '$app/components/_shared/PopupWindow';
|
|
import { PopupWindow } from '$app/components/_shared/PopupWindow';
|
|
|
|
+import { FieldType } from '@/services/backend';
|
|
|
|
+import { DateTypeOptions } from '$app/components/_shared/EditRow/DateTypeOptions';
|
|
|
|
|
|
export const EditFieldPopup = ({
|
|
export const EditFieldPopup = ({
|
|
top,
|
|
top,
|
|
@@ -18,7 +20,9 @@ export const EditFieldPopup = ({
|
|
viewId,
|
|
viewId,
|
|
onOutsideClick,
|
|
onOutsideClick,
|
|
fieldInfo,
|
|
fieldInfo,
|
|
|
|
+ fieldController,
|
|
changeFieldTypeClick,
|
|
changeFieldTypeClick,
|
|
|
|
+ onNumberFormat,
|
|
}: {
|
|
}: {
|
|
top: number;
|
|
top: number;
|
|
left: number;
|
|
left: number;
|
|
@@ -26,7 +30,9 @@ export const EditFieldPopup = ({
|
|
viewId: string;
|
|
viewId: string;
|
|
onOutsideClick: () => void;
|
|
onOutsideClick: () => void;
|
|
fieldInfo: FieldInfo | undefined;
|
|
fieldInfo: FieldInfo | undefined;
|
|
|
|
+ fieldController?: FieldController;
|
|
changeFieldTypeClick: (buttonTop: number, buttonRight: number) => void;
|
|
changeFieldTypeClick: (buttonTop: number, buttonRight: number) => void;
|
|
|
|
+ onNumberFormat?: (buttonLeft: number, buttonTop: number) => void;
|
|
}) => {
|
|
}) => {
|
|
const databaseStore = useAppSelector((state) => state.database);
|
|
const databaseStore = useAppSelector((state) => state.database);
|
|
const { t } = useTranslation('');
|
|
const { t } = useTranslation('');
|
|
@@ -59,6 +65,19 @@ export const EditFieldPopup = ({
|
|
onOutsideClick();
|
|
onOutsideClick();
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ const onNumberFormatClick: MouseEventHandler = (e) => {
|
|
|
|
+ e.stopPropagation();
|
|
|
|
+ let target = e.target as HTMLElement;
|
|
|
|
+
|
|
|
|
+ while (!(target instanceof HTMLButtonElement)) {
|
|
|
|
+ if (target.parentElement === null) return;
|
|
|
|
+ target = target.parentElement;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const { right: _left, top: _top } = target.getBoundingClientRect();
|
|
|
|
+ onNumberFormat?.(_left, _top);
|
|
|
|
+ };
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<PopupWindow
|
|
<PopupWindow
|
|
className={'px-2 py-2 text-xs'}
|
|
className={'px-2 py-2 text-xs'}
|
|
@@ -69,7 +88,7 @@ export const EditFieldPopup = ({
|
|
left={left}
|
|
left={left}
|
|
top={top}
|
|
top={top}
|
|
>
|
|
>
|
|
- <div className={'flex flex-col gap-2 p-2'}>
|
|
|
|
|
|
+ <div className={'flex flex-col gap-2'}>
|
|
<input
|
|
<input
|
|
value={name}
|
|
value={name}
|
|
onChange={(e) => setName(e.target.value)}
|
|
onChange={(e) => setName(e.target.value)}
|
|
@@ -79,24 +98,24 @@ export const EditFieldPopup = ({
|
|
|
|
|
|
<button
|
|
<button
|
|
onClick={() => onDeleteFieldClick()}
|
|
onClick={() => onDeleteFieldClick()}
|
|
- className={
|
|
|
|
- 'flex cursor-pointer items-center gap-2 rounded-lg px-2 py-2 text-main-alert hover:bg-main-secondary'
|
|
|
|
- }
|
|
|
|
|
|
+ className={'flex cursor-pointer items-center gap-2 rounded-lg py-2 text-main-alert hover:bg-main-secondary'}
|
|
>
|
|
>
|
|
- <i className={'h-5 w-5'}>
|
|
|
|
- <TrashSvg></TrashSvg>
|
|
|
|
- </i>
|
|
|
|
- <span>{t('grid.field.delete')}</span>
|
|
|
|
|
|
+ <span className={'flex items-center gap-2 pl-2'}>
|
|
|
|
+ <i className={'block h-5 w-5'}>
|
|
|
|
+ <TrashSvg></TrashSvg>
|
|
|
|
+ </i>
|
|
|
|
+ <span>{t('grid.field.delete')}</span>
|
|
|
|
+ </span>
|
|
</button>
|
|
</button>
|
|
|
|
|
|
<div
|
|
<div
|
|
ref={changeTypeButtonRef}
|
|
ref={changeTypeButtonRef}
|
|
onClick={() => onChangeFieldTypeClick()}
|
|
onClick={() => onChangeFieldTypeClick()}
|
|
className={
|
|
className={
|
|
- 'relative flex cursor-pointer items-center justify-between rounded-lg text-black hover:bg-main-secondary'
|
|
|
|
|
|
+ 'relative flex cursor-pointer items-center justify-between rounded-lg py-2 text-black hover:bg-main-secondary'
|
|
}
|
|
}
|
|
>
|
|
>
|
|
- <button className={'flex cursor-pointer items-center gap-2 rounded-lg px-2 py-2'}>
|
|
|
|
|
|
+ <button className={'flex cursor-pointer items-center gap-2 rounded-lg pl-2'}>
|
|
<i className={'h-5 w-5'}>
|
|
<i className={'h-5 w-5'}>
|
|
<FieldTypeIcon fieldType={cellIdentifier.fieldType}></FieldTypeIcon>
|
|
<FieldTypeIcon fieldType={cellIdentifier.fieldType}></FieldTypeIcon>
|
|
</i>
|
|
</i>
|
|
@@ -104,10 +123,35 @@ export const EditFieldPopup = ({
|
|
<FieldTypeName fieldType={cellIdentifier.fieldType}></FieldTypeName>
|
|
<FieldTypeName fieldType={cellIdentifier.fieldType}></FieldTypeName>
|
|
</span>
|
|
</span>
|
|
</button>
|
|
</button>
|
|
- <i className={'h-5 w-5'}>
|
|
|
|
- <MoreSvg></MoreSvg>
|
|
|
|
- </i>
|
|
|
|
|
|
+ <span className={'pr-2'}>
|
|
|
|
+ <i className={' block h-5 w-5'}>
|
|
|
|
+ <MoreSvg></MoreSvg>
|
|
|
|
+ </i>
|
|
|
|
+ </span>
|
|
</div>
|
|
</div>
|
|
|
|
+
|
|
|
|
+ {cellIdentifier.fieldType === FieldType.Number && (
|
|
|
|
+ <>
|
|
|
|
+ <hr className={'-mx-2 border-shade-6'} />
|
|
|
|
+ <button
|
|
|
|
+ onClick={onNumberFormatClick}
|
|
|
|
+ className={
|
|
|
|
+ 'flex w-full cursor-pointer items-center justify-between rounded-lg py-2 hover:bg-main-secondary'
|
|
|
|
+ }
|
|
|
|
+ >
|
|
|
|
+ <span className={'pl-2'}>{t('grid.field.numberFormat')}</span>
|
|
|
|
+ <span className={'pr-2'}>
|
|
|
|
+ <i className={'block h-5 w-5'}>
|
|
|
|
+ <MoreSvg></MoreSvg>
|
|
|
|
+ </i>
|
|
|
|
+ </span>
|
|
|
|
+ </button>
|
|
|
|
+ </>
|
|
|
|
+ )}
|
|
|
|
+
|
|
|
|
+ {cellIdentifier.fieldType === FieldType.DateTime && fieldController && (
|
|
|
|
+ <DateTypeOptions cellIdentifier={cellIdentifier} fieldController={fieldController}></DateTypeOptions>
|
|
|
|
+ )}
|
|
</div>
|
|
</div>
|
|
</PopupWindow>
|
|
</PopupWindow>
|
|
);
|
|
);
|