Properly remove user labels.
This commit is contained in:
parent
df09098f89
commit
126960ba82
|
@ -312,8 +312,10 @@ export class UserLabelsFeature extends Component<Props, State> {
|
||||||
value.remove();
|
value.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
userLabels.splice(index, 1);
|
for (const userLabel of userLabels.splice(index, 1)) {
|
||||||
await saveUserLabels(userLabels);
|
await userLabel.remove();
|
||||||
|
}
|
||||||
|
|
||||||
this.props.userLabels = userLabels;
|
this.props.userLabels = userLabels;
|
||||||
this.hide();
|
this.hide();
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,6 +30,7 @@ type State = {
|
||||||
hasUnsavedChanges: boolean;
|
hasUnsavedChanges: boolean;
|
||||||
newLabelUsername: string;
|
newLabelUsername: string;
|
||||||
userLabels: UserLabelsData;
|
userLabels: UserLabelsData;
|
||||||
|
userLabelsToRemove: UserLabelsData;
|
||||||
};
|
};
|
||||||
|
|
||||||
class App extends Component<Props, State> {
|
class App extends Component<Props, State> {
|
||||||
|
@ -40,6 +41,7 @@ class App extends Component<Props, State> {
|
||||||
hasUnsavedChanges: false,
|
hasUnsavedChanges: false,
|
||||||
newLabelUsername: "",
|
newLabelUsername: "",
|
||||||
userLabels: props.userLabels,
|
userLabels: props.userLabels,
|
||||||
|
userLabelsToRemove: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,20 +101,26 @@ class App extends Component<Props, State> {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
removeUserLabel = (targetId: number) => {
|
removeUserLabel = async (targetId: number) => {
|
||||||
const userLabels = this.state.userLabels.filter(
|
const {userLabels, userLabelsToRemove} = this.state;
|
||||||
({value: {id}}) => id !== targetId,
|
const index = userLabels.findIndex(({value}) => value.id === targetId);
|
||||||
);
|
userLabelsToRemove.push(...userLabels.splice(index, 1));
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
hasUnsavedChanges: true,
|
hasUnsavedChanges: true,
|
||||||
userLabels,
|
userLabels,
|
||||||
|
userLabelsToRemove,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
saveUserLabels = () => {
|
saveUserLabels = async () => {
|
||||||
|
for (const userLabel of this.state.userLabelsToRemove) {
|
||||||
|
await userLabel.remove();
|
||||||
|
}
|
||||||
|
|
||||||
this.props.userLabels = this.state.userLabels;
|
this.props.userLabels = this.state.userLabels;
|
||||||
void saveUserLabels(this.props.userLabels);
|
void saveUserLabels(this.props.userLabels);
|
||||||
this.setState({hasUnsavedChanges: false});
|
this.setState({hasUnsavedChanges: false, userLabelsToRemove: []});
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -155,8 +163,8 @@ class App extends Component<Props, State> {
|
||||||
this.editUserLabel(event, label.id, "priority");
|
this.editUserLabel(event, label.id, "priority");
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeHandler = () => {
|
const removeHandler = async () => {
|
||||||
this.removeUserLabel(label.id);
|
await this.removeUserLabel(label.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
userLabels.push(
|
userLabels.push(
|
||||||
|
|
Loading…
Reference in New Issue