Web console: Add frontend buttons to remove group by (#8537)

* Add frontend buttons to remove group by

* Change icon for remove group by

* Update web console to use latest toolkit

* Add test cases to verify that remove group by buttons are rendered

* Correct mistake of using incorrect components

* Update tests for two cases

* Put remove button after group by
This commit is contained in:
Evan Ren 2019-09-24 16:32:02 -07:00 committed by Vadim Ogievetsky
parent eabddffd6e
commit 0467cce7a0
11 changed files with 1269 additions and 169 deletions

View File

@ -4456,9 +4456,9 @@
"integrity": "sha512-0sYnfUHHMoajaud/i5BHKA12bUxiWEHJ9rxGqVEppFxsEcxef0TZQ5J59lU+UniEBcz/sG5fTESRyS7cOm3tSQ=="
},
"druid-query-toolkit": {
"version": "0.3.27",
"resolved": "https://registry.npmjs.org/druid-query-toolkit/-/druid-query-toolkit-0.3.27.tgz",
"integrity": "sha512-dGqTU3x9V1zPHAwng47hDihwKhx1UBJbIBJsOtFmlgb+D69iDcQVingPsjJOV+kHX2gVq/Azlhx6MZvC7+5tFQ==",
"version": "0.3.28",
"resolved": "https://registry.npmjs.org/druid-query-toolkit/-/druid-query-toolkit-0.3.28.tgz",
"integrity": "sha512-AtwTGlofLEzV1cnXwZrNlynHA3Htw6Fgt7r4ZEXx7SSzLUfMkS7lcZ0WY6haHzoZkC8GyUivEuoSivygRgEotg==",
"requires": {
"tslib": "^1.10.0"
}

View File

@ -63,7 +63,7 @@
"d3": "^5.10.1",
"d3-array": "^2.3.1",
"druid-console": "0.0.2",
"druid-query-toolkit": "^0.3.27",
"druid-query-toolkit": "^0.3.28",
"file-saver": "^2.0.2",
"has-own-prop": "^2.0.0",
"hjson": "^3.1.2",

View File

@ -1,64 +1,403 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`number menu matches snapshot 1`] = `
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
exports[`number menu matches snapshot when menu is opened for column inside group by 1`] = `
<div>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-target"
class="bp3-popover-wrapper"
>
<a
class="bp3-menu-item"
tabindex="0"
<span
class="bp3-popover-target"
>
<span
class="bp3-icon bp3-icon-filter"
icon="filter"
<a
class="bp3-menu-item"
tabindex="0"
>
<svg
data-icon="filter"
height="16"
viewBox="0 0 16 16"
width="16"
<span
class="bp3-icon bp3-icon-filter"
icon="filter"
>
<desc>
filter
</desc>
<path
d="M13.99.99h-12a1.003 1.003 0 00-.71 1.71l4.71 4.71V14a1.003 1.003 0 001.71.71l2-2c.18-.18.29-.43.29-.71V7.41L14.7 2.7a1.003 1.003 0 00-.71-1.71z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Filter
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
<svg
data-icon="filter"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
filter
</desc>
<path
d="M13.99.99h-12a1.003 1.003 0 00-.71 1.71l4.71 4.71V14a1.003 1.003 0 001.71.71l2-2c.18-.18.29-.43.29-.71V7.41L14.7 2.7a1.003 1.003 0 00-.71-1.71z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
Filter
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</span>
</li>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-group-objects"
icon="group-objects"
>
<svg
data-icon="group-objects"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
group-objects
</desc>
<path
d="M5 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6-3H5C2.24 3 0 5.24 0 8s2.24 5 5 5h6c2.76 0 5-2.24 5-5s-2.24-5-5-5zm0 9H5c-2.21 0-4-1.79-4-4s1.79-4 4-4h6c2.21 0 4 1.79 4 4s-1.79 4-4 4zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Group by
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
<li
class=""
>
<a
class="bp3-menu-item bp3-popover-dismiss"
>
<span
class="bp3-icon bp3-icon-ungroup-objects"
icon="ungroup-objects"
>
<svg
data-icon="ungroup-objects"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
ungroup-objects
</desc>
<path
d="M3.5 5C1.57 5 0 6.57 0 8.5S1.57 12 3.5 12 7 10.43 7 8.5 5.43 5 3.5 5zm9 0C10.57 5 9 6.57 9 8.5s1.57 3.5 3.5 3.5S16 10.43 16 8.5 14.43 5 12.5 5z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Remove group by
</div>
</a>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-function"
icon="function"
>
<svg
data-icon="function"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
function
</desc>
<path
d="M8.12 4.74H6.98c.33-1.29.75-2.24 1.28-2.84.33-.37.64-.56.95-.56.06 0 .11.02.15.05.04.04.06.09.06.15 0 .05-.04.15-.13.29-.09.14-.13.28-.13.4 0 .18.07.33.2.46.14.13.31.19.52.19.22 0 .41-.08.56-.23.15-.16.23-.37.23-.63 0-.3-.11-.55-.34-.74C10.1 1.09 9.74 1 9.24 1c-.78 0-1.49.22-2.12.67-.64.45-1.24 1.2-1.81 2.23-.2.36-.38.59-.56.69-.18.1-.46.15-.85.15l-.26.9h1.08l-1.59 6.12c-.27 1.01-.44 1.63-.54 1.86-.14.34-.34.63-.62.87-.11.1-.24.15-.4.15a.15.15 0 01-.11-.04l-.04-.05c0-.03.04-.08.12-.16.08-.08.12-.2.12-.36 0-.18-.06-.33-.19-.44-.12-.12-.3-.18-.54-.18-.28 0-.51.08-.68.23-.16.14-.25.32-.25.53 0 .22.1.42.31.59.21.17.53.25.97.25.7 0 1.32-.18 1.87-.54.54-.36 1.02-.92 1.42-1.67.41-.75.82-1.96 1.25-3.63l.91-3.54h1.1l.29-.89zm5.43 1.52c.2-.15.41-.23.62-.23.08 0 .23.03.45.09s.41.09.57.09c.23 0 .42-.08.57-.23.16-.16.24-.36.24-.61 0-.26-.08-.47-.23-.62-.15-.15-.37-.23-.66-.23-.25 0-.5.06-.72.18-.23.12-.51.38-.86.78-.26.3-.64.81-1.15 1.55-.2-.91-.55-1.75-1.05-2.51l-2.72.46-.06.29c.2-.04.37-.06.51-.06.27 0 .49.11.67.34.28.36.67 1.45 1.17 3.26-.39.52-.66.85-.8 1.01-.24.26-.44.42-.59.5-.12.06-.25.09-.41.09-.11 0-.3-.06-.56-.18-.18-.08-.34-.12-.48-.12-.27 0-.48.08-.66.25-.17.17-.26.38-.26.64 0 .25.08.44.24.6.16.15.37.23.64.23.26 0 .5-.05.73-.16.23-.11.52-.34.86-.69.35-.35.82-.9 1.43-1.67.23.73.44 1.25.61 1.58s.37.57.59.71c.22.15.5.22.83.22.32 0 .65-.11.98-.34.44-.3.88-.81 1.34-1.53l-.26-.15c-.31.43-.54.7-.69.8-.1.07-.22.1-.35.1-.16 0-.32-.1-.48-.3-.27-.34-.62-1.27-1.06-2.8.4-.68.73-1.13 1-1.34z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Aggregate
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
</div>
`;
exports[`number menu matches snapshot when menu is opened for column not inside group by 1`] = `
<div>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-filter"
icon="filter"
>
<svg
data-icon="filter"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
filter
</desc>
<path
d="M13.99.99h-12a1.003 1.003 0 00-.71 1.71l4.71 4.71V14a1.003 1.003 0 001.71.71l2-2c.18-.18.29-.43.29-.71V7.41L14.7 2.7a1.003 1.003 0 00-.71-1.71z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Filter
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-group-objects"
icon="group-objects"
>
<svg
data-icon="group-objects"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
group-objects
</desc>
<path
d="M5 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6-3H5C2.24 3 0 5.24 0 8s2.24 5 5 5h6c2.76 0 5-2.24 5-5s-2.24-5-5-5zm0 9H5c-2.21 0-4-1.79-4-4s1.79-4 4-4h6c2.21 0 4 1.79 4 4s-1.79 4-4 4zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Group by
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-function"
icon="function"
>
<svg
data-icon="function"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
function
</desc>
<path
d="M8.12 4.74H6.98c.33-1.29.75-2.24 1.28-2.84.33-.37.64-.56.95-.56.06 0 .11.02.15.05.04.04.06.09.06.15 0 .05-.04.15-.13.29-.09.14-.13.28-.13.4 0 .18.07.33.2.46.14.13.31.19.52.19.22 0 .41-.08.56-.23.15-.16.23-.37.23-.63 0-.3-.11-.55-.34-.74C10.1 1.09 9.74 1 9.24 1c-.78 0-1.49.22-2.12.67-.64.45-1.24 1.2-1.81 2.23-.2.36-.38.59-.56.69-.18.1-.46.15-.85.15l-.26.9h1.08l-1.59 6.12c-.27 1.01-.44 1.63-.54 1.86-.14.34-.34.63-.62.87-.11.1-.24.15-.4.15a.15.15 0 01-.11-.04l-.04-.05c0-.03.04-.08.12-.16.08-.08.12-.2.12-.36 0-.18-.06-.33-.19-.44-.12-.12-.3-.18-.54-.18-.28 0-.51.08-.68.23-.16.14-.25.32-.25.53 0 .22.1.42.31.59.21.17.53.25.97.25.7 0 1.32-.18 1.87-.54.54-.36 1.02-.92 1.42-1.67.41-.75.82-1.96 1.25-3.63l.91-3.54h1.1l.29-.89zm5.43 1.52c.2-.15.41-.23.62-.23.08 0 .23.03.45.09s.41.09.57.09c.23 0 .42-.08.57-.23.16-.16.24-.36.24-.61 0-.26-.08-.47-.23-.62-.15-.15-.37-.23-.66-.23-.25 0-.5.06-.72.18-.23.12-.51.38-.86.78-.26.3-.64.81-1.15 1.55-.2-.91-.55-1.75-1.05-2.51l-2.72.46-.06.29c.2-.04.37-.06.51-.06.27 0 .49.11.67.34.28.36.67 1.45 1.17 3.26-.39.52-.66.85-.8 1.01-.24.26-.44.42-.59.5-.12.06-.25.09-.41.09-.11 0-.3-.06-.56-.18-.18-.08-.34-.12-.48-.12-.27 0-.48.08-.66.25-.17.17-.26.38-.26.64 0 .25.08.44.24.6.16.15.37.23.64.23.26 0 .5-.05.73-.16.23-.11.52-.34.86-.69.35-.35.82-.9 1.43-1.67.23.73.44 1.25.61 1.58s.37.57.59.71c.22.15.5.22.83.22.32 0 .65-.11.98-.34.44-.3.88-.81 1.34-1.53l-.26-.15c-.31.43-.54.7-.69.8-.1.07-.22.1-.35.1-.16 0-.32-.1-.48-.3-.27-.34-.62-1.27-1.06-2.8.4-.68.73-1.13 1-1.34z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Aggregate
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
</div>
`;

View File

@ -25,7 +25,7 @@ import { NumberMenuItems } from './number-menu-items';
describe('number menu', () => {
const parser = sqlParserFactory(['COUNT']);
it('matches snapshot', () => {
it('matches snapshot when menu is opened for column not inside group by', () => {
const numberMenu = (
<NumberMenuItems
columnName={'added'}
@ -35,6 +35,19 @@ describe('number menu', () => {
);
const { container } = render(numberMenu);
expect(container.firstChild).toMatchSnapshot();
expect(container).toMatchSnapshot();
});
it('matches snapshot when menu is opened for column inside group by', () => {
const numberMenu = (
<NumberMenuItems
columnName={'added'}
parsedQuery={parser(`SELECT added, count(*) as cnt FROM wikipedia GROUP BY 1`)}
onQueryChange={() => {}}
/>
);
const { container } = render(numberMenu);
expect(container).toMatchSnapshot();
});
});

View File

@ -65,6 +65,20 @@ export class NumberMenuItems extends React.PureComponent<NumberMenuItemsProps> {
);
}
renderRemoveGroupBy(): JSX.Element | undefined {
const { columnName, parsedQuery, onQueryChange } = this.props;
if (!parsedQuery.hasGroupByForColumn(columnName)) return;
return (
<MenuItem
icon={IconNames.UNGROUP_OBJECTS}
text={'Remove group by'}
onClick={() => {
onQueryChange(parsedQuery.removeGroupBy(columnName), true);
}}
/>
);
}
renderGroupByMenu(): JSX.Element | undefined {
const { columnName, parsedQuery, onQueryChange } = this.props;
if (!parsedQuery.groupByClause) return;
@ -145,6 +159,7 @@ export class NumberMenuItems extends React.PureComponent<NumberMenuItemsProps> {
{this.renderFilterMenu()}
{this.renderRemoveFilter()}
{this.renderGroupByMenu()}
{this.renderRemoveGroupBy()}
{this.renderAggregateMenu()}
</>
);

View File

@ -1,64 +1,403 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`string menu matches snapshot 1`] = `
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
exports[`string menu matches snapshot when menu is opened for column inside group by 1`] = `
<div>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-target"
class="bp3-popover-wrapper"
>
<a
class="bp3-menu-item"
tabindex="0"
<span
class="bp3-popover-target"
>
<span
class="bp3-icon bp3-icon-filter"
icon="filter"
<a
class="bp3-menu-item"
tabindex="0"
>
<svg
data-icon="filter"
height="16"
viewBox="0 0 16 16"
width="16"
<span
class="bp3-icon bp3-icon-filter"
icon="filter"
>
<desc>
filter
</desc>
<path
d="M13.99.99h-12a1.003 1.003 0 00-.71 1.71l4.71 4.71V14a1.003 1.003 0 001.71.71l2-2c.18-.18.29-.43.29-.71V7.41L14.7 2.7a1.003 1.003 0 00-.71-1.71z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Filter
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
<svg
data-icon="filter"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
filter
</desc>
<path
d="M13.99.99h-12a1.003 1.003 0 00-.71 1.71l4.71 4.71V14a1.003 1.003 0 001.71.71l2-2c.18-.18.29-.43.29-.71V7.41L14.7 2.7a1.003 1.003 0 00-.71-1.71z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
Filter
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</span>
</li>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-group-objects"
icon="group-objects"
>
<svg
data-icon="group-objects"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
group-objects
</desc>
<path
d="M5 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6-3H5C2.24 3 0 5.24 0 8s2.24 5 5 5h6c2.76 0 5-2.24 5-5s-2.24-5-5-5zm0 9H5c-2.21 0-4-1.79-4-4s1.79-4 4-4h6c2.21 0 4 1.79 4 4s-1.79 4-4 4zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Group by
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
<li
class=""
>
<a
class="bp3-menu-item bp3-popover-dismiss"
>
<span
class="bp3-icon bp3-icon-ungroup-objects"
icon="ungroup-objects"
>
<svg
data-icon="ungroup-objects"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
ungroup-objects
</desc>
<path
d="M3.5 5C1.57 5 0 6.57 0 8.5S1.57 12 3.5 12 7 10.43 7 8.5 5.43 5 3.5 5zm9 0C10.57 5 9 6.57 9 8.5s1.57 3.5 3.5 3.5S16 10.43 16 8.5 14.43 5 12.5 5z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Remove group by
</div>
</a>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-function"
icon="function"
>
<svg
data-icon="function"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
function
</desc>
<path
d="M8.12 4.74H6.98c.33-1.29.75-2.24 1.28-2.84.33-.37.64-.56.95-.56.06 0 .11.02.15.05.04.04.06.09.06.15 0 .05-.04.15-.13.29-.09.14-.13.28-.13.4 0 .18.07.33.2.46.14.13.31.19.52.19.22 0 .41-.08.56-.23.15-.16.23-.37.23-.63 0-.3-.11-.55-.34-.74C10.1 1.09 9.74 1 9.24 1c-.78 0-1.49.22-2.12.67-.64.45-1.24 1.2-1.81 2.23-.2.36-.38.59-.56.69-.18.1-.46.15-.85.15l-.26.9h1.08l-1.59 6.12c-.27 1.01-.44 1.63-.54 1.86-.14.34-.34.63-.62.87-.11.1-.24.15-.4.15a.15.15 0 01-.11-.04l-.04-.05c0-.03.04-.08.12-.16.08-.08.12-.2.12-.36 0-.18-.06-.33-.19-.44-.12-.12-.3-.18-.54-.18-.28 0-.51.08-.68.23-.16.14-.25.32-.25.53 0 .22.1.42.31.59.21.17.53.25.97.25.7 0 1.32-.18 1.87-.54.54-.36 1.02-.92 1.42-1.67.41-.75.82-1.96 1.25-3.63l.91-3.54h1.1l.29-.89zm5.43 1.52c.2-.15.41-.23.62-.23.08 0 .23.03.45.09s.41.09.57.09c.23 0 .42-.08.57-.23.16-.16.24-.36.24-.61 0-.26-.08-.47-.23-.62-.15-.15-.37-.23-.66-.23-.25 0-.5.06-.72.18-.23.12-.51.38-.86.78-.26.3-.64.81-1.15 1.55-.2-.91-.55-1.75-1.05-2.51l-2.72.46-.06.29c.2-.04.37-.06.51-.06.27 0 .49.11.67.34.28.36.67 1.45 1.17 3.26-.39.52-.66.85-.8 1.01-.24.26-.44.42-.59.5-.12.06-.25.09-.41.09-.11 0-.3-.06-.56-.18-.18-.08-.34-.12-.48-.12-.27 0-.48.08-.66.25-.17.17-.26.38-.26.64 0 .25.08.44.24.6.16.15.37.23.64.23.26 0 .5-.05.73-.16.23-.11.52-.34.86-.69.35-.35.82-.9 1.43-1.67.23.73.44 1.25.61 1.58s.37.57.59.71c.22.15.5.22.83.22.32 0 .65-.11.98-.34.44-.3.88-.81 1.34-1.53l-.26-.15c-.31.43-.54.7-.69.8-.1.07-.22.1-.35.1-.16 0-.32-.1-.48-.3-.27-.34-.62-1.27-1.06-2.8.4-.68.73-1.13 1-1.34z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Aggregate
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
</div>
`;
exports[`string menu matches snapshot when menu is opened for column not inside group by 1`] = `
<div>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-filter"
icon="filter"
>
<svg
data-icon="filter"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
filter
</desc>
<path
d="M13.99.99h-12a1.003 1.003 0 00-.71 1.71l4.71 4.71V14a1.003 1.003 0 001.71.71l2-2c.18-.18.29-.43.29-.71V7.41L14.7 2.7a1.003 1.003 0 00-.71-1.71z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Filter
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-group-objects"
icon="group-objects"
>
<svg
data-icon="group-objects"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
group-objects
</desc>
<path
d="M5 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6-3H5C2.24 3 0 5.24 0 8s2.24 5 5 5h6c2.76 0 5-2.24 5-5s-2.24-5-5-5zm0 9H5c-2.21 0-4-1.79-4-4s1.79-4 4-4h6c2.21 0 4 1.79 4 4s-1.79 4-4 4zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Group by
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-function"
icon="function"
>
<svg
data-icon="function"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
function
</desc>
<path
d="M8.12 4.74H6.98c.33-1.29.75-2.24 1.28-2.84.33-.37.64-.56.95-.56.06 0 .11.02.15.05.04.04.06.09.06.15 0 .05-.04.15-.13.29-.09.14-.13.28-.13.4 0 .18.07.33.2.46.14.13.31.19.52.19.22 0 .41-.08.56-.23.15-.16.23-.37.23-.63 0-.3-.11-.55-.34-.74C10.1 1.09 9.74 1 9.24 1c-.78 0-1.49.22-2.12.67-.64.45-1.24 1.2-1.81 2.23-.2.36-.38.59-.56.69-.18.1-.46.15-.85.15l-.26.9h1.08l-1.59 6.12c-.27 1.01-.44 1.63-.54 1.86-.14.34-.34.63-.62.87-.11.1-.24.15-.4.15a.15.15 0 01-.11-.04l-.04-.05c0-.03.04-.08.12-.16.08-.08.12-.2.12-.36 0-.18-.06-.33-.19-.44-.12-.12-.3-.18-.54-.18-.28 0-.51.08-.68.23-.16.14-.25.32-.25.53 0 .22.1.42.31.59.21.17.53.25.97.25.7 0 1.32-.18 1.87-.54.54-.36 1.02-.92 1.42-1.67.41-.75.82-1.96 1.25-3.63l.91-3.54h1.1l.29-.89zm5.43 1.52c.2-.15.41-.23.62-.23.08 0 .23.03.45.09s.41.09.57.09c.23 0 .42-.08.57-.23.16-.16.24-.36.24-.61 0-.26-.08-.47-.23-.62-.15-.15-.37-.23-.66-.23-.25 0-.5.06-.72.18-.23.12-.51.38-.86.78-.26.3-.64.81-1.15 1.55-.2-.91-.55-1.75-1.05-2.51l-2.72.46-.06.29c.2-.04.37-.06.51-.06.27 0 .49.11.67.34.28.36.67 1.45 1.17 3.26-.39.52-.66.85-.8 1.01-.24.26-.44.42-.59.5-.12.06-.25.09-.41.09-.11 0-.3-.06-.56-.18-.18-.08-.34-.12-.48-.12-.27 0-.48.08-.66.25-.17.17-.26.38-.26.64 0 .25.08.44.24.6.16.15.37.23.64.23.26 0 .5-.05.73-.16.23-.11.52-.34.86-.69.35-.35.82-.9 1.43-1.67.23.73.44 1.25.61 1.58s.37.57.59.71c.22.15.5.22.83.22.32 0 .65-.11.98-.34.44-.3.88-.81 1.34-1.53l-.26-.15c-.31.43-.54.7-.69.8-.1.07-.22.1-.35.1-.16 0-.32-.1-.48-.3-.27-.34-.62-1.27-1.06-2.8.4-.68.73-1.13 1-1.34z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Aggregate
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
</div>
`;

View File

@ -25,7 +25,20 @@ import { StringMenuItems } from './string-menu-items';
describe('string menu', () => {
const parser = sqlParserFactory(['COUNT']);
it('matches snapshot', () => {
it('matches snapshot when menu is opened for column not inside group by', () => {
const stringMenu = (
<StringMenuItems
columnName={'cityName'}
parsedQuery={parser(`SELECT channel, count(*) as cnt FROM wikipedia GROUP BY 1`)}
onQueryChange={() => {}}
/>
);
const { container } = render(stringMenu);
expect(container).toMatchSnapshot();
});
it('matches snapshot when menu is opened for column inside group by', () => {
const stringMenu = (
<StringMenuItems
columnName={'channel'}
@ -35,6 +48,6 @@ describe('string menu', () => {
);
const { container } = render(stringMenu);
expect(container.firstChild).toMatchSnapshot();
expect(container).toMatchSnapshot();
});
});

View File

@ -72,6 +72,20 @@ export class StringMenuItems extends React.PureComponent<StringMenuItemsProps> {
);
}
renderRemoveGroupBy(): JSX.Element | undefined {
const { columnName, parsedQuery, onQueryChange } = this.props;
if (!parsedQuery.hasGroupByForColumn(columnName)) return;
return (
<MenuItem
icon={IconNames.UNGROUP_OBJECTS}
text={'Remove group by'}
onClick={() => {
onQueryChange(parsedQuery.removeGroupBy(columnName), true);
}}
/>
);
}
renderGroupByMenu(): JSX.Element | undefined {
const { columnName, parsedQuery, onQueryChange } = this.props;
if (!parsedQuery.hasGroupBy()) return;
@ -163,6 +177,7 @@ export class StringMenuItems extends React.PureComponent<StringMenuItemsProps> {
{this.renderFilterMenu()}
{this.renderRemoveFilter()}
{this.renderGroupByMenu()}
{this.renderRemoveGroupBy()}
{this.renderAggregateMenu()}
</>
);

View File

@ -1,64 +1,403 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`time menu matches snapshot 1`] = `
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
exports[`time menu matches snapshot when menu is opened for column inside group by 1`] = `
<div>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-target"
class="bp3-popover-wrapper"
>
<a
class="bp3-menu-item"
tabindex="0"
<span
class="bp3-popover-target"
>
<span
class="bp3-icon bp3-icon-filter"
icon="filter"
<a
class="bp3-menu-item"
tabindex="0"
>
<svg
data-icon="filter"
height="16"
viewBox="0 0 16 16"
width="16"
<span
class="bp3-icon bp3-icon-filter"
icon="filter"
>
<desc>
filter
</desc>
<path
d="M13.99.99h-12a1.003 1.003 0 00-.71 1.71l4.71 4.71V14a1.003 1.003 0 001.71.71l2-2c.18-.18.29-.43.29-.71V7.41L14.7 2.7a1.003 1.003 0 00-.71-1.71z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Filter
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
<svg
data-icon="filter"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
filter
</desc>
<path
d="M13.99.99h-12a1.003 1.003 0 00-.71 1.71l4.71 4.71V14a1.003 1.003 0 001.71.71l2-2c.18-.18.29-.43.29-.71V7.41L14.7 2.7a1.003 1.003 0 00-.71-1.71z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
Filter
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</span>
</li>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-group-objects"
icon="group-objects"
>
<svg
data-icon="group-objects"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
group-objects
</desc>
<path
d="M5 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6-3H5C2.24 3 0 5.24 0 8s2.24 5 5 5h6c2.76 0 5-2.24 5-5s-2.24-5-5-5zm0 9H5c-2.21 0-4-1.79-4-4s1.79-4 4-4h6c2.21 0 4 1.79 4 4s-1.79 4-4 4zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Group by
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
<li
class=""
>
<a
class="bp3-menu-item bp3-popover-dismiss"
>
<span
class="bp3-icon bp3-icon-ungroup-objects"
icon="ungroup-objects"
>
<svg
data-icon="ungroup-objects"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
ungroup-objects
</desc>
<path
d="M3.5 5C1.57 5 0 6.57 0 8.5S1.57 12 3.5 12 7 10.43 7 8.5 5.43 5 3.5 5zm9 0C10.57 5 9 6.57 9 8.5s1.57 3.5 3.5 3.5S16 10.43 16 8.5 14.43 5 12.5 5z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Remove group by
</div>
</a>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-function"
icon="function"
>
<svg
data-icon="function"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
function
</desc>
<path
d="M8.12 4.74H6.98c.33-1.29.75-2.24 1.28-2.84.33-.37.64-.56.95-.56.06 0 .11.02.15.05.04.04.06.09.06.15 0 .05-.04.15-.13.29-.09.14-.13.28-.13.4 0 .18.07.33.2.46.14.13.31.19.52.19.22 0 .41-.08.56-.23.15-.16.23-.37.23-.63 0-.3-.11-.55-.34-.74C10.1 1.09 9.74 1 9.24 1c-.78 0-1.49.22-2.12.67-.64.45-1.24 1.2-1.81 2.23-.2.36-.38.59-.56.69-.18.1-.46.15-.85.15l-.26.9h1.08l-1.59 6.12c-.27 1.01-.44 1.63-.54 1.86-.14.34-.34.63-.62.87-.11.1-.24.15-.4.15a.15.15 0 01-.11-.04l-.04-.05c0-.03.04-.08.12-.16.08-.08.12-.2.12-.36 0-.18-.06-.33-.19-.44-.12-.12-.3-.18-.54-.18-.28 0-.51.08-.68.23-.16.14-.25.32-.25.53 0 .22.1.42.31.59.21.17.53.25.97.25.7 0 1.32-.18 1.87-.54.54-.36 1.02-.92 1.42-1.67.41-.75.82-1.96 1.25-3.63l.91-3.54h1.1l.29-.89zm5.43 1.52c.2-.15.41-.23.62-.23.08 0 .23.03.45.09s.41.09.57.09c.23 0 .42-.08.57-.23.16-.16.24-.36.24-.61 0-.26-.08-.47-.23-.62-.15-.15-.37-.23-.66-.23-.25 0-.5.06-.72.18-.23.12-.51.38-.86.78-.26.3-.64.81-1.15 1.55-.2-.91-.55-1.75-1.05-2.51l-2.72.46-.06.29c.2-.04.37-.06.51-.06.27 0 .49.11.67.34.28.36.67 1.45 1.17 3.26-.39.52-.66.85-.8 1.01-.24.26-.44.42-.59.5-.12.06-.25.09-.41.09-.11 0-.3-.06-.56-.18-.18-.08-.34-.12-.48-.12-.27 0-.48.08-.66.25-.17.17-.26.38-.26.64 0 .25.08.44.24.6.16.15.37.23.64.23.26 0 .5-.05.73-.16.23-.11.52-.34.86-.69.35-.35.82-.9 1.43-1.67.23.73.44 1.25.61 1.58s.37.57.59.71c.22.15.5.22.83.22.32 0 .65-.11.98-.34.44-.3.88-.81 1.34-1.53l-.26-.15c-.31.43-.54.7-.69.8-.1.07-.22.1-.35.1-.16 0-.32-.1-.48-.3-.27-.34-.62-1.27-1.06-2.8.4-.68.73-1.13 1-1.34z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Aggregate
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
</div>
`;
exports[`time menu matches snapshot when menu is opened for column not inside group by 1`] = `
<div>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-filter"
icon="filter"
>
<svg
data-icon="filter"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
filter
</desc>
<path
d="M13.99.99h-12a1.003 1.003 0 00-.71 1.71l4.71 4.71V14a1.003 1.003 0 001.71.71l2-2c.18-.18.29-.43.29-.71V7.41L14.7 2.7a1.003 1.003 0 00-.71-1.71z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Filter
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-group-objects"
icon="group-objects"
>
<svg
data-icon="group-objects"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
group-objects
</desc>
<path
d="M5 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6-3H5C2.24 3 0 5.24 0 8s2.24 5 5 5h6c2.76 0 5-2.24 5-5s-2.24-5-5-5zm0 9H5c-2.21 0-4-1.79-4-4s1.79-4 4-4h6c2.21 0 4 1.79 4 4s-1.79 4-4 4zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Group by
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
<li
class="bp3-submenu"
>
<span
class="bp3-popover-wrapper"
>
<span
class="bp3-popover-target"
>
<a
class="bp3-menu-item"
tabindex="0"
>
<span
class="bp3-icon bp3-icon-function"
icon="function"
>
<svg
data-icon="function"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
function
</desc>
<path
d="M8.12 4.74H6.98c.33-1.29.75-2.24 1.28-2.84.33-.37.64-.56.95-.56.06 0 .11.02.15.05.04.04.06.09.06.15 0 .05-.04.15-.13.29-.09.14-.13.28-.13.4 0 .18.07.33.2.46.14.13.31.19.52.19.22 0 .41-.08.56-.23.15-.16.23-.37.23-.63 0-.3-.11-.55-.34-.74C10.1 1.09 9.74 1 9.24 1c-.78 0-1.49.22-2.12.67-.64.45-1.24 1.2-1.81 2.23-.2.36-.38.59-.56.69-.18.1-.46.15-.85.15l-.26.9h1.08l-1.59 6.12c-.27 1.01-.44 1.63-.54 1.86-.14.34-.34.63-.62.87-.11.1-.24.15-.4.15a.15.15 0 01-.11-.04l-.04-.05c0-.03.04-.08.12-.16.08-.08.12-.2.12-.36 0-.18-.06-.33-.19-.44-.12-.12-.3-.18-.54-.18-.28 0-.51.08-.68.23-.16.14-.25.32-.25.53 0 .22.1.42.31.59.21.17.53.25.97.25.7 0 1.32-.18 1.87-.54.54-.36 1.02-.92 1.42-1.67.41-.75.82-1.96 1.25-3.63l.91-3.54h1.1l.29-.89zm5.43 1.52c.2-.15.41-.23.62-.23.08 0 .23.03.45.09s.41.09.57.09c.23 0 .42-.08.57-.23.16-.16.24-.36.24-.61 0-.26-.08-.47-.23-.62-.15-.15-.37-.23-.66-.23-.25 0-.5.06-.72.18-.23.12-.51.38-.86.78-.26.3-.64.81-1.15 1.55-.2-.91-.55-1.75-1.05-2.51l-2.72.46-.06.29c.2-.04.37-.06.51-.06.27 0 .49.11.67.34.28.36.67 1.45 1.17 3.26-.39.52-.66.85-.8 1.01-.24.26-.44.42-.59.5-.12.06-.25.09-.41.09-.11 0-.3-.06-.56-.18-.18-.08-.34-.12-.48-.12-.27 0-.48.08-.66.25-.17.17-.26.38-.26.64 0 .25.08.44.24.6.16.15.37.23.64.23.26 0 .5-.05.73-.16.23-.11.52-.34.86-.69.35-.35.82-.9 1.43-1.67.23.73.44 1.25.61 1.58s.37.57.59.71c.22.15.5.22.83.22.32 0 .65-.11.98-.34.44-.3.88-.81 1.34-1.53l-.26-.15c-.31.43-.54.7-.69.8-.1.07-.22.1-.35.1-.16 0-.32-.1-.48-.3-.27-.34-.62-1.27-1.06-2.8.4-.68.73-1.13 1-1.34z"
fill-rule="evenodd"
/>
</svg>
</span>
<div
class="bp3-text-overflow-ellipsis bp3-fill"
>
Aggregate
</div>
<span
class="bp3-icon bp3-icon-caret-right"
icon="caret-right"
>
<svg
data-icon="caret-right"
height="16"
viewBox="0 0 16 16"
width="16"
>
<desc>
caret-right
</desc>
<path
d="M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z"
fill-rule="evenodd"
/>
</svg>
</span>
</a>
</span>
</span>
</li>
</div>
`;

View File

@ -25,7 +25,7 @@ import { TimeMenuItems } from './time-menu-items';
describe('time menu', () => {
const parser = sqlParserFactory(['COUNT']);
it('matches snapshot', () => {
it('matches snapshot when menu is opened for column not inside group by', () => {
const timeMenu = (
<TimeMenuItems
columnName={'__time'}
@ -35,6 +35,19 @@ describe('time menu', () => {
);
const { container } = render(timeMenu);
expect(container.firstChild).toMatchSnapshot();
expect(container).toMatchSnapshot();
});
it('matches snapshot when menu is opened for column inside group by', () => {
const timeMenu = (
<TimeMenuItems
columnName={'__time'}
parsedQuery={parser(`SELECT __time, count(*) as cnt FROM wikipedia GROUP BY 1`)}
onQueryChange={() => {}}
/>
);
const { container } = render(timeMenu);
expect(container).toMatchSnapshot();
});
});

View File

@ -278,6 +278,19 @@ export class TimeMenuItems extends React.PureComponent<TimeMenuItemsProps> {
/>
);
}
renderRemoveGroupBy(): JSX.Element | undefined {
const { columnName, parsedQuery, onQueryChange } = this.props;
if (!parsedQuery.hasGroupByForColumn(columnName)) return;
return (
<MenuItem
icon={IconNames.UNGROUP_OBJECTS}
text={'Remove group by'}
onClick={() => {
onQueryChange(parsedQuery.removeGroupBy(columnName), true);
}}
/>
);
}
renderGroupByMenu(): JSX.Element | undefined {
const { columnName, parsedQuery, onQueryChange } = this.props;
@ -365,6 +378,7 @@ export class TimeMenuItems extends React.PureComponent<TimeMenuItemsProps> {
{this.renderFilterMenu()}
{this.renderRemoveFilter()}
{this.renderGroupByMenu()}
{this.renderRemoveGroupBy()}
{this.renderAggregateMenu()}
</>
);