Skip to content

Commit

Permalink
add clear log button at bottom of log panel
Browse files Browse the repository at this point in the history
  • Loading branch information
bthaile committed Sep 21, 2023
1 parent bbc58fb commit e94ed67
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/Editor/BottomEditorPanel/RenderResponse/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { useProject } from 'providers/Project/projectHooks';
import { PROJECT_SERIALIZATION_KEY } from 'providers/Project/projectMutator';
import { SXStyles } from 'src/types';
import { Flex } from 'theme-ui';
import Button from 'components/Button';
import { getResultType } from 'components/Editor/CadenceEditor/ControlPanel/utils';

export const RenderResponse = () => {
const { active } = useProject();
const { active, clearLogPanel } = useProject();
const { data, error, loading } = useQuery(GET_CACHED_EXECUTION_RESULTS, {
context: {
serializationKey: PROJECT_SERIALIZATION_KEY,
Expand Down Expand Up @@ -38,6 +39,10 @@ export const RenderResponse = () => {
overflowY: 'auto',
// height: '100%',
},
button: {
marginTop: 'auto',
padding: '0.5rem',
},
};

return (
Expand All @@ -51,6 +56,16 @@ export const RenderResponse = () => {
),
)
: 'Welcome to the Playground!'}
{filteredResults.length > 0 && (
<Button
sx={styles.button}
variant="secondary"
size="sm"
onClick={() => clearLogPanel(resultType)}
>
Clear Log Contents
</Button>
)}
</Flex>
);
};
12 changes: 12 additions & 0 deletions src/providers/Project/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface ProjectContextValue {
setCurrentEditor: (editor: monacoEditor.ICodeEditor) => void;
currentEditor: monacoEditor.ICodeEditor | null;
hightlightedLines: number[];
clearLogPanel: (resultType: string) => void;
}

export const ProjectContext: React.Context<ProjectContextValue> =
Expand Down Expand Up @@ -391,6 +392,16 @@ export const ProjectProvider: React.FC<ProjectProviderProps> = ({
return res;
};

const clearLogPanel = async (resultType: string) => {
try {
await mutator.clearLog(resultType);
} catch (e) {
console.error(e);
checkAppErrors();
} finally {
setIsSaving(false);
}
};
const updateTransactionTemplate = async (
templateId: string,
script: string,
Expand Down Expand Up @@ -868,6 +879,7 @@ export const ProjectProvider: React.FC<ProjectProviderProps> = ({
setCurrentEditor,
currentEditor,
hightlightedLines,
clearLogPanel,
}}
>
{children}
Expand Down
14 changes: 14 additions & 0 deletions src/providers/Project/projectMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Project,
} from 'api/apollo/generated/graphql';
import {
CLEAR_EXECUTION_RESULTS,
CREATE_CONTRACT_DEPLOYMENT,
CREATE_CONTRACT_TEMPLATE,
CREATE_PROJECT,
Expand Down Expand Up @@ -333,6 +334,19 @@ export default class ProjectMutator {
return res;
}

async clearLog(resultType: string) {
const res = await this.client.mutate({
mutation: CLEAR_EXECUTION_RESULTS,
variables: {
resultType,
},
context: {
serializationKey: PROJECT_SERIALIZATION_KEY,
},
});
return res;
}

async updateTransactionTemplate(
templateId: string,
script: string,
Expand Down

0 comments on commit e94ed67

Please sign in to comment.