Skip to content

Commit a0fa859

Browse files
committed
Add Studio V2 store with common, console and plugin reducers
1 parent 46e0c36 commit a0fa859

16 files changed

+972
-0
lines changed

app/cdap/api/settings.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright © 2024 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
import DataSourceConfigurer from 'services/datasource/DataSourceConfigurer';
18+
import { apiCreator } from 'services/resource-helper';
19+
20+
const dataSrc = DataSourceConfigurer.getInstance();
21+
const basePath = '/namespaces/:namespace/configuration';
22+
const userSettingsPath = `${basePath}/user`;
23+
24+
export const SettingsApi = {
25+
getUserSettings: apiCreator(dataSrc, 'GET', 'REQUEST', `${userSettingsPath}`),
26+
updateUserSettings: apiCreator(dataSrc, 'PUT', 'REQUEST', `${userSettingsPath}`),
27+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright © 2024 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
import { MyArtifactApi } from 'api/artifact';
18+
import { IArtifactSummary, ILabeledArtifactSummary } from 'components/StudioV2/types';
19+
import { getArtifactDisaplayName } from 'components/StudioV2/utils/artifactUtils';
20+
import { getCurrentNamespace } from 'services/NamespaceStore';
21+
import { Theme } from 'services/ThemeHelper';
22+
import VersionStore from 'services/VersionStore';
23+
import { GLOBALS } from 'services/global-constants';
24+
import StudioV2Store from '..';
25+
26+
const PREFIX = 'COMMON_ACTIONS';
27+
28+
export const CommonActions = {
29+
SET_ARTIFACTS: `${PREFIX}/SET_ARTIFACTS`,
30+
SET_SELECTED_ARTIFACT: `${PREFIX}/SET_SELECTED_ARTIFACT`,
31+
};
32+
33+
export const fetchSystemArtifacts = () => {
34+
const cdapVersion = VersionStore.getState().version;
35+
const namespace = getCurrentNamespace();
36+
37+
const uiSupportedArtifacts = [GLOBALS.etlDataPipeline];
38+
if (Theme.showRealtimePipeline !== false) {
39+
uiSupportedArtifacts.push(GLOBALS.etlDataStreams);
40+
}
41+
if (Theme.showSqlPipeline !== false) {
42+
uiSupportedArtifacts.push(GLOBALS.eltSqlPipeline);
43+
}
44+
45+
MyArtifactApi.listScopedArtifacts({
46+
namespace,
47+
scope: 'SYSTEM',
48+
}).subscribe((res: IArtifactSummary[]) => {
49+
if (!res.length) {
50+
return;
51+
}
52+
53+
const filteredArtifacts = res.filter(
54+
(artifact) => artifact.version === cdapVersion && uiSupportedArtifacts.includes(artifact.name)
55+
);
56+
57+
const labeledArtifacts = filteredArtifacts.map((artifact) => ({
58+
...artifact,
59+
label: getArtifactDisaplayName(artifact.name),
60+
}));
61+
62+
StudioV2Store.dispatch({
63+
type: CommonActions.SET_ARTIFACTS,
64+
payload: labeledArtifacts,
65+
});
66+
});
67+
};
68+
69+
export const setSelectedArtifact = (artifact: ILabeledArtifactSummary) => {
70+
StudioV2Store.dispatch({
71+
type: CommonActions.SET_SELECTED_ARTIFACT,
72+
payload: artifact,
73+
});
74+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright © 2024 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
import { ILabeledArtifactSummary } from 'components/StudioV2/types';
18+
import { getArtifactDisaplayName } from 'components/StudioV2/utils/artifactUtils';
19+
import { GLOBALS } from 'services/global-constants';
20+
import { CommonActions } from './actions';
21+
22+
interface ICommonState {
23+
artifacts: ILabeledArtifactSummary[];
24+
selectedArtifact: ILabeledArtifactSummary;
25+
}
26+
27+
export const defaultSelectedArtifact: ILabeledArtifactSummary = {
28+
name: GLOBALS.etlDataPipeline,
29+
version: '',
30+
scope: 'SYSTEM',
31+
label: getArtifactDisaplayName(GLOBALS.etlDataPipeline),
32+
};
33+
34+
export const commonDefaultInitialState: ICommonState = {
35+
artifacts: [],
36+
selectedArtifact: defaultSelectedArtifact,
37+
};
38+
39+
export const common = (state: ICommonState = commonDefaultInitialState, action?): ICommonState => {
40+
switch (action.type) {
41+
case CommonActions.SET_ARTIFACTS:
42+
return { ...state, artifacts: action.payload };
43+
case CommonActions.SET_SELECTED_ARTIFACT:
44+
return { ...state, selectedArtifact: action.payload };
45+
default:
46+
return state;
47+
}
48+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright © 2024 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
import StudioV2Store from '..';
18+
19+
const PREFIX = 'CONSOLE_ACTIONS';
20+
21+
export const ConsoleActions = {
22+
ADD_MESSAGE: `${PREFIX}/ADD_MESSAGE`,
23+
ADD_MESSAGES: `${PREFIX}/ADD_MESSAGES`,
24+
RESET: `${PREFIX}/RESET`,
25+
};
26+
27+
export function resetConsoleMessages() {
28+
StudioV2Store.dispatch({
29+
type: ConsoleActions.RESET,
30+
});
31+
}
32+
33+
export function addConsoleMessage(payload) {
34+
StudioV2Store.dispatch({
35+
type: ConsoleActions.ADD_MESSAGE,
36+
payload,
37+
});
38+
}
39+
40+
export function addConsoleMessages(payload) {
41+
StudioV2Store.dispatch({
42+
type: ConsoleActions.ADD_MESSAGES,
43+
payload,
44+
});
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright © 2024 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
import { ConsoleActions } from './actions';
18+
19+
interface IConsoleState {
20+
messages: any[];
21+
}
22+
23+
export const consoleInitialState: IConsoleState = {
24+
messages: [],
25+
};
26+
27+
export const consoleReducer = (
28+
state: IConsoleState = consoleInitialState,
29+
action?
30+
): IConsoleState => {
31+
switch (action.type) {
32+
case ConsoleActions.ADD_MESSAGE:
33+
return { ...state, messages: [...state.messages, action.payload] };
34+
35+
case ConsoleActions.ADD_MESSAGES:
36+
return { ...state, messages: action.payload };
37+
38+
case ConsoleActions.RESET:
39+
return { ...consoleInitialState };
40+
41+
default:
42+
return state;
43+
}
44+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright © 2024 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
import { combineReducers, createStore } from 'redux';
18+
import { common, commonDefaultInitialState } from './common/reducer';
19+
import { consoleReducer, consoleInitialState } from './console/reducer';
20+
import { plugins, pluginsInitialState } from './plugins/reducer';
21+
22+
const defaultInitialState = {
23+
common: commonDefaultInitialState,
24+
console: consoleInitialState,
25+
plugins: pluginsInitialState,
26+
};
27+
28+
const StudioV2Store = createStore(
29+
combineReducers({
30+
common,
31+
console: consoleReducer,
32+
plugins,
33+
}),
34+
defaultInitialState,
35+
(window as any).__REDUX_DEVTOOLS_EXTENSION__ && (window as any).__REDUX_DEVTOOLS_EXTENSION__()
36+
);
37+
38+
export default StudioV2Store;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright © 2024 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
import { GLOBALS } from 'services/global-constants';
18+
import MySettingsService from 'components/StudioV2/utils/settings';
19+
import { IPlugin } from 'components/StudioV2/types';
20+
import StudioV2Store from '..';
21+
22+
const PREFIX = 'PLUGINS_ACTIONS';
23+
24+
export const PluginsActions = {
25+
FETCH_PLUGINS: `${PREFIX}/FETCH_PLUGINS`,
26+
FETCH_ALL_PLUGINS: `${PREFIX}/FETCH_ALL_PLUGINS`,
27+
FETCH_PLUGIN_TEMPLATE: `${PREFIX}/FETCH_PLUGIN_TEMPLATE`,
28+
FETCH_PLUGINS_DEFAULT_VERSIONS: `${PREFIX}/FETCH_PLUGINS_DEFAULT_VERSIONS`,
29+
UPDATE_PLUGINS_DEFAULT_VERSIONS: `${PREFIX}/UPDATE_PLUGINS_DEFAULT_VERSIONS`,
30+
CHECK_AND_UPDATE_PLUGIN_DEFAULT_VERSION: `${PREFIX}/CHECK_AND_UPDATE_PLUGIN_DEFAULT_VERSION`,
31+
FETCH_EXTENSIONS: `${PREFIX}/FETCH_EXTENSIONS`,
32+
RESET: `${PREFIX}/RESET`,
33+
};
34+
35+
export const keepUiSupportedExtensions = (pipelineType: string) => (extension: string) => {
36+
const extensionMap = GLOBALS.pluginTypes[pipelineType];
37+
return Object.keys(extensionMap).filter((ext) => extensionMap[ext] === extension).length;
38+
};
39+
40+
export async function fetchPluginsDefaultVersions() {
41+
try {
42+
const pluginDefalutVersion = await MySettingsService.getInstance().get(
43+
'plugin-default-version'
44+
);
45+
if (!pluginDefalutVersion) {
46+
return;
47+
}
48+
49+
StudioV2Store.dispatch({
50+
type: PluginsActions.FETCH_PLUGINS_DEFAULT_VERSIONS,
51+
payload: pluginDefalutVersion,
52+
});
53+
} catch (err) {
54+
return;
55+
}
56+
}
57+
58+
export async function updatePluginDefaultVersion(plugin: IPlugin) {
59+
try {
60+
let pluginDefalutVersion =
61+
(await MySettingsService.getInstance().get('plugin-default-version')) || {};
62+
const key = `${plugin.name}-${plugin.type}-${plugin.artifact.name}`;
63+
pluginDefalutVersion[key] = plugin.artifact;
64+
await MySettingsService.getInstance().set('plugin-default-version', pluginDefalutVersion);
65+
pluginDefalutVersion = await MySettingsService.getInstance().get('plugin-default-version');
66+
67+
if (!pluginDefalutVersion) {
68+
return;
69+
}
70+
StudioV2Store.dispatch({
71+
type: PluginsActions.FETCH_PLUGINS_DEFAULT_VERSIONS,
72+
payload: pluginDefalutVersion,
73+
});
74+
} catch (err) {
75+
return;
76+
}
77+
}

0 commit comments

Comments
 (0)