Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get version using restAPI #2242

Open
wants to merge 12 commits into
base: feature_branch/remove-experiment-tracking
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions package/kedro_viz/api/rest/responses/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""`kedro_viz.api.rest.responses.version` contains response classes
and utility functions for the `/version` REST endpoint"""

from kedro_viz import __version__
from pydantic import BaseModel, ConfigDict
from kedro_viz.api.rest.responses.base import BaseAPIResponse

class VersionAPIResponse(BaseAPIResponse):
"""
VersionAPIResponse is a subclass of BaseAPIResponse that represents the response structure for version API.

Attributes:
installed (str): The installed version of the Kedro Viz package.
isOutdated (bool): Whether the installed version is outdated.
latest (str): The latest available version of the Kedro Viz package.
"""

installed: str
isOutdated: bool
latest: str
model_config = ConfigDict(
json_schema_extra={
"installed": __version__,
"isOutdated": False,
"latest": "0.5.0" # how do i check the latest version?
}
)

def get_version_response():
"""API response for `/api/version`."""
installed_version = __version__
latest_version = "0.5.0" # how do i check the latest version?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from kedro_viz.integrations.pypi import get_latest_version, is_running_outdated_version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the same logic as we do in graphql

latest_version = get_latest_version()
is_outdated=is_running_outdated_version(installed_version, latest_version),

is_outdated = installed_version != latest_version

return VersionAPIResponse(
installed=installed_version,
isOutdated=is_outdated,
latest=latest_version
)
12 changes: 12 additions & 0 deletions package/kedro_viz/api/rest/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
GraphAPIResponse,
get_pipeline_response,
)
from kedro_viz.api.rest.responses.version import (
VersionAPIResponse,
get_version_response,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -49,6 +53,14 @@ async def get_single_node_metadata(node_id: str):
async def get_single_pipeline_data(registered_pipeline_id: str):
return get_pipeline_response(registered_pipeline_id)

@router.get(
"/version",
response_model=VersionAPIResponse,
)

asyn def get_version():
return get_version_response()


@router.post("/deploy")
async def deploy_kedro_viz(input_values: DeployerConfiguration):
Expand Down
28 changes: 24 additions & 4 deletions src/components/wrapper/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useApolloQuery } from '../../apollo/utils';
import { client } from '../../apollo/config';
import { GraphQLProvider } from '../provider/provider';
import { GET_VERSIONS } from '../../apollo/queries';
import { getVersion } from '../../utils';

import FeatureHints from '../feature-hints';
import GlobalToolbar from '../global-toolbar';
Expand All @@ -29,11 +30,30 @@ export const Wrapper = ({ displayGlobalNavigation, theme }) => {
const [latestVersion, setLatestVersion] = useState(null);

useEffect(() => {
if (versionData) {
setIsOutdated(versionData.version.isOutdated);
setLatestVersion(versionData.version.latest);
async function checkKedroVizVersion() {
try {
debugger;
const request = await getVersion();
const response = await request.json();

if (request.ok) {
setIsOutdated(response.isOutdated);
setLatestVersion(response.latest);
}
} catch (error) {
console.error('Error fetching Kedro-Viz version:', error);
}
}
}, [versionData]);

checkKedroVizVersion();
}, []);

// useEffect(() => {
// if (versionData) {
// setIsOutdated(versionData.version.isOutdated);
// setLatestVersion(versionData.version.latest);
// }
// }, [versionData]);

return (
<div
Expand Down
10 changes: 10 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ export async function deployViz(inputValues) {
return request;
}

export async function getVersion() {
const request = await fetch(`api/version`, {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
});
return request;
}

const nodeTypeMapObj = {
nodes: 'task',
task: 'nodes',
Expand Down
Loading