-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): TE-2448 added namespace config tab in configuration page (#…
…1604) * feat(ui): TE-2448 added namespace config tab in configuration page * added update and reset actions * handle disabled state * show full json * tab name chaged to Settings * fixes --------- Co-authored-by: Nalin Patidar <[email protected]>
- Loading branch information
1 parent
70e1196
commit 22d1dec
Showing
10 changed files
with
397 additions
and
5 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
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
141 changes: 141 additions & 0 deletions
141
thirdeye-ui/src/app/pages/namespace-configuration/api/index.tsx
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,141 @@ | ||
/* | ||
* Copyright 2024 StarTree Inc | ||
* | ||
* Licensed under the StarTree Community License (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.startree.ai/legal/startree-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OF ANY KIND, | ||
* either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
import { useEffect, useState } from "react"; | ||
import { ActionStatus } from "../../../rest/actions.interfaces"; | ||
import { | ||
useGetWorkspaceConfiguration, | ||
useResetWorkspaceConfiguration, | ||
useUpdateWorkspaceConfiguration, | ||
} from "../../../rest/workspace/workspace-action"; | ||
import { isEmpty, isEqual } from "lodash"; | ||
import { notifyIfErrors } from "../../../utils/notifications/notifications.util"; | ||
import { useNotificationProviderV1 } from "../../../platform/components"; | ||
import { useTranslation } from "react-i18next"; | ||
import { WorkspaceConfiguration } from "../../../rest/dto/workspace.interfaces"; | ||
|
||
type WorkspaceApiReques = { | ||
isError: boolean; | ||
isLoading: boolean; | ||
isUpdateDisabled: boolean; | ||
namespaceConfig: WorkspaceConfiguration | null; | ||
workspaceConfiguration: WorkspaceConfiguration | null; | ||
setNamespaceConfig: (config: WorkspaceConfiguration) => void; | ||
getWorkspaceConfiguration: () => Promise< | ||
WorkspaceConfiguration | undefined | ||
>; | ||
resetWorkspaceConfiguration: () => Promise< | ||
WorkspaceConfiguration | undefined | ||
>; | ||
updateWorkspaceConfiguration: ( | ||
config: WorkspaceConfiguration | ||
) => Promise<WorkspaceConfiguration | undefined>; | ||
}; | ||
|
||
export const useWorkspaceApiRequests = (): WorkspaceApiReques => { | ||
const [namespaceConfig, setNamespaceConfig] = | ||
useState<WorkspaceConfiguration | null>(null); | ||
|
||
const { notify } = useNotificationProviderV1(); | ||
const { t } = useTranslation(); | ||
|
||
const { | ||
workspaceConfiguration, | ||
getWorkspaceConfiguration, | ||
status: workspaceStatus, | ||
errorMessages: workspaceErrorMessages, | ||
} = useGetWorkspaceConfiguration(); | ||
|
||
const { | ||
resetWorkspaceConfiguration, | ||
status: resetStaus, | ||
errorMessages: resetErrorMessages, | ||
} = useResetWorkspaceConfiguration(); | ||
|
||
const { | ||
updateWorkspaceConfiguration, | ||
status: updateStatus, | ||
errorMessages: updateErrorMessages, | ||
} = useUpdateWorkspaceConfiguration(); | ||
|
||
useEffect(() => { | ||
getWorkspaceConfiguration(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (!isEmpty(workspaceConfiguration)) { | ||
setNamespaceConfig(workspaceConfiguration); | ||
} | ||
}, [workspaceConfiguration]); | ||
|
||
useEffect(() => { | ||
notifyIfErrors( | ||
workspaceStatus, | ||
workspaceErrorMessages, | ||
notify, | ||
t("message.error-while-fetching", { | ||
entity: t("label.settings"), | ||
}) | ||
); | ||
}, [workspaceStatus]); | ||
|
||
useEffect(() => { | ||
if (resetStaus === ActionStatus.Done) { | ||
getWorkspaceConfiguration(); | ||
} | ||
notifyIfErrors( | ||
resetStaus, | ||
resetErrorMessages, | ||
notify, | ||
t("message.update-error", { | ||
entity: t("label.settings"), | ||
}) | ||
); | ||
}, [resetStaus]); | ||
|
||
useEffect(() => { | ||
if (updateStatus === ActionStatus.Done) { | ||
getWorkspaceConfiguration(); | ||
} | ||
notifyIfErrors( | ||
updateStatus, | ||
updateErrorMessages, | ||
notify, | ||
t("message.update-error", { | ||
entity: t("label.settings"), | ||
}) | ||
); | ||
}, [updateStatus]); | ||
|
||
const isError = workspaceStatus === ActionStatus.Error; | ||
|
||
const isLoading = | ||
workspaceStatus === ActionStatus.Working || | ||
updateStatus === ActionStatus.Working || | ||
resetStaus === ActionStatus.Working; | ||
|
||
const isUpdateDisabled = isEqual(namespaceConfig, workspaceConfiguration); | ||
|
||
return { | ||
isError, | ||
isLoading, | ||
isUpdateDisabled, | ||
namespaceConfig, | ||
workspaceConfiguration, | ||
setNamespaceConfig, | ||
getWorkspaceConfiguration, | ||
resetWorkspaceConfiguration, | ||
updateWorkspaceConfiguration, | ||
}; | ||
}; |
91 changes: 91 additions & 0 deletions
91
thirdeye-ui/src/app/pages/namespace-configuration/index.tsx
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,91 @@ | ||
/* | ||
* Copyright 2024 StarTree Inc | ||
* | ||
* Licensed under the StarTree Community License (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.startree.ai/legal/startree-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OF ANY KIND, | ||
* either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
import React from "react"; | ||
import { ConfigurationPageHeader } from "../../components/configuration-page-header/configuration-page-header.component"; | ||
import { | ||
JSONEditorV1, | ||
PageContentsGridV1, | ||
PageV1, | ||
} from "../../platform/components"; | ||
import { LoadingErrorStateSwitch } from "../../components/page-states/loading-error-state-switch/loading-error-state-switch.component"; | ||
|
||
import { Box, Button, Grid } from "@material-ui/core"; | ||
import { WorkspaceConfiguration } from "../../rest/dto/workspace.interfaces"; | ||
import { useWorkspaceApiRequests } from "./api"; | ||
|
||
export const NamespaceConfiguration = (): JSX.Element => { | ||
const { | ||
isError, | ||
isLoading, | ||
isUpdateDisabled, | ||
namespaceConfig, | ||
setNamespaceConfig, | ||
resetWorkspaceConfiguration, | ||
updateWorkspaceConfiguration, | ||
} = useWorkspaceApiRequests(); | ||
|
||
const handleNamespaceConfigChange = (value: string): void => { | ||
setNamespaceConfig(JSON.parse(value)); | ||
}; | ||
const handleReset = (): void => { | ||
resetWorkspaceConfiguration(); | ||
}; | ||
const handleUpdate = async (): Promise<void> => { | ||
updateWorkspaceConfiguration(namespaceConfig as WorkspaceConfiguration); | ||
}; | ||
|
||
return ( | ||
<PageV1> | ||
<ConfigurationPageHeader selectedIndex={6} /> | ||
<PageContentsGridV1 fullHeight> | ||
<Grid container justifyContent="flex-end"> | ||
<Grid item xs={12}> | ||
<LoadingErrorStateSwitch | ||
wrapInCard | ||
wrapInGrid | ||
isError={isError} | ||
isLoading={isLoading} | ||
> | ||
<JSONEditorV1<any> | ||
hideValidationSuccessIcon | ||
value={namespaceConfig} | ||
onChange={handleNamespaceConfigChange} | ||
/> | ||
</LoadingErrorStateSwitch> | ||
</Grid> | ||
<Grid item> | ||
<Box display="flex" gridGap={12}> | ||
<Button | ||
color="primary" | ||
disabled={isUpdateDisabled} | ||
variant="outlined" | ||
onClick={handleUpdate} | ||
> | ||
Update | ||
</Button> | ||
<Button | ||
color="primary" | ||
variant="outlined" | ||
onClick={handleReset} | ||
> | ||
Reset | ||
</Button> | ||
</Box> | ||
</Grid> | ||
</Grid> | ||
</PageContentsGridV1> | ||
</PageV1> | ||
); | ||
}; |
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
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
Oops, something went wrong.