Skip to content

Commit

Permalink
Merge pull request #856 from MahtabBukhari/Add-an-archive-element-to-…
Browse files Browse the repository at this point in the history
…the-UI-for-features-on-workspace-view

Add an archive element to the UI for features on workspace view
  • Loading branch information
humansinstitute authored Jan 3, 2025
2 parents 1fa80ab + 6c8b2e1 commit 4a2304d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/people/widgetViews/WorkspaceMission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const EuiLinkStyled = styled(EuiLink)<{ isMobile: boolean }>`

const StatusWrap = styled.div`
margin-left: auto;
margin-right: 120px;
display: flex;
align-items: center;
justify-content: center;
Expand Down Expand Up @@ -283,6 +284,7 @@ const WorkspaceMission = () => {
const [workspaceData, setWorkspaceData] = useState<Workspace>();
const [loading, setLoading] = useState(true);
const [displayMission, setDidplayMission] = useState(false);
const [visibleFeatureStatus, setVisibleFeatureStatus] = useState<{ [key: string]: boolean }>({});
const [editMission, setEditMission] = useState(false);
const [displaySchematic, setDidplaySchematic] = useState(false);
const [editTactics, setEditTactics] = useState(false);
Expand Down Expand Up @@ -613,6 +615,30 @@ const WorkspaceMission = () => {
setDidplayMission(false);
};

const toggleFeatureStatus = (uuid: string) => {
setVisibleFeatureStatus((prevState: { [key: string]: boolean }) => ({
...prevState,
[uuid]: !prevState[uuid]
}));
};

const closeAllFeatureStatus = () => {
setVisibleFeatureStatus({});
};

const archiveFeatureStatus = async (uuid: string) => {
await main.archiveFeature(uuid);
ui.setToasts([
{
title: 'Archived',
color: 'success',
text: 'Feature is successfully archived'
}
]);
getFeatures();
closeAllFeatureStatus();
};

const missionChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
const newValue = e.target.value;
if (newValue.length) {
Expand Down Expand Up @@ -1224,6 +1250,26 @@ const WorkspaceMission = () => {
>
{feat.name}
</FeatureLink>
<OptionsWrap>
<MaterialIcon
icon={'more_horiz'}
className="MaterialIcon"
onClick={() => toggleFeatureStatus(feat.uuid)}
data-testid="mission-option-btn"
/>
{visibleFeatureStatus[feat.uuid] && (
<EditPopover>
<EditPopoverTail />
<EditPopoverContent
onClick={() => archiveFeatureStatus(feat.uuid)}
>
<EditPopoverText data-testid="mission-edit-btn">
Archive
</EditPopoverText>
</EditPopoverContent>
</EditPopover>
)}
</OptionsWrap>
<StatusWrap>
<StatusBox type="completed">
Completed
Expand Down
26 changes: 26 additions & 0 deletions src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3465,6 +3465,32 @@ export class MainStore {
}
}

async archiveFeature(uuid: string): Promise<any> {
try {
if (!uiStore.meInfo) return null;
const info = uiStore.meInfo;
const response = await fetch(`${TribesURL}/features/${uuid}/status`, {
method: 'PUT',
mode: 'cors',
headers: {
'x-jwt': info.tribe_jwt,
'Content-Type': 'application/json'
},
body: JSON.stringify({ status: 'archived' })
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

const data = await response.json();
return data;
} catch (e) {
console.log('Error archiveFeature', e);
return null;
}
}

async getRepositories(workspace_uuid: string): Promise<any> {
try {
if (!uiStore.meInfo) return [];
Expand Down

0 comments on commit 4a2304d

Please sign in to comment.