Skip to content

Commit

Permalink
Change 'enableSpaceAgnosticBehavior' field to 'behaviorContext'
Browse files Browse the repository at this point in the history
  • Loading branch information
jportner committed Feb 10, 2021
1 parent af4ebcc commit 94799fd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
17 changes: 10 additions & 7 deletions src/plugins/spaces_oss/public/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ export interface ShareToSpaceFlyoutProps {
*/
enableCreateNewSpaceLink?: boolean;
/**
* When enabled, the flyout will allow the user to remove the object from the current space. Otherwise, the current space is noted, and
* the user cannot interact with it.
* When set to 'within-space' (default), the flyout behaves like it is running on a page within the active space, and it will prevent the
* user from removing the object from the active space.
*
* Default value is false.
* Conversely, when set to 'outside-space', the flyout behaves like it is running on a page outside of any space, so it will allow the
* user to remove the object from the active space.
*/
enableSpaceAgnosticBehavior?: boolean;
behaviorContext?: 'within-space' | 'outside-space';
/**
* Optional handler that is called when the user has saved changes and there are spaces to be added to and/or removed from the object. If
* this is not defined, a default handler will be used that calls `/api/spaces/_share_saved_object_add` and/or
Expand Down Expand Up @@ -200,11 +201,13 @@ export interface SpaceListProps {
*/
displayLimit?: number;
/**
* When enabled, the space list will omit the active space. Otherwise, the active space is displayed.
* When set to 'within-space' (default), the space list behaves like it is running on a page within the active space, and it will omit the
* active space (e.g., it displays a list of all the _other_ spaces that an object is shared to).
*
* Default value is false.
* Conversely, when set to 'outside-space', the space list behaves like it is running on a page outside of any space, so it will not omit
* the active space.
*/
enableSpaceAgnosticBehavior?: boolean;
behaviorContext?: 'within-space' | 'outside-space';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ export const JobSpacesList: FC<Props> = ({ spacesApi, spaceIds, jobId, jobType,
title: jobId,
noun: objectNoun,
},
enableSpaceAgnosticBehavior: true,
behaviorContext: 'outside-space',
changeSpacesHandler,
onClose,
};

return (
<>
<EuiButtonEmpty onClick={() => setShowFlyout(true)} style={{ height: 'auto' }}>
<SpaceList namespaces={spaceIds} displayLimit={0} enableSpaceAgnosticBehavior={true} />
<SpaceList namespaces={spaceIds} displayLimit={0} behaviorContext="outside-space" />
</EuiButtonEmpty>
{showFlyout && <ShareToSpaceFlyout {...shareToSpaceFlyoutProps} />}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface SetupOpts {
canShareToAllSpaces?: boolean; // default: true
enableCreateCopyCallout?: boolean;
enableCreateNewSpaceLink?: boolean;
enableSpaceAgnosticBehavior?: boolean;
behaviorContext?: 'within-space' | 'outside-space';
mockFeatureId?: string; // optional feature ID to use for the SpacesContext
}

Expand Down Expand Up @@ -117,7 +117,7 @@ const setup = async (opts: SetupOpts = {}) => {
onClose={onClose}
enableCreateCopyCallout={opts.enableCreateCopyCallout}
enableCreateNewSpaceLink={opts.enableCreateNewSpaceLink}
enableSpaceAgnosticBehavior={opts.enableSpaceAgnosticBehavior}
behaviorContext={opts.behaviorContext}
/>
</SpacesContext>
);
Expand Down Expand Up @@ -674,7 +674,7 @@ describe('ShareToSpaceFlyout', () => {
expect(option.disabled).toBeUndefined();
};

describe('without enableSpaceAgnosticBehavior', () => {
describe('with behaviorContext="within-space" (default)', () => {
it('correctly defines space selection options', async () => {
const namespaces = ['my-active-space', 'space-1', 'space-3']; // the saved object's current namespaces
const { wrapper } = await setup({ mockSpaces, namespaces });
Expand Down Expand Up @@ -724,12 +724,12 @@ describe('ShareToSpaceFlyout', () => {
});
});

describe('with enableSpaceAgnosticBehavior', () => {
const enableSpaceAgnosticBehavior = true;
describe('with behaviorContext="outside-space"', () => {
const behaviorContext = 'outside-space';

it('correctly defines space selection options', async () => {
const namespaces = ['my-active-space', 'space-1', 'space-3']; // the saved object's current namespaces
const { wrapper } = await setup({ enableSpaceAgnosticBehavior, mockSpaces, namespaces });
const { wrapper } = await setup({ behaviorContext, mockSpaces, namespaces });

const selectable = wrapper.find(SelectableSpacesControl).find(EuiSelectable);
const options = selectable.prop('options');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const ShareToSpaceFlyoutInternal = (props: ShareToSpaceFlyoutProps) => {
}),
enableCreateCopyCallout = false,
enableCreateNewSpaceLink = false,
enableSpaceAgnosticBehavior = false,
behaviorContext,
changeSpacesHandler = createDefaultChangeSpacesHandler(
savedObjectTarget,
spacesManager,
Expand All @@ -126,6 +126,7 @@ export const ShareToSpaceFlyoutInternal = (props: ShareToSpaceFlyoutProps) => {
onUpdate = () => null,
onClose = () => null,
} = props;
const enableSpaceAgnosticBehavior = behaviorContext === 'outside-space';

const [shareOptions, setShareOptions] = useState<ShareOptions>({
selectedSpaceIds: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const getSpaceData = (inactiveSpaceCount: number = 0) => {

/**
* This node displays up to five named spaces (and an indicator for any number of unauthorized spaces) by default. The active space is
* omitted from this list unless enableSpaceAgnosticBehavior is enabled. If more than five named spaces would be displayed, the extras
* (along with the unauthorized spaces indicator, if present) are hidden behind a button.
* omitted from this list unless behaviorContext='outside-space'. If more than five named spaces would be displayed, the extras (along with
* the unauthorized spaces indicator, if present) are hidden behind a button.
* If '*' (aka "All spaces") is present, it supersedes all of the above and just displays a single badge without a button.
*/
describe('SpaceListInternal', () => {
Expand Down Expand Up @@ -264,8 +264,11 @@ describe('SpaceListInternal', () => {
expect(getButton(wrapper)).toHaveLength(0);
});

it('with enableSpaceAgnosticBehavior=true, shows badges with button', async () => {
const props = { namespaces: [...namespaces, '?'], enableSpaceAgnosticBehavior: true };
it('with behaviorContext="outside-space", shows badges with button', async () => {
const props: SpaceListProps = {
namespaces: [...namespaces, '?'],
behaviorContext: 'outside-space',
};
const wrapper = await createSpaceList({ spaces, props });

expect(getListText(wrapper)).toEqual(['D!', 'A', 'B', 'C', 'D']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const DEFAULT_DISPLAY_LIMIT = 5;
export const SpaceListInternal = ({
namespaces,
displayLimit = DEFAULT_DISPLAY_LIMIT,
enableSpaceAgnosticBehavior,
behaviorContext,
}: SpaceListProps) => {
const { shareToSpacesDataPromise } = useSpaces();

Expand Down Expand Up @@ -66,7 +66,7 @@ export const SpaceListInternal = ({
if (spaceTarget === undefined) {
// in the event that a new space was created after this page has loaded, fall back to displaying the space ID
enabledSpaceTargets.push({ id: namespace, name: namespace });
} else if (enableSpaceAgnosticBehavior || !spaceTarget.isActiveSpace) {
} else if (behaviorContext === 'outside-space' || !spaceTarget.isActiveSpace) {
if (spaceTarget.isFeatureDisabled) {
disabledSpaceTargets.push(spaceTarget);
} else {
Expand Down

0 comments on commit 94799fd

Please sign in to comment.