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

feat(dashboard): Add create chart button in dashboard edit mode #20126

Merged
merged 1 commit into from
May 19, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 44 additions & 1 deletion superset-frontend/src/dashboard/components/SliceAdder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ import React from 'react';
import PropTypes from 'prop-types';
import { List } from 'react-virtualized';
import { createFilter } from 'react-search-input';
import { t, styled, isFeatureEnabled, FeatureFlag } from '@superset-ui/core';
import {
t,
styled,
isFeatureEnabled,
FeatureFlag,
css,
} from '@superset-ui/core';
import { Input } from 'src/components/Input';
import { Select } from 'src/components';
import Loading from 'src/components/Loading';
import Button from 'src/components/Button';
import Icons from 'src/components/Icons';
import {
CHART_TYPE,
NEW_COMPONENT_SOURCE_TYPE,
Expand Down Expand Up @@ -79,13 +87,36 @@ const Controls = styled.div`
display: flex;
flex-direction: row;
padding: ${({ theme }) => theme.gridUnit * 3}px;
padding-top: ${({ theme }) => theme.gridUnit * 4}px;
`;

const StyledSelect = styled(Select)`
margin-left: ${({ theme }) => theme.gridUnit * 2}px;
min-width: 150px;
`;

const NewChartButtonContainer = styled.div`
${({ theme }) => css`
display: flex;
justify-content: flex-end;
padding-right: ${theme.gridUnit * 2}px;
`}
`;

const NewChartButton = styled(Button)`
${({ theme }) => css`
height: auto;
& > .anticon + span {
margin-left: 0;
}
& > [role='img']:first-of-type {
margin-right: ${theme.gridUnit}px;
padding-bottom: 1px;
line-height: 0;
}
`}
`;

class SliceAdder extends React.Component {
static sortByComparator(attr) {
const desc = attr === 'changed_on' ? -1 : 1;
Expand Down Expand Up @@ -240,6 +271,18 @@ class SliceAdder extends React.Component {
MARGIN_BOTTOM;
return (
<div className="slice-adder-container">
<NewChartButtonContainer>
<NewChartButton
buttonStyle="link"
buttonSize="xsmall"
onClick={() =>
window.open('/chart/add', '_blank', 'noopener noreferrer')
Copy link
Member

@villebro villebro May 19, 2022

Choose a reason for hiding this comment

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

It could be interesting to implement broadcasting so that the list is updated when a chart is created: https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! But wouldn't we actually need to use websocket instead to update the list when chart is saved on the backend? I just wonder if such frontend communication would be reliable enough

}
>
<Icons.PlusSmall />
{t('Create new chart')}
</NewChartButton>
</NewChartButtonContainer>
<Controls>
<Input
placeholder={t('Filter your charts')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
width: @builder-pane-width;
height: 100%;
box-shadow: -4px 0 4px 0 fade(@darkest, @opacity-light);
background-color: @lightest;
}

.slider-container {
Expand Down