Skip to content

Commit

Permalink
Merge pull request #495 from OHDSI/limit_default_sources
Browse files Browse the repository at this point in the history
Improve performance of network comparison tool
  • Loading branch information
fdefalco authored Dec 17, 2024
2 parents 0055d9c + 7c3687a commit 59ca5f6
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,58 @@
:options="getSourceOptions"
:meta-key-selection="false"
selectionMode="checkbox"
@node-select="onNodeSelect"
placeholder="Default sources"
/>
<p :class="countLeafSelections === 20 ? 'text-red-600' : ''">
Selected sources: {{ countLeafSelections }}/20
</p>
</template>

<script setup lang="ts">
import TreeSelect from "primevue/treeselect";
import { useStore } from "vuex";
import { computed, onBeforeMount, ref, watch } from "vue";
import { UPDATE_DEFAULT_SOURCES } from "@/widgets/settings/model/store/actions.type";
import { ADD_ALERT } from "@/widgets/snackbar/model/store/actions.type";
const store = useStore();
const countLeafSelections = computed(() => {
return Object.keys(selectedDefaultSources.value).filter(
(key) => key.split("-")[1]
).length;
});
const onNodeSelect = (node) => {
if (node.children) {
const overLimit = -20 + countLeafSelections.value;
if (overLimit > 0) {
store.dispatch(ADD_ALERT, {
status: "",
message: "Reached default sources limit",
});
const extraElements = node.children.slice(-overLimit);
for (const extraElement in extraElements) {
delete selectedDefaultSources.value[extraElements[extraElement].key];
}
if (overLimit === node.children.length) {
delete selectedDefaultSources.value[node.key];
} else {
selectedDefaultSources.value[node.key].partialChecked = true;
}
}
} else {
if (countLeafSelections.value >= 21) {
store.dispatch(ADD_ALERT, {
status: "",
message: "Reached default sources limit",
});
delete selectedDefaultSources.value[node.key];
}
}
};
const selectedDefaultSources = ref({});
const getParsedSelectedSources = computed(() => {
Expand Down

0 comments on commit 59ca5f6

Please sign in to comment.