Skip to content

Commit 1f054b0

Browse files
authored
client: fix PermissionsEditor not propagating changes to parent (#1412)
* client: fix `PermissionsEditor` not propagating changes to parent * format
1 parent fd6b128 commit 1f054b0

File tree

1 file changed

+8
-35
lines changed

1 file changed

+8
-35
lines changed

client/src/components/PermissionsEditor.vue

+8-35
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
v-model="item[r - 1]"
3232
:disabled="getLowestGranted(item) < r - 1"
3333
color="primary"
34+
@update:model-value="onCheckboxModified"
3435
/>
3536
<v-checkbox v-else v-model="item[r - 1]" :disabled="true" />
3637
</td>
@@ -41,7 +42,7 @@
4142
</template>
4243

4344
<script lang="ts">
44-
import { defineComponent, ref, Ref, watch, PropType } from "vue";
45+
import { defineComponent, ref, Ref, PropType } from "vue";
4546
import _ from "lodash";
4647
import { granted } from "@/util/grants";
4748
import { PERMISSIONS, ROLE_NAMES, Permission, Grants } from "ott-common/permissions";
@@ -62,10 +63,7 @@ export const PermissionsEditor = defineComponent({
6263
emits: ["update:modelValue"],
6364
setup(props, { emit }) {
6465
const permissions: Ref<Permission[]> = ref([]);
65-
const dirty = ref(false);
66-
const shouldAcceptExternalUpdate = ref(true);
6766
const isLoading = ref(false);
68-
const updateEpoch = ref(0);
6967
7068
const rolePerms = {
7169
[Role.Moderator]: "configure-room.set-permissions.for-moderator",
@@ -131,47 +129,22 @@ export const PermissionsEditor = defineComponent({
131129
return new Grants(grants);
132130
}
133131
134-
watch(props, () => {
135-
if (shouldAcceptExternalUpdate.value) {
136-
dirty.value = false;
137-
updateEpoch.value++;
138-
permissions.value = extractFromGrants(props.modelValue);
139-
} else {
140-
shouldAcceptExternalUpdate.value = true;
141-
}
142-
});
143-
144-
watch(
145-
permissions,
146-
() => {
147-
if (!dirty.value) {
148-
dirty.value = true;
149-
shouldAcceptExternalUpdate.value = false;
150-
permissions.value = extractFromGrants(rebuildMasks());
151-
}
152-
},
153-
{ deep: true }
154-
);
155-
156-
watch(dirty, val => {
157-
if (val) {
158-
emit("update:modelValue", rebuildMasks());
159-
dirty.value = false;
160-
}
161-
});
132+
function onCheckboxModified() {
133+
const masks = rebuildMasks();
134+
permissions.value = extractFromGrants(masks);
135+
emit("update:modelValue", masks);
136+
}
162137
163138
return {
164139
permissions,
165-
dirty,
166-
shouldAcceptExternalUpdate,
167140
isLoading,
168-
updateEpoch,
169141
granted,
170142
ROLE_NAMES,
171143
getLowestGranted,
172144
getHighestDenied,
173145
rolePerms,
174146
Role,
147+
onCheckboxModified,
175148
};
176149
},
177150
});

0 commit comments

Comments
 (0)