Skip to content

Commit

Permalink
Work in progress for migrating a view to use the composition API and …
Browse files Browse the repository at this point in the history
…imrpove unit test runtime in large views.
  • Loading branch information
SeriousHorncat committed Oct 29, 2024
1 parent 657ebc5 commit 8330bb2
Showing 4 changed files with 50 additions and 11 deletions.
7 changes: 4 additions & 3 deletions frontend/src/components/AnalysisView/useActionMenu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ref} from 'vue';
import {StatusType} from '@/config.js';
import {StatusType, getWorkflowStatusIcon} from '@/config.js';


/**
@@ -12,8 +12,9 @@ export function useActionMenu() {
const builder = {
addWorkflowActions: (latest, operation) => {
if ( latest in StatusType ) {
for ( const [text, nextEvent] of StatusType[latest].transitions) {
builder.addMenuAction(text, StatusType[latest].icon, () => {
for ( const [text, nextEvent, nextStatus] of StatusType[latest].transitions) {
console.log(text, nextEvent, nextStatus);
builder.addMenuAction(text, getWorkflowStatusIcon(nextStatus), () => {
operation(nextEvent);
});
}
29 changes: 25 additions & 4 deletions frontend/src/config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import {EventType} from './enums';

const DEFAULT_TRANSITIONS = [['Approve', EventType.APPROVE], ['Hold', EventType.HOLD], ['Decline', EventType.DECLINE]];
const DEFAULT_TRANSITIONS = [
['Approve', EventType.APPROVE, 'Approved'],
['Hold', EventType.HOLD, 'On-Hold'],
['Decline', EventType.DECLINE, 'Declined'],
];

export const StatusType = Object.freeze({
const StatusType = Object.freeze({
'Preparation': {
icon: 'asterisk',
color: '--rosalution-status-annotation',
actionText: 'Mark Ready',
transitions: [['Mark Ready', EventType.READY]],
transitions: [['Mark Ready', EventType.READY, 'Ready']],
},
'Ready': {
icon: 'clipboard-check',
color: '--rosalution-status-ready',
transitions: [['Mark Active', EventType.OPEN]],
transitions: [['Mark Active', EventType.OPEN, 'Active']],
},
'Active': {
icon: 'book-open',
@@ -35,3 +39,20 @@ export const StatusType = Object.freeze({
transitions: DEFAULT_TRANSITIONS,
},
});

/**
* Helper method that returns the Icon for a Workflow status. If none exist for
* that status a question mark is returned.
*
* @param {String} status the workflow status
* @return {String} the string value of the icon in that workflow
*/
function getWorkflowStatusIcon(status) {
if ( status in StatusType ) {
return StatusType[status].icon;
}

return 'question';
}

export {StatusType, getWorkflowStatusIcon};
19 changes: 18 additions & 1 deletion frontend/src/stores/analysisStore.js
Original file line number Diff line number Diff line change
@@ -43,6 +43,10 @@ export const analysisStore = reactive({
this.forceUpdate(updatedAnalysis);
},

/**
* Section Images
*/

async attachSectionImage(sectionName, field, attachment) {
const updatedSectionField = await Analyses.attachSectionImage(
this.analysis.name,
@@ -75,6 +79,10 @@ export const analysisStore = reactive({
this.replaceAnalysisSection(sectionWithReplacedField);
},

/**
* Section Operations
*/

replaceFieldInSection(sectionName, updatedField) {
const sectionToUpdate = this.analysis.sections.find((section) => {
return section.header == sectionName;
@@ -96,6 +104,10 @@ export const analysisStore = reactive({
this.analysis.sections.splice(originalSectionIndex, 1, sectionToReplace);
},

/**
* Analysis Attachments
*/

async addAttachment(attachment) {
const updatedAnalysisAttachments = await Analyses.attachSupportingEvidence(
this.analysis.name,
@@ -130,8 +142,13 @@ export const analysisStore = reactive({
this.analysis.supporting_evidence_files.splice(attachmentIndex, 1);
},

/**
* Analysis Operations
*/

forceUpdate(updatedAnalysis) {
// console.log(`AnalysisStore:forceUpdate - CALLED`)
this.analysis = {...this.analysis, ...updatedAnalysis};
Object.assign(this.analysis, updatedAnalysis);
// this.analysis = {...this.analysis, ...updatedAnalysis};
},
});
6 changes: 3 additions & 3 deletions frontend/src/views/AnalysisView.vue
Original file line number Diff line number Diff line change
@@ -145,14 +145,14 @@ watch([hasWritePermissions, latestStatus], () => {
builder.clear();
if ( !authStore.hasWritePermissions() ) {
builder.addMenuAction('Attach', 'paperclip', addSupportingEvidence);
return;
}
builder.addMenuAction('Edit', 'pencil', enableEditing);
builder.addMenuAction('Attach', 'paperclip', addSupportingEvidence);
builder.addDivider();
builder.addWorkflowActions(latestStatus.value, pushAnalysisEvent);
builder.addDivider();
builder.addMenuAction('Attach', 'paperclip', addSupportingEvidence);
builder.addMenuAction('Attach Monday.com', null, addMondayLink);
builder.addMenuAction('Connect PhenoTips', null, addPhenotipsLink);
// console.log('AnalysisView::watch-latestStatus&hasWritePermissions - watch complete')

0 comments on commit 8330bb2

Please sign in to comment.