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

[dash builder fix] combine markdown and slice name, slice picker height #5165

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
4 changes: 3 additions & 1 deletion superset/assets/src/dashboard/actions/sliceEntities.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export function fetchAllSlices(userId) {
description: slice.description,
description_markdown: slice.description_markeddown,
viz_type: slice.viz_type,
modified: slice.modified,
modified: slice.modified
? slice.modified.replace(/<[^>]*>/g, '')
: '',
};
}
});
Expand Down
44 changes: 30 additions & 14 deletions superset/assets/src/dashboard/components/SliceAdder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { DropdownButton, MenuItem } from 'react-bootstrap';
import { List } from 'react-virtualized';
import { CellMeasurer, CellMeasurerCache, List } from 'react-virtualized';
import SearchInput, { createFilter } from 'react-search-input';

import AddSliceCard from './AddSliceCard';
Expand Down Expand Up @@ -42,6 +42,12 @@ const KEYS_TO_SORT = [
const MARGIN_BOTTOM = 16;
const SIDEPANE_HEADER_HEIGHT = 55;
const SLICE_ADDER_CONTROL_HEIGHT = 64;
const DEFAULT_CELL_HEIGHT = 136;

const cache = new CellMeasurerCache({
defaultHeight: DEFAULT_CELL_HEIGHT,
fixedWidth: true,
});

class SliceAdder extends React.Component {
static sortByComparator(attr) {
Expand Down Expand Up @@ -133,7 +139,7 @@ class SliceAdder extends React.Component {
});
}

rowRenderer({ key, index, style }) {
rowRenderer({ key, index, style, parent }) {
const { filteredSlices, selectedSliceIdsSet } = this.state;
const cellData = filteredSlices[index];
const isSelected = selectedSliceIdsSet.has(cellData.slice_id);
Expand All @@ -160,19 +166,28 @@ class SliceAdder extends React.Component {
// we must use a custom drag preview within the List because
// it does not seem to work within a fixed-position container
useEmptyDragPreview
// List library expect style props here
// actual style should be applied to nested AddSliceCard component
style={{}}
>
{({ dragSourceRef }) => (
<AddSliceCard
innerRef={dragSourceRef}
style={style}
sliceName={cellData.slice_name}
lastModified={
cellData.modified ? cellData.modified.replace(/<[^>]*>/g, '') : ''
}
visType={cellData.viz_type}
datasourceLink={cellData.datasource_link}
isSelected={isSelected}
/>
<CellMeasurer
cache={cache}
columnIndex={0}
key={key}
parent={parent}
rowIndex={index}
>
<AddSliceCard
innerRef={dragSourceRef}
style={style}
sliceName={cellData.slice_name}
lastModified={cellData.modified}
visType={cellData.viz_type}
datasourceLink={cellData.datasource_link}
isSelected={isSelected}
/>
</CellMeasurer>
)}
</DragDroppable>
);
Expand Down Expand Up @@ -223,7 +238,8 @@ class SliceAdder extends React.Component {
width={376}
height={slicesListHeight}
rowCount={this.state.filteredSlices.length}
rowHeight={136}
deferredMeasurementCache={cache}
rowHeight={cache.rowHeight}
rowRenderer={this.rowRenderer}
searchTerm={this.state.searchTerm}
sortBy={this.state.sortBy}
Expand Down
1 change: 1 addition & 0 deletions superset/assets/src/dashboard/reducers/getInitialState.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export default function(bootstrapData) {
datasource: slice.form_data.datasource,
description: slice.description,
description_markeddown: slice.description_markeddown,
modified: slice.modified ? slice.modified.replace(/<[^>]*>/g, '') : '',
};

sliceIds.add(key);
Expand Down
11 changes: 6 additions & 5 deletions superset/assets/src/dashboard/stylesheets/builder-sidepane.less
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
.chart-card {
border: 1px solid @gray-light;
font-weight: 200;
height: 120px;
padding: 16px;
margin: 16px;
position: relative;
Expand All @@ -88,6 +87,7 @@
}

.card-title {
margin-right: 60px;
Copy link
Author

Choose a reason for hiding this comment

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

here is to wrap title.

Copy link
Contributor

Choose a reason for hiding this comment

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

@graceguo-supercat this is regardless of whether the slice has been added, right? I think we only want an early wrap if it has been added/the ADDED label is there?

margin-bottom: 8px;
font-weight: 800;
}
Expand All @@ -97,10 +97,12 @@
flex-direction: column;

.item {
height: 18px;
span {
word-break: break-all;

span:first-child {
font-weight: 400;
&:first-child {
font-weight: 400;
}
}
}
}
Expand All @@ -118,7 +120,6 @@
text-transform: uppercase;
position: absolute;
padding: 4px 8px;
position: absolute;
top: 32px;
right: 32px;
pointer-events: none;
Expand Down
10 changes: 5 additions & 5 deletions superset/assets/src/dashboard/util/dashboardLayoutConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ function getChartHolder(item) {
Math.round(size_y / GRID_RATIO * 100 / ROW_HEIGHT),
);
if (code !== undefined) {
let markdownContent = '';
if (slice_name) {
markdownContent = `##### **${slice_name}**\n`;
}
let markdownContent = ' '; // white-space markdown
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite follow this comment, what do you mean by it? it could be more clear if you say the approach we're using: use code if it exists, else use title if it exists.

Copy link
Author

Choose a reason for hiding this comment

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

if markdownContent is null or '', we will add markdown sample code into it. i saw a few places user use empty markdown as blank separator.

Copy link
Contributor

Choose a reason for hiding this comment

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

ohhh I see. thanks for the explanation, good catch.

if (code) {
markdownContent += code;
markdownContent = code;
} else if (slice_name.trim()) {
markdownContent = `##### ${slice_name}`;
}

return {
type: MARKDOWN_TYPE,
id: `DASHBOARD_MARKDOWN_TYPE-${generateId()}`,
Expand Down
1 change: 1 addition & 0 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def data(self):
'slice_id': self.id,
'slice_name': self.slice_name,
'slice_url': self.slice_url,
'modified': self.modified(),
}

@property
Expand Down
2 changes: 1 addition & 1 deletion superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def changed_on_(self):
return Markup(
'<span class="no-wrap">{}</span>'.format(self.changed_on))

@renders('changed_on')
@renders('modified')
def modified(self):
s = humanize.naturaltime(datetime.now() - self.changed_on)
return Markup('<span class="no-wrap">{}</span>'.format(s))
Expand Down