## Description Rename package `design-system-old` to `@appsmith/ads-old`. ## Automation /ok-to-test tags="@tag.All" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!CAUTION] > 🔴 🔴 🔴 Some tests have failed. > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/10286195096> > Commit: c0d478694b12f35b88687b6dae6f252967fba540 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10286195096&attempt=1&selectiontype=test&testsstatus=failed&specsstatus=fail" target="_blank">Cypress dashboard</a>. > Tags: @tag.All > Spec: > The following are new failures, please fix them before merging the PR: <ol> > <li>cypress/e2e/Regression/ClientSide/BugTests/DatasourceSchema_spec.ts</ol> > <a href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master" target="_blank">List of identified flaky tests</a>. > <hr>Wed, 07 Aug 2024 15:26:02 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No
162 lines
4.3 KiB
TypeScript
162 lines
4.3 KiB
TypeScript
import * as React from "react";
|
|
import { useState } from "react";
|
|
import styled from "styled-components";
|
|
import type { ControlProps } from "./BaseControl";
|
|
import BaseControl from "./BaseControl";
|
|
import type { ControlType } from "constants/PropertyControlConstants";
|
|
import type { SetProgress } from "@appsmith/ads-old";
|
|
import { FilePickerV2, FileType } from "@appsmith/ads-old";
|
|
import type { WrappedFieldInputProps, WrappedFieldMetaProps } from "redux-form";
|
|
import { Field } from "redux-form";
|
|
import { useEffect, useCallback } from "react";
|
|
import { replayHighlightClass } from "globalStyles/portals";
|
|
import { Button, Modal, ModalBody, ModalContent } from "design-system";
|
|
|
|
const StyledDiv = styled.div`
|
|
flex: 1;
|
|
border: 1px solid var(--ads-v2-color-border);
|
|
border-right: none;
|
|
padding: 6px 12px;
|
|
font-size: 14px;
|
|
white-space: nowrap;
|
|
text-overflow: ellipsis;
|
|
overflow: hidden;
|
|
border-radius: var(--ads-v2-border-radius) 0 0 var(--ads-v2-border-radius);
|
|
`;
|
|
|
|
const FilePickerWrapper = styled.div`
|
|
width: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
`;
|
|
|
|
const FilePickerContainer = styled.div`
|
|
flex-direction: row;
|
|
display: flex;
|
|
width: 270px;
|
|
.btn-select {
|
|
border-radius: 0 var(--ads-v2-border-radius) var(--ads-v2-border-radius) 0 !important;
|
|
}
|
|
`;
|
|
type RenderFilePickerProps = FilePickerControlProps & {
|
|
input?: WrappedFieldInputProps;
|
|
meta?: WrappedFieldMetaProps;
|
|
disabled?: boolean;
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
onChange: (event: any) => void;
|
|
};
|
|
|
|
function RenderFilePicker(props: RenderFilePickerProps) {
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
const [appFileToBeUploaded, setAppFileToBeUploaded] = useState<{
|
|
file: File;
|
|
setProgress: SetProgress;
|
|
} | null>(null);
|
|
|
|
// const changeOpenState = (state: boolean) => setIsOpen(state);
|
|
const FileUploader = useCallback(
|
|
async (file: File, setProgress: SetProgress) => {
|
|
if (!!file) {
|
|
setAppFileToBeUploaded({
|
|
file,
|
|
setProgress,
|
|
});
|
|
} else {
|
|
setAppFileToBeUploaded(null);
|
|
}
|
|
},
|
|
[],
|
|
);
|
|
|
|
const onRemoveFile = useCallback(() => setAppFileToBeUploaded(null), []);
|
|
|
|
useEffect(() => {
|
|
if (appFileToBeUploaded?.file) {
|
|
const reader = new FileReader();
|
|
reader.readAsDataURL(appFileToBeUploaded?.file);
|
|
reader.onloadend = () => {
|
|
const base64data = reader.result;
|
|
props.input?.onChange({
|
|
name: appFileToBeUploaded?.file.name,
|
|
base64Content: base64data,
|
|
});
|
|
};
|
|
}
|
|
}, [appFileToBeUploaded]);
|
|
|
|
return (
|
|
<>
|
|
<FilePickerContainer className={replayHighlightClass}>
|
|
<StyledDiv title={props?.input?.value?.name}>
|
|
{props?.input?.value?.name}
|
|
</StyledDiv>
|
|
<Button
|
|
className="btn-select"
|
|
disabled={props.disabled}
|
|
kind="secondary"
|
|
onClick={() => {
|
|
setIsOpen(true);
|
|
}}
|
|
size="md"
|
|
>
|
|
Select
|
|
</Button>
|
|
</FilePickerContainer>
|
|
{isOpen ? (
|
|
<Modal
|
|
onOpenChange={() => {
|
|
setIsOpen(false);
|
|
}}
|
|
open={isOpen}
|
|
>
|
|
<ModalContent style={{ width: "640px" }}>
|
|
<ModalBody>
|
|
<FilePickerWrapper>
|
|
<FilePickerV2
|
|
delayedUpload
|
|
fileType={FileType.ANY}
|
|
fileUploader={FileUploader}
|
|
onFileRemoved={onRemoveFile}
|
|
/>
|
|
</FilePickerWrapper>
|
|
</ModalBody>
|
|
</ModalContent>
|
|
</Modal>
|
|
) : null}
|
|
</>
|
|
);
|
|
}
|
|
class FilePickerControl extends BaseControl<FilePickerControlProps> {
|
|
constructor(props: FilePickerControlProps) {
|
|
super(props);
|
|
this.state = {
|
|
isOpen: false,
|
|
};
|
|
}
|
|
|
|
render() {
|
|
const { configProperty, disabled } = this.props;
|
|
return (
|
|
<Field
|
|
component={RenderFilePicker}
|
|
disabled={disabled}
|
|
name={configProperty}
|
|
/>
|
|
);
|
|
}
|
|
|
|
getControlType(): ControlType {
|
|
return "FILE_PICKER";
|
|
}
|
|
}
|
|
|
|
export interface FilePickerComponentState {
|
|
isOpen: boolean;
|
|
}
|
|
|
|
export type FilePickerControlProps = ControlProps;
|
|
|
|
export default FilePickerControl;
|