Skip to content

Commit

Permalink
#231 warn when changing Asana workspace or site tag settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleBlanchette committed Nov 25, 2024
1 parent 30dac30 commit 4aa5513
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/settings/WorkspaceSettings.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Button, Card, CardBody, CardDivider, CardHeader, CardMedia, ComboboxControl, Flex, FlexBlock, FlexItem, SelectControl } from '@wordpress/components';
import { Button, Card, CardBody, CardDivider, CardHeader, CardMedia, ComboboxControl, Flex, FlexBlock, FlexItem, Notice, SelectControl } from '@wordpress/components';

import CollaboratorsTable from '../users/CollaboratorsTable';
import MissingPermissionsBadge from '../users/MissingPermissionsBadge';

import { SettingsContext } from './SettingsContext';

import apiFetch from '@wordpress/api-fetch';
import { useContext, useRef, useState } from '@wordpress/element';
import { useContext, useEffect, useRef, useState } from '@wordpress/element';

export default function WorkspaceSettings() {
const { settings, hasConnectedAsana, updateSettings, getWorkspaceCollaborators, userCan } = useContext(SettingsContext);
Expand All @@ -29,6 +29,12 @@ export default function WorkspaceSettings() {
const tagTypeaheadAbortControllerRef = useRef(null);
const PREFIX_CREATE_TAG = '__create__';

useEffect(() => {
if ( ! asanaTagOptionsByWorkspace[ asanaWorkspaceValue ]?.some(option => asanaTagValue === option?.value) ) {
setAsanaTagValue(''); // The current site tag value is invalid since there is no matching option.
}
}, [asanaTagOptionsByWorkspace, asanaWorkspaceValue, asanaTagValue, setAsanaTagValue]);

function handleAsanaTagFilterValueChange(value) {

if ( 'function' === typeof tagTypeaheadAbortControllerRef.current?.abort ) {
Expand Down Expand Up @@ -139,6 +145,10 @@ export default function WorkspaceSettings() {
onChange={setAsanaWorkspaceValue}
disabled={ ! hasConnectedAsana() || ! userCan('manage_options') }
/>
{
( settings?.workspace?.asana_site_workspace?.gid && asanaWorkspaceValue !== settings?.workspace?.asana_site_workspace?.gid ) &&
<Notice status='warning' isDismissible={false} style={{ margin: '8px 0 0' }}>{`Changing workspaces will remove all ${settings?.workspace?.total_pinned_tasks || '(unknown count)'} currently pinned tasks from this site.`}</Notice>
}
</CardBody>
<CardBody>
<ComboboxControl
Expand All @@ -154,6 +164,10 @@ export default function WorkspaceSettings() {
required={true}
disabled={ ! asanaWorkspaceValue || ! hasConnectedAsana() || ! userCan('manage_options') }
/>
{
( settings?.workspace?.asana_site_tag?.gid && asanaTagValue !== settings?.workspace?.asana_site_tag?.gid ) &&
<Notice status='warning' isDismissible={false} style={{ margin: '8px 0 0' }}>Changing the site's tag will remove any pinned tasks that do not have the new tag.</Notice>
}
</CardBody>
<CardBody>
<Button
Expand Down

0 comments on commit 4aa5513

Please sign in to comment.