Skip to content

Commit

Permalink
datacube: support saving/saving as new query
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed Dec 30, 2024
1 parent 451d148 commit 26ab5ee
Show file tree
Hide file tree
Showing 24 changed files with 485 additions and 287 deletions.
18 changes: 18 additions & 0 deletions .changeset/honest-pillows-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@finos/legend-application-data-cube-deployment': patch
'@finos/legend-application-data-cube-bootstrap': patch
'@finos/legend-vscode-extension-dependencies': patch
'@finos/legend-extension-dsl-data-quality': patch
'@finos/legend-extension-dsl-data-space': patch
'@finos/legend-application-data-cube': patch
'@finos/legend-application-pure-ide': patch
'@finos/legend-application-studio': patch
'@finos/legend-application-query': patch
'@finos/legend-application-repl': patch
'@finos/legend-query-builder': patch
'@finos/legend-application': patch
'@finos/legend-data-cube': patch
'@finos/legend-shared': patch
'@finos/legend-graph': patch
'@finos/legend-art': patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const LegendDataCubeNewQueryBuilder = observer(

return (
<>
<div className="relative h-[calc(100%_-_40px)] w-full px-2 pt-2">
<div className="h-[calc(100%_-_40px)] w-full px-2 pt-2">
<div className="h-full w-full overflow-auto border border-neutral-300 bg-white">
<div className="h-full w-full select-none p-2">
<div className="flex h-6 w-full items-center">
Expand Down Expand Up @@ -94,37 +94,22 @@ export const LegendDataCubeNewQueryBuilder = observer(
</div>
</div>
<div className="flex h-10 items-center justify-end px-2">
<FormButton onClick={() => state.display.close()} autoFocus={true}>
Cancel
</FormButton>
<FormButton onClick={() => state.display.close()}>Cancel</FormButton>
<FormButton
className="ml-2"
disabled={!sourceBuilder.isValid}
disabled={
!sourceBuilder.isValid || state.finalizeState.isInProgress
}
onClick={() => {
// editor.applyChanges();
state.generateQuery().then((query) => {});
state.display.close();
state
.finalize()
.catch((error) => state.engine.alertUnhandledError(error));
}}
>
OK
</FormButton>
</div>
</>
// <div className="flex h-20 items-center justify-end border-b-0 border-l-0 border-r-0 border-t border-solid border-slate-300 p-2 px-2">
// <button
// className="ml-2 h-10 w-20 rounded border border-neutral-400 bg-neutral-300 bg-sky-700 px-2 text-white hover:brightness-95 disabled:cursor-not-allowed disabled:border-neutral-300 disabled:bg-gray-200 disabled:text-white disabled:hover:brightness-100"
// disabled={!sourceState.isValid}
// // onClick={() => {
// // flowResult(
// // sourceBuilder.inputSource(
// // (source: DataCubeGenericSource, engine: DataCubeEngine) =>
// // store.initializeView(source, engine),
// // ),
// // ).catch(store.context.application.alertUnhandledError);
// // }}
// >
// Open
// </button>
);
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
type DataCubeState,
type DataCubeSettingValues,
} from '@finos/legend-data-cube';
import { formatDate } from '@finos/legend-shared';
import {
DataCubeIcon,
DropdownMenu,
Expand All @@ -42,77 +41,9 @@ import {
import { useEffect } from 'react';
import { LegendDataCubeSettingStorageKey } from '../../__lib__/LegendDataCubeSetting.js';

// const CreateQueryDialog = observer(
// (props: { view: LegendCubeViewer; store: LegendDataCubeBaseStore }) => {
// const { store } = props;
// const close = (): void => store.setSaveModal(false);
// const [queryName, setQueryName] = useState('');
// const create = (): void => {
// flowResult(store.saveQuery(queryName)).catch(
// store.application.alertUnhandledError,
// );
// };
// const isEmptyName = !queryName;
// // name
// const nameInputRef = useRef<HTMLInputElement>(null);
// const setFocus = (): void => {
// nameInputRef.current?.focus();
// };
// const changeName: React.ChangeEventHandler<HTMLInputElement> = (event) => {
// setQueryName(event.target.value);
// };
// useEffect(() => {
// setTimeout(() => setFocus(), 1);
// }, []);
// return (
// <Dialog
// open={store.saveModal}
// onClose={close}
// classes={{
// root: 'editor-modal__root-container',
// container: 'editor-modal__container',
// paper: 'editor-modal__content',
// }}
// >
// <Modal darkMode={false} className="query-export">
// <ModalHeader title="Create New Query" />
// <ModalBody>
// <PanelLoadingIndicator
// isLoading={store.saveModalState.isInProgress}
// />
// <PanelListItem>
// <div className="input--with-validation">
// <input
// ref={nameInputRef}
// className={clsx('input input--dark', {
// 'input--caution': false,
// })}
// spellCheck={false}
// value={queryName}
// onChange={changeName}
// title="New Query Name"
// />
// </div>
// </PanelListItem>
// </ModalBody>
// <ModalFooter>
// <ModalFooterButton
// text="Create Query"
// title="Create new query"
// disabled={isEmptyName}
// onClick={create}
// />
// </ModalFooter>
// </Modal>
// </Dialog>
// );
// },
// );

const LegendDataCubeQueryBuilderHeader = observer(
(props: { dataCube?: DataCubeState | undefined }) => {
const store = useLegendDataCubeQueryBuilderStore();
const { dataCube } = props;

return (
<div className="flex h-full items-center">
Expand All @@ -122,7 +53,6 @@ const LegendDataCubeQueryBuilderHeader = observer(
disabled={true}
>
Load Query
<FormBadge_WIP />
</FormButton>
<FormButton
compact={true}
Expand All @@ -131,7 +61,12 @@ const LegendDataCubeQueryBuilderHeader = observer(
>
New Query
</FormButton>
<FormButton compact={true} className="ml-1.5" disabled={!store.builder}>
<FormButton
compact={true}
className="ml-1.5"
disabled={!store.builder?.dataCube}
onClick={() => store.saverDisplay.open()}
>
Save Query
</FormButton>
</div>
Expand Down Expand Up @@ -227,6 +162,7 @@ const LegendDataCubeBlankQueryBuilder = observer(() => {
export const LegendDataCubeQueryBuilder = withLegendDataCubeQueryBuilderStore(
observer(() => {
const store = useLegendDataCubeQueryBuilderStore();
const builder = store.builder;
const application = store.application;
const params = useParams<LegendDataCubeQueryBuilderQueryPathParams>();
const queryId = params[LEGEND_DATA_CUBE_ROUTE_PATTERN_TOKEN.QUERY_ID];
Expand All @@ -246,19 +182,16 @@ export const LegendDataCubeQueryBuilder = withLegendDataCubeQueryBuilderStore(
}
}, [store, queryId]);

if (!store.builder) {
if (!builder) {
return <LegendDataCubeBlankQueryBuilder />;
}
return (
<DataCube
key={store.builder.uuid}
query={store.builder.query}
query={builder.query}
engine={store.baseStore.engine}
options={{
onNameChanged(name, source) {
application.layoutService.setWindowTitle(
`\u229E ${name} - ${formatDate(new Date(store.baseStore.startTime), 'HH:mm:ss EEE MMM dd yyyy')}`,
);
onInitialized(dataCube) {
builder.setDataCube(dataCube);
},
innerHeaderComponent: (dataCube) => (
<LegendDataCubeQueryBuilderHeader dataCube={dataCube} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
DEFAULT_REPORT_NAME,
FormButton,
FormTextInput,
} from '@finos/legend-data-cube';
import { observer } from 'mobx-react-lite';
import { useEffect, useState } from 'react';
import { useLegendDataCubeQueryBuilderStore } from './LegendDataCubeQueryBuilderStoreProvider.js';
import { guaranteeNonNullable } from '@finos/legend-shared';

export const LegendDataCubeQuerySaver = observer(() => {
const [name, setName] = useState(DEFAULT_REPORT_NAME);
const store = useLegendDataCubeQueryBuilderStore();
const builder = guaranteeNonNullable(store.builder);

useEffect(() => {
setName(builder.persistentQuery?.name ?? DEFAULT_REPORT_NAME);
}, [builder]);

return (
<>
<div className="h-[calc(100%_-_40px)] w-full px-2 pt-2">
<div className="h-full w-full overflow-auto border border-neutral-300 bg-white">
<div className="h-full w-full select-none p-2">
<div className="flex h-6 w-full items-center">
<div className="flex h-full w-32 flex-shrink-0 items-center text-sm">
Name:
</div>
<FormTextInput
className="w-80"
value={name}
onChange={(event) => {
setName(event.target.value.trim());
}}
autoFocus={true}
/>
</div>
</div>
</div>
</div>
<div className="flex h-10 items-center justify-end px-2">
<FormButton onClick={() => store.saverDisplay.close()}>
Cancel
</FormButton>
{builder.persistentQuery ? (
// updating existing query
<>
<FormButton
className="ml-2"
disabled={!builder.dataCube || store.saveQueryState.isInProgress}
onClick={() => {
store
.saveQuery(name, false)
.catch((error) => store.engine.alertUnhandledError(error));
}}
>
Save
</FormButton>
<FormButton
className="ml-2"
disabled={!builder.dataCube || store.saveQueryState.isInProgress}
onClick={() => {
store
.saveQuery(name, true)
.catch((error) => store.engine.alertUnhandledError(error));
}}
>
Save As
</FormButton>
</>
) : (
// creating new query
<>
<FormButton
className="ml-2"
disabled={!builder.dataCube || store.saveQueryState.isInProgress}
onClick={() => {
store
.createQuery(name)
.catch((error) => store.engine.alertUnhandledError(error));
}}
>
Save
</FormButton>
</>
)}
</div>
</>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ export class LegendDataCubeBaseStore {
readonly graphManager: V1_PureGraphManager;
readonly engineServerClient: V1_EngineServerClient;
readonly engine: LegendDataCubeDataCubeEngine;

readonly startTime = Date.now();
readonly initState = ActionState.create();

readonly dataCubeSettings: DataCubeSetting[];
Expand Down
Loading

0 comments on commit 26ab5ee

Please sign in to comment.