File size: 4,526 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* eslint-disable no-unused-vars */
import Toolbar from "@mui/material/Toolbar";
import Chip from "@mui/material/Chip";
import Typography from "@mui/material/Typography";
import PropTypes from "prop-types";
import * as React from "react";
import { Droppable, Draggable } from "react-beautiful-dnd";
/* eslint-enable no-unused-vars */

class MTableGroupbar extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  getItemStyle = (isDragging, draggableStyle) => ({
    // some basic styles to make the items look a bit nicer
    userSelect: "none",
    // padding: '8px 16px',
    margin: `0 ${8}px 0 0`,

    // change background colour if dragging
    // background: isDragging ? 'lightgreen' : 'grey',

    // styles we need to apply on draggables
    ...draggableStyle,
  });

  getListStyle = (isDraggingOver) => ({
    // background: isDraggingOver ? 'lightblue' : '#0000000a',
    background: "#0000000a",
    display: "flex",
    width: "100%",
    padding: 8,
    overflow: "auto",
    border: "1px solid #ccc",
    borderStyle: "dashed",
  });

  render() {
    return (
      <Toolbar style={{ padding: 0, minHeight: "unset" }}>
        <Droppable
          droppableId="groups"
          direction="horizontal"
          placeholder="Deneme"
        >
          {(provided, snapshot) => (
            <div
              ref={provided.innerRef}
              style={this.getListStyle(snapshot.isDraggingOver)}
            >
              {this.props.groupColumns.length > 0 && (
                <Typography variant="caption" style={{ padding: 8 }}>
                  {this.props.localization.groupedBy}
                </Typography>
              )}
              {this.props.groupColumns.map((columnDef, index) => {
                return (
                  <Draggable
                    key={columnDef.tableData.id}
                    draggableId={columnDef.tableData.id.toString()}
                    index={index}
                  >
                    {(provided, snapshot) => (
                      <div
                        ref={provided.innerRef}
                        {...provided.draggableProps}
                        {...provided.dragHandleProps}
                        style={this.getItemStyle(
                          snapshot.isDragging,
                          provided.draggableProps.style
                        )}
                      >
                        <Chip
                          {...provided.dragHandleProps}
                          onClick={() => this.props.onSortChanged(columnDef)}
                          label={
                            <div
                              style={{ display: "flex", alignItems: "center" }}
                            >
                              <div style={{ float: "left" }}>
                                {columnDef.title}
                              </div>
                              {columnDef.tableData.groupSort && (
                                <this.props.icons.SortArrow
                                  style={{
                                    transition: "300ms ease all",
                                    transform:
                                      columnDef.tableData.groupSort === "asc"
                                        ? "rotate(-180deg)"
                                        : "none",
                                    fontSize: 18,
                                  }}
                                />
                              )}
                            </div>
                          }
                          style={{ boxShadow: "none", textTransform: "none" }}
                          onDelete={() =>
                            this.props.onGroupRemoved(columnDef, index)
                          }
                        />
                      </div>
                    )}
                  </Draggable>
                );
              })}
              {this.props.groupColumns.length === 0 && (
                <Typography variant="caption" style={{ padding: 8 }}>
                  {this.props.localization.placeholder}
                </Typography>
              )}
              {provided.placeholder}
            </div>
          )}
        </Droppable>
      </Toolbar>
    );
  }
}

MTableGroupbar.defaultProps = {};

MTableGroupbar.propTypes = {
  localization: PropTypes.shape({
    groupedBy: PropTypes.string,
    placeholder: PropTypes.string,
  }),
};

export default MTableGroupbar;