Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
fix: LOPS-322: [FE] Update CandidateTask preview to handle text
Browse files Browse the repository at this point in the history
  • Loading branch information
yyassi-heartex committed Jul 17, 2023
1 parent 5212cb9 commit d1f4d09
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
37 changes: 36 additions & 1 deletion src/components/CandidateTaskView/CandidateTaskView.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { observer } from "mobx-react";
import React, { forwardRef, useCallback, useRef } from "react";
import { Block, Elem } from "../../utils/bem";
import { Spinner } from "../Common/Spinner";
import "./CandidateTaskView.styl";
import { getRoot } from "mobx-state-tree";
import { useEffect, useState } from "react";
Expand All @@ -12,17 +13,51 @@ const imgDefaultProps = {};
if (isFF(FF_LSDV_4711)) imgDefaultProps.crossOrigin = 'anonymous';

const DataItemVisual = forwardRef(({ columns, dataKey, data }, imageRef) => {
const [isInProgress, setIsInProgress] = useState();
const [fileContent, setFileContent] = useState();
const [isFileError, setIsFileError] = useState(false);
const isUrlData = /https?:\/\/.*/.test(data);
const columnDefinition = columns.find(colData => colData.alias === dataKey);

useEffect(async () => {
if ( isUrlData && columnDefinition?.currentType === "Text" ) {
setIsInProgress(true);
setIsFileError(false);
const response = await fetch(data);

if (response.status === 200) {
setFileContent(response);
} else {
console.error("Error:", response);
setIsFileError(true);
}
setIsInProgress(false);
}
}, [isUrlData, data, columnDefinition]);

if (columnDefinition?.currentType === "Image") {
return (
<Elem name="data-display" mod={{ image: true }}>
<img {...imgDefaultProps} ref={imageRef} src={data} />
</Elem>
);
} else if (columnDefinition?.currentType === "Text" && isUrlData && !isFileError) {
return (
<Elem name="data-display" mod={{ text: true }}>
{isInProgress ? <Spinner /> : (
<Elem name='textdata' tag="pre">
{fileContent}
</Elem>
)}
</Elem>
);
} else if (isUrlData) {
<Elem name="data-display" mod={{ link: true }} >
<a href={data} target="_blank">{data}</a>
</Elem>;
}
return (
<Elem name="data-display" mod={{ text: true }} >
<Elem name="data-display" mod={{ [columnDefinition?.currentType ?? "text"]: true }} >
{data}
</Elem>
);
Expand Down
12 changes: 6 additions & 6 deletions src/components/Common/Spinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import Running from "../../assets/running";

const injector = inject(({ store }) => {
return {
SDK: store.SDK,
SDK: store?.SDK,
};
});

export const Spinner = injector(({ SDK, visible = true, ...props }) => {
const size = React.useMemo(() => {
switch (props.size) {
case "large":
return SDK.spinnerSize?.large ?? 128;
return SDK?.spinnerSize?.large ?? 128;
case "middle":
return SDK.spinnerSize?.middle ??48;
return SDK?.spinnerSize?.middle ?? 48;
case "small":
return SDK.spinnerSize?.small ?? 24;
return SDK?.spinnerSize?.small ?? 24;
default:
return SDK.spinnerSize?.middle ??48;
return SDK?.spinnerSize?.middle ?? 48;
}
}, [props.size]);

Expand All @@ -32,7 +32,7 @@ export const Spinner = injector(({ SDK, visible = true, ...props }) => {
objectFit: "contain",
};

const ExternalSpinner = SDK.spinner;
const ExternalSpinner = SDK?.spinner;

return visible ? (
<div
Expand Down

0 comments on commit d1f4d09

Please sign in to comment.