Skip to content

Commit 591bc47

Browse files
committed
fix(savedViews): Update QuerySavedViewProcess for single-view mode to also add quick-view attributes to the found view (namely, to replace its label)
1 parent 2aa0e94 commit 591bc47

File tree

2 files changed

+84
-3
lines changed

2 files changed

+84
-3
lines changed

qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/savedviews/QuerySavedViewProcess.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,13 @@ public void run(RunBackendStepInput runBackendStepInput, RunBackendStepOutput ru
110110
throw (new QNotFoundException("The requested view was not found."));
111111
}
112112

113-
runBackendStepOutput.addRecord(output.getRecord());
114-
runBackendStepOutput.addValue("savedView", output.getRecord());
115-
runBackendStepOutput.addValue("savedViewList", (Serializable) List.of(output.getRecord()));
113+
List<QRecord> recordList = List.of(output.getRecord());
114+
115+
lookupQuickViews(runBackendStepInput, recordList);
116+
117+
runBackendStepOutput.addRecord(recordList.get(0));
118+
runBackendStepOutput.addValue("savedView", recordList.get(0));
119+
runBackendStepOutput.addValue("savedViewList", (Serializable) recordList);
116120
}
117121
else
118122
{

qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/processes/implementations/savedviews/QuerySavedViewProcessTest.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
3030
import com.kingsrook.qqq.backend.core.context.QContext;
3131
import com.kingsrook.qqq.backend.core.exceptions.QException;
32+
import com.kingsrook.qqq.backend.core.exceptions.QNotFoundException;
3233
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
3334
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessInput;
3435
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessOutput;
@@ -49,7 +50,9 @@
4950
import org.junit.jupiter.api.AfterEach;
5051
import org.junit.jupiter.api.BeforeEach;
5152
import org.junit.jupiter.api.Test;
53+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
5254
import static org.junit.jupiter.api.Assertions.assertEquals;
55+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5356
import static org.junit.jupiter.api.Assertions.assertNull;
5457
import static org.junit.jupiter.api.Assertions.assertTrue;
5558

@@ -82,6 +85,64 @@ void afterEach()
8285

8386

8487

88+
/*******************************************************************************
89+
**
90+
*******************************************************************************/
91+
@Test
92+
void testSingleViewFetch() throws Exception
93+
{
94+
QInstance qInstance = QContext.getQInstance();
95+
new SavedViewsMetaDataProvider()
96+
.withIsQuickSavedViewEnabled(true)
97+
.defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
98+
String tableName = TestUtils.TABLE_NAME_PERSON_MEMORY;
99+
100+
///////////////////////////////////////////////////
101+
// make sure a not-found view throws as expected //
102+
///////////////////////////////////////////////////
103+
{
104+
assertThatThrownBy(() -> runQuerySavedViewsProcessForSingleView(tableName, -1))
105+
.isInstanceOf(QNotFoundException.class);
106+
}
107+
108+
/////////////////////////////////////////////////////
109+
// insert one saved view, but no quick saved views //
110+
/////////////////////////////////////////////////////
111+
Integer savedViewId;
112+
{
113+
savedViewId = new InsertAction().execute(new InsertInput(SavedView.TABLE_NAME).withRecordEntity(
114+
new SavedView().withTableName(tableName).withLabel("one").withUserId(QContext.getQSession().getUser().getIdReference()))).getRecords().get(0).getValueInteger("id");
115+
116+
QRecord savedView = runQuerySavedViewsProcessForSingleView(tableName, savedViewId);
117+
118+
assertNotNull(savedView);
119+
assertEquals("one", savedView.getValue("label"));
120+
assertNull(savedView.getValue("type"));
121+
}
122+
123+
///////////////////////////////////////////////////////////
124+
// insert a quick saved view referencing that saved view //
125+
///////////////////////////////////////////////////////////
126+
{
127+
new InsertAction().execute(new InsertInput(QuickSavedView.TABLE_NAME).withRecordEntity(
128+
new QuickSavedView().withLabel("Quickly").withSavedViewId(savedViewId).withDoCount(true).withSortOrder(17)));
129+
130+
QRecord savedView = runQuerySavedViewsProcessForSingleView(tableName, savedViewId);
131+
assertNotNull(savedView);
132+
133+
//////////////////////////////////////////////////////
134+
// attributes should come from the quick-saved view //
135+
//////////////////////////////////////////////////////
136+
assertEquals("quickView", savedView.getValue("type"));
137+
assertEquals("Quickly", savedView.getValue("label"));
138+
assertTrue(savedView.getValueBoolean("doCount"));
139+
assertEquals(17, savedView.getValue("sortOrder"));
140+
}
141+
142+
}
143+
144+
145+
85146
/*******************************************************************************
86147
**
87148
*******************************************************************************/
@@ -305,6 +366,22 @@ void testUserIdLock() throws Exception
305366

306367

307368

369+
/***************************************************************************
370+
*
371+
***************************************************************************/
372+
private static QRecord runQuerySavedViewsProcessForSingleView(String tableName, Integer id) throws QException
373+
{
374+
RunProcessInput runProcessInput = new RunProcessInput();
375+
runProcessInput.setProcessName(QuerySavedViewProcess.getProcessMetaData().getName());
376+
runProcessInput.addValue("tableName", tableName);
377+
runProcessInput.addValue("id", id);
378+
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
379+
QRecord savedView = (QRecord) runProcessOutput.getValue("savedView");
380+
return savedView;
381+
}
382+
383+
384+
308385
/***************************************************************************
309386
*
310387
***************************************************************************/

0 commit comments

Comments
 (0)