/** * 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 { DataCubeSpecification, DEFAULT_REPORT_NAME, FormBadge_Advanced, FormButton, FormCheckbox, FormTextInput, } from '@finos/legend-data-cube'; import { observer } from 'mobx-react-lite'; import { useEffect, useState } from 'react'; import { useLegendDataCubeBuilderStore } from './LegendDataCubeBuilderStoreProvider.js'; import { guaranteeNonNullable, returnUndefOnError } from '@finos/legend-shared'; export const LegendDataCubeSaver = observer(() => { const [name, setName] = useState(DEFAULT_REPORT_NAME); const [syncName, setSyncName] = useState(false); const [autoEnableCache, setAutoEnableCache] = useState(false); const [showAdvancedSettings, setShowAdvancedSettings] = useState(false); const store = useLegendDataCubeBuilderStore(); const builder = guaranteeNonNullable(store.builder); useEffect(() => { const persistentDataCube = builder.persistentDataCube; const latestSpecification = persistentDataCube ? returnUndefOnError(() => DataCubeSpecification.serialization.fromJson( persistentDataCube.content, ), ) : undefined; setName( persistentDataCube?.name ?? builder.initialSpecification.configuration?.name ?? DEFAULT_REPORT_NAME, ); setSyncName(false); setAutoEnableCache(latestSpecification?.options?.autoEnableCache ?? false); }, [builder]); return ( <>
Name:
{ setName(event.target.value); }} autoFocus={true} />
setSyncName(!syncName)} />
{showAdvancedSettings && ( <>
Caching:
setAutoEnableCache(!autoEnableCache)} />
)}
setShowAdvancedSettings(!showAdvancedSettings)} />
store.saverDisplay.close()}> Cancel {builder.persistentDataCube ? ( // updating existing DataCube <> { store .saveDataCube(name, { syncName, autoEnableCache, saveAsNew: false, }) .catch((error) => store.alertService.alertUnhandledError(error), ); }} > Save { store .saveDataCube(name, { syncName, autoEnableCache, saveAsNew: true, }) .catch((error) => store.alertService.alertUnhandledError(error), ); }} > Save As ) : ( // creating new DataCube <> { store .createNewDataCube(name, { syncName, autoEnableCache, }) .catch((error) => store.alertService.alertUnhandledError(error), ); }} > Save )}
); });