Change some API calls to use getEndpoint utility (#8180)

This commit is contained in:
Azri Kahar
2021-09-21 12:20:01 +08:00
committed by GitHub
parent b9815ee1e4
commit cf11946f1d
4 changed files with 8 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import { addRelatedPrimaryKeyToFields } from '@/utils/add-related-primary-key-to
import { cloneDeep, get, merge } from 'lodash';
import { Ref, ref, watch } from 'vue';
import { RelationInfo } from './use-relation';
import { getEndpoint } from '@/utils/get-endpoint';
type UsablePreview = {
tableHeaders: Ref<Header[]>;
@@ -194,11 +195,9 @@ export default function usePreview(
) {
if (fields === null || fields.length === 0 || primaryKeys === null || primaryKeys.length === 0) return [];
const endpoint = collection.startsWith('directus_') ? `/${collection.substring(9)}` : `/items/${collection}`;
const fieldsToFetch = addRelatedPrimaryKeyToFields(collection, fields);
const response = await api.get(endpoint, {
const response = await api.get(getEndpoint(collection), {
params: {
fields: fieldsToFetch,
[`filter[${filteredField}][_in]`]: primaryKeys.join(','),

View File

@@ -38,6 +38,7 @@ import DrawerItem from '@/views/private/components/drawer-item';
import { unexpectedError } from '@/utils/unexpected-error';
import { getFieldsFromTemplate } from '@directus/shared/utils';
import { adjustFieldsForDisplays } from '@/utils/adjust-fields-for-displays';
import { getEndpoint } from '@/utils/get-endpoint';
import { useI18n } from 'vue-i18n';
export default defineComponent({
@@ -128,7 +129,7 @@ export default defineComponent({
try {
const sort = props.sortField;
const res = await api.get(`/items/${props.collection}`, {
const res = await api.get(getEndpoint(props.collection), {
params: {
fields: [
primaryKeyField.value.field,

View File

@@ -17,6 +17,7 @@ import { Filter } from '@directus/shared/types';
import { useI18n } from 'vue-i18n';
import { abbreviateNumber } from '@/utils/abbreviate-number';
import { isNil } from 'lodash';
import { getEndpoint } from '@/utils/get-endpoint';
export default defineComponent({
props: {
@@ -156,7 +157,7 @@ export default defineComponent({
[props.function]: [props.field || '*'],
};
const res = await api.get(`/items/${props.collection}`, {
const res = await api.get(getEndpoint(props.collection), {
params: {
aggregate,
filter: props.filter,

View File

@@ -12,6 +12,7 @@ import { isEqual, isNil } from 'lodash';
import { useFieldsStore } from '@/stores';
import { Filter } from '@directus/shared/types';
import { abbreviateNumber } from '@/utils/abbreviate-number';
import { getEndpoint } from '@/utils/get-endpoint';
export default defineComponent({
props: {
@@ -134,7 +135,7 @@ export default defineComponent({
loading.value = true;
try {
const results = await api.get(`/items/${props.collection}`, {
const results = await api.get(getEndpoint(props.collection), {
params: {
groupBy: getGroups(),
aggregate: {