Skip to content

Commit b7ce753

Browse files
lorem--ipsumvogievetsky
authored andcommitted
People can now remove attributes int he data table view
1 parent ab5d1a3 commit b7ce753

File tree

7 files changed

+39
-5
lines changed

7 files changed

+39
-5
lines changed

src/client/components/modal/modal.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
.button-bar {
9494
margin-top: 10px;
9595

96-
button {
96+
button:not(:last-child) {
9797
margin-right: 8px;
9898
}
9999
}

src/client/config/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export const STRINGS = {
125125
quicklyAddSomeUsing: 'Quickly add some using',
126126
rawData: 'Raw Data',
127127
regex: 'Regex',
128+
removeAttribute: 'Remove attribute',
128129
relative: 'Relative',
129130
save: 'Save',
130131
segment: 'segment',

src/client/modals/attribute-modal/attribute-modal.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
$checkbox-width: 20px;
1919

2020
.attribute-modal {
21+
@import '../../utils/styles/grid';
22+
2123
form {
2224
@extend %form;
2325
width: 100%;

src/client/modals/attribute-modal/attribute-modal.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface AttributeModalProps extends React.Props<any> {
3434
attributeInfo: AttributeInfo;
3535
onSave?: (attribute: AttributeInfo) => void;
3636
onClose?: () => void;
37+
onRemove?: () => void;
3738
mode?: 'create' | 'edit';
3839
}
3940

@@ -95,7 +96,7 @@ export class AttributeModal extends React.Component<AttributeModalProps, Attribu
9596
}
9697

9798
render() {
98-
const { attributeInfo, onClose, mode } = this.props;
99+
const { attributeInfo, onClose, mode, onRemove } = this.props;
99100
const { newInstance, canSave, errors } = this.state;
100101
const saveButtonDisabled = !canSave || attributeInfo.equals(newInstance);
101102
if (!newInstance) return null;
@@ -142,9 +143,17 @@ export class AttributeModal extends React.Component<AttributeModalProps, Attribu
142143
/>
143144
</div>
144145
</form>
145-
<div className="button-bar">
146-
<Button type="primary" title={okText} onClick={this.save.bind(this)} disabled={saveButtonDisabled} />
147-
<Button className="cancel" title={STRINGS.cancel} type="secondary" onClick={onClose}/>
146+
<div className="grid-row button-bar">
147+
<div className="grid-col-50">
148+
<Button type="primary" title={okText} onClick={this.save.bind(this)} disabled={saveButtonDisabled} />
149+
<Button className="cancel" title={STRINGS.cancel} type="secondary" onClick={onClose}/>
150+
</div>
151+
<div className="grid-col-50 right">
152+
{ onRemove
153+
? <Button className="warn" title={STRINGS.removeAttribute} type="warn" onClick={onRemove}/>
154+
: null
155+
}
156+
</div>
148157
</div>
149158
</Modal>;
150159
}

src/client/views/settings-view/data-table/data-table.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112

113113
border-right: 1px solid hsla(0, 0%, 87%, 1.00);
114114

115+
padding: 14px 10px 5px 5px;
116+
115117
&:first-child {
116118
border-left: 1px solid hsla(0, 0%, 87%, 1.00);
117119
}

src/client/views/settings-view/data-table/data-table.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,16 @@ export class DataTable extends React.Component<DataTableProps, DataTableState> {
143143
onClose();
144144
};
145145

146+
const onRemove = () => {
147+
onChange(dataCube.removeAttribute(editedAttribute));
148+
onClose();
149+
};
150+
146151
return <AttributeModal
147152
attributeInfo={editedAttribute}
148153
onClose={onClose}
149154
onSave={onSave}
155+
onRemove={onRemove}
150156
/>;
151157
}
152158

src/common/models/data-cube/data-cube.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,20 @@ export class DataCube implements Instance<DataCubeValue, DataCubeJS> {
830830
return this.changeAttributes(attributes);
831831
}
832832

833+
public removeAttribute(attribute: AttributeInfo): DataCube {
834+
835+
var index = this.attributes.indexOf(attribute);
836+
837+
if (index === -1) {
838+
throw new Error(`Unknown attribute : ${attribute.toString()}`);
839+
}
840+
841+
var newAttributes = this.attributes.concat();
842+
newAttributes.splice(index, 1);
843+
844+
return this.changeAttributes(newAttributes);
845+
}
846+
833847
public appendAttributes(attributes: Attributes): DataCube {
834848
return this.changeAttributes(this.attributes.concat(attributes));
835849
}

0 commit comments

Comments
 (0)