Skip to content

Commit

Permalink
fix: Bugs after latest update (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmevladik authored and MykolaMarusenko committed Nov 15, 2024
1 parent cc65b34 commit fa62847
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import React from 'react';
import { ICONS } from '../../../../../../../../icons/iconify-icons-mapping';
import { CodebaseBranchActionsMenu } from '../../../../../../../../widgets/CodebaseBranchActionsMenu';
import { useTypedPermissions } from '../../../../../../hooks/useTypedPermissions';
import { useDynamicDataContext } from '../../../../../../providers/DynamicData/hooks';
import { ActionsProps } from './types';

export const Actions = ({
codebaseBranchData,
codebaseData,
pipelines,
defaultBranch,
}: ActionsProps) => {
export const Actions = ({ codebaseBranchData }: ActionsProps) => {
const buttonRef = React.createRef<HTMLButtonElement>();
const [anchor, setAnchor] = React.useState<EventTarget & HTMLButtonElement>(null);

const permissions = useTypedPermissions();

const {
codebaseBranches: { data: codebaseBranches },
component: { data: codebaseData },
pipelines: { data: pipelines },
} = useDynamicDataContext();

const defaultBranch = codebaseBranches?.[0];

return (
<>
<IconButton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { CodebaseKubeObjectInterface } from '../../../../../../../../k8s/groups/EDP/Codebase/types';
import { CodebaseBranchKubeObjectInterface } from '../../../../../../../../k8s/groups/EDP/CodebaseBranch/types';

export interface ActionsProps {
codebaseBranchData: CodebaseBranchKubeObjectInterface;
codebaseData: CodebaseKubeObjectInterface;
defaultBranch: CodebaseBranchKubeObjectInterface;
pipelines: {
review: string;
build: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { GIT_PROVIDERS } from '../../../../../../../../constants/gitProviders';
import { CUSTOM_RESOURCE_STATUSES } from '../../../../../../../../constants/statuses';
import { ICONS } from '../../../../../../../../icons/iconify-icons-mapping';
import { CodebaseBranchKubeObject } from '../../../../../../../../k8s/groups/EDP/CodebaseBranch';
import { useGitServerByCodebaseQuery } from '../../../../../../../../k8s/groups/EDP/GitServer/hooks/useGitServerByCodebaseQuery';
import { PipelineRunKubeObject } from '../../../../../../../../k8s/groups/Tekton/PipelineRun';
import { PIPELINE_RUN_REASON } from '../../../../../../../../k8s/groups/Tekton/PipelineRun/constants';
import { useCreateBuildPipelineRun } from '../../../../../../../../k8s/groups/Tekton/PipelineRun/hooks/useCreateBuildPipelineRun';
Expand All @@ -18,25 +17,21 @@ import { useTriggerTemplateByNameQuery } from '../../../../../../../../k8s/group
import { LinkCreationService } from '../../../../../../../../services/link-creation';
import { rem } from '../../../../../../../../utils/styling/rem';
import { useTypedPermissions } from '../../../../../../hooks/useTypedPermissions';
import { useDynamicDataContext } from '../../../../../../providers/DynamicData/hooks';
import { isDefaultBranch } from '../../../../../../utils';
import { Actions } from '../Actions';
import { useStyles } from './styles';
import { SummaryProps } from './types';

export const Summary = ({
codebaseData,
codebaseBranchData,
pipelineRuns,
defaultBranch,
pipelines,
}: SummaryProps) => {
export const Summary = ({ codebaseBranchData, pipelineRuns }: SummaryProps) => {
const {
component: { data: codebaseData },
gitServerByCodebase: { data: gitServerByCodebase },
} = useDynamicDataContext();

const permissions = useTypedPermissions();
const { createBuildPipelineRun } = useCreateBuildPipelineRun({});

const { data: gitServerByCodebase } = useGitServerByCodebaseQuery({
props: { codebaseGitServer: codebaseData?.spec.gitServer },
});

const { data: buildTriggerTemplate } = useTriggerTemplateByNameQuery({
props: {
name: `${gitServerByCodebase?.spec?.gitProvider}-build-template`,
Expand Down Expand Up @@ -234,12 +229,7 @@ export const Summary = ({
e.stopPropagation();
}}
>
<Actions
codebaseBranchData={codebaseBranchData}
codebaseData={codebaseData}
defaultBranch={defaultBranch}
pipelines={pipelines}
/>
<Actions codebaseBranchData={codebaseBranchData} />
</Grid>
</Grid>
</Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { CodebaseKubeObjectInterface } from '../../../../../../../../k8s/groups/EDP/Codebase/types';
import { CodebaseBranchKubeObjectInterface } from '../../../../../../../../k8s/groups/EDP/CodebaseBranch/types';
import { PipelineRunKubeObjectInterface } from '../../../../../../../../k8s/groups/Tekton/PipelineRun/types';

export interface SummaryProps {
codebaseBranchData: CodebaseBranchKubeObjectInterface;
codebaseData: CodebaseKubeObjectInterface;
pipelineRuns: {
all: PipelineRunKubeObjectInterface[];
latestBuildPipelineRun: PipelineRunKubeObjectInterface;
};
defaultBranch: CodebaseBranchKubeObjectInterface;
pipelines: {
review: string;
build: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PIPELINE_RUN_LABEL_SELECTOR_CODEBASE_BRANCH } from '../../../../../../k
import { PipelineRunKubeObjectInterface } from '../../../../../../k8s/groups/Tekton/PipelineRun/types';
import { sortKubeObjectByCreationTimestamp } from '../../../../../../utils/sort/sortKubeObjectsByCreationTimestamp';
import { rem } from '../../../../../../utils/styling/rem';
import { useDynamicDataContext } from '../../../../providers/DynamicData/hooks';
import { Details } from './components/Details';
import { Summary } from './components/Summary';
import { CodebaseBranchProps } from './types';
Expand All @@ -16,10 +17,11 @@ export const CodebaseBranch = ({
expandedPanel,
id,
handlePanelChange,
codebaseData,
defaultBranch,
pipelines,
}: CodebaseBranchProps) => {
const {
component: { data: codebaseData },
} = useDynamicDataContext();

const [pipelineRuns, setPipelineRuns] = React.useState<{
all: PipelineRunKubeObjectInterface[];
latestBuildPipelineRun: PipelineRunKubeObjectInterface;
Expand Down Expand Up @@ -87,13 +89,7 @@ export const CodebaseBranch = ({
},
}}
>
<Summary
codebaseData={codebaseData}
codebaseBranchData={codebaseBranchData}
pipelineRuns={pipelineRuns}
defaultBranch={defaultBranch}
pipelines={pipelines}
/>
<Summary codebaseBranchData={codebaseBranchData} pipelineRuns={pipelineRuns} />
</AccordionSummary>
<AccordionDetails>
<Details codebaseData={codebaseData} pipelineRuns={pipelineRuns} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import React from 'react';
import { CodebaseKubeObjectInterface } from '../../../../../../k8s/groups/EDP/Codebase/types';
import { CodebaseBranchKubeObjectInterface } from '../../../../../../k8s/groups/EDP/CodebaseBranch/types';

export interface CodebaseBranchProps {
codebaseBranchData: CodebaseBranchKubeObjectInterface;
expandedPanel: string;
id: string;
codebaseData: CodebaseKubeObjectInterface;
handlePanelChange: (panel: string) => (event: React.SyntheticEvent, isExpanded: boolean) => void;
defaultBranch: CodebaseBranchKubeObjectInterface;
pipelines: {
review: string;
build: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ export const CodebaseBranchesList = () => {
id={branchId}
codebaseBranchData={codebaseBranchData}
expandedPanel={expandedPanel}
codebaseData={component}
handlePanelChange={handleChange}
defaultBranch={codebaseBranches?.[0]}
pipelines={pipelines}
/>
);
})}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/component-details/providers/DynamicData/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ const initialData = {
export const DynamicDataContext = React.createContext<DynamicDataContextProviderValue>({
component: initialData,
pipelines: initialData,
codebaseBranches: initialData
codebaseBranches: initialData,
gitServerByCodebase: initialData,
});
15 changes: 14 additions & 1 deletion src/pages/component-details/providers/DynamicData/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiError } from '@kinvolk/headlamp-plugin/lib/lib/k8s/apiProxy';
import React from 'react';
import { useParams } from 'react-router-dom';
import { CodebaseKubeObject } from '../../../../k8s/groups/EDP/Codebase';
Expand All @@ -17,7 +18,11 @@ export const DynamicDataContextProvider: React.FC = ({ children }) => {

const [component, error] = CodebaseKubeObject.useGet(name, namespace);

const { data: gitServerByCodebase } = useGitServerByCodebaseQuery({
const {
data: gitServerByCodebase,
isLoading: gitServerByCodebaseIsLoading,
error: gitServerByCodebaseError,
} = useGitServerByCodebaseQuery({
props: { codebaseGitServer: component?.spec.gitServer },
});

Expand Down Expand Up @@ -60,13 +65,21 @@ export const DynamicDataContextProvider: React.FC = ({ children }) => {
error: codebaseBranchesError,
isLoading: codebaseBranches === null,
},
gitServerByCodebase: {
data: gitServerByCodebase,
error: gitServerByCodebaseError as ApiError,
isLoading: gitServerByCodebaseIsLoading,
},
}),
[
buildPipelineRefName,
codebaseBranches,
codebaseBranchesError,
component,
error,
gitServerByCodebase,
gitServerByCodebaseError,
gitServerByCodebaseIsLoading,
reviewPipelineRefName,
sortedCodebaseBranches,
]
Expand Down
2 changes: 2 additions & 0 deletions src/pages/component-details/providers/DynamicData/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CodebaseKubeObjectInterface } from '../../../../k8s/groups/EDP/Codebase/types';
import { CodebaseBranchKubeObjectInterface } from '../../../../k8s/groups/EDP/CodebaseBranch/types';
import { GitServerKubeObjectInterface } from '../../../../k8s/groups/EDP/GitServer/types';
import { DataProviderValue } from '../../../../types/pages';

export interface DynamicDataContextProviderValue {
Expand All @@ -9,4 +10,5 @@ export interface DynamicDataContextProviderValue {
build: string;
}>;
codebaseBranches: DataProviderValue<CodebaseBranchKubeObjectInterface[]>;
gitServerByCodebase: DataProviderValue<GitServerKubeObjectInterface>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ export const useTabs = ({ taskRun, task, stepName, pods }) => {
[stepName]
);

const defaultContainer = getDefaultContainer(pods?.[0]);

return React.useMemo(() => {
return [
{
label: 'Logs',
component: (
<TabContent>
<PodsLogViewer pods={pods} getDefaultContainer={getDefaultContainer} />
<PodsLogViewer
key={defaultContainer}
pods={pods}
getDefaultContainer={getDefaultContainer}
/>
</TabContent>
),
disabled: !pods?.length,
Expand All @@ -35,5 +41,5 @@ export const useTabs = ({ taskRun, task, stepName, pods }) => {
),
},
];
}, [details, getDefaultContainer, pods]);
}, [defaultContainer, details, getDefaultContainer, pods]);
};
2 changes: 1 addition & 1 deletion src/pages/pipeline-details/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function () {
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const queryParamTaskRun = queryParams.get('taskRun');

return (
<PageLogicWrapper>
<PermissionsContextProvider permissionConfigs={permissionsToCheckConfig}>
Expand Down
3 changes: 1 addition & 2 deletions src/pages/stage-details/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export const PageView = () => {

const permissions = useTypedPermissions();


const { activeTab, handleChangeTab} = useTabsContext();
const { activeTab, handleChangeTab } = useTabsContext();

return (
<PageWrapper
Expand Down
3 changes: 1 addition & 2 deletions src/providers/Tabs/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ import React from 'react';
import { TabsContext } from './context';
import { TabsContextProviderValue } from './types';

export const useTabsContext = () =>
React.useContext<TabsContextProviderValue>(TabsContext);
export const useTabsContext = () => React.useContext<TabsContextProviderValue>(TabsContext);
4 changes: 4 additions & 0 deletions src/services/link-creation/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export const GitURLService = {
}
},
createRepoBranchLink: (gitServer: GIT_PROVIDERS, baseUrl: string, branch: string) => {
if (!gitServer) {
return baseUrl;
}

const updatedUrl = new URL(baseUrl);

switch (gitServer.toLowerCase()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Icon } from '@iconify/react';
import {
ButtonGroup,
ClickAwayListener,
Grow,
ListItemIcon,
ListItemText,
MenuItem,
MenuList,
Paper,
Popper,
Stack,
useTheme,
ButtonGroup,
ClickAwayListener,
Grow,
ListItemIcon,
ListItemText,
MenuItem,
MenuList,
Paper,
Popper,
Stack,
useTheme,
} from '@mui/material';
import React from 'react';
import { ActionsInlineList } from '../../../../components/ActionsInlineList';
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/PodsLogViewer/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PodKubeObjectInterface } from "../../k8s/groups/default/Pod/types";
import { PodKubeObjectInterface } from '../../k8s/groups/default/Pod/types';

export interface PodsLogViewerProps {
pods: PodKubeObjectInterface[];
Expand Down

0 comments on commit fa62847

Please sign in to comment.