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

Replace some Bootstrap components/classes with Ant analogues #4588

Closed
wants to merge 8 commits into from
Closed
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
102 changes: 67 additions & 35 deletions client/app/assets/less/ant.less
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
@import '~antd/lib/style/core/iconfont';
@import '~antd/lib/style/core/motion';
@import '~antd/lib/alert/style/index';
@import '~antd/lib/input/style/index';
@import '~antd/lib/input-number/style/index';
@import '~antd/lib/date-picker/style/index';
@import '~antd/lib/modal/style/index';
@import '~antd/lib/tooltip/style/index';
@import '~antd/lib/select/style/index';
@import '~antd/lib/checkbox/style/index';
@import '~antd/lib/upload/style/index';
@import '~antd/lib/form/style/index';
@import '~antd/lib/button/style/index';
@import '~antd/lib/radio/style/index';
@import '~antd/lib/time-picker/style/index';
@import '~antd/lib/pagination/style/index';
@import '~antd/lib/table/style/index';
@import '~antd/lib/popover/style/index';
@import '~antd/lib/icon/style/index';
@import '~antd/lib/tag/style/index';
@import '~antd/lib/grid/style/index';
@import '~antd/lib/switch/style/index';
@import '~antd/lib/empty/style/index';
@import '~antd/lib/drawer/style/index';
@import '~antd/lib/card/style/index';
@import '~antd/lib/steps/style/index';
@import '~antd/lib/divider/style/index';
@import '~antd/lib/dropdown/style/index';
@import '~antd/lib/menu/style/index';
@import '~antd/lib/list/style/index';
@import "~antd/lib/style/core/iconfont";
@import "~antd/lib/style/core/motion";
@import "~antd/lib/alert/style/index";
@import "~antd/lib/input/style/index";
@import "~antd/lib/input-number/style/index";
@import "~antd/lib/date-picker/style/index";
@import "~antd/lib/modal/style/index";
@import "~antd/lib/tooltip/style/index";
@import "~antd/lib/select/style/index";
@import "~antd/lib/checkbox/style/index";
@import "~antd/lib/upload/style/index";
@import "~antd/lib/form/style/index";
@import "~antd/lib/button/style/index";
@import "~antd/lib/radio/style/index";
@import "~antd/lib/time-picker/style/index";
@import "~antd/lib/pagination/style/index";
@import "~antd/lib/table/style/index";
@import "~antd/lib/popover/style/index";
@import "~antd/lib/icon/style/index";
@import "~antd/lib/tag/style/index";
@import "~antd/lib/grid/style/index";
@import "~antd/lib/switch/style/index";
@import "~antd/lib/empty/style/index";
@import "~antd/lib/drawer/style/index";
@import "~antd/lib/card/style/index";
@import "~antd/lib/steps/style/index";
@import "~antd/lib/divider/style/index";
@import "~antd/lib/dropdown/style/index";
@import "~antd/lib/menu/style/index";
@import "~antd/lib/list/style/index";
@import "~antd/lib/badge/style/index";
@import "~antd/lib/card/style/index";
@import "~antd/lib/spin/style/index";
Expand All @@ -36,7 +36,7 @@
@import "~antd/lib/collapse/style/index";
@import "~antd/lib/progress/style/index";
@import "~antd/lib/typography/style/index";
@import 'inc/ant-variables';
@import "inc/ant-variables";

// Increase z-indexes to avoid conflicts with some other libraries (e.g. Plotly)
@zindex-modal: 2000;
Expand Down Expand Up @@ -237,11 +237,11 @@
&-item {
// custom rule
&.selected {
background-color: #F6F8F9;
background-color: #f6f8f9;
}

&.disabled {
background-color: fade(#F6F8F9, 40%);
background-color: fade(#f6f8f9, 40%);

& > * {
opacity: 0.4;
Expand All @@ -250,6 +250,31 @@
}
}

.@{list-prefix-cls}-bordered.@{list-prefix-cls}-sm {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The actual change, other is from Prettier

.@{list-prefix-cls}-item-link {
padding: 0;

> a {
display: block;
flex: 1 1 auto;
padding: 8px 16px;
cursor: pointer;
text-decoration: none;
color: inherit;

&:hover,
&:active {
background: fade(@redash-gray, 5%);
}

&.inactive {
cursor: not-allowed;
background: fade(@redash-gray, 5%);
}
}
}
}

.@{dialog-prefix-cls} {
// styling for short modals (no lines)
&.shortModal {
Expand Down Expand Up @@ -367,7 +392,7 @@
top: auto !important;
bottom: 8px;

// makes the icon white instead of see-through
// makes the icon white instead of see-through
& svg {
background: white;
border-radius: 50%;
Expand All @@ -394,9 +419,16 @@
}

// overrides for checkbox
@checkbox-prefix-cls: ~'@{ant-prefix}-checkbox';
@checkbox-prefix-cls: ~"@{ant-prefix}-checkbox";

.@{checkbox-prefix-cls}-wrapper + span,
.@{checkbox-prefix-cls} + span {
padding-right: 0;
}

// set some defaults for badge
.@{badge-prefix-cls} {
&-count {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The actual change, other is from Prettier

background: @processing-color;
}
}
4 changes: 0 additions & 4 deletions client/app/assets/less/redash/query.less
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ body.fixed-layout {
height: 100% !important;
width: calc(~"25% - 10px");
margin-right: 10px;

.form-control {
height: 30px;
}
}

.query-alerts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Dropdown from "antd/lib/dropdown";
import Icon from "antd/lib/icon";
import Menu from "antd/lib/menu";

import FavoritesControl from "@/components/FavoritesControl";
import HelpTrigger from "@/components/HelpTrigger";

export default function FavoritesDropdown({ fetch, urlTemplate }) {
Expand Down Expand Up @@ -41,18 +42,14 @@ export default function FavoritesDropdown({ fetch, urlTemplate }) {
<Menu className="favorites-dropdown">
{noItems ? (
<Menu.Item>
<span className="btn-favourite m-r-5">
<i className="fa fa-star" />
</span>
<FavoritesControl className="m-r-5" item={{ is_favorite: true }} readOnly />
No favorites selected yet <HelpTrigger type="FAVORITES" />
</Menu.Item>
) : (
items.map(item => (
<Menu.Item key={item.id}>
<a href={urlCompiled(item)}>
<span className="btn-favourite m-r-5">
<i className="fa fa-star" />
</span>
<FavoritesControl className="m-r-5" item={item} readOnly />
{item.name}
</a>
</Menu.Item>
Expand Down
19 changes: 17 additions & 2 deletions client/app/components/FavoritesControl.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import React from "react";
import PropTypes from "prop-types";
import cx from "classnames";

export default class FavoritesControl extends React.Component {
static propTypes = {
item: PropTypes.shape({
is_favorite: PropTypes.bool.isRequired,
}).isRequired,
readOnly: PropTypes.bool,
onChange: PropTypes.func,
className: PropTypes.string,
};

static defaultProps = {
readOnly: false,
onChange: () => {},
className: null,
};

toggleItem(event, item, callback) {
Expand All @@ -25,13 +30,23 @@ export default class FavoritesControl extends React.Component {
}

render() {
const { item, onChange } = this.props;
const { item, readOnly, onChange, className, ...props } = this.props;
const icon = item.is_favorite ? "fa fa-star" : "fa fa-star-o";
const title = item.is_favorite ? "Remove from favorites" : "Add to favorites";

if (readOnly) {
return (
<span {...props} className={cx("favorites-control btn-favourite", className)}>
<i className={icon} aria-hidden="true" />
</span>
);
}

return (
<a
{...props}
title={title}
className="favorites-control btn-favourite"
className={cx("favorites-control btn-favourite", className)}
onClick={event => this.toggleItem(event, item, onChange)}>
<i className={icon} aria-hidden="true" />
</a>
Expand Down
14 changes: 8 additions & 6 deletions client/app/components/Parameters.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { size, filter, forEach, extend } from "lodash";
import React from "react";
import PropTypes from "prop-types";
import Button from "antd/lib/button";
import { SortableContainer, SortableElement, DragHandle } from "@/components/sortable";
import location from "@/services/location";
import { Parameter, createParameter } from "@/services/parameters";
Expand Down Expand Up @@ -123,15 +124,16 @@ export default class Parameters extends React.Component {
return (
<div key={param.name} className="di-block" data-test={`ParameterName-${param.name}`}>
<div className="parameter-heading">
<label>{param.title || toHuman(param.name)}</label>
<label>
<span>{param.title || toHuman(param.name)}</span>
</label>
{editable && (
<button
className="btn btn-default btn-xs m-l-5"
<Button
size="small"
icon="setting"
onClick={() => this.showParameterSettings(param, index)}
data-test={`ParameterSettings-${param.name}`}
type="button">
<i className="fa fa-cog" />
</button>
/>
)}
</div>
<ParameterValueInput
Expand Down
42 changes: 30 additions & 12 deletions client/app/components/Parameters.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '../assets/less/ant';
@import "../assets/less/ant";

.parameter-block {
display: inline-block;
Expand All @@ -20,27 +20,43 @@
}

&.parameter-dragged {
box-shadow: 0 4px 9px -3px rgba(102, 136, 153, 0.15);
box-shadow: 0 4px 9px -3px rgba(102, 136, 153, 0.15);
}
}

.parameter-heading {
display: flex;
align-items: center;
justify-content: stretch;
padding-bottom: 4px;

label {
flex: 1 1 auto;
margin-bottom: 1px;
overflow: hidden;
text-overflow: ellipsis;
min-width: 100%;
max-width: 195px;
white-space: nowrap;

.parameter-block[data-editable] & {
min-width: calc(100% - 27px); // make room for settings button
max-width: 195px - 27px;
Copy link
Member

@gabrieldutra gabrieldutra Feb 1, 2020

Choose a reason for hiding this comment

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

It may be trickier to reach the same Label behavior for parameters:

Before
image
After
image

The idea is to keep it with a flexible width, if the label itself has more text and the width is not in it's limit, the whole parameter can take up more space 🙂. You couldn't get it to work with the previous css or you just wanted to move it to flex?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wanted to make it flex (and get rid of calc). Thank you for pointing, I'll check this once more 👍

position: relative;

&:before {
content: "Ij"; // placeholder
visibility: hidden;
}

span {
position: absolute;
left: 0;
right: 0;

overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}

.ant-btn {
flex: 0 0 auto;
margin-left: 5px;
padding: 0 !important;
width: 26px;
text-align: center;
}
}

Expand Down Expand Up @@ -88,7 +104,9 @@
height: 27px;
}

&:hover, &:focus, &:active {
&:hover,
&:focus,
&:active {
background-color: #eef7fe;
}

Expand Down
Loading