Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions querybook/webapp/components/DataDoc/DataDoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { Message } from 'ui/Message/Message';

import { DataDocCellControl } from './DataDocCellControl';
import { DataDocContentContainer } from './DataDocContentContainer';
import { DataDocDeletePreview } from './DataDocDeletePreview';
import { DataDocError } from './DataDocError';
import { DataDocHeader } from './DataDocHeader';
import { DataDocLoading } from './DataDocLoading';
Expand Down Expand Up @@ -427,9 +428,18 @@ class DataDocComponent extends React.PureComponent<IProps, IState> {
}
};
if (shouldConfirm) {
let cellName = '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is same as

cellName = ` ${cell.meta.title ?? ''}`

Copy link
Contributor Author

@lilyli9 lilyli9 Feb 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Structured this part in this way to avoid the below linting error.

Property 'title' does not exist on type 'IDataQueryCellMeta | IDataCellMetaBase | IDataChartCellMeta'.
  Property 'title' does not exist on type 'IDataCellMetaBase'.

if ('title' in cell.meta) {
cellName = cell.meta.title
? ` "${cell.meta.title}"`
: cellName;
}
sendConfirm({
header: 'Delete Cell?',
message: 'Deleted cells cannot be recovered',
header: `Delete ${
cell.cell_type[0].toUpperCase() +
cell.cell_type.slice(1).toLowerCase()
} Cell${cellName}?`,
message: <DataDocDeletePreview cell={cell} />,
onConfirm: deleteCell,
onHide: resolve,
confirmColor: 'cancel',
Expand Down
31 changes: 31 additions & 0 deletions querybook/webapp/components/DataDoc/DataDocDeletePreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useEffect, useState } from 'react';

import { IDataCell } from 'const/datadoc';
import { ThemedCodeHighlightWithMark } from 'ui/CodeHighlight/ThemedCodeHighlightWithMark';

interface IProps {
cell: IDataCell;
}

export const DataDocDeletePreview: React.FunctionComponent<IProps> = ({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably don't need another component for this

Copy link
Contributor Author

@lilyli9 lilyli9 Feb 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Responding to this and the previous comment, the separate component was added because without it CodeMirror wouldn't show the query contents when the delete confirmation first loaded. The fix we found was to force it to rerender by changing the state variable with useEffect, which isn't possible without a separate component.

cell,
}) => {
const [query, setQuery] = useState<string>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need query as a state? vs

const query = cell.context as string


useEffect(() => {
setQuery(cell.context as string);
}, [cell.context]);

return (
<div>
<span>Deleted cells cannot be recovered</span>
{cell.cell_type === 'query' && query !== '' && (
<ThemedCodeHighlightWithMark
query={query}
maxEditorHeight="20vh"
autoHeight={false}
/>
)}
</div>
);
};