Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Dec 20, 2024
1 parent 9b07310 commit 28619d4
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 86 deletions.
15 changes: 12 additions & 3 deletions web/src/core/usecases/dataExplorer/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const columns = createSelector(
createSelector(
createSelector(state, state => state.data),
data => {
if (data === undefined) {
if (data.state !== "loaded") {
return undefined;
}

Expand Down Expand Up @@ -45,12 +45,21 @@ const main = createSelector(state, columns, (state, columns) => {
return { isQuerying, errorMessage: errorMessage };
}

if (data === undefined) {
return { isQuerying, rows: undefined };
if (data.state === "empty") {
return {
isQuerying,
rows: undefined
};
}

if (data.state === "unknownFileType") {
return { isQuerying, queryParams, shouldAskFileType: true };
}

assert(columns !== undefined);
assert(queryParams !== undefined);
assert(queryParams.rowsPerPage !== undefined);
assert(queryParams.page !== undefined);
assert(extraRestorableStates !== undefined);

const { rowsPerPage, page } = queryParams;
Expand Down
52 changes: 43 additions & 9 deletions web/src/core/usecases/dataExplorer/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export type State = {
queryParams:
| {
sourceUrl: string;
rowsPerPage: number;
page: number;
rowsPerPage: number | undefined;
page: number | undefined;
}
| undefined;
extraRestorableStates:
Expand All @@ -22,12 +22,14 @@ export type State = {
errorMessage: string | undefined;
data:
| {
state: "loaded";
rows: any[];
rowCount: number | undefined;
fileDownloadUrl: string;
// fileType: "parquet" | "csv" | "json";
fileType: "parquet" | "csv" | "json";
}
| undefined;
| { state: "unknownFileType"; fileType: undefined; fileDownloadUrl: string }
| { state: "empty" };
};

export const { actions, reducer } = createUsecaseActions({
Expand All @@ -37,7 +39,7 @@ export const { actions, reducer } = createUsecaseActions({
queryParams: undefined,
extraRestorableStates: undefined,
errorMessage: undefined,
data: undefined
data: { state: "empty" }
}),
reducers: {
queryStarted: (
Expand Down Expand Up @@ -96,10 +98,42 @@ export const { actions, reducer } = createUsecaseActions({
assert(state.extraRestorableStates !== undefined);
state.extraRestorableStates.columnVisibility = columnVisibility;
},
querySucceeded: (state, { payload }: { payload: NonNullable<State["data"]> }) => {
const { rowCount, rows, fileDownloadUrl } = payload;

querySucceeded: (
state,
{
payload
}: {
payload: {
rows: any[];
rowCount: number | undefined;
fileDownloadUrl: string;
fileType: "parquet" | "csv" | "json";
};
}
) => {
const { rowCount, rows, fileDownloadUrl, fileType } = payload;
state.isQuerying = false;
state.data = { state: "loaded", rowCount, rows, fileDownloadUrl, fileType };
},
//Rename this, i want to end query because not able to auto detect fileType
terminateQueryDueToUnknownFileType: (
state,
{
payload
}: {
payload: {
fileDownloadUrl: string;
};
}
) => {
const { fileDownloadUrl } = payload;
state.isQuerying = false;
state.data = { rowCount, rows, fileDownloadUrl };
state.data = {
state: "unknownFileType",
fileDownloadUrl,
fileType: undefined
};
},
queryCanceled: state => {
state.isQuerying = false;
Expand All @@ -114,7 +148,7 @@ export const { actions, reducer } = createUsecaseActions({
restoreState: state => {
state.queryParams = undefined;
state.extraRestorableStates = undefined;
state.data = undefined;
state.data = { state: "empty" };
}
}
});
Loading

0 comments on commit 28619d4

Please sign in to comment.