Skip to content

Commit

Permalink
feat: add share button on web for logs trace
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Jul 11, 2024
1 parent c63498e commit d8b3730
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ type BaseClientSideLoggingToolMenuOnyxProps = {
shouldStoreLogs: OnyxEntry<boolean>;
};

type File = {
path: string;
newFileName: string;
size: number;
};
type BaseClientSideLoggingToolProps = {
/** Locally created file */
file?: {path: string; newFileName: string; size: number};
file?: File;
/** Action to run when pressing Share button */
onShareLogs?: () => void;
/** Action to run when disabling the switch */
Expand Down Expand Up @@ -96,3 +101,4 @@ export default withOnyx<BaseClientSideLoggingToolProps, BaseClientSideLoggingToo
key: ONYXKEYS.SHOULD_STORE_LOGS,
},
})(BaseClientSideLoggingToolMenu);
export type {File};
22 changes: 19 additions & 3 deletions src/components/ClientSideLoggingToolMenu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import React from 'react';
import React, { useState } from 'react';
import type {Log} from '@libs/Console';
import localFileDownload from '@libs/localFileDownload';
import type {File} from './BaseClientSideLoggingToolMenu';
import BaseClientSideLoggingToolMenu from './BaseClientSideLoggingToolMenu';

function ClientSideLoggingToolMenu() {
const [localLogs, setLocalLogs] = useState<Log[]>([]);
const [file, setFile] = useState<File | undefined>(undefined);
const downloadFile = (logs: Log[]) => {
localFileDownload('logs', JSON.stringify(logs, null, 2));
const data = JSON.stringify(logs, null, 2);
setFile({
path: './logs',
newFileName: 'logs',
size: data.length,
});
setLocalLogs(logs);
localFileDownload('logs', data);
};
const hideShareButton = () => {
setFile(undefined);
};
const shareLogs = () => {
downloadFile(localLogs);
};

return <BaseClientSideLoggingToolMenu onDisableLogging={downloadFile} />;
return <BaseClientSideLoggingToolMenu file={file} onDisableLogging={downloadFile} onEnableLogging={hideShareButton} onShareLogs={shareLogs} displayPath={file?.path} />;
}

ClientSideLoggingToolMenu.displayName = 'ClientSideLoggingToolMenu';
Expand Down

0 comments on commit d8b3730

Please sign in to comment.