Skip to content

Commit

Permalink
feat: sync changes from v2 to alpha (#734) [skip ci]
Browse files Browse the repository at this point in the history
Co-authored-by: mguellsegarra <[email protected]>
  • Loading branch information
giscegit and mguellsegarra authored Dec 2, 2024
1 parent ae958ca commit ea45d9a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 34 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/react-ooui",
"version": "2.41.0",
"version": "2.44.0",
"engines": {
"node": "20.5.0"
},
Expand Down Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"@ant-design/plots": "^1.0.9",
"@gisce/fiber-diagram": "2.1.1",
"@gisce/ooui": "2.19.0",
"@gisce/ooui": "2.20.0",
"@gisce/react-formiga-components": "1.8.0",
"@gisce/react-formiga-table": "1.9.0-alpha.8",
"@monaco-editor/react": "^4.4.5",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { HTMLPreview } from "@/widgets/custom/HTMLPreview";
import { Alert } from "@/widgets/custom/Alert";
import { DashboardGrid } from "@/widgets/views/DashboardGrid";
import { GraphIndicator } from "@/widgets/views/Graph/GraphIndicator";
import { Spinner } from "@/widgets/custom/Spinner";

import type {
TreeView,
Expand Down Expand Up @@ -177,4 +178,5 @@ export {
HTMLPreview,
Alert,
dayjs,
Spinner,
};
3 changes: 3 additions & 0 deletions src/widgets/WidgetFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
CommentsTimelineField,
HTMLPreview,
Alert,
Spinner,
} from "@/index";
import { Image } from "./base/Image";
import { FiberGrid } from "./custom/FiberGrid";
Expand Down Expand Up @@ -130,6 +131,8 @@ const getWidgetType = (type: string) => {
return HTMLPreview;
case "alert":
return Alert;
case "spinner":
return Spinner;
default:
return undefined;
}
Expand Down
52 changes: 32 additions & 20 deletions src/widgets/base/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useRef } from "react";
import React, { useRef, useMemo } from "react";
import { Row, Space } from "antd";
import Field from "@/common/Field";
import { Image as ImageOoui } from "@gisce/ooui";
Expand All @@ -12,20 +12,39 @@ import {
import { toBase64, getMimeType } from "@/helpers/filesHelper";
import iconMapper from "@/helpers/iconMapper";
import { useLocale } from "@gisce/react-formiga-components";
import isBase64 from "validator/lib/isBase64";

type Props = {
type ImageProps = {
ooui: ImageOoui;
};

export const Image = (props: Props) => {
type ImageRenderProps = {
value?: string;
style?: any;
};

export const ImageRender = (props: ImageRenderProps) => {
const { value, style = {} } = props;
if (value) {
const Icon: React.ElementType = iconMapper(value) as any;
if (Icon) {
return <Icon />;
} else {
return (
<img
src={`data:image/*;base64,${value}`}
style={{ ...{ maxWidth: "100px" }, ...style }}
/>
);
}
}
};

export const Image = (props: ImageProps) => {
const { ooui } = props;
const { required, id } = ooui;

const Icon: React.ElementType = iconMapper(id) as any;

if (Icon) {
return <Icon />;
if (iconMapper(id)) {
return <ImageRender value={id} />;
}

return (
Expand All @@ -47,13 +66,6 @@ export const ImageInput = (props: ImageInputProps) => {
const inputFile = useRef(null);
const { t } = useLocale();

if (value) {
const Icon: React.ElementType = iconMapper(value) as any;
if (Icon) {
return <Icon height={50} />;
}
}

const triggerChange = (changedValue?: string) => {
onChange?.(changedValue);
};
Expand Down Expand Up @@ -83,11 +95,11 @@ export const ImageInput = (props: ImageInputProps) => {
return (
<>
<Row gutter={8} wrap={false} justify="center">
{value && isBase64(value) && (
<img
src={`data:image/*;base64,${value}`}
style={{ maxWidth: "100px" }}
/>
{useMemo(
() => (
<ImageRender value={value} />
),
[value, ooui],
)}
<input
type="file"
Expand Down
19 changes: 19 additions & 0 deletions src/widgets/custom/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import { WidgetProps } from "@/types";
import { Spinner as SpinnerOoui } from "@gisce/ooui";
import { Spin } from "antd";
import Container from "@/widgets/containers/Container";

type SpinnerProps = WidgetProps & {
ooui: SpinnerOoui;
};

export const Spinner = (props: SpinnerProps) => {
const { ooui } = props;

return (
<Spin tip={ooui.label} size="large" spinning={ooui.loading}>
<Container container={ooui.container} responsiveBehaviour={false} />
</Spin>
);
};
8 changes: 2 additions & 6 deletions src/widgets/views/Tree/treeComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { DatePickerConfig } from "@/common/DatePicker";
import ConnectionProvider from "@/ConnectionProvider";
import { colorFromString } from "@/helpers/formHelper";
import { EmailTagsRender } from "@/widgets/custom/EmailTags";
import { ImageRender } from "@/widgets/base/Image";

export const BooleanComponent = ({
value,
Expand Down Expand Up @@ -114,12 +115,7 @@ export const NumberComponent = ({ value }: { value: number }): ReactElement => {

export const ImageComponent = ({ value }: { value: string }): ReactElement => {
return useMemo(
() => (
<img
src={`data:image/*;base64,${value}`}
style={{ maxWidth: "50px", padding: "5px" }}
/>
),
() => <ImageRender value={value} style={{ maxHeight: "30px" }} />,
[value],
);
};
Expand Down

0 comments on commit ea45d9a

Please sign in to comment.