From 33d139e3aa41b341914e3ee2380e11e9cef606f2 Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Thu, 22 Aug 2024 19:14:56 +0200 Subject: [PATCH] add mass updates to time entry aggregate rows, make package actions run on manual dispatch --- .github/workflows/npm-publish-api.yml | 3 +- .github/workflows/npm-publish-ui.yml | 3 +- resources/js/Pages/Time.vue | 6 +-- .../src/TimeEntry/TimeEntryAggregateRow.vue | 39 ++++++++----------- .../src/TimeEntry/TimeEntryGroupedTable.vue | 2 +- resources/js/utils/useTimeEntries.ts | 26 +++++++++++++ 6 files changed, 48 insertions(+), 31 deletions(-) diff --git a/.github/workflows/npm-publish-api.yml b/.github/workflows/npm-publish-api.yml index 173c715a..1a6bdc7d 100644 --- a/.github/workflows/npm-publish-api.yml +++ b/.github/workflows/npm-publish-api.yml @@ -1,6 +1,5 @@ name: Publish API package to NPM -on: - push: +on: workflow_dispatch jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/npm-publish-ui.yml b/.github/workflows/npm-publish-ui.yml index da1caa0c..c3d166d7 100644 --- a/.github/workflows/npm-publish-ui.yml +++ b/.github/workflows/npm-publish-ui.yml @@ -1,6 +1,5 @@ name: Publish UI package to NPM -on: - push: +on: workflow_dispatch jobs: build: runs-on: ubuntu-latest diff --git a/resources/js/Pages/Time.vue b/resources/js/Pages/Time.vue index 6dcdd530..9bcd2e5a 100644 --- a/resources/js/Pages/Time.vue +++ b/resources/js/Pages/Time.vue @@ -32,10 +32,8 @@ const { timeEntries, allTimeEntriesLoaded } = storeToRefs(timeEntriesStore); const { updateTimeEntry, fetchTimeEntries, createTimeEntry } = useTimeEntriesStore(); -function updateTimeEntries(timeEntries: TimeEntry[]) { - timeEntries.forEach((entry) => { - useTimeEntriesStore().updateTimeEntry(entry); - }); +function updateTimeEntries(ids: string[], changes: Partial) { + useTimeEntriesStore().updateTimeEntries(ids, changes); fetchTimeEntries(); } diff --git a/resources/js/packages/ui/src/TimeEntry/TimeEntryAggregateRow.vue b/resources/js/packages/ui/src/TimeEntry/TimeEntryAggregateRow.vue index 81811e96..6408f288 100644 --- a/resources/js/packages/ui/src/TimeEntry/TimeEntryAggregateRow.vue +++ b/resources/js/packages/ui/src/TimeEntry/TimeEntryAggregateRow.vue @@ -34,45 +34,37 @@ const props = defineProps<{ createProject: (project: CreateProjectBody) => Promise; createClient: (client: CreateClientBody) => Promise; onStartStopClick: (timeEntry: TimeEntry) => void; - updateTimeEntries: (timeEntries: TimeEntry[]) => void; + updateTimeEntries: (ids: string[], changes: Partial) => void; deleteTimeEntries: (timeEntries: TimeEntry[]) => void; currency: string; }>(); function updateTimeEntryDescription(description: string) { - const updatedTimeEntries = props.timeEntry.timeEntries.map( - (entry: TimeEntry) => { - return { ...entry, description }; - } + props.updateTimeEntries( + props.timeEntry.timeEntries.map((timeEntry: TimeEntry) => timeEntry.id), + { description: description } ); - props.updateTimeEntries(updatedTimeEntries); } function updateTimeEntryTags(tags: string[]) { - const updatedTimeEntries = props.timeEntry.timeEntries.map( - (entry: TimeEntry) => { - return { ...entry, tags }; - } + props.updateTimeEntries( + props.timeEntry.timeEntries.map((timeEntry: TimeEntry) => timeEntry.id), + { tags: tags } ); - props.updateTimeEntries(updatedTimeEntries); } function updateTimeEntryBillable(billable: boolean) { - const updatedTimeEntries = props.timeEntry.timeEntries.map( - (entry: TimeEntry) => { - return { ...entry, billable }; - } + props.updateTimeEntries( + props.timeEntry.timeEntries.map((timeEntry: TimeEntry) => timeEntry.id), + { billable: billable } ); - props.updateTimeEntries(updatedTimeEntries); } function updateProjectAndTask(projectId: string, taskId: string) { - const updatedTimeEntries = props.timeEntry.timeEntries.map( - (entry: TimeEntry) => { - return { ...entry, project_id: projectId, task_id: taskId }; - } + props.updateTimeEntries( + props.timeEntry.timeEntries.map((timeEntry: TimeEntry) => timeEntry.id), + { project_id: projectId, task_id: taskId } ); - props.updateTimeEntries(updatedTimeEntries); } const expanded = ref(false); @@ -163,7 +155,10 @@ const expanded = ref(false); :createProject :tags="tags" indent - :updateTimeEntry="(arg: TimeEntry) => updateTimeEntries([arg])" + :updateTimeEntry=" + (timeEntry: TimeEntry) => + updateTimeEntries([timeEntry.id], { ...timeEntry }) + " :onStartStopClick="() => onStartStopClick(subEntry)" :deleteTimeEntry="() => deleteTimeEntries([subEntry])" :currency="currency" diff --git a/resources/js/packages/ui/src/TimeEntry/TimeEntryGroupedTable.vue b/resources/js/packages/ui/src/TimeEntry/TimeEntryGroupedTable.vue index 419f3731..272a99a3 100644 --- a/resources/js/packages/ui/src/TimeEntry/TimeEntryGroupedTable.vue +++ b/resources/js/packages/ui/src/TimeEntry/TimeEntryGroupedTable.vue @@ -28,7 +28,7 @@ const props = defineProps<{ clients: Client[]; createTag: (name: string) => Promise; updateTimeEntry: (entry: TimeEntry) => void; - updateTimeEntries: (entries: TimeEntry[]) => void; + updateTimeEntries: (ids: string[], changes: Partial) => void; deleteTimeEntries: (entries: TimeEntry[]) => void; createTimeEntry: (entry: Omit) => void; createProject: (project: CreateProjectBody) => Promise; diff --git a/resources/js/utils/useTimeEntries.ts b/resources/js/utils/useTimeEntries.ts index d709914d..28c7ab28 100644 --- a/resources/js/utils/useTimeEntries.ts +++ b/resources/js/utils/useTimeEntries.ts @@ -77,6 +77,31 @@ export const useTimeEntriesStore = defineStore('timeEntries', () => { } } + async function updateTimeEntries( + ids: string[], + changes: Partial + ) { + const organizationId = getCurrentOrganizationId(); + if (organizationId) { + await handleApiRequestNotifications( + () => + api.updateMultipleTimeEntries( + { + ids: ids, + changes: changes, + }, + { + params: { + organization: organizationId, + }, + } + ), + 'Time entries updated successfully', + 'Failed to update time entries' + ); + } + } + async function updateTimeEntry(timeEntry: TimeEntry) { const organizationId = getCurrentOrganizationId(); if (organizationId) { @@ -147,5 +172,6 @@ export const useTimeEntriesStore = defineStore('timeEntries', () => { deleteTimeEntry, fetchMoreTimeEntries, allTimeEntriesLoaded, + updateTimeEntries, }; });