Skip to content

Commit

Permalink
fix: children render of Result
Browse files Browse the repository at this point in the history
  • Loading branch information
Col0ring committed Dec 16, 2024
1 parent 553da55 commit 4479e8a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 27 deletions.
33 changes: 21 additions & 12 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: publish
on:
push:
branches:
# - main
- disabled
- main
env:
CI: true

Expand All @@ -17,35 +16,45 @@ jobs:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Get the Last Commit Message
run: |
echo "COMMIT_MESSAGE=$(git log --format=%s -n 1)" >> $GITHUB_ENV
- name: Checkout Code Repository
if: env.COMMIT_MESSAGE == 'chore: update versions'
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.12
if: env.COMMIT_MESSAGE == 'chore: update versions'
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Python Dependencies
if: env.COMMIT_MESSAGE == 'chore: update versions'
run: pip install gradio twine build
- name: Setup Node.js
if: env.COMMIT_MESSAGE == 'chore: update versions'
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install Pnpm
if: env.COMMIT_MESSAGE == 'chore: update versions'
run: npm i pnpm@latest -g
- name: Install Node Dependencies
if: env.COMMIT_MESSAGE == 'chore: update versions'
run: pnpm install
- name: Create Release Pull Request to Update Versions
id: changesets
uses: changesets/action@v1
with:
version: pnpm run ci:version
title: 'chore: update versions'
commit: 'chore: update versions'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Create Release Pull Request to Update Versions
# id: changesets
# uses: changesets/action@v1
# with:
# version: pnpm run ci:version
# title: 'chore: update versions'
# commit: 'chore: update versions'
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build Packages and Publish to PyPI
if: steps.changesets.outputs.hasChangesets != 'true'
# if: steps.changesets.outputs.hasChangesets != 'true'
if: env.COMMIT_MESSAGE == 'chore: update versions'
id: publish
run: pnpm run ci:publish
env:
Expand Down
29 changes: 19 additions & 10 deletions frontend/antd/result/result.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import { sveltify } from '@svelte-preprocess-react';
import { ReactSlot } from '@svelte-preprocess-react/react-slot';
import React from 'react';
import { useTargets } from '@utils/hooks/useTargets';
import { type GetProps, Result as AResult } from 'antd';

export const Result = sveltify<
GetProps<typeof AResult>,
['extra', 'icon', 'subTitle', 'title']
>(({ slots, ...props }) => {
>(({ slots, children, ...props }) => {
const targets = useTargets(children);
return (
<AResult
{...props}
extra={slots.extra ? <ReactSlot slot={slots.extra} /> : props.extra}
icon={slots.icon ? <ReactSlot slot={slots.icon} /> : props.icon}
subTitle={
slots.subTitle ? <ReactSlot slot={slots.subTitle} /> : props.subTitle
}
title={slots.title ? <ReactSlot slot={slots.title} /> : props.title}
/>
<>
<div style={{ display: 'none' }}>
{targets.length > 0 ? null : children}
</div>
<AResult
{...props}
extra={slots.extra ? <ReactSlot slot={slots.extra} /> : props.extra}
icon={slots.icon ? <ReactSlot slot={slots.icon} /> : props.icon}
subTitle={
slots.subTitle ? <ReactSlot slot={slots.subTitle} /> : props.subTitle
}
title={slots.title ? <ReactSlot slot={slots.title} /> : props.title}
>
{targets.length > 0 ? children : null}
</AResult>
</>
);
});

Expand Down
14 changes: 9 additions & 5 deletions frontend/base/application/Application.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
bind_mount_event?: boolean;
bind_resize_event?: boolean;
bind_unmount_event?: boolean;
bind_custom_event?: boolean;
} = {};
export let gradio: Gradio<{
custom: any;
mount: ApplicationPageData;
resize: ApplicationPageData;
unmount: ApplicationPageData;
}>;
export let attached_events: string[] = [];
export let visible = true;
let container: HTMLDivElement;
function get_data(): ApplicationPageData {
return {
theme: gradio.theme,
Expand Down Expand Up @@ -69,31 +71,33 @@
function on_mount() {
value = get_data();
if (_internal.bind_mount_event) {
if (_internal.bind_mount_event || attached_events.includes('mount')) {
gradio.dispatch('mount', get_data());
}
}
const on_resize = wrap_event(() => {
value = get_data();
if (_internal.bind_resize_event) {
if (_internal.bind_resize_event || attached_events.includes('resize')) {
gradio.dispatch('resize', get_data());
}
}, 500);
const on_before_unload = wrap_event(() => {
value = get_data();
if (_internal.bind_unmount_event) {
if (_internal.bind_unmount_event || attached_events.includes('unmount')) {
gradio.dispatch('unmount', get_data());
}
});
window.ms_globals.dispatch = (...args) => {
gradio.dispatch('custom', args);
};
onMount(() => {
requestAnimationFrame(() => {
on_mount();
});
window.addEventListener('resize', on_resize);
window.addEventListener('beforeunload', on_before_unload);
});
Expand All @@ -105,7 +109,7 @@
</script>

{#if visible}
<div class="ms-gr-container">
<div class="ms-gr-container" bind:this={container}>
<slot />
</div>
{/if}
Expand Down

0 comments on commit 4479e8a

Please sign in to comment.