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

[MI-2410] Updated subscription card to display run event filters and filter popover for pipelines #123

Merged
merged 14 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 13 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
18 changes: 17 additions & 1 deletion server/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ const (
FilterAll = "all"
FilterBoards = "boards"
FilterRepos = "repos"
EventTypeRelease = "release"
FilterPipelines = "pipelines"
FilterReleaseDefinitionID = "releaseDefinitionId"
FilterReleaseEnvironmentID = "releaseEnvironmentId"

EventOfTypeRelease = "release"
ayusht2810 marked this conversation as resolved.
Show resolved Hide resolved

DefaultPage = 0
DefaultPerPageLimit = 50

Expand Down Expand Up @@ -163,6 +165,20 @@ var (
SubscriptionEventCodePushed: true,
}

ValidSubscriptionEventsForPipelines = map[string]bool{
SubscriptionEventBuildCompleted: true,
SubscriptionEventReleaseAbandoned: true,
SubscriptionEventReleaseCreated: true,
SubscriptionEventReleaseDeploymentApprovalCompleted: true,
SubscriptionEventReleaseDeploymentEventPending: true,
SubscriptionEventReleaseDeploymentCompleted: true,
SubscriptionEventReleaseDeploymentStarted: true,
SubscriptionEventRunStageApprovalCompleted: true,
SubscriptionEventRunStageStateChanged: true,
SubscriptionEventRunStageWaitingForApproval: true,
SubscriptionEventRunStateChanged: true,
}

ValidSubscriptionEventsForRun = map[string]bool{
SubscriptionEventRunStageApprovalCompleted: true,
SubscriptionEventRunStageStateChanged: true,
Expand Down
20 changes: 20 additions & 0 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,15 @@ func (p *Plugin) handleCreateSubscription(w http.ResponseWriter, r *http.Request
ApprovalTypeName: body.ApprovalTypeName,
ApprovalStatusName: body.ApprovalStatusName,
RunPipeline: body.RunPipeline,
RunPipelineName: body.RunPipelineName,
RunStageName: body.RunStageName,
RunEnvironmentName: body.RunEnvironmentName,
RunStageNameID: body.RunStageNameID,
RunStageStateID: body.RunStageStateID,
RunStageStateIDName: body.RunStageStateIDName,
RunStageResultID: body.RunStageResultID,
RunStateID: body.RunStateID,
RunStateIDName: body.RunStateIDName,
RunResultID: body.RunResultID,
}); storeErr != nil {
p.API.LogError("Error in creating a subscription", "Error", storeErr.Error())
Expand Down Expand Up @@ -457,6 +460,17 @@ func (p *Plugin) handleGetSubscriptions(w http.ResponseWriter, r *http.Request)
subscriptionByProject = append(subscriptionByProject, subscription)
}
}
case constants.FilterPipelines:
switch eventType {
case "", constants.FilterAll:
if constants.ValidSubscriptionEventsForPipelines[subscription.EventType] {
subscriptionByProject = append(subscriptionByProject, subscription)
}
default:
if subscription.EventType == eventType {
subscriptionByProject = append(subscriptionByProject, subscription)
}
}
}
}
}
Expand All @@ -480,13 +494,16 @@ func (p *Plugin) handleGetSubscriptions(w http.ResponseWriter, r *http.Request)
subscriptionByProject[i].StageNameValue+
subscriptionByProject[i].ReleaseStatusName+
subscriptionByProject[i].RunPipeline+
subscriptionByProject[i].RunPipelineName+
subscriptionByProject[i].ReleasePipelineName+
subscriptionByProject[i].RunStageName+
subscriptionByProject[i].RunEnvironmentName+
subscriptionByProject[i].RunStageNameID+
subscriptionByProject[i].RunStageStateID+
subscriptionByProject[i].RunStageStateIDName+
subscriptionByProject[i].RunStageResultID+
subscriptionByProject[i].RunStateID+
subscriptionByProject[i].RunStateIDName+
subscriptionByProject[i].RunResultID <
subscriptionByProject[j].ChannelName+
subscriptionByProject[j].EventType+
Expand All @@ -505,13 +522,16 @@ func (p *Plugin) handleGetSubscriptions(w http.ResponseWriter, r *http.Request)
subscriptionByProject[i].StageNameValue+
subscriptionByProject[i].ReleaseStatusName+
subscriptionByProject[i].RunPipeline+
subscriptionByProject[i].RunPipelineName+
subscriptionByProject[i].ReleasePipelineName+
subscriptionByProject[i].RunStageName+
subscriptionByProject[i].RunEnvironmentName+
subscriptionByProject[i].RunStageNameID+
subscriptionByProject[i].RunStageStateID+
subscriptionByProject[i].RunStageStateIDName+
subscriptionByProject[i].RunStageResultID+
subscriptionByProject[i].RunStateID+
subscriptionByProject[i].RunStateIDName+
subscriptionByProject[i].RunResultID
})

Expand Down
8 changes: 4 additions & 4 deletions server/plugin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ func (c *client) GetSubscriptionFilterPossibleValues(request *serializers.GetSub

var subscriptionFilters []*serializers.SubscriptionFilter
for _, filter := range request.Filters {
if strings.Contains(request.EventType, constants.EventTypeRelease) && (filter == constants.FilterReleaseDefinitionID || filter == constants.FilterReleaseEnvironmentID) {
if strings.Contains(request.EventType, constants.EventOfTypeRelease) && (filter == constants.FilterReleaseDefinitionID || filter == constants.FilterReleaseEnvironmentID) {
subscriptionFilters = append(subscriptionFilters, &serializers.SubscriptionFilter{InputID: filter})
} else if !strings.Contains(request.EventType, constants.EventTypeRelease) {
} else if !strings.Contains(request.EventType, constants.EventOfTypeRelease) {
subscriptionFilters = append(subscriptionFilters, &serializers.SubscriptionFilter{InputID: filter})
}
}
Expand All @@ -297,7 +297,7 @@ func (c *client) GetSubscriptionFilterPossibleValues(request *serializers.GetSub
}
}

if strings.Contains(request.EventType, constants.EventTypeRelease) {
if strings.Contains(request.EventType, constants.EventOfTypeRelease) {
subscriptionFiltersRequest.Subscription.PublisherInputs = serializers.PublisherInputsGeneric{
ProjectID: request.ProjectID,
ReleaseDefinitionID: request.ReleasePipelineID,
Expand All @@ -312,7 +312,7 @@ func (c *client) GetSubscriptionFilterPossibleValues(request *serializers.GetSub
}

baseURL := c.plugin.getConfiguration().AzureDevopsAPIBaseURL
if strings.Contains(request.EventType, constants.EventTypeRelease) {
if strings.Contains(request.EventType, constants.EventOfTypeRelease) {
baseURL = strings.Replace(baseURL, "://", "://vsrm.", 1)
}

Expand Down
6 changes: 6 additions & 0 deletions server/serializers/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ type CreateSubscriptionRequestPayload struct {
ReleaseStatus string `json:"releaseStatus"`
ReleaseStatusName string `json:"releaseStatusName"`
RunPipeline string `json:"runPipeline"`
RunPipelineName string `json:"runPipelineName"`
RunStageName string `json:"runStage"`
RunEnvironmentName string `json:"runEnvironment"`
RunStageNameID string `json:"runStageId"`
RunStageStateID string `json:"runStageStateId"`
RunStageStateIDName string `json:"runStageStateIdName"`
RunStageResultID string `json:"runStageResultId"`
RunStateID string `json:"runStateId"`
RunStateIDName string `json:"runStateIdName"`
RunResultID string `json:"runResultId"`
}

Expand Down Expand Up @@ -189,12 +192,15 @@ type SubscriptionDetails struct {
ReleaseStatus string `json:"releaseStatus"`
ReleaseStatusName string `json:"releaseStatusName"`
RunPipeline string `json:"runPipeline"`
RunPipelineName string `json:"runPipelineName"`
RunStageName string `json:"runStage"`
RunEnvironmentName string `json:"runEnvironment"`
RunStageNameID string `json:"runStageId"`
RunStageStateID string `json:"runStageStateId"`
RunStageStateIDName string `json:"runStageStateIdName"`
RunStageResultID string `json:"runStageResultId"`
RunStateID string `json:"runStateId"`
RunStateIDName string `json:"runStateIdName"`
RunResultID string `json:"runResultId"`
}

Expand Down
3 changes: 3 additions & 0 deletions server/store/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ func (subscriptionList *SubscriptionList) AddSubscription(userID string, subscri
ApprovalTypeName: subscription.ApprovalTypeName,
ApprovalStatusName: subscription.ApprovalStatusName,
RunPipeline: subscription.RunPipeline,
RunPipelineName: subscription.RunPipelineName,
RunStageName: subscription.RunStageName,
RunEnvironmentName: subscription.RunEnvironmentName,
RunStageNameID: subscription.RunStageNameID,
RunStageStateID: subscription.RunStageStateID,
RunStageStateIDName: subscription.RunStageStateIDName,
RunStageResultID: subscription.RunStageResultID,
RunStateID: subscription.RunStateID,
RunStateIDName: subscription.RunStateIDName,
RunResultID: subscription.RunResultID,
}
subscriptionList.ByMattermostUserID[userID][subscriptionKey] = subscriptionListValue
Expand Down
10 changes: 9 additions & 1 deletion webapp/src/components/card/subscription/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type SubscriptionCardProps = {
subscriptionDetails: SubscriptionDetails
}

const SubscriptionCard = ({handleDeleteSubscrption, subscriptionDetails: {channelType, eventType, serviceType, channelName, createdBy, targetBranch, repositoryName, pullRequestCreatedByName, pullRequestReviewersContainsName, pushedByName, mergeResultName, notificationTypeName, areaPath, releasePipelineName, buildPipeline, buildStatusName, approvalStatusName, approvalTypeName, releaseStatusName, stageNameValue}, subscriptionDetails}: SubscriptionCardProps) => {
const SubscriptionCard = ({handleDeleteSubscrption, subscriptionDetails: {channelType, eventType, serviceType, channelName, createdBy, targetBranch, repositoryName, pullRequestCreatedByName, pullRequestReviewersContainsName, pushedByName, mergeResultName, notificationTypeName, areaPath, releasePipelineName, buildPipeline, buildStatusName, approvalStatusName, approvalTypeName, releaseStatusName, stageNameValue, runPipelineName, runEnvironment, runStage, runStageId, runResultId, runStageResultId, runStageStateIdName, runStateIdName}, subscriptionDetails}: SubscriptionCardProps) => {
const showFilter = areaPath || repositoryName || targetBranch || pullRequestCreatedByName || pullRequestReviewersContainsName || pushedByName || mergeResultName || notificationTypeName;

return (
Expand Down Expand Up @@ -97,6 +97,14 @@ const SubscriptionCard = ({handleDeleteSubscrption, subscriptionDetails: {channe
{approvalStatusName && <Chip text={`Approval status is: ${approvalStatusName}`}/>}
{approvalTypeName && <Chip text={`Approval type is: ${approvalTypeName}`}/>}
{releaseStatusName && <Chip text={`Release status is: ${releaseStatusName}`}/>}
{runPipelineName && <Chip text={`Pipeline is: ${runPipelineName}`}/>}
{runEnvironment && <Chip text={`Environment is: ${runEnvironment}`}/>}
{runStage && <Chip text={`Stage is: ${runStage}`}/>}
{runStageId && <Chip text={`Stage is: ${runStageId}`}/>}
ayusht2810 marked this conversation as resolved.
Show resolved Hide resolved
raghavaggarwal2308 marked this conversation as resolved.
Show resolved Hide resolved
{runStageStateIdName && <Chip text={`Stage state is: ${runStageStateIdName}`}/>}
{runStageResultId && <Chip text={`Stage result is: ${runStageResultId}`}/>}
{runStateIdName && <Chip text={`State is: ${runStateIdName}`}/>}
avas27JTG marked this conversation as resolved.
Show resolved Hide resolved
{runResultId && <Chip text={`Result is: ${runResultId}`}/>}
</div>
</div>
)
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/containers/Rhs/projectDetails/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import useApiRequestCompletionState from 'hooks/useApiRequestCompletionState';
import IconButton from 'components/buttons/iconButton';
import SVGWrapper from 'components/svgWrapper';
import useOutsideClick from 'hooks/useClickOutside';
import {subscriptionFilterEventTypeReposOptions} from 'pluginConstants/form';
import utils from 'utils';

type HeaderProps = {
Expand All @@ -33,7 +32,7 @@ type HeaderProps = {
const Header = ({projectDetails, showAllSubscriptions, handlePagination, setShowAllSubscriptions, handleResetProjectDetails, filter, setFilter, setSubscriptionList}: HeaderProps) => {
const {projectName} = projectDetails;
const {defaultSubscriptionFilters, subscriptionFilters, filterLabelValuePairAll} = pluginConstants.common;
const {subscriptionFilterCreatedByOptions, subscriptionFilterServiceTypeOptions, subscriptionFilterEventTypeBoardsOptions, subscriptionModal} = pluginConstants.form;
const {subscriptionFilterCreatedByOptions, subscriptionFilterServiceTypeOptions, subscriptionFilterEventTypeBoardsOptions, subscriptionFilterEventTypeReposOptions, subscriptionFilterEventTypePipelinesOptions} = pluginConstants.form;
const [showProjectConfirmationModal, setShowProjectConfirmationModal] = useState(false);
const [deleteSubscriptions, setDeleteSubscriptions] = useState(false);
const [showDeleteSubscriptionsCheckbox, setShowDeleteSubscriptionsCheckbox] = useState(true);
Expand All @@ -51,6 +50,8 @@ const Header = ({projectDetails, showAllSubscriptions, handlePagination, setShow
return subscriptionFilterEventTypeBoardsOptions();
case subscriptionFilters.serviceType.repos:
return subscriptionFilterEventTypeReposOptions();
case subscriptionFilters.serviceType.pipelines:
return subscriptionFilterEventTypePipelinesOptions();
default:
return [filterLabelValuePairAll];
}
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/containers/Rhs/projectDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,15 @@ const ProjectDetails = memo((projectDetails: ProjectDetails) => {
stageNameValue: subscriptionDetails.stageNameValue,
releaseStatusName: subscriptionDetails.releaseStatusName,
runPipeline: subscriptionDetails.runPipeline,
runPipelineName: subscriptionDetails.runPipelineName,
runStage: subscriptionDetails.runStage,
runEnvironment: subscriptionDetails.runEnvironment,
runStageId: subscriptionDetails.runStageId,
runStageStateId: subscriptionDetails.runStageStateId,
runStageStateIdName: subscriptionDetails.runStageStateIdName,
runStageResultId: subscriptionDetails.runStageResultId,
runStateId: subscriptionDetails.runStateId,
runStateIdName: subscriptionDetails.runStateIdName,
runResultId: subscriptionDetails.runResultId,
});
setDeleteConfirmationModalError(null);
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/containers/modals/SubscribeModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ const SubscribeModal = () => {
setSpecificFieldValue({
...formFields,
runPipeline: newValue === filterLabelValuePairAll.value ? '' : newValue,
runPipelineName: pipelienName === filterLabelValuePairAll.value ? '' : pipelienName,
runStage: newValue === filterLabelValuePairAll.value ? '' : formFields.runStage,
runStageId: newValue === filterLabelValuePairAll.value ? '' : formFields.runStageId,
});
Expand All @@ -385,6 +386,7 @@ const SubscribeModal = () => {
setSpecificFieldValue({
...formFields,
runStageStateId: newValue === filterLabelValuePairAll.value ? '' : newValue,
runStageStateIdName: stateId === filterLabelValuePairAll.value ? '' : stateId,
runStageResultId: (newValue !== filterLabelValuePairAll.value && newValue !== 'Completed') ? '' : formFields.runStageResultId,
});

Expand All @@ -398,6 +400,7 @@ const SubscribeModal = () => {
setSpecificFieldValue({
...formFields,
runStateId: newValue === filterLabelValuePairAll.value ? '' : newValue,
runStateIdName: stateId === filterLabelValuePairAll.value ? '' : stateId,
runResultId: (newValue !== filterLabelValuePairAll.value && newValue !== 'Completed') ? '' : formFields.runResultId,
});

Expand Down
4 changes: 4 additions & 0 deletions webapp/src/pluginConstants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const subscriptionFilters = {
serviceType: {
boards: 'boards',
repos: 'repos',
pipelines: 'pipelines',
all: 'all',
},
eventType: {
Expand All @@ -96,6 +97,9 @@ export const subscriptionFilters = {
repos: {
...eventTypeRepos,
},
pipelines: {
...eventTypePipelines,
},
all: 'all',
},
};
Expand Down
32 changes: 32 additions & 0 deletions webapp/src/pluginConstants/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ export const subscriptionModal: Record<SubscriptionModalFields, ModalFormFieldCo
type: 'hidden',
value: '',
},
runPipelineName: {
label: 'Pipeline',
type: 'hidden',
value: '',
},
runStage: {
label: 'Stage',
type: 'hidden',
Expand All @@ -469,6 +474,12 @@ export const subscriptionModal: Record<SubscriptionModalFields, ModalFormFieldCo
value: '',
optionsList: runStageStateIdOptions,
},
runStageStateIdName: {
label: 'State',
type: 'hidden',
value: '',
optionsList: runStageStateIdOptions,
},
runStageResultId: {
label: 'Result',
type: 'hidden',
Expand All @@ -481,6 +492,12 @@ export const subscriptionModal: Record<SubscriptionModalFields, ModalFormFieldCo
value: '',
optionsList: runStateIdOptions,
},
runStateIdName: {
label: 'State',
type: 'hidden',
value: '',
optionsList: runStateIdOptions,
},
runResultId: {
label: 'Result',
type: 'hidden',
Expand Down Expand Up @@ -612,6 +629,10 @@ export const subscriptionFilterServiceTypeOptions = [
value: subscriptionFilters.serviceType.repos,
label: 'Repos',
},
{
value: subscriptionFilters.serviceType.pipelines,
label: 'Pipelines',
},
{
...filterLabelValuePairAll,
},
Expand Down Expand Up @@ -639,6 +660,17 @@ export const subscriptionFilterEventTypeReposOptions = () => {
return options;
};

export const subscriptionFilterEventTypePipelinesOptions = () => {
const options: LabelValuePair[] = [];
Object.keys(subscriptionFilters.eventType.pipelines).forEach((eventType) => options.push({
value: eventType,
label: subscriptionFilters.eventType.pipelines[eventType as EventTypePipelines],
}));

options.push(filterLabelValuePairAll);
return options;
};

// Repos subscription filters
export const mergeResultOptons: LabelValuePair[] = [
{
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/pluginConstants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
subscriptionModal,
subscriptionFilterCreatedByOptions,
subscriptionFilterServiceTypeOptions,
subscriptionFilterEventTypePipelinesOptions,
subscriptionFilterEventTypeBoardsOptions,
subscriptionFilterEventTypeReposOptions,
mergeResultOptons,
Expand Down Expand Up @@ -83,6 +84,7 @@ export default {
subscriptionModal,
subscriptionFilterCreatedByOptions,
subscriptionFilterServiceTypeOptions,
subscriptionFilterEventTypePipelinesOptions,
subscriptionFilterEventTypeBoardsOptions,
subscriptionFilterEventTypeReposOptions,
mergeResultOptons,
Expand Down
Loading