-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Studio V2 store with common, console and plugin reducers
- Loading branch information
Showing
14 changed files
with
910 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* 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 DataSourceConfigurer from 'services/datasource/DataSourceConfigurer'; | ||
import { apiCreator } from 'services/resource-helper'; | ||
|
||
const dataSrc = DataSourceConfigurer.getInstance(); | ||
const basePath = '/namespaces/:namespace/configuration'; | ||
const userSettingsPath = `${basePath}/user`; | ||
|
||
export const SettingsApi = { | ||
getUserSettings: apiCreator(dataSrc, 'GET', 'REQUEST', `${userSettingsPath}`), | ||
updateUserSettings: apiCreator(dataSrc, 'PUT', 'REQUEST', `${userSettingsPath}`), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* 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 { MyArtifactApi } from 'api/artifact'; | ||
import { IArtifactSummary, ILabeledArtifactSummary } from 'components/StudioV2/types'; | ||
import { getArtifactDisaplayName } from 'components/StudioV2/utils/artifactUtils'; | ||
import { getCurrentNamespace } from 'services/NamespaceStore'; | ||
import { Theme } from 'services/ThemeHelper'; | ||
import VersionStore from 'services/VersionStore'; | ||
import { GLOBALS } from 'services/global-constants'; | ||
import StudioV2Store from '..'; | ||
|
||
const PREFIX = 'COMMON_ACTIONS'; | ||
|
||
export const CommonActions = { | ||
SET_ARTIFACTS: `${PREFIX}/SET_ARTIFACTS`, | ||
SET_SELECTED_ARTIFACT: `${PREFIX}/SET_SELECTED_ARTIFACT`, | ||
}; | ||
|
||
export const fetchSystemArtifacts = () => { | ||
const cdapVersion = VersionStore.getState().version; | ||
const namespace = getCurrentNamespace(); | ||
|
||
const uiSupportedArtifacts = [GLOBALS.etlDataPipeline]; | ||
if (Theme.showRealtimePipeline !== false) { | ||
uiSupportedArtifacts.push(GLOBALS.etlDataStreams); | ||
} | ||
if (Theme.showSqlPipeline !== false) { | ||
uiSupportedArtifacts.push(GLOBALS.eltSqlPipeline); | ||
} | ||
|
||
MyArtifactApi.listScopedArtifacts({ | ||
namespace, | ||
scope: 'SYSTEM', | ||
}).subscribe((res: IArtifactSummary[]) => { | ||
if (!res.length) { | ||
return; | ||
} | ||
|
||
const filteredArtifacts = res.filter( | ||
(artifact) => artifact.version === cdapVersion && uiSupportedArtifacts.includes(artifact.name) | ||
); | ||
|
||
const labeledArtifacts = filteredArtifacts.map((artifact) => ({ | ||
...artifact, | ||
label: getArtifactDisaplayName(artifact.name), | ||
})); | ||
|
||
StudioV2Store.dispatch({ | ||
type: CommonActions.SET_ARTIFACTS, | ||
payload: labeledArtifacts, | ||
}); | ||
}); | ||
}; | ||
|
||
export const setSelectedArtifact = (artifact: ILabeledArtifactSummary) => { | ||
StudioV2Store.dispatch({ | ||
type: CommonActions.SET_SELECTED_ARTIFACT, | ||
payload: artifact, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* 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 { ILabeledArtifactSummary } from 'components/StudioV2/types'; | ||
import { getArtifactDisaplayName } from 'components/StudioV2/utils/artifactUtils'; | ||
import { GLOBALS } from 'services/global-constants'; | ||
import { CommonActions } from './actions'; | ||
|
||
interface ICommonState { | ||
artifacts: ILabeledArtifactSummary[]; | ||
selectedArtifact: ILabeledArtifactSummary; | ||
} | ||
|
||
export const defaultSelectedArtifact: ILabeledArtifactSummary = { | ||
name: GLOBALS.etlDataPipeline, | ||
version: '', | ||
scope: 'SYSTEM', | ||
label: getArtifactDisaplayName(GLOBALS.etlDataPipeline), | ||
}; | ||
|
||
export const commonDefaultInitialState: ICommonState = { | ||
artifacts: [], | ||
selectedArtifact: defaultSelectedArtifact, | ||
}; | ||
|
||
export const common = (state: ICommonState = commonDefaultInitialState, action?): ICommonState => { | ||
switch (action.type) { | ||
case CommonActions.SET_ARTIFACTS: | ||
return { ...state, artifacts: action.payload }; | ||
case CommonActions.SET_SELECTED_ARTIFACT: | ||
return { ...state, selectedArtifact: action.payload }; | ||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* 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 StudioV2Store from '..'; | ||
|
||
const PREFIX = 'CONSOLE_ACTIONS'; | ||
|
||
export const ConsoleActions = { | ||
ADD_MESSAGE: `${PREFIX}/ADD_MESSAGE`, | ||
ADD_MESSAGES: `${PREFIX}/ADD_MESSAGES`, | ||
RESET: `${PREFIX}/RESET`, | ||
}; | ||
|
||
export function resetConsoleMessages() { | ||
StudioV2Store.dispatch({ | ||
type: ConsoleActions.RESET, | ||
}); | ||
} | ||
|
||
export function addConsoleMessage(payload) { | ||
StudioV2Store.dispatch({ | ||
type: ConsoleActions.ADD_MESSAGE, | ||
payload, | ||
}); | ||
} | ||
|
||
export function addConsoleMessages(payload) { | ||
StudioV2Store.dispatch({ | ||
type: ConsoleActions.ADD_MESSAGES, | ||
payload, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* 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 { ConsoleActions } from './actions'; | ||
|
||
interface IConsoleState { | ||
messages: any[]; | ||
} | ||
|
||
export const consoleInitialState: IConsoleState = { | ||
messages: [], | ||
}; | ||
|
||
export const consoleReducer = ( | ||
state: IConsoleState = consoleInitialState, | ||
action? | ||
): IConsoleState => { | ||
switch (action.type) { | ||
case ConsoleActions.ADD_MESSAGE: | ||
return { ...state, messages: [...state.messages, action.payload] }; | ||
|
||
case ConsoleActions.ADD_MESSAGES: | ||
return { ...state, messages: action.payload }; | ||
|
||
case ConsoleActions.RESET: | ||
return { ...consoleInitialState }; | ||
|
||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* 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 { combineReducers, createStore } from 'redux'; | ||
import { common, commonDefaultInitialState } from './common/reducer'; | ||
import { consoleReducer, consoleInitialState } from './console/reducer'; | ||
import { plugins, pluginsInitialState } from './plugins/reducer'; | ||
|
||
const defaultInitialState = { | ||
common: commonDefaultInitialState, | ||
console: consoleInitialState, | ||
plugins: pluginsInitialState, | ||
}; | ||
|
||
const StudioV2Store = createStore( | ||
combineReducers({ | ||
common, | ||
console: consoleReducer, | ||
plugins, | ||
}), | ||
defaultInitialState, | ||
(window as any).__REDUX_DEVTOOLS_EXTENSION__ && (window as any).__REDUX_DEVTOOLS_EXTENSION__() | ||
); | ||
|
||
export default StudioV2Store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* 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 { GLOBALS } from 'services/global-constants'; | ||
import { getPluginIcon } from 'components/StudioV2/utils/pluginUtils'; | ||
import MySettingsService from 'components/StudioV2/utils/settings'; | ||
import { IPlugin } from 'components/StudioV2/types'; | ||
import StudioV2Store from '..'; | ||
|
||
const PREFIX = 'PLUGINS_ACTIONS'; | ||
|
||
export const PluginsActions = { | ||
FETCH_PLUGINS: `${PREFIX}/FETCH_PLUGINS`, | ||
FETCH_ALL_PLUGINS: `${PREFIX}/FETCH_ALL_PLUGINS`, | ||
FETCH_PLUGIN_TEMPLATE: `${PREFIX}/FETCH_PLUGIN_TEMPLATE`, | ||
FETCH_PLUGINS_DEFAULT_VERSIONS: `${PREFIX}/FETCH_PLUGINS_DEFAULT_VERSIONS`, | ||
UPDATE_PLUGINS_DEFAULT_VERSIONS: `${PREFIX}/UPDATE_PLUGINS_DEFAULT_VERSIONS`, | ||
CHECK_AND_UPDATE_PLUGIN_DEFAULT_VERSION: `${PREFIX}/CHECK_AND_UPDATE_PLUGIN_DEFAULT_VERSION`, | ||
FETCH_EXTENSIONS: `${PREFIX}/FETCH_EXTENSIONS`, | ||
RESET: `${PREFIX}/RESET`, | ||
}; | ||
|
||
export const getTemplatesWithAddedInfo = (templates = [], extension = '') => | ||
templates.map((template) => ({ | ||
...template, | ||
nodeClass: 'plugin-templates', | ||
name: template.pluginTemplate, | ||
pluginName: template.pluginName, | ||
type: extension, | ||
icon: getPluginIcon(template.pluginName), | ||
allArtifacts: [template.artifact], | ||
})); | ||
|
||
export const keepUiSupportedExtensions = (pipelineType: string) => (extension: string) => { | ||
const extensionMap = GLOBALS.pluginTypes[pipelineType]; | ||
return Object.keys(extensionMap).filter((ext) => extensionMap[ext] === extension).length; | ||
}; | ||
|
||
export async function fetchPluginsDefaultVersions() { | ||
try { | ||
const pluginDefalutVersion = await MySettingsService.getInstance().get( | ||
'plugin-default-version' | ||
); | ||
if (!pluginDefalutVersion) { | ||
return; | ||
} | ||
|
||
StudioV2Store.dispatch({ | ||
type: PluginsActions.FETCH_PLUGINS_DEFAULT_VERSIONS, | ||
payload: pluginDefalutVersion, | ||
}); | ||
} catch (err) { | ||
return; | ||
} | ||
} | ||
|
||
export async function updatePluginDefaultVersion(plugin: IPlugin) { | ||
try { | ||
let pluginDefalutVersion = | ||
(await MySettingsService.getInstance().get('plugin-default-version')) || {}; | ||
const key = `${plugin.name}-${plugin.type}-${plugin.artifact.name}`; | ||
pluginDefalutVersion[key] = plugin.artifact; | ||
await MySettingsService.getInstance().set('plugin-default-version', pluginDefalutVersion); | ||
pluginDefalutVersion = await MySettingsService.getInstance().get('plugin-default-version'); | ||
|
||
if (!pluginDefalutVersion) { | ||
return; | ||
} | ||
StudioV2Store.dispatch({ | ||
type: PluginsActions.FETCH_PLUGINS_DEFAULT_VERSIONS, | ||
payload: pluginDefalutVersion, | ||
}); | ||
} catch (err) { | ||
return; | ||
} | ||
} |
Oops, something went wrong.