Skip to content

Commit

Permalink
Better loading screen behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
whscullin committed Nov 27, 2024
1 parent 3c2634c commit d5cdf54
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ export const ExploreQueryEditor: React.FC<ExploreQueryEditorProps> = ({
}) => {
const [result, setResult] = useState<MalloyResult>();
const [error, setError] = useState<Error>();
const [_lastRunQuery, setLastRunQuery] = useState<string>();

const query = queryWriter.getQueryStringForNotebook();
const {isRunnable} = querySummary ?? {isRunnable: false};

const runQueryCallback = React.useCallback(() => {
if (!isRunnable || !query) {
return;
}
setResult(undefined);
setError(undefined);
setLastRunQuery(query);
runQuery(query);
}, [isRunnable, query, runQuery]);
const runQueryCallback = React.useCallback(
(query: string) => {
if (!isRunnable) {
return;
}
setResult(undefined);
setError(undefined);
runQuery(query);
},
[isRunnable, runQuery]
);

useEffect(() => {
if (currentResult instanceof Error) {
Expand All @@ -86,6 +86,7 @@ export const ExploreQueryEditor: React.FC<ExploreQueryEditorProps> = ({
modelPath={modelPath}
queryModifiers={queryModifiers}
querySummary={querySummary}
queryWriter={queryWriter}
source={source}
refreshModel={refreshModel}
runQuery={runQueryCallback}
Expand Down
17 changes: 14 additions & 3 deletions packages/query-composer/src/components/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {QueryModifiers} from '../../hooks';
import {QuerySummary} from '../../types';
import styled from 'styled-components';
import {SearchContext} from '../../contexts/search_context';
import {QueryWriter} from '../../core/query';

const useLoad = true;

Expand All @@ -27,7 +28,8 @@ export interface QueryEditorProps {
refreshModel?: () => void;
queryModifiers: QueryModifiers;
querySummary: QuerySummary | undefined;
runQuery: () => void;
queryWriter: QueryWriter;
runQuery: (query: string) => void;
source: SourceDef;
topValues: SearchValueMapResult[] | undefined;
}
Expand All @@ -38,17 +40,21 @@ export const QueryEditor = ({
modelPath,
queryModifiers,
querySummary,
queryWriter,
refreshModel,
runQuery,
source,
topValues,
}: QueryEditorProps) => {
const [insertOpen, setInsertOpen] = useState(false);
const [loadOpen, setLoadOpen] = useState(false);
const [lastRunQuery, setLastRunQuery] = useState<string>('');

const isQueryEmpty = !querySummary || querySummary.stages.length === 0;
const {isRunnable} = querySummary ?? {isRunnable: false};

const query = queryWriter.getQueryStringForNotebook();

const clearQuery = () => {
queryModifiers.clearQuery();
};
Expand All @@ -61,7 +67,12 @@ export const QueryEditor = ({
queryModifiers.loadQuery(name);
};

const dirty = false; // query !== lastRunQuery;
const dirty = query !== lastRunQuery;

const onRun = () => {
setLastRunQuery(query);
runQuery(query);
};

return (
<SearchContext.Provider value={{topValues}}>
Expand Down Expand Up @@ -125,7 +136,7 @@ export const QueryEditor = ({
/>
<StyledRunIcon
width="80px"
onClick={runQuery}
onClick={onRun}
className={
isRunning
? 'running'
Expand Down
2 changes: 1 addition & 1 deletion src/app/CommonElements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const EmptyMessage = styled.div`
text-align: center;
margin-top: 30px;
margin-bottom: 30px;
font-family: Roboto;
font-family: var(--malloy-composer-fontFamily, sans-serif);
text-transform: none;
font-size: 16px;
font-weight: normal;
Expand Down
32 changes: 15 additions & 17 deletions src/app/Explore/Explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ export const Explore: React.FC = () => {
isRunning,
} = useRunQuery(modelDef, modelPath, runQueryExt);

useEffect(() => {
reset();
}, [querySummary, reset]);

useEffect(() => {
if (builderError) {
setError(builderError);
Expand Down Expand Up @@ -322,16 +318,6 @@ export const Explore: React.FC = () => {
};

const topValues = useTopValues(modelDef, modelPath, sourceDef);
if (loading || (appId && !appInfo)) {
section = 'loading';
}

// eslint-disable-next-line no-console
console.log({
model,
modelPath,
source,
});

return (
<Main handlers={handlers} keyMap={KEY_MAP}>
Expand Down Expand Up @@ -427,10 +413,10 @@ export const Explore: React.FC = () => {
<Apps />
</PageContent>
)}
{section === 'loading' && (
<EmptyMessage>
{loading && (
<LoadingOverlay>
<LoadingSpinner text="Loading Data..." />
</EmptyMessage>
</LoadingOverlay>
)}
</PageContainer>
</Page>
Expand Down Expand Up @@ -519,6 +505,7 @@ const HeaderLeft = styled.div`
const Page = styled(Content)`
margin-top: 10px;
height: unset;
position: relative;
`;

const RightChannel = styled.div`
Expand All @@ -539,6 +526,17 @@ const BottomChannel = styled.div`
background-color: ${COLORS.mainBackground};
`;

const LoadingOverlay = styled(EmptyMessage)`
background-color: ${COLORS.mainBackground};
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 9999;
margin: 0;
`;

function generateReadme(appInfo: AppInfo) {
let readme = '';
const title = appInfo.title || 'Malloy';
Expand Down

0 comments on commit d5cdf54

Please sign in to comment.