Skip to content

Commit

Permalink
fix(web): get domain from bucket info (#803)
Browse files Browse the repository at this point in the history
* fix(we): refactor bucket domain

* fix(web): get domain from bucket info
  • Loading branch information
LeezQ authored Feb 17, 2023
1 parent abadcb3 commit 7ed542c
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 80 deletions.
2 changes: 1 addition & 1 deletion web/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"cnameHostSuffixTip": "After the resolution takes effect, the custom domain name can be bound.",
"editHostTip": "oss-bucket needs to be in read mode to enable website hosting",
"CreateWebHosting": "Bind custom domain name",
"CustomDomain": "CustomDomain",
"CustomDomain": "Custom Domain",
"CurrentDomain": "Current domain: ",
"RemoveHost": "Remove Host",
"CancelHost": "Cancel Host"
Expand Down
118 changes: 69 additions & 49 deletions web/src/apis/typing.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface TApplication {
export type TApplication = {
id: string;
name: string;
appid: string;
Expand All @@ -11,16 +11,16 @@ export interface TApplication {
createdAt: string;
updatedAt: string;
createdBy: string;
bundle: Bundle;
bundle: TBundle;
runtime: Runtime;
configuration: Configuration;
domain: Domain;
storage: Storage;
tls: boolean;
develop_token: string;
}
};

export interface Bundle {
export type TBundle = {
id: string;
name: string;
displayName: string;
Expand All @@ -35,128 +35,148 @@ export interface Bundle {
priority: number;
state: string;
price: number;
}
};

export interface Runtime {
export type Runtime = {
id: string;
name: string;
type: string;
image: Image;
version: string;
latest: boolean;
}
};

export interface Image {
export type Image = {
main: string;
init: string;
sidecar: any;
}
};

export interface Configuration {
export type Configuration = {
id: string;
appid: string;
environments: Environment[];
dependencies: any[];
createdAt: string;
updatedAt: string;
}
};

export interface Environment {
export type Environment = {
name: string;
value: string;
}
};

export interface Domain {
export type Domain = {
id: string;
appid: string;
bucketName: string;
domain: string;
state: string;
phase: string;
createdAt: string;
updatedAt: string;
}
lockedAt: string;
};

export interface Storage {
export type Storage = {
id: string;
appid: string;
accessKey: string;
secretKey: string;
createdAt: string;
updatedAt: string;
credentials: Credentials;
}
};

export interface Credentials {
export type Credentials = {
endpoint: string;
accessKeyId: string;
secretAccessKey: string;
sessionToken: string;
expiration: string;
}
};

export interface TBucket {
export type TBucket = {
id: string;
appid: string;
name: string;
shortName: string;
policy: string;
state: string;
phase: string;
lockedAt: string;
createdAt: string;
updatedAt: string;
domain: Domain;
websiteHosting: TWebsiteHosting;
};

export type TWebsiteHosting = {
id: string;
appid: string;
bucketName: string;
domain: string;
isCustom: boolean;
state: string;
phase: string;
createdAt: string;
updatedAt: string;
websiteHosting?: any;
}
lockedAt: string;
};

export interface Spec {
export type Spec = {
policy: string;
storage: string;
}
};

export interface Status {
export type Status = {
capacity: Capacity;
conditions: Condition[];
policy: string;
user: string;
versioning: boolean;
}
};

export interface Capacity {
export type Capacity = {
maxStorage: string;
objectCount: number;
storage: string;
}
};

export interface Condition {
export type Condition = {
lastTransitionTime: string;
message: string;
reason: string;
status: string;
type: string;
}
};

export interface TDB {
export type TDB = {
name: string;
type: string;
options: Options;
info: Info;
idIndex: IdIndex;
}
};

export interface Options {}
export type Options = {};

export interface Info {
export type Info = {
readOnly: boolean;
uuid: string;
}
};

export interface IdIndex {
export type IdIndex = {
v: number;
key: Key;
name: string;
}
};

export interface Key {
export type Key = {
_id: number;
}
};

export interface TFunction {
export type TFunction = {
id: string;
appid: string;
name: string;
Expand All @@ -168,39 +188,39 @@ export interface TFunction {
createdAt: string;
updatedAt: string;
createdBy: string;
}
};

export type TMethod = "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "PATCH";

export interface Source {
export type Source = {
code: string;
compiled: string;
uri: any;
version: number;
hash: any;
lang: any;
}
};

export interface TLogItem {
export type TLogItem = {
_id: string;
request_id: string;
func: string;
data: string;
created_at: string;
}
};

// user data
export interface TUserInfo {
export type TUserInfo = {
id: string;
username: string;
email: any;
phone: any;
createdAt: string;
updatedAt: string;
profile: TProfile;
}
};

export interface TProfile {
export type TProfile = {
id: string;
uid: string;
openid: string;
Expand All @@ -209,4 +229,4 @@ export interface TProfile {
name: string;
createdAt: string;
updatedAt: string;
}
};
4 changes: 2 additions & 2 deletions web/src/components/CopyText/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { t } from "i18next";
import useGlobalStore from "@/pages/globalStore";

export default function CopyText(props: {
text: string;
text?: string;
tip?: string;
className?: string;
children?: React.ReactElement;
Expand All @@ -18,7 +18,7 @@ export default function CopyText(props: {
const { children = <CopyIcon />, text, tip, className, hideToolTip } = props;

useEffect(() => {
setValue(text);
setValue(text || "");
}, [setValue, text]);

return (
Expand Down
31 changes: 12 additions & 19 deletions web/src/pages/app/storages/mods/CreateWebsiteModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ import SiteStatus from "./SiteStatus";

function CreateWebsiteModal() {
const { isOpen, onOpen, onClose } = useDisclosure();
const { currentStorage } = useStorageStore();
const { currentStorage, getCurrentBucketDomain } = useStorageStore();
const { register, setFocus, handleSubmit, reset } = useForm<{ domain: string }>();
const { t } = useTranslation();
const createWebsiteMutation = useWebsiteCreateMutation();
const deleteWebsiteMutation = useWebsiteDeleteMutation();
const updateWebsiteMutation = useWebSiteUpdateMutation();
const toast = useToast();
const cnameDomain = getCurrentBucketDomain(false);
return (
<>
{currentStorage?.websiteHosting &&
currentStorage.websiteHosting.state === BUCKET_STATUS.Active ? (
<>
<span className="font-semibold">{t("StoragePanel.CurrentDomain")}</span>

<div className="flex">
<span className="font-semibold mr-2">{t("StoragePanel.CurrentDomain")}</span>
<Link
className="cursor-pointer"
className="cursor-pointer mr-2"
href={`//${currentStorage?.websiteHosting?.domain}`}
isExternal
>
Expand All @@ -64,8 +64,8 @@ function CreateWebsiteModal() {
<SiteStatus />

<Menu>
<MenuButton>
<MoreIcon fontSize={10} mt="-3px" />
<MenuButton className="ml-2 -mt-[2px]">
<MoreIcon fontSize={10} />
</MenuButton>
<MenuList minWidth="100px">
<MenuItem
Expand All @@ -92,7 +92,7 @@ function CreateWebsiteModal() {
</MenuItem>
</MenuList>
</Menu>
</>
</div>
) : (
<Button
size="xs"
Expand Down Expand Up @@ -132,14 +132,9 @@ function CreateWebsiteModal() {
<FormControl>
<FormLabel>CNAME</FormLabel>
<InputGroup size="sm">
<Input variant="filled" value={currentStorage?.websiteHosting?.domain} readOnly />
<Input variant="filled" value={cnameDomain} readOnly />
<InputRightAddon
children={
<CopyText
text={currentStorage?.websiteHosting?.domain}
className="cursor-pointer"
/>
}
children={<CopyText text={cnameDomain} className="cursor-pointer" />}
/>
</InputGroup>
</FormControl>
Expand All @@ -154,10 +149,8 @@ function CreateWebsiteModal() {
/>
<p className="mt-2 text-grayModern-600">
{t("StoragePanel.cnameHostPreTip")}
<span className="mx-2 whitespace-nowrap">
{currentStorage?.websiteHosting?.domain}
</span>
,{t("StoragePanel.cnameHostSuffixTip")}
<span className="mx-2 whitespace-nowrap">{cnameDomain}</span>,
{t("StoragePanel.cnameHostSuffixTip")}
</p>
</FormControl>
</VStack>
Expand Down
Loading

0 comments on commit 7ed542c

Please sign in to comment.