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

Refactor and introduce base history #19

Merged
merged 14 commits into from
May 14, 2022
Prev Previous commit
Next Next commit
WIP
joachimdalen committed May 7, 2022
commit c7ba67342d43f27d183a59881e4d1527eeb5f685
7 changes: 7 additions & 0 deletions .azext/changelog-cache.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"issues": [
{
"id": 1168792610,
"number": 3,
"submitter": "joachimdalen",
"title": "Processing history",
"url": "https://github.com/joachimdalen/azdevops-acceptance-criterias/issues/3"
},
{
"id": 1222231439,
"number": 16,
43 changes: 43 additions & 0 deletions .azext/changelog.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
[
{
"publishDate": "2022-05-XX",
"version": "1.1.0",
"changes": [
{
"type": "fix",
"description": "Fixed an issue that could cause an error to show when performing multiple processing actions without closing the panel"
}
],
"modules": [
{
"name": "work-hub",
"version": "1.0.3",
"changes": [
{
"type": "maint",
"description": "Remove unused setting from settings view"
}
]
},
{
"name": "wi-control",
"version": "1.0.1",
"changes": [
{
"type": "maint",
"description": "Remove unused code"
}
]
},
{
"name": "criteria-panel",
"version": "1.1.0",
"changes": [
{
"type": "feature",
"description": "Added processing history",
"issue": 3
}
]
}
]
},
{
"publishDate": "2022-05-01",
"version": "1.0.2",
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

## 1.1.0 (2022-05-XX)

### 🐛 Fixes (1)

- Fixed an issue that could cause an error to show when performing multiple processing actions without closing the panel

## 📦 Module changes

### 🛠️ Maintenance (2)

#### `[email protected]`

- Remove unused setting from settings view

#### `[email protected]`

- Remove unused code

### 🚀 Features (1)

#### `[email protected]`

- Added processing history
- Suggested in [GH#3 - Processing history](https://github.com/joachimdalen/azdevops-acceptance-criterias/issues/3)

---

## 1.0.2 (2022-05-01)

### 🛠️ Maintenance (1)
27 changes: 8 additions & 19 deletions src/common/services/CriteriaService.ts
Original file line number Diff line number Diff line change
@@ -147,35 +147,17 @@ class CriteriaService {
complete: boolean
): Promise<{ details: CriteriaDetailDocument; criteria?: IAcceptanceCriteria } | undefined> {
try {
const doc = await this._dataStore.getCriteriasForWorkItem(workItemId);
const details: CriteriaDetailDocument = (await this.getCriteriaDetails(criteriaId)) || {
id: criteriaId
};

const itemIndex = details.checklist?.criterias?.findIndex(x => x.id === checkItemId);

if (details.checklist?.criterias !== undefined && itemIndex !== undefined && itemIndex > -1) {
const preEditComplete = details.checklist.criterias.every(x => x.completed);
const newItem = { ...details.checklist.criterias[itemIndex] };
newItem.completed = complete;
details.checklist.criterias[itemIndex] = newItem;
const updated = await this._dataStore.setCriteriaDetailsDocument(details);
const isAllCompleted = details.checklist.criterias.every(x => x.completed);
if (doc !== undefined && (isAllCompleted || preEditComplete)) {
const newDoc = { ...doc };
const criteria = newDoc.criterias.find(x => x.id === criteriaId);
if (criteria !== undefined) {
const updt = this.setCriteriaItems(criteria, updated);
if (updt.criteria && updt.details) {
this.update(doc, updt.criteria, updt.details);

return {
details: updt.details,
criteria: updt.criteria
};
}
}
}

return {
details: updated
@@ -317,8 +299,15 @@ class CriteriaService {
}

const stateDoc = this.setFullState(newDocument);
await this._dataStore.setCriteriaDocument(stateDoc);
const updated = await this._dataStore.setCriteriaDocument(stateDoc);
const updatedDetails = await this._dataStore.setCriteriaDetailsDocument(details);

const docIndex = this._data.findIndex(x => x.id === stateDoc.id);

if (docIndex > -1) {
this._data[docIndex] = updated;
}

return {
criteria: criteria,
details: updatedDetails
20 changes: 20 additions & 0 deletions src/common/services/StorageService.ts
Original file line number Diff line number Diff line change
@@ -285,6 +285,26 @@ class StorageService implements IStorageService {
}
}

public async deleteHistory(id: string): Promise<void> {
try {
const dataService = await this.getDataService();
if (this._criteriaHistoryCollection === undefined) {
throw new Error('Failed to initialize ');
}
const dataManager = await dataService.getExtensionDataManager(
DevOps.getExtensionContext().id,
await DevOps.getAccessToken()
);
await dataManager.deleteDocument(this._criteriaHistoryCollection, id, {
scopeType: this.scopeType
});
} catch (error: any) {
if (error?.status !== 404) {
throw new Error(error);
}
}
}

public async getHistory(id: string): Promise<HistoryDocument | undefined> {
const dataService = await this.getDataService();

14 changes: 7 additions & 7 deletions src/common/types.ts
Original file line number Diff line number Diff line change
@@ -163,19 +163,19 @@ export const historyEventProperties: Map<HistoryEvent, EventProperties> = new Ma
>([
[
HistoryEvent.Completed,
{ icon: 'CheckMark', iconColor: 'text-blue', title: 'Completed criteria' }
],
[
HistoryEvent.ReOpened,
{ icon: 'Refresh', iconColor: 'text-purple', title: 'Reset back to new' }
{ icon: 'SkypeCircleCheck', iconColor: 'text-blue', title: 'Completed criteria' }
],
[HistoryEvent.ReOpened, { icon: 'CirclePlus', iconColor: 'text-blue', title: 'Reset back to new' }],
[
HistoryEvent.Approved,
{ icon: 'CheckMark', iconColor: 'text-green', title: 'Approved criteria' }
],
[
HistoryEvent.ReApprove,
{ icon: 'CheckMark', iconColor: 'text-green', title: 'Sent to re approval' }
{ icon: 'Refresh', iconColor: 'text-orange', title: 'Sent to re approval' }
],
[HistoryEvent.Rejected, { icon: 'Cancel', iconColor: 'text-red', title: 'Rejected criteria' }]
[
HistoryEvent.Rejected,
{ icon: 'StatusErrorFull', iconColor: 'text-red', title: 'Rejected criteria' }
]
]);
20 changes: 13 additions & 7 deletions src/criteria-panel/CriteriaPanel.tsx
Original file line number Diff line number Diff line change
@@ -56,10 +56,10 @@ import TextCriteriaViewSection from './components/view/TextCriteriaViewSection';
import { useCriteriaPanelContext } from './CriteriaPanelContext';
import { getSchema } from './CriteriaPanelData';


const CriteriaPanel = (): React.ReactElement => {
const { state: panelState, dispatch } = useCriteriaPanelContext();
const [tabId, setTabId] = useState('history');
const [tabId, setTabId] = useState('details');
const [eTag, setEtag] = useState<number | undefined>();
const [isError, setIsError] = useBooleanToggle();
const [criteriaService, storageService, historyService] = useMemo(
() => [
@@ -183,13 +183,15 @@ const CriteriaPanel = (): React.ReactElement => {
const crit = doc?.criterias.find(x => x.id === config.criteriaId);

if (crit) {
if (historyEvents === undefined || doc?.__etag !== eTag) {
setEtag(doc?.__etag);
const historyEvents = await historyService.getHistory(crit.id);
setHistoryEvents(historyEvents);
}
setCriteriaInfo(crit, details);
await checkApproval(crit);
}
}, config.workItemId);

const historyEvents = await historyService.getHistory(config.criteriaId);
setHistoryEvents(historyEvents);
}

setWorkItemId(config.workItemId);
@@ -456,8 +458,12 @@ const CriteriaPanel = (): React.ReactElement => {
selectedTabId={tabId}
className="margin-bottom-16"
>
<Tab id="details" name="Details" />
<Tab id="history" name="History" />
<Tab id="details" name="Details" iconProps={{ iconName: 'Page' }} />
<Tab
id="history"
name={`History (${historyEvents?.items.length})`}
iconProps={{ iconName: 'History' }}
/>
</TabBar>
</Surface>
</ConditionalChildren>
4 changes: 2 additions & 2 deletions src/criteria-panel/index.scss
Original file line number Diff line number Diff line change
@@ -24,6 +24,6 @@
.text-blue {
color: $status-info-foreground;
}
.text-purple {
color: purple;
.text-orange {
color: orange;
}
2 changes: 1 addition & 1 deletion src/criteria-panel/module.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"id": "criteria-panel",
"version": {
"Major": 1,
"Minor": 0,
"Minor": 1,
"Patch": 0
}
}
2 changes: 1 addition & 1 deletion src/wi-control/module.json
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 0
"Patch": 1
}
}
2 changes: 1 addition & 1 deletion src/work-hub/module.json
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 2
"Patch": 3
}
}