Skip to content

Commit

Permalink
datacube: cleanup fetch config method in engine
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed Dec 23, 2024
1 parent 6b450fb commit 6fc825c
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ import type { LegendPureIDEPluginManager } from '../application/LegendPureIDEPlu

const EditorStoreContext = createContext<PureIDEStore | undefined>(undefined);

export const PureIDEStoreProvider = ({
children,
}: {
children: React.ReactNode;
}): React.ReactElement => {
export const PureIDEStoreProvider = (props: { children: React.ReactNode }) => {
const { children } = props;
const applicationStore = useApplicationStore<
LegendPureIDEApplicationConfig,
LegendPureIDEPluginManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ import {
} from './LegendREPLFramworkProvider.js';

const LegendREPLDataCube = observer(() => {
const baseStore = useLegendREPLBaseStore();
const engine = useMemo(
() => new LegendREPLDataCubeEngine(baseStore),
[baseStore],
);
const application = baseStore.application;
const store = useLegendREPLBaseStore();
const engine = useMemo(() => new LegendREPLDataCubeEngine(store), [store]);
const application = store.application;

useEffect(() => {
engine.blockNavigation(
Expand Down Expand Up @@ -74,10 +71,10 @@ const LegendREPLDataCube = observer(() => {
onSettingChanged(key, value) {
engine.persistSettingValue(key, value);
},

enableDebugMode: application.settingService.getBooleanValue(
DataCubeSettingKey.ENABLE_DEBUG_MODE,
),
gridClientLicense: store.gridClientLicense,
gridClientRowBuffer: application.settingService.getNumericValue(
DataCubeSettingKey.GRID_CLIENT_ROW_BUFFER,
),
Expand All @@ -101,16 +98,28 @@ export const LEGEND_REPL_GRID_CLIENT_ROUTE_PATTERN = Object.freeze({
DATA_CUBE: `/dataCube`,
});

export const LegendREPLRouter = observer(() => (
<div className="h-full">
<Routes>
<Route
path={LEGEND_REPL_GRID_CLIENT_ROUTE_PATTERN.DATA_CUBE}
element={<LegendREPLDataCube />}
/>
</Routes>
</div>
));
export const LegendREPLRouter = observer(() => {
const store = useLegendREPLBaseStore();

useEffect(() => {
store
.initialize()
.catch((error) => store.application.alertUnhandledError(error));
}, [store]);

return (
<div className="h-full">
{store.initState.hasSucceeded && (
<Routes>
<Route
path={LEGEND_REPL_GRID_CLIENT_ROUTE_PATTERN.DATA_CUBE}
element={<LegendREPLDataCube />}
/>
</Routes>
)}
</div>
);
});

export const LegendREPLWebApplication = (props: { baseUrl: string }) => {
const { baseUrl } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import {
ActionState,
LogEvent,
NetworkClient,
assertErrorThrown,
guaranteeNonNullable,
Expand All @@ -34,14 +35,17 @@ import {
import { LegendREPLDataCubeSource } from './LegendREPLDataCubeSource.js';
import { PersistentDataCubeQuery } from '@finos/legend-graph';
import { LegendREPLPublishDataCubeAlert } from '../components/LegendREPLPublishDataCubeAlert.js';
import { APPLICATION_EVENT } from '@finos/legend-application';

export class LegendREPLBaseStore {
readonly application: LegendREPLApplicationStore;
readonly client: LegendREPLServerClient;
readonly initState = ActionState.create();
readonly publishState = ActionState.create();

sourceQuery?: string | undefined;
currentUser?: string | undefined;
gridClientLicense?: string | undefined;
queryServerBaseUrl?: string | undefined;
hostedApplicationBaseUrl?: string | undefined;

Expand All @@ -60,6 +64,26 @@ export class LegendREPLBaseStore {
);
}

async initialize() {
this.initState.inProgress();
try {
const info = await this.client.getInfrastructureInfo();
this.currentUser = info.currentUser;
this.queryServerBaseUrl = info.queryServerBaseUrl;
this.hostedApplicationBaseUrl = info.hostedApplicationBaseUrl;
this.gridClientLicense = info.gridClientLicense;
this.initState.pass();
} catch (error) {
assertErrorThrown(error);
this.application.logService.error(
LogEvent.create(APPLICATION_EVENT.APPLICATION_LOAD__FAILURE),
`Can't initialize REPL`,
error,
);
this.initState.fail();
}
}

async publishDataCube(dataCube: DataCubeState) {
if (
!this.sourceQuery ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,6 @@ export class LegendREPLDataCubeEngine extends DataCubeEngine {

// ---------------------------------- IMPLEMENTATION ----------------------------------

override async fetchConfiguration() {
const info = await this.client.getInfrastructureInfo();
this.baseStore.currentUser = info.currentUser;
this.baseStore.queryServerBaseUrl = info.queryServerBaseUrl;
this.baseStore.hostedApplicationBaseUrl = info.hostedApplicationBaseUrl;
return {
gridClientLicense: info.gridClientLicense,
};
}

async getBaseQuery() {
return DataCubeQuery.serialization.fromJson(
await this.client.getBaseQuery(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ const ProjectReviewerStoreContext = createContext<
ProjectReviewerStore | undefined
>(undefined);

export const ProjectReviewerStoreProvider = ({
children,
}: {
export const ProjectReviewerStoreProvider = (props: {
children: React.ReactNode;
}): React.ReactElement => {
}) => {
const { children } = props;
const editorStore = useEditorStore();
editorStore.setMode(EDITOR_MODE.REVIEW);
const store = useLocalObservable(() => new ProjectReviewerStore(editorStore));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import { useApplicationStore } from './ApplicationStoreProvider.js';
import { useApplicationPlatform } from './ApplicationPlatformProvider.js';

export const ApplicationFrameworkProvider = observer(
(props: {
children: React.ReactNode;
simple?: boolean | undefined;
}): React.ReactElement => {
(props: { children: React.ReactNode; simple?: boolean | undefined }) => {
const { children, simple } = props;
const platform = useApplicationPlatform();
const applicationStore = useApplicationStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ export const useApplicationStore = <
export const ApplicationStoreProvider = <
T extends LegendApplicationConfig,
V extends LegendApplicationPluginManager<LegendApplicationPlugin>,
>({
children,
store,
}: {
>(props: {
children: React.ReactNode;
store: ApplicationStore<T, V>;
}): React.ReactElement => {
}) => {
const { children, store } = props;
const applicationStore = useLocalObservable(() => store);
return (
<ApplicationStoreContext.Provider value={applicationStore}>
Expand Down
4 changes: 3 additions & 1 deletion packages/legend-data-cube/src/components/DataCube.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type { DataCubeEngine } from '../stores/core/DataCubeEngine.js';
import { DataCubeState } from '../stores/DataCubeState.js';
import { type DataCubeOptions } from '../stores/DataCubeOptions.js';
import { DataCubeContextProvider, useDataCube } from './DataCubeProvider.js';
import type { DataCubeQuery } from '../stores/core/models/DataCubeQuery.js';

const DataCubeTitleBar = observer(() => {
const dataCube = useDataCube();
Expand Down Expand Up @@ -119,8 +120,9 @@ const DataCubeRoot = observer(() => {
export const DataCube = observer(
(props: {
engine: DataCubeEngine;
query?: DataCubeQuery | undefined;
options?: DataCubeOptions | undefined;
}): React.ReactElement => {
}) => {
const { engine, options } = props;
const state = useLocalObservable(() => new DataCubeState(engine, options));

Expand Down
1 change: 1 addition & 0 deletions packages/legend-data-cube/src/stores/DataCubeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { DataCubeState } from './DataCubeState.js';

export type DataCubeOptions = {
enableDebugMode?: boolean | undefined;
gridClientLicense?: string | undefined;
gridClientRowBuffer?: number | undefined;
gridClientPurgeClosedRowNodes?: boolean | undefined;
gridClientSuppressLargeDatasetWarning?: boolean | undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/legend-data-cube/src/stores/DataCubeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class DataCubeSettings {
DEFAULT_SETTINGS[
DataCubeSettingKey.GRID_CLIENT_SUPPRESS_LARGE_DATASET_WARNING
];
gridClientLicense?: string | undefined;

setEnableDebugMode(value: boolean) {
this.enableDebugMode = value;
Expand Down
1 change: 1 addition & 0 deletions packages/legend-data-cube/src/stores/DataCubeState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class DataCubeState implements DataCubeAPI {
options?.gridClientSuppressLargeDatasetWarning !== undefined
? options.gridClientSuppressLargeDatasetWarning
: this.settings.gridClientSuppressLargeDatasetWarning;
this.settings.gridClientLicense = options?.gridClientLicense;
}

getSettings() {
Expand Down
20 changes: 6 additions & 14 deletions packages/legend-data-cube/src/stores/core/DataCubeEngine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ type DataCubeExecutionResult = {
executedSQL: string;
};

export type DataCubeEngineConfiguration = {
gridClientLicense?: string | undefined;
};

export abstract class DataCubeEngine {
readonly layout = new LayoutManagerState();
readonly filterOperations = [
Expand Down Expand Up @@ -176,16 +172,13 @@ export abstract class DataCubeEngine {
new DataCubeQueryAggregateOperation__JoinStrings(),
];

protected async fetchConfiguration(): Promise<DataCubeEngineConfiguration> {
return {
gridClientLicense: undefined,
};
}
abstract getBaseQuery(): Promise<DataCubeQuery | undefined>;

async initialize(): Promise<void> {
const config = await this.fetchConfiguration();
if (config.gridClientLicense) {
LicenseManager.setLicenseKey(config.gridClientLicense);
async initialize(options?: {
gridClientLicense?: string | undefined;
}): Promise<void> {
if (options?.gridClientLicense) {
LicenseManager.setLicenseKey(options.gridClientLicense);
}
await configureCodeEditor(DataCubeFont.ROBOTO_MONO, (error) => {
throw error;
Expand All @@ -203,7 +196,6 @@ export abstract class DataCubeEngine {
return getAggregateOperation(value, this.aggregateOperations);
}

abstract getBaseQuery(): Promise<DataCubeQuery | undefined>;
abstract processQuerySource(value: PlainObject): Promise<DataCubeSource>;

abstract parseValueSpecification(
Expand Down

0 comments on commit 6fc825c

Please sign in to comment.