Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App migrate views #22169

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
80f93ec
migrated the v-upload component to the SDK
br41nslug Apr 9, 2024
94da9aa
migrated the basic-import-sidebar-detail component to the SDK
br41nslug Apr 9, 2024
5ec0574
migrated the comment-input component to the SDK
br41nslug Apr 9, 2024
1b0230a
migrated the comment-item-header component to the SDK
br41nslug Apr 9, 2024
4aed653
migrated the comment-item component to the SDK
br41nslug Apr 9, 2024
0578e12
migrated the comments-sidebar-detail component to the SDK
br41nslug Apr 9, 2024
a7c9841
migrated the comments-sidebar-detail component to the SDK
br41nslug Apr 9, 2024
99548cb
migrated the drawer-batch component to the SDK
br41nslug Apr 10, 2024
011bab2
migrated the drawer-item component to the SDK
br41nslug Apr 10, 2024
3447c26
migrated the export-sidebar-detail component to the SDK
br41nslug Apr 10, 2024
6dfbe2f
prettier
br41nslug Apr 10, 2024
8f8c1ba
migrated the files-navigation-folder component to the SDK
br41nslug Apr 10, 2024
c9421d2
migrated the flows-sidebar-detail component to the SDK
br41nslug Apr 11, 2024
e60f9f5
updated flow signature
br41nslug Apr 11, 2024
df8bf1f
migrated the image-editor component to the SDK
br41nslug Apr 11, 2024
73beb03
migrated the notification-drawer component to the SDK
br41nslug Apr 11, 2024
3ae182a
migrated the shares-sidebar-detail component to the SDK
br41nslug Apr 11, 2024
8302bcf
migrated the user-popover component to the SDK
br41nslug Apr 11, 2024
ed2f97e
migrated the users-invite component to the SDK
br41nslug Apr 11, 2024
eb24cab
Merge branch 'main' into app-migrate-views
br41nslug Apr 11, 2024
17b2508
prettier
br41nslug Apr 11, 2024
3032bfd
Merge branch 'app-migrate-views' of https://github.com/directus/direc…
br41nslug Apr 11, 2024
05840dc
_and/_or no longer erroring
br41nslug Apr 19, 2024
4a760d8
Removed obsolete comments and added abort controller
br41nslug Apr 22, 2024
6a9527e
Updated error extraction
br41nslug Apr 22, 2024
b7dea60
Merge branch 'main' into app-migrate-views
br41nslug Apr 22, 2024
3eadd45
prettier
br41nslug Apr 22, 2024
51cae77
Merge branch 'app-migrate-views' of https://github.com/directus/direc…
br41nslug Apr 22, 2024
242580b
prettier
br41nslug Apr 22, 2024
e5f0b5f
Create rare-chefs-hope.md
br41nslug Apr 22, 2024
02c834f
updated sdk ofetch
br41nslug Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/rare-chefs-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

Check warning on line 1 in .changeset/rare-chefs-hope.md

View workflow job for this annotation

GitHub Actions / Lint

File ignored by default.
"@directus/app": patch
"@directus/sdk": patch
---

Migrated views components in the App to the Sdk
30 changes: 15 additions & 15 deletions app/src/components/v-upload.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script setup lang="ts">
import api from '@/api';
import { emitter, Events } from '@/events';
import { unexpectedError } from '@/utils/unexpected-error';
import { uploadFile } from '@/utils/upload-file';
import { uploadFiles } from '@/utils/upload-files';
import DrawerFiles from '@/views/private/components/drawer-files.vue';
import { useSdk } from '@directus/composables';
import { importFile, readFile, readFiles } from '@directus/sdk';
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';

Expand Down Expand Up @@ -146,28 +147,29 @@ function useDragging() {
}

function useSelection() {
const sdk = useSdk();

return { setSelection };

async function setSelection(selection: (string | number)[] | null) {
if (!selection) return;

if (props.multiple) {
const filesResponse = await api.get(`/files`, {
params: {
const filesResponse = await sdk.request(
readFiles({
filter: {
id: {
_in: selection,
},
},
},
});
}),
);

emit('input', filesResponse.data.data);
emit('input', filesResponse);
} else {
if (selection[0]) {
const id = selection[0];
const fileResponse = await api.get(`/files/${id}`);
emit('input', fileResponse.data.data);
const fileResponse = await sdk.request(readFile(String(selection[0])));
emit('input', fileResponse);
} else {
emit('input', null);
}
Expand All @@ -176,6 +178,7 @@ function useSelection() {
}

function useURLImport() {
const sdk = useSdk();
const url = ref('');
const loading = ref(false);

Expand All @@ -200,17 +203,14 @@ function useURLImport() {
};

try {
const response = await api.post(`/files/import`, {
url: url.value,
data,
});
const response = await sdk.request(importFile(url.value, data));

emitter.emit(Events.upload);

if (props.multiple) {
emit('input', [response.data.data]);
emit('input', [response]);
} else {
emit('input', response.data.data);
emit('input', response);
}

activeDialog.value = null;
Expand Down
2 changes: 1 addition & 1 deletion app/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const baseClient = ofetch.create({
},
});

export const sdk: SdkClient = createDirectus(getPublicURL(), { globals: { fetch: baseClient.native } })
export const sdk: SdkClient = createDirectus(getPublicURL(), { globals: { fetch: baseClient } })
.with(authentication('session', { credentials: 'include', msRefreshBeforeExpires: 10_000 }))
.with(rest({ credentials: 'include' }));

Expand Down
18 changes: 8 additions & 10 deletions app/src/views/private/components/basic-import-sidebar-detail.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import api from '@/api';
import { useCollectionPermissions } from '@/composables/use-permissions';
import { notify } from '@/utils/notify';
import { readableMimeType } from '@/utils/readable-mime-type';
import { unexpectedError } from '@/utils/unexpected-error';
import type { AxiosProgressEvent } from 'axios';
import { useSdk } from '@directus/composables';
import { utilsImport } from '@directus/sdk';
import { computed, ref, toRefs } from 'vue';
import { useI18n } from 'vue-i18n';

Expand Down Expand Up @@ -48,6 +48,7 @@ function importData() {
}

function useUpload() {
const sdk = useSdk();
const uploading = ref(false);
const importing = ref(false);
const progress = ref(0);
Expand All @@ -63,13 +64,10 @@ function useUpload() {
formData.append('file', file);

try {
await api.post(`/utils/import/${collection.value}`, formData, {
onUploadProgress: (progressEvent: AxiosProgressEvent) => {
const percentCompleted = Math.floor((progressEvent.loaded * 100) / progressEvent.total!);
progress.value = percentCompleted;
importing.value = percentCompleted === 100 ? true : false;
},
});
await sdk.request(utilsImport(collection.value, formData));

progress.value = 100;
importing.value = false;

clearFileInput();

Expand All @@ -79,7 +77,7 @@ function useUpload() {
title: t('import_data_success', { filename: file.name }),
});
} catch (error: any) {
const code = error?.response?.data?.errors?.[0]?.extensions?.code;
const code = error?.errors?.[0]?.extensions?.code;

notify({
title: te(`errors.${code}`) ? t(`errors.${code}`) : t('import_data_error'),
Expand Down
57 changes: 33 additions & 24 deletions app/src/views/private/components/comment-input.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<script setup lang="ts">
import api from '@/api';
import { useShortcut } from '@/composables/use-shortcut';
import { Activity } from '@/types/activity';
import { getAssetUrl } from '@/utils/get-asset-url';
import { md } from '@/utils/md';
import { notify } from '@/utils/notify';
import { unexpectedError } from '@/utils/unexpected-error';
import { userName } from '@/utils/user-name';
import { useSdk } from '@directus/composables';
import { createComment, readUsers, updateComment, withOptions } from '@directus/sdk';
import { User } from '@directus/types';
import axios, { CancelTokenSource } from 'axios';
import { cloneDeep, throttle } from 'lodash';
import { ComponentPublicInstance, computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';

const sdk = useSdk();

const props = withDefaults(
defineProps<{
refresh: () => Promise<void>;
Expand Down Expand Up @@ -53,7 +55,8 @@ watch(
const saving = ref(false);
const showMentionDropDown = ref(false);

const searchResult = ref<Pick<User, 'id' | 'email' | 'first_name' | 'last_name' | 'avatar'>[]>([]);
type SearchUser = Pick<User, 'id' | 'email' | 'first_name' | 'last_name' | 'avatar'>;
const searchResult = ref<SearchUser[]>([]);
const userPreviews = ref<Record<string, string>>({});

watch(
Expand All @@ -72,14 +75,14 @@ watch(
let triggerCaretPosition = 0;
const selectedKeyboardIndex = ref<number>(0);

let cancelToken: CancelTokenSource | null = null;
let abortController: AbortController | null = null;

const loadUsers = throttle(async (name: string): Promise<any> => {
if (cancelToken !== null) {
cancelToken.cancel();
if (abortController !== null) {
abortController.abort();
}

cancelToken = axios.CancelToken.source();
abortController = new AbortController();

const regex = /\s@[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}/gi;

Expand Down Expand Up @@ -112,23 +115,25 @@ const loadUsers = throttle(async (name: string): Promise<any> => {
}

try {
const result = await api.get('/users', {
params: {
filter: name === '' || !name ? undefined : filter,
fields: ['first_name', 'last_name', 'email', 'id', 'avatar.id'],
},
cancelToken: cancelToken.token,
});
const result = await sdk.request<SearchUser[]>(
withOptions(
readUsers({
filter: name === '' || !name ? undefined : filter,
fields: ['first_name', 'last_name', 'email', 'id', 'avatar.id'],
}),
{ signal: abortController.signal },
),
);

const newUsers = cloneDeep(userPreviews.value);

result.data.data.forEach((user: any) => {
result.forEach((user: any) => {
newUsers[user.id] = userName(user);
});

userPreviews.value = newUsers;

searchResult.value = result.data.data;
searchResult.value = result;
} catch (error) {
return error;
}
Expand Down Expand Up @@ -228,15 +233,19 @@ async function postComment() {

try {
if (props.existingComment) {
await api.patch(`/activity/comment/${props.existingComment.id}`, {
comment: newCommentContent.value,
});
await sdk.request(
updateComment(props.existingComment.id, {
comment: newCommentContent.value,
}),
);
} else {
await api.post(`/activity/comment`, {
collection: props.collection,
item: props.primaryKey,
comment: newCommentContent.value,
});
await sdk.request(
createComment({
collection: props.collection,
item: String(props.primaryKey),
comment: newCommentContent.value,
}),
);
}

props.refresh();
Expand Down
7 changes: 5 additions & 2 deletions app/src/views/private/components/comment-item-header.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<script setup lang="ts">
import api from '@/api';
import { Activity } from '@/types/activity';
import { getAssetUrl } from '@/utils/get-asset-url';
import { unexpectedError } from '@/utils/unexpected-error';
import { userName } from '@/utils/user-name';
import { useSdk } from '@directus/composables';
import { deleteComment } from '@directus/sdk';
import type { User } from '@directus/types';
import { format } from 'date-fns';
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';

const sdk = useSdk();

const props = defineProps<{
activity: Activity & {
display: string;
Expand Down Expand Up @@ -48,7 +51,7 @@ function useDelete() {
deleting.value = true;

try {
await api.delete(`/activity/comment/${props.activity.id}`);
await sdk.request(deleteComment(props.activity.id));
await props.refresh();
confirmDelete.value = false;
} catch (error) {
Expand Down
9 changes: 5 additions & 4 deletions app/src/views/private/components/comment-item.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<script setup lang="ts">
import api from '@/api';
import { Activity } from '@/types/activity';
import { unexpectedError } from '@/utils/unexpected-error';
import type { User } from '@directus/types';
import { ref, watch } from 'vue';
import CommentInput from './comment-input.vue';
import CommentItemHeader from './comment-item-header.vue';
import { useSdk } from '@directus/composables';
import { updateComment } from '@directus/sdk';

const sdk = useSdk();

const props = withDefaults(
defineProps<{
Expand Down Expand Up @@ -41,9 +44,7 @@ function useEdits() {
savingEdits.value = true;

try {
await api.patch(`/activity/comment/${props.activity.id}`, {
comment: edits.value,
});
await sdk.request(updateComment(props.activity.id, { comment: edits.value }));

props.refresh();
} catch (error) {
Expand Down