-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dev/separate-ui-package
- Loading branch information
Showing
22 changed files
with
192 additions
and
113 deletions.
There are no files selected for viewing
Binary file modified
BIN
-17.4 KB
(96%)
...sts/__screenshots__/darwin/add-element.spec.ts/can-add-a-Footer-component-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.71 KB
(94%)
e2e-tests/__screenshots__/darwin/deploy.spec.ts/can-deploy-changes-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.71 KB
(94%)
...hots__/darwin/field-picker-dropdown.spec.ts/renders-field-picker-dropdown-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.71 KB
(94%)
....ts/can-update-initial-props-of-a-component-and-see-UI-is-updated-via-HMR-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-4.25 KB
(92%)
....ts/can-update-initial-props-of-a-component-and-see-UI-is-updated-via-HMR-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-15.4 KB
(96%)
...ests/__screenshots__/win32/add-element.spec.ts/can-add-a-Footer-component-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.38 KB
(95%)
e2e-tests/__screenshots__/win32/deploy.spec.ts/can-deploy-changes-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.38 KB
(95%)
...shots__/win32/field-picker-dropdown.spec.ts/renders-field-picker-dropdown-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.38 KB
(95%)
....ts/can-update-initial-props-of-a-component-and-see-UI-is-updated-via-HMR-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.23 KB
(94%)
....ts/can-update-initial-props-of-a-component-and-see-UI-is-updated-via-HMR-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
packages/studio-ui/src/components/AddElementMenu/AddElementList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { FileMetadataKind, ComponentMetadata } from "@yext/studio-plugin"; | ||
import useStudioStore from "../../store/useStudioStore"; | ||
import { ElementType } from "./AddElementMenu"; | ||
import AddElementOption from "./AddElementOption"; | ||
import path from "path-browserify"; | ||
import renderIconForType from "../common/renderIconForType"; | ||
import { useMemo } from "react"; | ||
|
||
interface AddElementListProps { | ||
activeType: ElementType; | ||
afterSelect?: () => void; | ||
} | ||
|
||
/** | ||
* The list of available, addable elements for the current activeType. | ||
*/ | ||
export default function AddElementList({ | ||
activeType, | ||
afterSelect, | ||
}: AddElementListProps) { | ||
const options = useOptions(activeType, afterSelect); | ||
|
||
if (options.length === 0) { | ||
return ( | ||
<div className="flex flex-col items-start py-3 pl-6 opacity-50"> | ||
Nothing to see here! | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col items-start py-1"> | ||
{options.map((props) => { | ||
return ( | ||
<AddElementOption {...props} icon={renderIconForType(activeType)} /> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
function useOptions(activeType: ElementType, afterSelect?: () => void) { | ||
const [UUIDToFileMetadata, layoutNameToLayoutState, addComponent, addLayout] = | ||
useStudioStore((store) => { | ||
return [ | ||
store.fileMetadatas.UUIDToFileMetadata, | ||
store.layouts.layoutNameToLayoutState, | ||
store.actions.addComponent, | ||
store.actions.addLayout, | ||
]; | ||
}); | ||
|
||
return useMemo(() => { | ||
if (activeType === ElementType.Layouts) { | ||
return Object.values(layoutNameToLayoutState).map((layoutState) => { | ||
return { | ||
displayName: path.basename(layoutState.filepath, ".tsx"), | ||
key: layoutState.filepath, | ||
handleSelect: () => { | ||
addLayout(layoutState); | ||
afterSelect?.(); | ||
}, | ||
}; | ||
}); | ||
} | ||
|
||
return Object.values(UUIDToFileMetadata) | ||
.filter((metadata): metadata is ComponentMetadata => { | ||
if (metadata.kind !== FileMetadataKind.Component) { | ||
return false; | ||
} | ||
if (activeType === ElementType.Components) { | ||
return !metadata.acceptsChildren; | ||
} else if (activeType === ElementType.Containers) { | ||
return !!metadata.acceptsChildren; | ||
} | ||
return false; | ||
}) | ||
.map((componentMetadata) => { | ||
return { | ||
displayName: path.basename(componentMetadata.filepath, ".tsx"), | ||
key: componentMetadata.filepath, | ||
handleSelect: () => { | ||
addComponent(componentMetadata); | ||
afterSelect?.(); | ||
}, | ||
}; | ||
}); | ||
}, [ | ||
UUIDToFileMetadata, | ||
activeType, | ||
addComponent, | ||
addLayout, | ||
afterSelect, | ||
layoutNameToLayoutState, | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/studio-ui/src/components/AddElementMenu/AddElementOption.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export default function AddElementOption({ | ||
displayName, | ||
handleSelect, | ||
icon, | ||
}: { | ||
displayName: string; | ||
handleSelect?: () => void; | ||
icon: JSX.Element | null; | ||
}) { | ||
return ( | ||
<button | ||
className="flex items-center gap-x-2 px-6 py-2 cursor-pointer hover:bg-gray-100 w-full text-left" | ||
onClick={handleSelect} | ||
aria-label={`Add ${displayName} Element`} | ||
> | ||
{icon} | ||
{displayName} | ||
</button> | ||
); | ||
} |
89 changes: 0 additions & 89 deletions
89
packages/studio-ui/src/components/AddElementMenu/ElementSelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1 @@ | ||
import { FileMetadataKind, ComponentMetadata } from "@yext/studio-plugin"; | ||
import { useCallback } from "react"; | ||
import useStudioStore from "../../store/useStudioStore"; | ||
import path from "path-browserify"; | ||
import { ElementType } from "./AddElementMenu"; | ||
import renderIconForType from "../common/renderIconForType"; | ||
|
||
interface ElementSelectorProps { | ||
activeType: ElementType; | ||
afterSelect?: () => void; | ||
} | ||
|
||
/** | ||
* The list of available, addable elements for the current activeType. | ||
*/ | ||
export default function ElementSelector({ | ||
activeType, | ||
afterSelect, | ||
}: ElementSelectorProps) { | ||
const UUIDToFileMetadata = useStudioStore((store) => { | ||
return store.fileMetadatas.UUIDToFileMetadata; | ||
}); | ||
|
||
const addableElements = Object.values(UUIDToFileMetadata).filter( | ||
(metadata): metadata is ComponentMetadata => { | ||
if (metadata.kind !== FileMetadataKind.Component) { | ||
return false; | ||
} | ||
if (activeType === ElementType.Components) { | ||
return !metadata.acceptsChildren; | ||
} else if (activeType === ElementType.Containers) { | ||
return !!metadata.acceptsChildren; | ||
} | ||
return false; | ||
} | ||
); | ||
|
||
if (addableElements.length === 0) { | ||
return ( | ||
<div className="flex flex-col items-start py-3 pl-6 opacity-50"> | ||
Nothing to see here! | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col items-start py-1"> | ||
{addableElements.map((metadata) => { | ||
return ( | ||
<Option | ||
metadata={metadata} | ||
activeType={activeType} | ||
key={metadata.metadataUUID} | ||
afterSelect={afterSelect} | ||
/> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
function Option({ | ||
metadata, | ||
activeType, | ||
afterSelect, | ||
}: { | ||
metadata: ComponentMetadata; | ||
} & ElementSelectorProps) { | ||
const componentName = path.basename(metadata.filepath, ".tsx"); | ||
|
||
const addComponent = useStudioStore((store) => { | ||
return store.actions.addComponent; | ||
}); | ||
|
||
const handleSelect = useCallback(() => { | ||
addComponent(metadata); | ||
afterSelect?.(); | ||
}, [afterSelect, addComponent, metadata]); | ||
|
||
return ( | ||
<button | ||
className="flex items-center gap-x-2 px-6 py-2 cursor-pointer hover:bg-gray-100 w-full text-left" | ||
onClick={handleSelect} | ||
aria-label={`Add ${componentName} Element`} | ||
> | ||
{renderIconForType(activeType)} | ||
{componentName} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.