Skip to content

Commit

Permalink
minor improvements for grew history
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed Jul 22, 2024
1 parent 9de4567 commit 0be1e7e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 44 deletions.
65 changes: 24 additions & 41 deletions src/components/grewSearch/GrewHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,37 @@
</q-tooltip>
</q-btn>
</div>
<div v-if="selectedItems.some(item => item)" class="row q-pa-md rounded-borders items-center custom-frame1">
<q-btn flat icon="close" @click="unselectItems()" />
<span v-if="selectedItems.filter(item => item).length > 1">
{{ selectedItems.filter(item => item).length }} selected items
</span>
<span v-else>
1 selected item
</span>
<q-btn flat icon="delete" @click="deleteSelectedHistoryItems()"></q-btn>
</div>
<q-scroll-area style="height: 80vh;">
<q-list v-for="(record, index) in filteredHistory" bordered separator class="custom-frame2">
<q-list v-for="record in filteredHistory" bordered separator class="custom-frame2">
<q-item>
<q-item-section top avatar>
<q-item-label caption> {{ formatDate(record.date) }}</q-item-label>
<q-item-label v-if="record.type === 'rewrite'" caption> {{ record.modified_sentences }} {{ $t('grewHistory.modifiedSentences')}} </q-item-label>
<q-item-label v-else caption> {{ $t('grewHistory.noModifiedSentences') }} </q-item-label>
<q-checkbox v-model="selectedItems[index]"></q-checkbox>
<div>
<q-btn flat icon="delete" color="primary" @click="deleteHistory(record)">
<q-tooltip>
{{ $t('grewHistory.deleteHistoryItem') }}
</q-tooltip>
</q-btn>
<q-btn flat icon="content_copy" color="primary" @click="copyRequest(record)">
<q-tooltip>
{{ $t('grewHistory.copyTooltip') }}
</q-tooltip>
</q-btn>
<q-toggle v-model="record.favorite" color="primary" checked-icon="star" @update:model-value="updateHistoryFavorites(record)">
<q-tooltip v-if="!record.favorite">
{{ $t('grewHistory.favoriteTooltip[0]') }}
</q-tooltip>
<q-tooltip v-else>
{{ $t('grewHistory.favoriteTooltip[1]') }}
</q-tooltip>
</q-toggle>
</div>
</q-item-section>
<q-item-section>
<GrewCodeMirror v-model:value="record.request" :disabled="true" :line-numbers="false"></GrewCodeMirror>
</q-item-section>
<q-item-section side>
<q-btn flat icon="content_copy" color="primary" @click="copyRequest(record)">
<q-tooltip>
{{ $t('grewHistory.copyTooltip') }}
</q-tooltip>
</q-btn>
<q-toggle v-model="record.favorite" color="primary" checked-icon="star" @update:model-value="updateHistoryFavorites(record)">
<q-tooltip v-if="!record.favorite">
{{ $t('grewHistory.favoriteTooltip[0]') }}
</q-tooltip>
<q-tooltip v-else>
{{ $t('grewHistory.favoriteTooltip[1]') }}
</q-tooltip>
</q-toggle>
</q-item-section>
</q-item>
</q-list>
</q-scroll-area>
Expand All @@ -92,10 +86,10 @@ import ConfirmAction from '../ConfirmAction.vue';
import { mapActions, mapState } from 'pinia';
import { useGrewHistoryStore } from 'src/pinia/modules/grewHistory';
import { useProjectStore } from 'src/pinia/modules/project';
import { notifyMessage } from 'src/utils/notify';
import { grewHistoryRecord_t } from 'src/api/backend-types';
import { defineComponent } from 'vue';
export default defineComponent({
components: {
GrewCodeMirror,
Expand All @@ -110,15 +104,13 @@ export default defineComponent({
{ value: 'favorites', label: this.$t('grewHistory.historyTypes[3]') },
];
const confirmActionCallback = null as unknown as CallableFunction;
const selectedItems: boolean[] = [];
return {
showHistoryDial: true,
filterRequest: '',
historyTypes,
historyType: historyTypes[0],
confirmDelete: false,
confirmActionCallback,
selectedItems,
};
},
computed: {
Expand Down Expand Up @@ -155,7 +147,6 @@ export default defineComponent({
const historyItems = history.filter((record) => {
return record.request.toLowerCase().includes(this.filterRequest.toLowerCase());
}, []);
this.selectedItems = Array(historyItems.length).fill(false);
return historyItems;
},
copyRequest(record: grewHistoryRecord_t) {
Expand All @@ -165,16 +156,8 @@ export default defineComponent({
this.confirmDelete = true;
this.confirmActionCallback = method;
},
unselectItems() {
this.selectedItems.fill(false);
},
deleteSelectedHistoryItems() {
this.selectedItems.forEach((item, index) => {
if (item) {
let recordId = this.filteredHistory[index].uuid;
this.deleteHistoryItem(recordId);
}
})
deleteHistory(record: grewHistoryRecord_t) {
this.deleteHistoryItem(record.uuid);
this.getHistory();
}
},
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en-us/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ export default {
noSearchResults: 'No search results',
historyTypes: ['All', 'Search', 'Rewrite', 'Favorites'],
deleteHistory: 'Delete History',
deleteHistoryItem: 'Delete request from history',
favoriteTooltip: ['Add this request to the favorites', 'Remove this request from the favorites'],
copyTooltip: 'Copy this request',
deleteTooltip: 'Delete all the history',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/fr-fra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ export default {
noSearchResults: 'Aucun résultat de recherche',
historyTypes: ["Tout l'historique", 'Recherche', 'Réécriture', 'Favoris'],
deleteHistory: "Supprimer tout l'historique",
deleteHistoryItem: "Supprimer la requête de l'historique",
favoriteTooltip: ['Ajoutez cette requête aux favoris', 'Supprimez cette requête des favoris'],
copyTooltip: 'Copiez cette requête',
deleteTooltip: "Supprimez tout l'historique",
Expand Down
3 changes: 0 additions & 3 deletions src/pinia/modules/grewHistory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ export const useGrewHistoryStore = defineStore('grewHistory', {
deleteHistoryItem(recordId: string) {
api
.deleteHistoryRecord(useProjectStore().name, recordId)
.then(() => {
notifyMessage({ message: 'History item deleted' });
})
.catch(() => {
notifyError({ error: 'Error happened while deleting history item' });
});
Expand Down

0 comments on commit 0be1e7e

Please sign in to comment.