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: add icon display #18

Merged
merged 8 commits into from
Oct 8, 2021
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: 1 addition & 3 deletions app/assets/components/Button/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@
}

.panel-actived {
svg {
fill: #0091ff;
}
color: #0091ff;
}
13 changes: 12 additions & 1 deletion app/assets/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,18 @@ const CustomizeTooltipBtn = (props: IMenuButton) => {
onClick={!disabled ? action : undefined}
/>
) : (
component
<div
className={classnames({
'panel-disabled': disabled,
'panel-actived': active,
})}
onClick={!disabled && action ? action : undefined}
data-track-category={trackCategory}
data-track-action={trackAction}
data-track-label={trackLabel}
>
{component}
</div>
)}
</Tooltip>
);
Expand Down
33 changes: 14 additions & 19 deletions app/assets/components/ColorPicker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Popover } from 'antd';
import React from 'react';
import { TwitterPicker } from 'react-color';

Expand Down Expand Up @@ -26,35 +25,31 @@ class ColorPicker extends React.Component<IProps, IState> {

handleChange = color => {
if (this.props.handleChange) {
this.props.handleChange(color);
const { hex: _color } = color;
this.props.handleChange(_color);
}
};

handleChangeComplete = (color, _event) => {
if (this.props.handleChangeColorComplete) {
this.props.handleChangeColorComplete(color);
const { hex: _color } = color;
this.props.handleChangeColorComplete(_color);
}
};

render() {
return (
<Popover
placement="bottom"
overlayClassName="popover-color"
content={
<TwitterPicker
width="240px"
className="custom-picker"
onChange={this.handleChange}
onChangeComplete={this.handleChangeComplete}
colors={COLOR_PICK_LIST}
triangle="hide"
/>
}
trigger="click"
>
<div className="popover-color">
<TwitterPicker
width="240px"
className="custom-picker"
onChange={this.handleChange}
onChangeComplete={this.handleChangeComplete}
colors={COLOR_PICK_LIST}
triangle="hide"
/>
{this.props.children}
</Popover>
</div>
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/components/Expand/ExpandForm/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
.btn-color {
position: absolute;
right: 0;
bottom: 3px;
bottom: -12px;
}
}
}
Expand Down
128 changes: 73 additions & 55 deletions app/assets/components/Expand/ExpandForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { connect } from 'react-redux';
import { Instruction } from '#assets/components';
import GQLModal from '#assets/components/GQLModal';
import IconFont from '#assets/components/Icon';
import VertexStyleSet from '#assets/components/VertexStyleSet';
import { DEFAULT_COLOR_PICKER } from '#assets/config/explore';
import ColorPickerBtn from '#assets/modules/Explore/NebulaGraph/Panel/ColorPicker';
import { IDispatch, IRootState } from '#assets/store';
import { RELATION_OPERATORS } from '#assets/utils/constant';
import { getExploreMatchGQL } from '#assets/utils/gql';
Expand Down Expand Up @@ -61,6 +61,7 @@ interface IState {
filters: IFilter[];
visible: boolean;
customColor: string;
customIcon: string;
}

class Expand extends React.Component<IProps, IState> {
Expand All @@ -71,18 +72,22 @@ class Expand extends React.Component<IProps, IState> {
filters: [],
visible: false,
customColor: DEFAULT_COLOR_PICKER,
customIcon: '',
};
this.gqlRef = React.createRef();
}

componentDidMount() {
this.props.asyncGetEdgesAndFields();
const {
exploreRules: { filters },
exploreRules: { filters, customIcon },
} = this.props;
if (filters) {
this.setState({ filters });
}
if (customIcon) {
this.setState({ customIcon });
}
}

renderFilters = () => {
Expand Down Expand Up @@ -138,47 +143,49 @@ class Expand extends React.Component<IProps, IState> {
handleExpand = () => {
const { selectVertexes, edgesFields } = this.props;
const { getFieldsValue } = this.props.form;
const { filters, customColor } = this.state;
const { filters, customColor, customIcon } = this.state;
this.props.form.validateFields(async err => {
if (!err) {
const {
edgeTypes,
edgeDirection,
stepsType,
step,
minStep,
maxStep,
vertexColor,
quantityLimit,
} = getFieldsValue();
(this.props.asyncGetExpand({
filters,
selectVertexes,
edgeTypes,
edgesFields,
edgeDirection,
vertexColor,
quantityLimit,
stepsType,
step,
minStep,
maxStep,
customColor,
}) as any).then(
async () => {
message.success(intl.get('common.success'));
trackEvent('explore', 'expand', 'ajax success');
},
(e: any) => {
trackEvent('explore', 'expand', 'ajax fail');
if (e.message) {
message.error(e.message);
} else {
message.info(intl.get('common.noData'));
}
},
);
if (err) {
return;
}
const {
edgeTypes,
edgeDirection,
stepsType,
step,
minStep,
maxStep,
vertexStyle,
quantityLimit,
} = getFieldsValue();
(this.props.asyncGetExpand({
filters,
selectVertexes,
edgeTypes,
edgesFields,
edgeDirection,
vertexStyle,
quantityLimit,
stepsType,
step,
minStep,
maxStep,
customColor,
customIcon,
}) as any).then(
async () => {
message.success(intl.get('common.success'));
trackEvent('explore', 'expand', 'ajax success');
},
(e: any) => {
trackEvent('explore', 'expand', 'ajax fail');
if (e.message) {
message.error(e.message);
} else {
message.info(intl.get('common.noData'));
}
},
);
});
};

Expand Down Expand Up @@ -230,9 +237,18 @@ class Expand extends React.Component<IProps, IState> {
);
};

handleCustomIcon = icon => {
this.setState(
{
customIcon: icon.content ? icon.type : '',
},
this.handleUpdateRules,
);
};

handleUpdateRules = () => {
const { getFieldsValue } = this.props.form;
const { filters, customColor } = this.state;
const { filters, customColor, customIcon } = this.state;
setTimeout(() => {
const {
edgeTypes,
Expand All @@ -241,19 +257,20 @@ class Expand extends React.Component<IProps, IState> {
step,
minStep,
maxStep,
vertexColor,
vertexStyle,
quantityLimit,
} = getFieldsValue();
this.props.updateExploreRules({
edgeTypes,
edgeDirection,
vertexColor,
vertexStyle,
quantityLimit,
stepsType,
step,
minStep,
maxStep,
customColor,
customIcon,
filters,
});
}, 100);
Expand All @@ -268,7 +285,7 @@ class Expand extends React.Component<IProps, IState> {
close,
} = this.props;
const { getFieldDecorator, getFieldsValue } = this.props.form;
const { filters, customColor } = this.state;
const { filters, customColor, customIcon } = this.state;
const {
edgeTypes: selectEdgeTypes,
edgeDirection,
Expand Down Expand Up @@ -424,26 +441,27 @@ class Expand extends React.Component<IProps, IState> {
</Form.Item>
</div>
)}
<Form.Item label={intl.get('explore.vertexColor')}>
{getFieldDecorator('vertexColor', {
initialValue: rules.vertexColor || 'groupByTag',
<Form.Item label={intl.get('explore.vertexStyle')}>
{getFieldDecorator('vertexStyle', {
initialValue: rules.vertexStyle || 'colorGroupByTag',
rules: [
{
required: true,
},
],
})(
<Radio.Group onChange={this.handleUpdateRules}>
<Radio value="groupByTag">
{intl.get('explore.groupByTag')}
<Radio value="colorGroupByTag">
{intl.get('explore.colorGroupByTag')}
</Radio>
<Radio value="custom">
{intl.get('explore.customColor')}
{intl.get('explore.customStyle')}
</Radio>
<ColorPickerBtn
onChange={this.handleCustomColor}
customColor={customColor}
editing={true}
<VertexStyleSet
handleChangeColorComplete={this.handleCustomColor}
handleChangeIconComplete={this.handleCustomIcon}
icon={customIcon}
color={customColor}
/>
</Radio.Group>,
)}
Expand Down
Loading