Skip to content

Commit 4bf740c

Browse files
committed
Merge remote-tracking branch 'origin/master' into sso-exclusive-all
2 parents 32f6959 + 9b0e913 commit 4bf740c

File tree

12 files changed

+137
-106
lines changed

12 files changed

+137
-106
lines changed

src/packages/frontend/editors/slate/upload.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function uploadTarget(path: string, file: { name: string }): string {
2020

2121
export default function useUpload(
2222
editor: SlateEditor,
23-
body: JSX.Element
23+
body: JSX.Element,
2424
): JSX.Element {
2525
const dropzoneRef = useRef<Dropzone>(null);
2626
const { actions, project_id, path } = useFrameContext();
@@ -50,7 +50,7 @@ export default function useUpload(
5050
if (file != null) {
5151
const blob = file.slice(0, -1, item.type);
5252
dropzoneRef?.current?.addFile(
53-
new File([blob], `paste-${Math.random()}`, { type: item.type })
53+
new File([blob], `paste-${Math.random()}`, { type: item.type }),
5454
);
5555
}
5656
return; // what if more than one ?
@@ -95,8 +95,6 @@ export default function useUpload(
9595
};
9696
}, []);
9797

98-
// Note: using show_upload={false} since showing the upload right in the
99-
// wysiwyg editor is really disconcerting.
10098
return (
10199
<FileUploadWrapper
102100
className="smc-vfill"
@@ -105,7 +103,7 @@ export default function useUpload(
105103
event_handlers={updloadEventHandlers}
106104
style={{ height: "100%", width: "100%" }}
107105
dropzone_ref={dropzoneRef}
108-
show_upload={false}
106+
show_upload={true}
109107
>
110108
{body}
111109
</FileUploadWrapper>

src/packages/frontend/file-upload.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ const CHUNK_SIZE_MB = 8;
3535

3636
const TIMEOUT_S = 100;
3737

38+
const CLOSE_BUTTON_STYLE = {
39+
position: "absolute",
40+
right: 0,
41+
zIndex: 1, // so it floats above text/markdown buttons
42+
background: "white",
43+
cursor: "pointer",
44+
} as const;
45+
3846
/*
3947
CHUNK_SIZE_MB being set properly is critical for cloudflare to work --
4048
we want this to be as big as possible, but MUST be smaller than
@@ -123,7 +131,7 @@ export const FileUpload: React.FC<FileUploadProps> = (props) => {
123131

124132
function render_close_button() {
125133
return (
126-
<div className="close-button pull-right">
134+
<div className="close-button" style={CLOSE_BUTTON_STYLE}>
127135
<span
128136
onClick={props.close_button_onclick}
129137
className="close-button-x"
@@ -311,7 +319,7 @@ export const FileUploadWrapper: React.FC<FileUploadWrapperProps> = (props) => {
311319

312320
return (
313321
<div style={style}>
314-
<div className="close-button pull-right">
322+
<div className="close-button" style={CLOSE_BUTTON_STYLE}>
315323
<span
316324
onClick={() => {
317325
close_preview();

src/packages/frontend/project/new/file-type-selector.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface Props {
4040
selectedExt?: string;
4141
filename: string;
4242
makeNewFilename?: (ext: string) => void;
43+
filenameChanged?: boolean;
4344
}
4445

4546
// Use Rows and Cols to append more buttons to this class.
@@ -55,6 +56,7 @@ export function FileTypeSelector({
5556
children,
5657
filename,
5758
makeNewFilename,
59+
filenameChanged,
5860
}: Props) {
5961
const { project_id } = useProjectContext();
6062

@@ -103,6 +105,7 @@ export function FileTypeSelector({
103105
btnActive={btnActive}
104106
grid={[sm, md]}
105107
filename={filename}
108+
filenameChanged={filenameChanged}
106109
makeNewFilename={() => makeNewFilename?.("ipynb")}
107110
/>
108111
{renderLaTeX()}
@@ -362,6 +365,7 @@ export function FileTypeSelector({
362365
project_id={project_id}
363366
mode="flyout"
364367
ext={ext}
368+
filename={filenameChanged ? filename : undefined}
365369
/>
366370
</Flex>
367371
</Flex>
@@ -375,6 +379,7 @@ export function FileTypeSelector({
375379
project_id={project_id}
376380
mode="full"
377381
ext={ext}
382+
filename={filenameChanged ? filename : undefined}
378383
/>
379384
</Col>
380385
);

src/packages/frontend/project/new/jupyter-buttons.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ interface JupyterNotebookButtonsProps {
5252
btnActive: (name: string) => boolean;
5353
grid: [number, number];
5454
filename: string;
55+
filenameChanged?: boolean;
5556
mode: "full" | "flyout";
5657
makeNewFilename?: () => void;
5758
}
@@ -71,6 +72,7 @@ export function JupyterNotebookButtons({
7172
btnActive,
7273
grid,
7374
filename,
75+
filenameChanged,
7476
mode,
7577
makeNewFilename,
7678
}: JupyterNotebookButtonsProps) {
@@ -244,6 +246,7 @@ export function JupyterNotebookButtons({
244246
project_id={project_id}
245247
mode="flyout"
246248
ext="ipynb"
249+
filename={filename}
247250
/>
248251
</Col>
249252
</>
@@ -286,6 +289,7 @@ export function JupyterNotebookButtons({
286289
project_id={project_id}
287290
mode="flyout"
288291
ext="ipynb"
292+
filename={filenameChanged ? filename : undefined}
289293
/>
290294
</Flex>
291295
</Flex>
@@ -299,6 +303,7 @@ export function JupyterNotebookButtons({
299303
project_id={project_id}
300304
mode="full"
301305
ext="ipynb"
306+
filename={filenameChanged ? filename : undefined}
302307
/>
303308
</Col>
304309
);

src/packages/frontend/project/new/new-file-page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export default function NewFilePage(props: Props) {
6969
const [filename, setFilename] = useState<string>(
7070
filename0 ? filename0 : default_filename(undefined, project_id),
7171
);
72+
const [filenameChanged, setFilenameChanged] = useState<boolean>(false);
7273
const file_creation_error = useTypedRedux(
7374
{ project_id },
7475
"file_creation_error",
@@ -391,6 +392,7 @@ export default function NewFilePage(props: Props) {
391392
"Name your file, folder, or a URL to download from..."
392393
}
393394
onChange={(e) => {
395+
setFilenameChanged(true);
394396
if (extensionWarning) {
395397
setExtensionWarning(false);
396398
} else {
@@ -429,6 +431,7 @@ export default function NewFilePage(props: Props) {
429431
projectActions={actions}
430432
availableFeatures={availableFeatures}
431433
filename={filename}
434+
filenameChanged={filenameChanged}
432435
>
433436
<Tip
434437
title={"Download files from the Internet"}

src/packages/frontend/project/page/flyouts/new.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ export function NewFlyout({
406406
create_file={handleOnClick}
407407
availableFeatures={availableFeatures}
408408
filename={filename}
409+
filenameChanged={manual}
409410
makeNewFilename={(ext: string) => setFilename(getNewFilename(ext))}
410411
/>
411412
<Tag color={COLORS.ANTD_ORANGE}>Additional types</Tag>

src/packages/frontend/project/page/home-page/ai-generate-document.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,21 @@ type Ipynb = {
118118
metadata: { kernelspec: KernelSpec };
119119
};
120120

121+
function ensureExtension(filename, ext) {
122+
if (!filename) return filename;
123+
if (!filename.endsWith("." + ext)) {
124+
return filename + "." + ext;
125+
}
126+
return filename;
127+
}
128+
121129
interface Props {
122130
project_id: string;
123131
onSuccess: () => void;
124132
ext: Ext;
125133
docName: string;
126134
show: boolean;
135+
filename?: string;
127136
}
128137

129138
function AIGenerateDocument({
@@ -132,6 +141,7 @@ function AIGenerateDocument({
132141
project_id,
133142
ext,
134143
docName,
144+
filename: filename0,
135145
}: Props) {
136146
const projectActions = useActions({ project_id });
137147
const current_path = useTypedRedux({ project_id }, "current_path");
@@ -145,7 +155,12 @@ function AIGenerateDocument({
145155
const [saving, setSaving] = useState<boolean>(false);
146156
const [error, setError] = useState<string>("");
147157
const [preview, setPreview] = useState<string | null>(null);
148-
const [filename, setFilename] = useState<string>("");
158+
const [filename, setFilename] = useState<string>(
159+
ensureExtension(filename0 ?? "", ext),
160+
);
161+
useEffect(() => {
162+
setFilename(ensureExtension(filename0 ?? "", ext));
163+
}, [filename0]);
149164
const promptRef = useRef<HTMLElement>(null);
150165

151166
const [kernelSpecs, setKernelSpecs] = useState<KernelSpec[] | null | string>(
@@ -452,6 +467,9 @@ function AIGenerateDocument({
452467
}
453468

454469
function updateFilename(fnNext: string) {
470+
if (filename) {
471+
return;
472+
}
455473
const fn = sanitizeFilename(fnNext, ext);
456474
const timestamp = getTimestamp();
457475
setFilename(`${fn}-${timestamp}.${ext}`);
@@ -741,7 +759,6 @@ function AIGenerateDocument({
741759
}
742760

743761
function renderDialog() {
744-
const empty = prompt.trim() == "";
745762
return (
746763
<>
747764
<Paragraph strong>
@@ -754,7 +771,7 @@ function AIGenerateDocument({
754771
/>
755772
</Paragraph>
756773
{renderJupyterKernelSelector()}
757-
<Paragraph type={empty ? "danger" : undefined}>
774+
<Paragraph>
758775
Provide a detailed description of the {docName} document you want to
759776
create:
760777
</Paragraph>
@@ -767,7 +784,6 @@ function AIGenerateDocument({
767784
placeholder={PLACEHOLDER}
768785
value={prompt}
769786
disabled={querying}
770-
status={empty ? "error" : undefined}
771787
onChange={({ target: { value } }) => setPrompt(value)}
772788
onPressEnter={(e) => {
773789
if (e.shiftKey) {
@@ -899,7 +915,7 @@ function AIGenerateDocument({
899915
setPreview(null);
900916
}}
901917
>
902-
<Icon name="arrow-left" /> Discard
918+
Cancel
903919
</Button>
904920
<Button
905921
type="primary"
@@ -959,12 +975,14 @@ export function AIGenerateDocumentModal({
959975
setShow,
960976
project_id,
961977
ext,
978+
filename,
962979
}: {
963980
show: boolean;
964981
setShow: (val: boolean) => void;
965982
project_id: string;
966983
style?: CSS;
967984
ext: Props["ext"];
985+
filename?: string;
968986
}) {
969987
const docName = file_options(`x.${ext}`).name ?? `${capitalize(ext)}`;
970988

@@ -986,6 +1004,7 @@ export function AIGenerateDocumentModal({
9861004
onSuccess={() => setShow(false)}
9871005
ext={ext}
9881006
docName={docName}
1007+
filename={filename}
9891008
/>
9901009
</Modal>
9911010
);
@@ -996,11 +1015,13 @@ export function AIGenerateDocumentButton({
9961015
style,
9971016
mode = "full",
9981017
ext,
1018+
filename,
9991019
}: {
10001020
project_id: string;
10011021
style?: CSS;
10021022
mode?: "full" | "flyout";
10031023
ext: Props["ext"];
1024+
filename?: string;
10041025
}) {
10051026
const [show, setShow] = useState<boolean>(false);
10061027

@@ -1046,6 +1067,7 @@ export function AIGenerateDocumentButton({
10461067
show={show}
10471068
setShow={setShow}
10481069
project_id={project_id}
1070+
filename={filename}
10491071
/>
10501072
</>
10511073
);

src/packages/frontend/project/page/home-page/ai-generate-examples.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type Language = "python" | "r" | "sagemath" | "octave" | "julia";
77

88
export const EXAMPLES_COMMON: readonly Example[] = [
99
[
10-
"Help me Studying ...",
10+
"Help me Study...",
1111
"I am a student. I want to learn more about a topic. Explain it to me using code, formulas and plots!\n\nTopic: DESCRIBE_TOPIC_HERE",
1212
["student", "learning"],
1313
],

0 commit comments

Comments
 (0)