Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where query row was not showing properly #1001

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/components/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const QueryEditor: React.FC<Props> = (props) => {
setDirty={() => !dirty && setDirty(true)}
/>
) : null}
{!query.rawMode && !query.OpenAI && query.expression ? (
{!query.rawMode && !query.OpenAI ? (
<VisualQueryEditor
{...props}
schema={schema.value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ const AggregateSection: React.FC<AggregateSectionProps> = ({
templateVariableOptions,
onChange: onQueryChange,
}) => {
const expressions = query.expression.reduce.expressions;
const expressions = query.expression?.reduce?.expressions;
const [aggregates, setAggregates] = useState(expressions);
const [currentTable, setCurrentTable] = useState(query.expression.from?.property.name);
const [currentTable, setCurrentTable] = useState(query.expression?.from?.property.name);

useEffect(() => {
if (!aggregates.length && expressions?.length) {
setAggregates(expressions);
}
}, [aggregates.length, expressions]);
}, [aggregates?.length, expressions]);

useEffect(() => {
// New table
if (currentTable !== query.expression.from?.property.name) {
// Reset state
setAggregates([]);
setCurrentTable(query.expression.from?.property.name);
setCurrentTable(query.expression?.from?.property.name);
}
}, [currentTable, query.expression.from?.property.name]);
}, [currentTable, query.expression?.from?.property.name]);

const onChange = (newItems: Array<Partial<QueryEditorReduceExpression>>) => {
const cleaned = newItems.map((v): QueryEditorReduceExpression => {
Expand All @@ -67,7 +67,7 @@ const AggregateSection: React.FC<AggregateSectionProps> = ({

const newExpression = {
...query.expression,
reduce: { ...query.expression.reduce, expressions: validExpressions },
reduce: { ...query.expression?.reduce, expressions: validExpressions },
};
onQueryChange({
...query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const FilterSection: React.FC<FilterSectionProps> = ({
<EditorFieldGroup>
<EditorField label="Filters" optional={true}>
<>
{query.expression.where.expressions.length ? (
{query.expression?.where?.expressions.length ? (
<div className={styles.filters}>
{query.expression.where.expressions.map((_, i) => (
{query.expression?.where?.expressions.map((_, i) => (
<div key={`filter${i}`}>
<KQLFilter
index={i}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ const GroupBySection: React.FC<GroupBySectionProps> = ({
templateVariableOptions,
onChange: onQueryChange,
}) => {
const expressions = query.expression.groupBy.expressions;
const expressions = query.expression?.groupBy?.expressions;
const [groupBys, setGroupBys] = useState(expressions);
const [currentTable, setCurrentTable] = useState(query.expression.from?.property.name);
const [currentTable, setCurrentTable] = useState(query.expression?.from?.property.name);

useEffect(() => {
if (!groupBys.length && expressions?.length) {
setGroupBys(expressions);
}
}, [groupBys.length, expressions]);
}, [groupBys?.length, expressions]);

useEffect(() => {
// New table
if (currentTable !== query.expression.from?.property.name) {
if (currentTable !== query.expression?.from?.property.name) {
// Reset state
setGroupBys([]);
setCurrentTable(query.expression.from?.property.name);
setCurrentTable(query.expression?.from?.property.name);
}
}, [currentTable, query.expression.from?.property.name]);
}, [currentTable, query.expression?.from?.property.name]);

const onChange = (newItems: Array<Partial<QueryEditorGroupByExpression>>) => {
const cleaned = newItems.map((v): QueryEditorGroupByExpression => {
Expand All @@ -66,7 +66,7 @@ const GroupBySection: React.FC<GroupBySectionProps> = ({

const newExpression = {
...query.expression,
groupBy: { ...query.expression.groupBy, expressions: validExpressions },
groupBy: { ...query.expression?.groupBy, expressions: validExpressions },
};
onQueryChange({
...query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const TableSection: React.FC<TableSectionProps> = ({
<Select
aria-label="Columns"
isMulti
value={query.expression.columns?.columns ? query.expression.columns.columns : []}
value={query.expression?.columns?.columns ? query.expression?.columns?.columns : []}
options={toColumnNames(tableSchema.value || [])
.map((c) => ({ label: c, value: c }))
.concat({
Expand Down
Loading