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

New pipeline flow is displayed on view page if there are no previous … #181

Merged
merged 2 commits into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
54 changes: 54 additions & 0 deletions app/mainapp/graphql/private/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/mainapp/graphql/private/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/mainapp/graphql/private/resolvers/pipelines.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Pipelines {
current: String!
workerGroup: String!
created_at: Time!
updated_at: Time!
node_type: String!
node_type_desc: String!
schedule: String!
Expand Down
5 changes: 3 additions & 2 deletions app/mainapp/graphql/private/resolvers/pipelines.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package privateresolvers

import (
"context"
permissions "dataplane/mainapp/auth_permissions"
"dataplane/mainapp/auth_permissions"
"dataplane/mainapp/config"
"dataplane/mainapp/database"
"dataplane/mainapp/database/models"
Expand Down Expand Up @@ -96,7 +96,6 @@ func (r *mutationResolver) AddUpdatePipelineFlow(ctx context.Context, input *pri
currentUser := ctx.Value("currentUser").(string)
platformID := ctx.Value("platformID").(string)

// Doesnt require concurrency safety, should be written / read in sequence.
var destinations = make(map[string][]string)
var dependencies = make(map[string][]string)
var triggerType string = ""
Expand Down Expand Up @@ -581,6 +580,7 @@ a.description,
a.active,
a.worker_group,
a.created_at,
a.updated_at,
b.node_type,
b.node_type_desc,
b.online,
Expand Down Expand Up @@ -614,6 +614,7 @@ a.description,
a.active,
a.worker_group,
a.created_at,
a.updated_at,
b.node_type,
b.node_type_desc,
b.online,
Expand Down
15 changes: 5 additions & 10 deletions frontend/src/components/TableContent/PipelineTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,19 @@ const PipelineTable = ({ data, filter, setPipelineCount, environmentID, getPipel
),
},
{
accessor: 'node_type_desc',
Header: 'Trigger',
accessor: (row) => row,
Cell: (row) =>
row.value ? (
row.value.node_type_desc ? (
<Box display="flex" alignItems="center">
<Box component={FontAwesomeIcon} fontSize={19} sx={{ color: 'secondary.main' }} icon={row.value === 'play' ? faPlayCircle : faClock} mr={1.5} />
<Typography color="secondary.main" variant="body2">
{row.value[0]?.toUpperCase() + row.value?.slice(1) + ' trigger'}
{row.value.node_type_desc[0]?.toUpperCase() + row.value.node_type_desc.slice(1) + ' trigger'}
{row.value.schedule && ' - ' + formatSchedule(row.value.schedule, row.value.schedule_type)}
</Typography>
</Box>
) : null,
},
{
Header: 'Schedule',
accessor: (row) => [row.schedule, row.schedule_type],
Cell: (row) => {
return <Typography variant="body2">{formatSchedule(row.value[0], row.value[1])}</Typography>;
},
},
{
accessor: 'online',
Cell: (row) => {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/graphql/getPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const query = gql`
online
current
created_at
updated_at
node_type
node_type_desc
schedule
Expand Down
1 change: 1 addition & 0 deletions frontend/src/graphql/getPipelineRuns.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const query = gql`
run_json
created_at
ended_at
updated_at
}
}
`;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/View/ActionLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import React from 'react';
import { useGlobalFlowState } from '../Flow';
import Timer from './Timer';

export function ActionLayer({ setElements, environmentId }) {
export function ActionLayer({ setElements, environmentId, pipeline }) {
// Global states
const FlowState = useGlobalFlowState();

return (
<Grid mt={4} container alignItems="center" sx={{ width: { xl: '88%' }, flexWrap: 'nowrap' }}>
{/* Timer */}
{FlowState.elements.get().length > 0 ? <Timer environmentID={environmentId} setElements={setElements} /> : null}
{FlowState.elements.get().length > 0 ? <Timer environmentID={environmentId} setElements={setElements} pipeline={pipeline} /> : null}
</Grid>
);
}
33 changes: 28 additions & 5 deletions frontend/src/pages/View/RunsDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import { useSnackbar } from 'notistack';
import { usePipelineTasksRun } from '../../graphql/getPipelineTasksRun';
import { useGlobalFlowState } from '../Flow';

export default function RunsDropdown({ environmentID, setElements, setPrevRunTime }) {
export default function RunsDropdown({ environmentID, setElements, setPrevRunTime, pipeline }) {
// Global states
const RunState = useGlobalRunState();

// Local state
const [selectedRun, setSelectedRun] = useState();
const [runs, setRuns] = useState([]);
const [isNewFlow, setIsNewFlow] = useState(true);

// GraphQL hooks
const getPipelineRuns = useGetPipelineRunsHook(environmentID, setRuns, setSelectedRun);
const getPipelineRuns = useGetPipelineRunsHook(environmentID, setRuns, setSelectedRun, pipeline);
const getPipelineTasksRun = usePipelineTasksRunHook();

// Get pipeline runs on load and environment change and after each run.
Expand All @@ -34,6 +35,15 @@ export default function RunsDropdown({ environmentID, setElements, setPrevRunTim
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [RunState.pipelineRunsTrigger.get()]);

// Set flow status,color on change
useEffect(() => {
if (runs.length === 0 || !pipeline) return;
if (pipeline.updated_at < runs[0].updated_at) {
setSelectedRun(runs[0]);
setIsNewFlow(false);
}
}, [pipeline, runs]);

// Update elements on run dropdown change
useEffect(() => {
if (!selectedRun) return;
Expand All @@ -52,7 +62,21 @@ export default function RunsDropdown({ environmentID, setElements, setPrevRunTim

return (
<Grid item alignItems="center" display="flex" width={520}>
{selectedRun || runs.length === 0 ? (
{selectedRun ? (
<Autocomplete
id="run_autocomplete"
onChange={(event, newValue) => {
setSelectedRun(newValue);
}}
value={selectedRun}
disableClearable
sx={{ minWidth: '520px' }}
options={runs}
getOptionLabel={(a) => formatDate(a.created_at) + ' - ' + a.run_id}
renderInput={(params) => <TextField {...params} label="Run" id="run" size="small" sx={{ fontSize: '.75rem', display: 'flex' }} />}
/>
) : null}
{isNewFlow ? (
<Autocomplete
id="run_autocomplete"
onChange={(event, newValue) => {
Expand All @@ -71,7 +95,7 @@ export default function RunsDropdown({ environmentID, setElements, setPrevRunTim
}

// ------ Custom hook
export const useGetPipelineRunsHook = (environmentID, setRuns, setSelectedRun) => {
export const useGetPipelineRunsHook = (environmentID, setRuns, setSelectedRun, pipeline) => {
// GraphQL hook
const getPipelineRuns = useGetPipelineRuns();

Expand All @@ -93,7 +117,6 @@ export const useGetPipelineRunsHook = (environmentID, setRuns, setSelectedRun) =
response.errors.map((err) => enqueueSnackbar(err.message, { variant: 'error' }));
} else {
setRuns(response);
setSelectedRun(response[0]);
}
};
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/View/Timer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useWebSocket, { useGlobalRunState } from './useWebSocket';
import StatusChips from './StatusChips';
import RunsDropdown from './RunsDropdown';

export default function Timer({ environmentID, setElements }) {
export default function Timer({ environmentID, setElements, pipeline }) {
// Global state
const FlowState = useGlobalFlowState();
const RunState = useGlobalRunState();
Expand Down Expand Up @@ -115,7 +115,7 @@ export default function Timer({ environmentID, setElements }) {

<StatusChips />

<RunsDropdown environmentID={environmentID} setElements={setElements} setPrevRunTime={setPrevRunTime} />
<RunsDropdown environmentID={environmentID} setElements={setElements} setPrevRunTime={setPrevRunTime} pipeline={pipeline} />

{isRunning ? (
<Typography variant="h3" ml={2}>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/View/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const View = () => {
</Grid>

{/* Run/Stop button, Chips, Timer */}
<ActionLayer setElements={setElements} environmentId={Environment.id.get()} />
<ActionLayer setElements={setElements} environmentId={Environment.id.get()} pipeline={pipeline} />
</Box>
{!FlowState.isOpenLogDrawer.get() && !isOpenAnalytics ? (
<Box mt={7} sx={{ position: 'absolute', top: offsetHeight, left: 0, right: 0, bottom: 0 }} ref={reactFlowWrapper}>
Expand Down