Skip to content

Commit

Permalink
Add default query; various touch ups
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanLeRoy committed May 17, 2024
1 parent 94a5301 commit 7a7d43e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
7 changes: 7 additions & 0 deletions packages/core/components/QuerySidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export default function QuerySidebar(props: QuerySidebarProps) {
const dataSources = useSelector(interaction.selectors.getAllDataSources);
const currentGlobalURL = useSelector(selection.selectors.getEncodedFileExplorerUrl);

// Select query by default if none is selected
React.useEffect(() => {
if (!selectedQuery && queries.length) {
dispatch(selection.actions.changeQuery(queries[0]));
}
}, [selectedQuery, queries, dispatch]);

// Determine a default query to render or prompt the user for a data source
// if no default is accessible
React.useEffect(() => {
Expand Down
5 changes: 4 additions & 1 deletion packages/core/entity/FileDetail/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ export default class FileDetail {

public get size(): number | undefined {
const size = this.fileDetail.file_size || this.getFirstAnnotationValue("File Size");
if (size === undefined || typeof size === "number") {
if (size === undefined) {
return 0; // Default to 0 if size is not defined for now, need better system
}
if (typeof size === "number") {
return size;
}
return parseInt(size as string, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,16 @@ export default class DatabaseFileService implements FileService {
// If the file system is accessible we can just have DuckDB write the
// output query directly to the system rather than to a buffer then the file
if (this.downloadService.isFileSystemAccessible) {
const downloadDir = this.downloadService.getDefaultDownloadDirectory();
const destination = `${downloadDir}file-selection-${new Date()}`;
const downloadDir = await this.downloadService.getDefaultDownloadDirectory();
const lowerCaseUserAgent = navigator.userAgent.toLowerCase();
const separator = lowerCaseUserAgent.includes("Windows") ? "\\" : "/";
const destination = `${downloadDir}${separator}file-selection-${Date.now().toLocaleString(
"en-us"
)}`;
await this.databaseService.saveQuery(destination, sqlBuilder.toSQL(), format);
return {
downloadRequestId: uniqueId(),
msg: `File downloaded to ${destination}.${format}`,
resolution: DownloadResolution.SUCCESS,
};
}
Expand Down
5 changes: 3 additions & 2 deletions packages/core/services/FileService/HttpFileService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ export default class HttpFileService extends HttpServiceBase implements FileServ
*/
public async isNetworkAccessible(): Promise<boolean> {
try {
await this.get(`${this.baseUrl}/`);
await this.get(`${this.baseUrl}/${HttpFileService.BASE_FILE_COUNT_URL}`);
return true;
} catch {
} catch (error) {
console.error(`Unable to access AICS network ${error}`);
return false;
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/core/state/interaction/logics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const downloadManifest = createLogic({
dispatch(
processStart(
manifestDownloadProcessId,
"Download of CSV manifest in progress.",
"Download of metadata manifest in progress.",
onManifestDownloadCancel
)
);
Expand All @@ -112,11 +112,13 @@ const downloadManifest = createLogic({
if (result.resolution === DownloadResolution.CANCELLED) {
dispatch(removeStatus(manifestDownloadProcessId));
} else {
const successMsg = `Download of CSV manifest finished.<br/>${result.msg}`;
const successMsg = `Download of metadata manifest finished.<br/>${
result.msg || ""
}`;
dispatch(processSuccess(manifestDownloadProcessId, successMsg));
}
} catch (err) {
const errorMsg = `Download of CSV manifest failed. Details: ${
const errorMsg = `Download of metadata manifest failed. Details: ${
err instanceof Error ? err.message : err
}`;
dispatch(processFailure(manifestDownloadProcessId, errorMsg));
Expand Down
4 changes: 4 additions & 0 deletions packages/web/src/services/NotificationServiceWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ export default class NotificationServiceWeb implements NotificationService {
public async showError(): Promise<void> {
throw new Error("NotificationServiceWeb::showError is not yet implemented");
}

public async showQuestion(): Promise<boolean> {
throw new Error("NotificationServiceWeb::showQuestion is not yet implemented");
}
}

0 comments on commit 7a7d43e

Please sign in to comment.