/** * 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 { clsx, PanelLoadingIndicator, QuestionCircleIcon, CogIcon, MoreHorizontalIcon, ControlledDropdownMenu, PencilIcon, ThinChevronDownIcon, CircleIcon, MenuContent, MenuContentItem, MenuContentItemIcon, MenuContentItemLabel, CheckIcon, MenuContentDivider, AssistantIcon, } from '@finos/legend-art'; import { guaranteeNonNullable } from '@finos/legend-shared'; import { observer, useLocalObservable } from 'mobx-react-lite'; import { createContext, useContext, useEffect } from 'react'; import { LEGEND_QUERY_SETUP_QUERY_PARAM_TOKEN } from '../__lib__/LegendQueryNavigation.js'; import { QuerySetupLandingPageStore, type BaseQuerySetupStore, } from '../stores/QuerySetupStore.js'; import { MASTER_SNAPSHOT_ALIAS, SNAPSHOT_VERSION_ALIAS, type StoreProjectData, } from '@finos/legend-server-depot'; import { useApplicationStore } from '@finos/legend-application'; import { useLegendQueryApplicationStore } from './LegendQueryFrameworkProvider.js'; import type { QuerySetupActionConfiguration } from '../stores/LegendQueryApplicationPlugin.js'; export type ProjectOption = { label: string; value: StoreProjectData }; export const buildProjectOption = ( project: StoreProjectData, ): ProjectOption => ({ label: `${project.groupId}.${project.artifactId}`, value: project, }); export type VersionOption = { label: string; value: string }; export const buildVersionOption = (version: string): VersionOption => { if (version === MASTER_SNAPSHOT_ALIAS) { return { label: SNAPSHOT_VERSION_ALIAS, value: version, }; } return { label: version, value: version, }; }; const QuerySetupLandingPageStoreContext = createContext< QuerySetupLandingPageStore | undefined >(undefined); const QuerySetupLandingPageStoreProvider: React.FC<{ children: React.ReactNode; }> = ({ children }) => { const applicationStore = useLegendQueryApplicationStore(); const store = useLocalObservable( () => new QuerySetupLandingPageStore(applicationStore), ); return ( {children} ); }; export const useQuerySetupLandingPageStore = (): QuerySetupLandingPageStore => guaranteeNonNullable( useContext(QuerySetupLandingPageStoreContext), `Can't find query setup landing page store in context`, ); export const withQuerySetupLandingPageStore = ( WrappedComponent: React.FC, ): React.FC => function WithQuerySetupLandingPageStore() { return ( ); }; const QuerySetupAction = observer( (props: { action: QuerySetupActionConfiguration }) => { const { action } = props; const setupStore = useQuerySetupLandingPageStore(); const applicationStore = useApplicationStore(); const onClick = (): void => { action.action(setupStore).catch(applicationStore.alertUnhandledError); }; if (!setupStore.showAdvancedActions && action.isAdvanced) { return null; } return ( ); }, ); const QuerySetupActionGroupConfigMenu = observer(() => { const setupStore = useQuerySetupLandingPageStore(); const toggleShowAdvancedActions = (): void => setupStore.setShowAdvancedActions(!setupStore.showAdvancedActions); const toggleShowAllGroups = (): void => setupStore.setShowAllGroups(!setupStore.showAllGroups); const reset = (): void => setupStore.resetConfig(); const showAll = (): void => { setupStore.setShowAdvancedActions(true); setupStore.setShowAllGroups(true); }; return ( {setupStore.showAdvancedActions ? : null} Show advanced actions {setupStore.showAllGroups ? : null} Show all action groups Focus on action group: setupStore.setTagToFocus(undefined)}> {!setupStore.tagToFocus ? : null} (none) {setupStore.tags.map((groupKey) => ( setupStore.setTagToFocus(groupKey)} > {setupStore.tagToFocus === groupKey ? : null} {groupKey} ))} Show All Reset ); }); const QuerySetupActionGroup = observer( (props: { tag?: string | undefined }) => { const { tag } = props; const setupStore = useQuerySetupLandingPageStore(); const actions = setupStore.actions.filter((action) => action.tag === tag); const createActions = actions.filter((action) => action.isCreateAction); const editActions = actions.filter((action) => !action.isCreateAction); const showAdvancedActions = (): void => setupStore.setShowAdvancedActions(true); return (
{tag && (
{tag}
)}
{(!tag || setupStore.tagToFocus === tag) && ( } menuProps={{ anchorOrigin: { vertical: 'bottom', horizontal: 'left' }, transformOrigin: { vertical: 'top', horizontal: 'left' }, }} > {setupStore.isCustomized && (
)}
)}
{editActions.map((action) => ( ))}
{createActions.map((action) => ( ))}
{!setupStore.showAdvancedActions && ( )}
); }, ); export const QuerySetupLandingPage = withQuerySetupLandingPageStore( observer(() => { const setupStore = useQuerySetupLandingPageStore(); const applicationStore = useLegendQueryApplicationStore(); const showAdvancedActions = applicationStore.navigationService.navigator.getCurrentLocationParameterValue( LEGEND_QUERY_SETUP_QUERY_PARAM_TOKEN.SHOW_ADVANCED_ACTIONS, ); const showAllGroups = applicationStore.navigationService.navigator.getCurrentLocationParameterValue( LEGEND_QUERY_SETUP_QUERY_PARAM_TOKEN.SHOW_ALL_GROUPS, ); const tagToFocus = applicationStore.navigationService.navigator.getCurrentLocationParameterValue( LEGEND_QUERY_SETUP_QUERY_PARAM_TOKEN.TAG, ); const goToStudio = (): void => applicationStore.navigationService.navigator.visitAddress( applicationStore.config.studioApplicationUrl, ); const showAllActionGroup = (): void => setupStore.setShowAllGroups(true); const toggleAssistant = (): void => applicationStore.assistantService.toggleAssistant(); useEffect(() => { setupStore.initialize(showAdvancedActions, showAllGroups, tagToFocus); }, [setupStore, showAdvancedActions, showAllGroups, tagToFocus]); return ( <>
{setupStore.initState.hasCompleted && ( <>
What do you want to do today
{setupStore.tagToFocus && ( )} {!setupStore.tagToFocus && ( <> {setupStore.showAllGroups && ( <> {setupStore.tags.map((tag) => ( ))}
Developer Workstation
)} {!setupStore.showAllGroups && (
)} )}
)}
); }), ); export const BaseQuerySetupStoreContext = createContext< BaseQuerySetupStore | undefined >(undefined); export const useBaseQuerySetupStore = (): BaseQuerySetupStore => guaranteeNonNullable( useContext(BaseQuerySetupStoreContext), `Can't find base query setup store in context`, ); export const BaseQuerySetup = observer( (props: { children: React.ReactNode }) => { const { children } = props; const setupStore = useBaseQuerySetupStore(); const applicationStore = useLegendQueryApplicationStore(); const toggleAssistant = (): void => applicationStore.assistantService.toggleAssistant(); useEffect(() => { setupStore.initialize(); }, [setupStore]); return ( <> {setupStore.initState.hasCompleted && ( <>
{children}
)} ); }, );