fix(skills): ignore stale catalog scans (#1157)
* fix(skills): ignore stale catalog scans * fix(skills): clear stale catalog identities --------- Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
8f1e5c0085
commit
088237c606
@@ -96,10 +96,22 @@ export const AddCatalogDialog: React.FC<AddCatalogDialogProps> = ({ open, onOpen
|
|||||||
|
|
||||||
const [identityOptions, setIdentityOptions] = React.useState<IdentityOption[]>([]);
|
const [identityOptions, setIdentityOptions] = React.useState<IdentityOption[]>([]);
|
||||||
const [gitIdentityId, setGitIdentityId] = React.useState<string | null>(null);
|
const [gitIdentityId, setGitIdentityId] = React.useState<string | null>(null);
|
||||||
|
const scanRequestIdRef = React.useRef(0);
|
||||||
|
|
||||||
|
const invalidateScan = React.useCallback((options?: { clearIdentity?: boolean }) => {
|
||||||
|
scanRequestIdRef.current += 1;
|
||||||
|
setScanOk(false);
|
||||||
|
setScanCount(null);
|
||||||
|
if (options?.clearIdentity) {
|
||||||
|
setIdentityOptions([]);
|
||||||
|
setGitIdentityId(null);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!open) return;
|
if (!open) return;
|
||||||
|
|
||||||
|
scanRequestIdRef.current += 1;
|
||||||
setLabel('');
|
setLabel('');
|
||||||
setSource('');
|
setSource('');
|
||||||
setSubpath('');
|
setSubpath('');
|
||||||
@@ -140,6 +152,8 @@ export const AddCatalogDialog: React.FC<AddCatalogDialogProps> = ({ open, onOpen
|
|||||||
|
|
||||||
setScanOk(false);
|
setScanOk(false);
|
||||||
setScanCount(null);
|
setScanCount(null);
|
||||||
|
const requestId = scanRequestIdRef.current + 1;
|
||||||
|
scanRequestIdRef.current = requestId;
|
||||||
|
|
||||||
const result = await scanRepo({
|
const result = await scanRepo({
|
||||||
source: trimmedSource,
|
source: trimmedSource,
|
||||||
@@ -147,6 +161,10 @@ export const AddCatalogDialog: React.FC<AddCatalogDialogProps> = ({ open, onOpen
|
|||||||
gitIdentityId: gitIdentityId || undefined,
|
gitIdentityId: gitIdentityId || undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (scanRequestIdRef.current !== requestId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
if (result.error?.kind === 'authRequired') {
|
if (result.error?.kind === 'authRequired') {
|
||||||
if (isVSCodeRuntime()) {
|
if (isVSCodeRuntime()) {
|
||||||
@@ -257,8 +275,7 @@ export const AddCatalogDialog: React.FC<AddCatalogDialogProps> = ({ open, onOpen
|
|||||||
value={source}
|
value={source}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setSource(e.target.value);
|
setSource(e.target.value);
|
||||||
setScanOk(false);
|
invalidateScan({ clearIdentity: true });
|
||||||
setScanCount(null);
|
|
||||||
}}
|
}}
|
||||||
placeholder={t('settings.skills.catalog.shared.field.repositoryPlaceholder')}
|
placeholder={t('settings.skills.catalog.shared.field.repositoryPlaceholder')}
|
||||||
/>
|
/>
|
||||||
@@ -273,8 +290,7 @@ export const AddCatalogDialog: React.FC<AddCatalogDialogProps> = ({ open, onOpen
|
|||||||
value={subpath}
|
value={subpath}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setSubpath(e.target.value);
|
setSubpath(e.target.value);
|
||||||
setScanOk(false);
|
invalidateScan({ clearIdentity: true });
|
||||||
setScanCount(null);
|
|
||||||
}}
|
}}
|
||||||
placeholder={t('settings.skills.catalog.shared.field.subpathPlaceholder')}
|
placeholder={t('settings.skills.catalog.shared.field.subpathPlaceholder')}
|
||||||
/>
|
/>
|
||||||
@@ -286,7 +302,13 @@ export const AddCatalogDialog: React.FC<AddCatalogDialogProps> = ({ open, onOpen
|
|||||||
<span className="typography-ui-label text-[var(--status-warning)]">{t('settings.skills.catalog.shared.auth.title')}</span>
|
<span className="typography-ui-label text-[var(--status-warning)]">{t('settings.skills.catalog.shared.auth.title')}</span>
|
||||||
<span className="typography-meta text-muted-foreground ml-2">{t('settings.skills.catalog.shared.auth.description')}</span>
|
<span className="typography-meta text-muted-foreground ml-2">{t('settings.skills.catalog.shared.auth.description')}</span>
|
||||||
</div>
|
</div>
|
||||||
<Select value={gitIdentityId || ''} onValueChange={(v) => setGitIdentityId(v)}>
|
<Select
|
||||||
|
value={gitIdentityId || ''}
|
||||||
|
onValueChange={(v) => {
|
||||||
|
setGitIdentityId(v);
|
||||||
|
invalidateScan();
|
||||||
|
}}
|
||||||
|
>
|
||||||
<SelectTrigger className="w-fit">
|
<SelectTrigger className="w-fit">
|
||||||
<span>{identityOptions.find((i) => i.id === gitIdentityId)?.name || t('settings.skills.catalog.shared.auth.chooseIdentity')}</span>
|
<span>{identityOptions.find((i) => i.id === gitIdentityId)?.name || t('settings.skills.catalog.shared.auth.chooseIdentity')}</span>
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
|||||||
Reference in New Issue
Block a user