script[setup]: interfaces/system-collection (#18395)

* script[setup]: interfaces/system-collection

* Apply latest from main

* Align default value of includeSingleton
This commit is contained in:
Rijk van Zanten
2023-05-02 16:52:12 -04:00
committed by GitHub
parent 7c4892cfdc
commit 6d5109b201

View File

@@ -8,63 +8,52 @@
/>
</template>
<script lang="ts">
<script setup lang="ts">
import { useCollectionsStore } from '@/stores/collections';
import { computed, defineComponent } from 'vue';
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
export default defineComponent({
props: {
value: {
type: String,
default: null,
},
disabled: {
type: Boolean,
default: false,
},
includeSystem: {
type: Boolean,
default: false,
},
includeSingleton: {
type: Boolean,
default: true,
},
},
emits: ['input'],
setup(props) {
const { t } = useI18n();
const props = withDefaults(
defineProps<{
value: string | null;
disabled?: boolean;
includeSystem?: boolean;
includeSingleton?: boolean;
}>(),
{ includeSingleton: true }
);
const collectionsStore = useCollectionsStore();
defineEmits<{
(e: 'input', value: string | null): void;
}>();
const collections = computed(() => {
let collections = collectionsStore.collections;
const { t } = useI18n();
if (!props.includeSingleton) {
collections = collections.filter((collection) => collection?.meta?.singleton === false);
}
const collectionsStore = useCollectionsStore();
return [
...collections.filter((collection) => collection.collection.startsWith('directus_') === false),
...(props.includeSystem ? collectionsStore.crudSafeSystemCollections : []),
];
});
const collections = computed(() => {
let collections = collectionsStore.collections;
const items = computed(() => {
return collections.value.reduce<{ text: string; value: string }[]>((acc, collection) => {
if (collection.type !== 'alias') {
acc.push({
text: collection.name,
value: collection.collection,
});
}
if (!props.includeSingleton) {
collections = collections.filter((collection) => collection?.meta?.singleton === false);
}
return acc;
}, []);
});
return [
...collections.filter((collection) => collection.collection.startsWith('directus_') === false),
...(props.includeSystem ? collectionsStore.crudSafeSystemCollections : []),
];
});
return { items, t };
},
const items = computed(() => {
return collections.value.reduce<{ text: string; value: string }[]>((acc, collection) => {
if (collection.type !== 'alias') {
acc.push({
text: collection.name,
value: collection.collection,
});
}
return acc;
}, []);
});
</script>