mirror of
https://github.com/directus/directus.git
synced 2026-01-29 22:57:55 -05:00
has-edits as part of use-item (#11016)
This commit is contained in:
@@ -17,6 +17,7 @@ import { translate } from '@/utils/translate-object-values';
|
||||
|
||||
type UsableItem = {
|
||||
edits: Ref<Record<string, any>>;
|
||||
hasEdits: Ref<boolean>;
|
||||
item: Ref<Record<string, any> | null>;
|
||||
error: Ref<any>;
|
||||
loading: Ref<boolean>;
|
||||
@@ -45,6 +46,7 @@ export function useItem(collection: Ref<string>, primaryKey: Ref<string | number
|
||||
const deleting = ref(false);
|
||||
const archiving = ref(false);
|
||||
const edits = ref<Record<string, any>>({});
|
||||
const hasEdits = computed(() => Object.keys(edits.value).length > 0);
|
||||
const isNew = computed(() => primaryKey.value === '+');
|
||||
const isBatch = computed(() => typeof primaryKey.value === 'string' && primaryKey.value.includes(','));
|
||||
const isSingle = computed(() => !!collectionInfo.value?.meta?.singleton);
|
||||
@@ -71,6 +73,7 @@ export function useItem(collection: Ref<string>, primaryKey: Ref<string | number
|
||||
|
||||
return {
|
||||
edits,
|
||||
hasEdits,
|
||||
item,
|
||||
error,
|
||||
loading,
|
||||
|
||||
@@ -266,6 +266,7 @@ export default defineComponent({
|
||||
const {
|
||||
isNew,
|
||||
edits,
|
||||
hasEdits,
|
||||
item,
|
||||
saving,
|
||||
loading,
|
||||
@@ -283,8 +284,6 @@ export default defineComponent({
|
||||
|
||||
const { templateData, loading: templateDataLoading } = useTemplateData(collectionInfo, primaryKey);
|
||||
|
||||
const hasEdits = computed(() => Object.keys(edits.value).length > 0);
|
||||
|
||||
const isSavable = computed(() => {
|
||||
if (saveAllowed.value === false) return false;
|
||||
if (hasEdits.value === true) return true;
|
||||
|
||||
@@ -235,6 +235,7 @@ export default defineComponent({
|
||||
const {
|
||||
isNew,
|
||||
edits,
|
||||
hasEdits,
|
||||
item,
|
||||
saving,
|
||||
loading,
|
||||
@@ -248,8 +249,6 @@ export default defineComponent({
|
||||
validationErrors,
|
||||
} = useItem(ref('directus_files'), primaryKey);
|
||||
|
||||
const hasEdits = computed<boolean>(() => Object.keys(edits.value).length > 0);
|
||||
|
||||
unsavedChanges(hasEdits);
|
||||
|
||||
const confirmDelete = ref(false);
|
||||
|
||||
@@ -139,13 +139,11 @@ export default defineComponent({
|
||||
const userInviteModalActive = ref(false);
|
||||
const { primaryKey } = toRefs(props);
|
||||
|
||||
const { edits, item, saving, loading, error, save, remove, deleting, isBatch } = useItem(
|
||||
const { edits, hasEdits, item, saving, loading, error, save, remove, deleting, isBatch } = useItem(
|
||||
ref('directus_roles'),
|
||||
primaryKey
|
||||
);
|
||||
|
||||
const hasEdits = computed<boolean>(() => Object.keys(edits.value).length > 0);
|
||||
|
||||
const confirmDelete = ref(false);
|
||||
|
||||
const adminEnabled = computed(() => {
|
||||
|
||||
@@ -114,6 +114,7 @@ export default defineComponent({
|
||||
const {
|
||||
isNew,
|
||||
edits,
|
||||
hasEdits,
|
||||
item,
|
||||
saving,
|
||||
loading,
|
||||
@@ -126,7 +127,6 @@ export default defineComponent({
|
||||
validationErrors,
|
||||
} = useItem(ref('directus_webhooks'), primaryKey);
|
||||
|
||||
const hasEdits = computed<boolean>(() => Object.keys(edits.value).length > 0);
|
||||
const confirmDelete = ref(false);
|
||||
|
||||
const title = computed(() => {
|
||||
|
||||
@@ -238,6 +238,7 @@ export default defineComponent({
|
||||
const {
|
||||
isNew,
|
||||
edits,
|
||||
hasEdits,
|
||||
item,
|
||||
saving,
|
||||
loading,
|
||||
@@ -259,8 +260,6 @@ export default defineComponent({
|
||||
};
|
||||
}
|
||||
|
||||
const hasEdits = computed<boolean>(() => Object.keys(edits.value).length > 0);
|
||||
|
||||
unsavedChanges(hasEdits);
|
||||
|
||||
const confirmDelete = ref(false);
|
||||
|
||||
Reference in New Issue
Block a user