-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor regex enhancer; implement edit feature for attachment proper…
…ty when variant=default;
- Loading branch information
Showing
8 changed files
with
124 additions
and
30 deletions.
There are no files selected for viewing
86 changes: 74 additions & 12 deletions
86
...lientApp/src/components/StandardValue/ValueRenderer/Renderers/AttachmentValueRenderer.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 |
---|---|---|
@@ -1,40 +1,102 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { DeleteOutlined, FileAddOutlined, LoadingOutlined, UploadOutlined } from '@ant-design/icons'; | ||
import { Img } from 'react-image'; | ||
import React from 'react'; | ||
import type { ValueRendererProps } from '../models'; | ||
import serverConfig from '@/serverConfig'; | ||
import BApi from '@/sdk/BApi'; | ||
import NotSet from '@/components/StandardValue/ValueRenderer/Renderers/components/NotSet'; | ||
import CustomIcon from '@/components/CustomIcon'; | ||
import { Button, Snippet, Tooltip } from '@/components/bakaui'; | ||
import { splitPathIntoSegments } from '@/components/utils'; | ||
import { useBakabaseContext } from '@/components/ContextProvider/BakabaseContextProvider'; | ||
import FileSystemSelectorDialog from '@/components/FileSystemSelector/Dialog'; | ||
|
||
type AttachmentValueRendererProps = Omit<ValueRendererProps<string[]>, 'variant'> & { | ||
variant: ValueRendererProps<string[]>['variant']; | ||
}; | ||
|
||
export default ({ value, variant, editor, ...props }: AttachmentValueRendererProps) => { | ||
const { t } = useTranslation(); | ||
const { createPortal } = useBakabaseContext(); | ||
|
||
const v = variant ?? 'default'; | ||
|
||
if (!value || value.length == 0) { | ||
return ( | ||
<NotSet /> | ||
); | ||
} | ||
const editable = !!editor; | ||
|
||
switch (v) { | ||
case 'default': | ||
return ( | ||
<div className={'flex items-center gap-2 flex-wrap'}> | ||
{value.map(v => { | ||
{value?.map(v => { | ||
const pathSegments = splitPathIntoSegments(v); | ||
return ( | ||
<img src={`${serverConfig.apiEndpoint}/tool/thumbnail?path=${encodeURIComponent(v)}`} alt={v} /> | ||
<div className={'flex flex-col gap-1 max-w-[100px] relative group'}> | ||
<Img | ||
src={[`${serverConfig.apiEndpoint}/tool/thumbnail?path=${encodeURIComponent(v)}`]} | ||
loader={( | ||
<LoadingOutlined className={'text-2xl'} /> | ||
)} | ||
unloader={( | ||
<CustomIcon type={'image-slash'} className={'text-2xl'} /> | ||
)} | ||
alt={''} | ||
style={{ | ||
maxWidth: 100, | ||
maxHeight: 100, | ||
}} | ||
title={v} | ||
/> | ||
<Button | ||
isIconOnly | ||
color={'danger'} | ||
size={'sm'} | ||
// variant={'light'} | ||
className={'top-0 right-0 absolute hidden group-hover:block'} | ||
style={{ transform: 'translate(50%, -50%)', zIndex: 1 }} | ||
onClick={() => { | ||
const newValue = value.filter(e => e != v); | ||
editor?.onValueChange?.(newValue, newValue); | ||
}} | ||
> | ||
<DeleteOutlined className={'text-lg'} /> | ||
</Button> | ||
</div> | ||
); | ||
})} | ||
{editable && ( | ||
<div className={'flex items-center justify-center w-[80px] h-[80px]'}> | ||
<Button | ||
isIconOnly | ||
color={'primary'} | ||
variant={'light'} | ||
onClick={() => { | ||
createPortal(FileSystemSelectorDialog, { | ||
targetType: 'file', | ||
onSelected: entry => { | ||
const newValue = (value ?? []).concat([entry.path]); | ||
editor?.onValueChange?.(newValue, newValue); | ||
}, | ||
}); | ||
}} | ||
> | ||
<FileAddOutlined className={'text-lg'} /> | ||
</Button> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
case 'light': | ||
return ( | ||
<span> | ||
{(value.join(','))} | ||
</span> | ||
); | ||
if (!value || value.length == 0) { | ||
return ( | ||
<NotSet /> | ||
); | ||
} else { | ||
return ( | ||
<span> | ||
{(value.join(','))} | ||
</span> | ||
); | ||
} | ||
} | ||
}; |
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
4 changes: 3 additions & 1 deletion
4
src/modules/Bakabase.Modules.Enhancer/Resources/EnhancerResource.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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