-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
159 changed files
with
841 additions
and
8,700 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
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
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
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
37 changes: 37 additions & 0 deletions
37
.../workspaces/codegen/react-new/src/modules/fireback/components/entity-manager/CopyCell.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,37 @@ | ||
import { Toast } from "../../hooks/toast"; | ||
|
||
export const CopyCell = ({ value }: { value?: string }) => { | ||
const onCopy = (e: any) => { | ||
e.stopPropagation(); | ||
navigator.clipboard | ||
.writeText(value) | ||
.then(() => { | ||
Toast(`Copied ${value}`, { type: "info", autoClose: 600 }); | ||
}) | ||
.catch((err) => { | ||
Toast(`Copy failed.`, { type: "error", autoClose: 600 }); | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="table-copy-btn" onClick={onCopy}> | ||
<CopyIcon /> | ||
</div> | ||
); | ||
}; | ||
|
||
const CopyIcon = ({ size = 16, color = "silver", style = {} }) => ( | ||
<svg | ||
width={size} | ||
height={size} | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
style={style} | ||
> | ||
<path | ||
d="M16 1H6C4.9 1 4 1.9 4 3V17H6V3H16V1ZM18 5H10C8.9 5 8 5.9 8 7V21C8 22.1 8.9 23 10 23H18C19.1 23 20 22.1 20 21V7C20 5.9 19.1 5 18 5ZM18 21H10V7H18V21Z" | ||
fill={color} | ||
/> | ||
</svg> | ||
); |
156 changes: 156 additions & 0 deletions
156
...degen/react-new/src/modules/fireback/components/forms/form-image-asset/FormImageAsset.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,156 @@ | ||
import { useT } from "../../../hooks/useT"; | ||
import { useFileUploader } from "../../../modules/drive/DriveTools"; | ||
|
||
import { debounce } from "lodash"; | ||
import { useRef } from "react"; | ||
import { useFileListener } from "../../window-drop/WindowDrop"; | ||
import { useRemoteInformation } from "../../../hooks/useEnvironment"; | ||
import { FileEntity } from "@/modules/fireback/sdk/modules/workspaces/FileEntity"; | ||
|
||
export interface ImageAsset { | ||
width?: number | undefined; | ||
height?: number | undefined; | ||
attachment?: FileEntity | undefined; | ||
attachmentId?: string | undefined; | ||
} | ||
|
||
export interface ImageAssetPlaceholder { | ||
width: number; | ||
height: number; | ||
title?: string; | ||
description?: string; | ||
} | ||
|
||
interface FormImageAssetProps { | ||
onChange?: (value: ImageAsset[]) => void; | ||
value?: ImageAsset[]; | ||
label?: string; | ||
hint?: string; | ||
placeHolders: ImageAssetPlaceholder[]; | ||
} | ||
|
||
export const FormImageAsset = ({ | ||
onChange, | ||
value, | ||
label, | ||
placeHolders, | ||
}: FormImageAssetProps) => { | ||
const { directPath } = useRemoteInformation(); | ||
const readonly = !!onChange; | ||
const { upload } = useFileUploader(); | ||
const data = useRef<FileEntity[]>([]); | ||
const t = useT(); | ||
// Use debounced onChange | ||
const onChangeDebounced = debounce( | ||
(items: FileEntity[]) => { | ||
// onChange && onChange(items); | ||
}, | ||
250, | ||
{ maxWait: 1000 } | ||
); | ||
|
||
const uploadFn = (files: File[]) => { | ||
const items = upload(files); | ||
items.forEach((item) => { | ||
item.then((x) => { | ||
data.current.push({ uniqueId: x } as any); | ||
onChangeDebounced(data.current); | ||
}); | ||
}); | ||
|
||
return items; | ||
}; | ||
|
||
useFileListener({ | ||
enabled: !readonly, | ||
label: "Attach documents about the payment", | ||
extentions: ["*"], | ||
onCaptureFile(files) { | ||
Promise.all(uploadFn(files)).then((result) => {}); | ||
}, | ||
}); | ||
|
||
const onUploadDialog = () => { | ||
var input = document.createElement("input"); | ||
input.type = "file"; | ||
input.multiple = true; | ||
|
||
input.onchange = (e: any) => { | ||
Promise.all(uploadFn(Array.from(e.target.files))).then((result) => {}); | ||
}; | ||
|
||
input.click(); | ||
}; | ||
|
||
const itemExtractor = ( | ||
items: ImageAsset[], | ||
width: number, | ||
height: number | ||
) => { | ||
return (items || []).find( | ||
(item) => item.width === width && item.height === height | ||
); | ||
}; | ||
|
||
return ( | ||
<div> | ||
{label && <label>{label}</label>} | ||
|
||
<div className="image-assets"> | ||
{placeHolders.map((x) => { | ||
const { width, height } = calculateProportionalSize( | ||
x.width, | ||
x.height | ||
); | ||
|
||
const item = itemExtractor(value, x.width, x.height); | ||
|
||
if (item && item.attachment) { | ||
return ( | ||
<div | ||
className="image-asset-item" | ||
style={{ | ||
fontSize: "11px", | ||
display: "flex", | ||
width: `${width}px`, | ||
height: `${height}px`, | ||
flexDirection: "column", | ||
}} | ||
key={`${x.width}_${x.height}`} | ||
> | ||
{x.width}x{x.height} | ||
<img | ||
style={{ width: "100%" }} | ||
src={directPath(item.attachment as any)} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div | ||
className="image-asset-item" | ||
style={{ | ||
width: `${width}px`, | ||
height: `${height}px`, | ||
}} | ||
key={`${x.width}_${x.height}`} | ||
> | ||
{x.width}x{x.height} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const MAX_SIZE = 180; | ||
|
||
const calculateProportionalSize = (width, height) => { | ||
const scaleFactor = MAX_SIZE / Math.max(width, height); | ||
return { | ||
width: Math.round(width * scaleFactor), | ||
height: Math.round(height * scaleFactor), | ||
}; | ||
}; |
Oops, something went wrong.