Skip to content

Commit

Permalink
fix(core/pipeline): fully re-render list of trigger configs after a d…
Browse files Browse the repository at this point in the history
…elete (spinnaker#7571)
  • Loading branch information
Erik Munson authored and mergify[bot] committed Oct 28, 2019
1 parent 629a98f commit d71daa5
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { SETTINGS } from 'core/config/settings';
import { PipelineRoles } from './PipelineRoles';
import { Trigger } from './Trigger';

const { useState } = React;

export interface ITriggersPageContentProps {
application: Application;
pipeline: IPipeline;
Expand All @@ -28,9 +30,15 @@ export function TriggersPageContent(props: ITriggersPageContentProps) {
updatePipelineConfig,
} = props;
// must keep track of state to avoid race condition -- Remove once PipelineConfigurer is converted over to React
const [expectedArtifacts, setExpectedArtifacts] = React.useState<IExpectedArtifact[]>(
const [expectedArtifacts, setExpectedArtifacts] = useState<IExpectedArtifact[]>(
props.pipeline.expectedArtifacts ? props.pipeline.expectedArtifacts : [],
);
// KLUDGE: because we don't have a stable identifier to use for each trigger object, we need to reset the keys
// used for each trigger in the list when a delete happens (because the array of triggers shifts by one).
// For now, we do this by incrementing a counter every time a delete happens, and sticking that number
// into the key of each trigger before its index value. Ideally, we should generate stable UUIDs for
// each trigger object that we can use instead of relying on index keys.
const [deleteCount, setDeleteCount] = useState(0);

function updateRoles(roles: any[]): void {
updatePipelineConfig({ roles });
Expand All @@ -48,6 +56,7 @@ export function TriggersPageContent(props: ITriggersPageContentProps) {
function removeTrigger(triggerIndex: number): void {
const newTriggers = triggers.slice(0);
newTriggers.splice(triggerIndex, 1);
setDeleteCount(deleteCount + 1);
updatePipelineConfig({ triggers: newTriggers });
}

Expand Down Expand Up @@ -125,7 +134,7 @@ export function TriggersPageContent(props: ITriggersPageContentProps) {
</div>
)}
{triggers.map((trigger, index) => (
<div className="trigger-config" key={index}>
<div className="trigger-config" key={`${deleteCount}:${index}`}>
<Trigger
application={application}
index={index}
Expand Down

0 comments on commit d71daa5

Please sign in to comment.